test_hyperbolic.py 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  1. from sympy.calculus.accumulationbounds import AccumBounds
  2. from sympy.core.function import (expand_mul, expand_trig)
  3. from sympy.core.numbers import (E, I, Integer, Rational, nan, oo, pi, zoo)
  4. from sympy.core.singleton import S
  5. from sympy.core.symbol import (Symbol, symbols)
  6. from sympy.functions.elementary.complexes import (im, re)
  7. from sympy.functions.elementary.exponential import (exp, log)
  8. from sympy.functions.elementary.hyperbolic import (acosh, acoth, acsch, asech, asinh, atanh, cosh, coth, csch, sech, sinh, tanh)
  9. from sympy.functions.elementary.miscellaneous import sqrt
  10. from sympy.functions.elementary.trigonometric import (acos, asin, cos, cot, sec, sin, tan)
  11. from sympy.series.order import O
  12. from sympy.core.expr import unchanged
  13. from sympy.core.function import ArgumentIndexError
  14. from sympy.testing.pytest import raises
  15. def test_sinh():
  16. x, y = symbols('x,y')
  17. k = Symbol('k', integer=True)
  18. assert sinh(nan) is nan
  19. assert sinh(zoo) is nan
  20. assert sinh(oo) is oo
  21. assert sinh(-oo) is -oo
  22. assert sinh(0) == 0
  23. assert unchanged(sinh, 1)
  24. assert sinh(-1) == -sinh(1)
  25. assert unchanged(sinh, x)
  26. assert sinh(-x) == -sinh(x)
  27. assert unchanged(sinh, pi)
  28. assert sinh(-pi) == -sinh(pi)
  29. assert unchanged(sinh, 2**1024 * E)
  30. assert sinh(-2**1024 * E) == -sinh(2**1024 * E)
  31. assert sinh(pi*I) == 0
  32. assert sinh(-pi*I) == 0
  33. assert sinh(2*pi*I) == 0
  34. assert sinh(-2*pi*I) == 0
  35. assert sinh(-3*10**73*pi*I) == 0
  36. assert sinh(7*10**103*pi*I) == 0
  37. assert sinh(pi*I/2) == I
  38. assert sinh(-pi*I/2) == -I
  39. assert sinh(pi*I*Rational(5, 2)) == I
  40. assert sinh(pi*I*Rational(7, 2)) == -I
  41. assert sinh(pi*I/3) == S.Half*sqrt(3)*I
  42. assert sinh(pi*I*Rational(-2, 3)) == Rational(-1, 2)*sqrt(3)*I
  43. assert sinh(pi*I/4) == S.Half*sqrt(2)*I
  44. assert sinh(-pi*I/4) == Rational(-1, 2)*sqrt(2)*I
  45. assert sinh(pi*I*Rational(17, 4)) == S.Half*sqrt(2)*I
  46. assert sinh(pi*I*Rational(-3, 4)) == Rational(-1, 2)*sqrt(2)*I
  47. assert sinh(pi*I/6) == S.Half*I
  48. assert sinh(-pi*I/6) == Rational(-1, 2)*I
  49. assert sinh(pi*I*Rational(7, 6)) == Rational(-1, 2)*I
  50. assert sinh(pi*I*Rational(-5, 6)) == Rational(-1, 2)*I
  51. assert sinh(pi*I/105) == sin(pi/105)*I
  52. assert sinh(-pi*I/105) == -sin(pi/105)*I
  53. assert unchanged(sinh, 2 + 3*I)
  54. assert sinh(x*I) == sin(x)*I
  55. assert sinh(k*pi*I) == 0
  56. assert sinh(17*k*pi*I) == 0
  57. assert sinh(k*pi*I/2) == sin(k*pi/2)*I
  58. assert sinh(x).as_real_imag(deep=False) == (cos(im(x))*sinh(re(x)),
  59. sin(im(x))*cosh(re(x)))
  60. x = Symbol('x', extended_real=True)
  61. assert sinh(x).as_real_imag(deep=False) == (sinh(x), 0)
  62. x = Symbol('x', real=True)
  63. assert sinh(I*x).is_finite is True
  64. assert sinh(x).is_real is True
  65. assert sinh(I).is_real is False
  66. p = Symbol('p', positive=True)
  67. assert sinh(p).is_zero is False
  68. assert sinh(0, evaluate=False).is_zero is True
  69. assert sinh(2*pi*I, evaluate=False).is_zero is True
  70. def test_sinh_series():
  71. x = Symbol('x')
  72. assert sinh(x).series(x, 0, 10) == \
  73. x + x**3/6 + x**5/120 + x**7/5040 + x**9/362880 + O(x**10)
  74. def test_sinh_fdiff():
  75. x = Symbol('x')
  76. raises(ArgumentIndexError, lambda: sinh(x).fdiff(2))
  77. def test_cosh():
  78. x, y = symbols('x,y')
  79. k = Symbol('k', integer=True)
  80. assert cosh(nan) is nan
  81. assert cosh(zoo) is nan
  82. assert cosh(oo) is oo
  83. assert cosh(-oo) is oo
  84. assert cosh(0) == 1
  85. assert unchanged(cosh, 1)
  86. assert cosh(-1) == cosh(1)
  87. assert unchanged(cosh, x)
  88. assert cosh(-x) == cosh(x)
  89. assert cosh(pi*I) == cos(pi)
  90. assert cosh(-pi*I) == cos(pi)
  91. assert unchanged(cosh, 2**1024 * E)
  92. assert cosh(-2**1024 * E) == cosh(2**1024 * E)
  93. assert cosh(pi*I/2) == 0
  94. assert cosh(-pi*I/2) == 0
  95. assert cosh((-3*10**73 + 1)*pi*I/2) == 0
  96. assert cosh((7*10**103 + 1)*pi*I/2) == 0
  97. assert cosh(pi*I) == -1
  98. assert cosh(-pi*I) == -1
  99. assert cosh(5*pi*I) == -1
  100. assert cosh(8*pi*I) == 1
  101. assert cosh(pi*I/3) == S.Half
  102. assert cosh(pi*I*Rational(-2, 3)) == Rational(-1, 2)
  103. assert cosh(pi*I/4) == S.Half*sqrt(2)
  104. assert cosh(-pi*I/4) == S.Half*sqrt(2)
  105. assert cosh(pi*I*Rational(11, 4)) == Rational(-1, 2)*sqrt(2)
  106. assert cosh(pi*I*Rational(-3, 4)) == Rational(-1, 2)*sqrt(2)
  107. assert cosh(pi*I/6) == S.Half*sqrt(3)
  108. assert cosh(-pi*I/6) == S.Half*sqrt(3)
  109. assert cosh(pi*I*Rational(7, 6)) == Rational(-1, 2)*sqrt(3)
  110. assert cosh(pi*I*Rational(-5, 6)) == Rational(-1, 2)*sqrt(3)
  111. assert cosh(pi*I/105) == cos(pi/105)
  112. assert cosh(-pi*I/105) == cos(pi/105)
  113. assert unchanged(cosh, 2 + 3*I)
  114. assert cosh(x*I) == cos(x)
  115. assert cosh(k*pi*I) == cos(k*pi)
  116. assert cosh(17*k*pi*I) == cos(17*k*pi)
  117. assert unchanged(cosh, k*pi)
  118. assert cosh(x).as_real_imag(deep=False) == (cos(im(x))*cosh(re(x)),
  119. sin(im(x))*sinh(re(x)))
  120. x = Symbol('x', extended_real=True)
  121. assert cosh(x).as_real_imag(deep=False) == (cosh(x), 0)
  122. x = Symbol('x', real=True)
  123. assert cosh(I*x).is_finite is True
  124. assert cosh(I*x).is_real is True
  125. assert cosh(I*2 + 1).is_real is False
  126. assert cosh(5*I*S.Pi/2, evaluate=False).is_zero is True
  127. assert cosh(x).is_zero is False
  128. def test_cosh_series():
  129. x = Symbol('x')
  130. assert cosh(x).series(x, 0, 10) == \
  131. 1 + x**2/2 + x**4/24 + x**6/720 + x**8/40320 + O(x**10)
  132. def test_cosh_fdiff():
  133. x = Symbol('x')
  134. raises(ArgumentIndexError, lambda: cosh(x).fdiff(2))
  135. def test_tanh():
  136. x, y = symbols('x,y')
  137. k = Symbol('k', integer=True)
  138. assert tanh(nan) is nan
  139. assert tanh(zoo) is nan
  140. assert tanh(oo) == 1
  141. assert tanh(-oo) == -1
  142. assert tanh(0) == 0
  143. assert unchanged(tanh, 1)
  144. assert tanh(-1) == -tanh(1)
  145. assert unchanged(tanh, x)
  146. assert tanh(-x) == -tanh(x)
  147. assert unchanged(tanh, pi)
  148. assert tanh(-pi) == -tanh(pi)
  149. assert unchanged(tanh, 2**1024 * E)
  150. assert tanh(-2**1024 * E) == -tanh(2**1024 * E)
  151. assert tanh(pi*I) == 0
  152. assert tanh(-pi*I) == 0
  153. assert tanh(2*pi*I) == 0
  154. assert tanh(-2*pi*I) == 0
  155. assert tanh(-3*10**73*pi*I) == 0
  156. assert tanh(7*10**103*pi*I) == 0
  157. assert tanh(pi*I/2) is zoo
  158. assert tanh(-pi*I/2) is zoo
  159. assert tanh(pi*I*Rational(5, 2)) is zoo
  160. assert tanh(pi*I*Rational(7, 2)) is zoo
  161. assert tanh(pi*I/3) == sqrt(3)*I
  162. assert tanh(pi*I*Rational(-2, 3)) == sqrt(3)*I
  163. assert tanh(pi*I/4) == I
  164. assert tanh(-pi*I/4) == -I
  165. assert tanh(pi*I*Rational(17, 4)) == I
  166. assert tanh(pi*I*Rational(-3, 4)) == I
  167. assert tanh(pi*I/6) == I/sqrt(3)
  168. assert tanh(-pi*I/6) == -I/sqrt(3)
  169. assert tanh(pi*I*Rational(7, 6)) == I/sqrt(3)
  170. assert tanh(pi*I*Rational(-5, 6)) == I/sqrt(3)
  171. assert tanh(pi*I/105) == tan(pi/105)*I
  172. assert tanh(-pi*I/105) == -tan(pi/105)*I
  173. assert unchanged(tanh, 2 + 3*I)
  174. assert tanh(x*I) == tan(x)*I
  175. assert tanh(k*pi*I) == 0
  176. assert tanh(17*k*pi*I) == 0
  177. assert tanh(k*pi*I/2) == tan(k*pi/2)*I
  178. assert tanh(x).as_real_imag(deep=False) == (sinh(re(x))*cosh(re(x))/(cos(im(x))**2
  179. + sinh(re(x))**2),
  180. sin(im(x))*cos(im(x))/(cos(im(x))**2 + sinh(re(x))**2))
  181. x = Symbol('x', extended_real=True)
  182. assert tanh(x).as_real_imag(deep=False) == (tanh(x), 0)
  183. assert tanh(I*pi/3 + 1).is_real is False
  184. assert tanh(x).is_real is True
  185. assert tanh(I*pi*x/2).is_real is None
  186. def test_tanh_series():
  187. x = Symbol('x')
  188. assert tanh(x).series(x, 0, 10) == \
  189. x - x**3/3 + 2*x**5/15 - 17*x**7/315 + 62*x**9/2835 + O(x**10)
  190. def test_tanh_fdiff():
  191. x = Symbol('x')
  192. raises(ArgumentIndexError, lambda: tanh(x).fdiff(2))
  193. def test_coth():
  194. x, y = symbols('x,y')
  195. k = Symbol('k', integer=True)
  196. assert coth(nan) is nan
  197. assert coth(zoo) is nan
  198. assert coth(oo) == 1
  199. assert coth(-oo) == -1
  200. assert coth(0) is zoo
  201. assert unchanged(coth, 1)
  202. assert coth(-1) == -coth(1)
  203. assert unchanged(coth, x)
  204. assert coth(-x) == -coth(x)
  205. assert coth(pi*I) == -I*cot(pi)
  206. assert coth(-pi*I) == cot(pi)*I
  207. assert unchanged(coth, 2**1024 * E)
  208. assert coth(-2**1024 * E) == -coth(2**1024 * E)
  209. assert coth(pi*I) == -I*cot(pi)
  210. assert coth(-pi*I) == I*cot(pi)
  211. assert coth(2*pi*I) == -I*cot(2*pi)
  212. assert coth(-2*pi*I) == I*cot(2*pi)
  213. assert coth(-3*10**73*pi*I) == I*cot(3*10**73*pi)
  214. assert coth(7*10**103*pi*I) == -I*cot(7*10**103*pi)
  215. assert coth(pi*I/2) == 0
  216. assert coth(-pi*I/2) == 0
  217. assert coth(pi*I*Rational(5, 2)) == 0
  218. assert coth(pi*I*Rational(7, 2)) == 0
  219. assert coth(pi*I/3) == -I/sqrt(3)
  220. assert coth(pi*I*Rational(-2, 3)) == -I/sqrt(3)
  221. assert coth(pi*I/4) == -I
  222. assert coth(-pi*I/4) == I
  223. assert coth(pi*I*Rational(17, 4)) == -I
  224. assert coth(pi*I*Rational(-3, 4)) == -I
  225. assert coth(pi*I/6) == -sqrt(3)*I
  226. assert coth(-pi*I/6) == sqrt(3)*I
  227. assert coth(pi*I*Rational(7, 6)) == -sqrt(3)*I
  228. assert coth(pi*I*Rational(-5, 6)) == -sqrt(3)*I
  229. assert coth(pi*I/105) == -cot(pi/105)*I
  230. assert coth(-pi*I/105) == cot(pi/105)*I
  231. assert unchanged(coth, 2 + 3*I)
  232. assert coth(x*I) == -cot(x)*I
  233. assert coth(k*pi*I) == -cot(k*pi)*I
  234. assert coth(17*k*pi*I) == -cot(17*k*pi)*I
  235. assert coth(k*pi*I) == -cot(k*pi)*I
  236. assert coth(log(tan(2))) == coth(log(-tan(2)))
  237. assert coth(1 + I*pi/2) == tanh(1)
  238. assert coth(x).as_real_imag(deep=False) == (sinh(re(x))*cosh(re(x))/(sin(im(x))**2
  239. + sinh(re(x))**2),
  240. -sin(im(x))*cos(im(x))/(sin(im(x))**2 + sinh(re(x))**2))
  241. x = Symbol('x', extended_real=True)
  242. assert coth(x).as_real_imag(deep=False) == (coth(x), 0)
  243. assert expand_trig(coth(2*x)) == (coth(x)**2 + 1)/(2*coth(x))
  244. assert expand_trig(coth(3*x)) == (coth(x)**3 + 3*coth(x))/(1 + 3*coth(x)**2)
  245. assert expand_trig(coth(x + y)) == (1 + coth(x)*coth(y))/(coth(x) + coth(y))
  246. def test_coth_series():
  247. x = Symbol('x')
  248. assert coth(x).series(x, 0, 8) == \
  249. 1/x + x/3 - x**3/45 + 2*x**5/945 - x**7/4725 + O(x**8)
  250. def test_coth_fdiff():
  251. x = Symbol('x')
  252. raises(ArgumentIndexError, lambda: coth(x).fdiff(2))
  253. def test_csch():
  254. x, y = symbols('x,y')
  255. k = Symbol('k', integer=True)
  256. n = Symbol('n', positive=True)
  257. assert csch(nan) is nan
  258. assert csch(zoo) is nan
  259. assert csch(oo) == 0
  260. assert csch(-oo) == 0
  261. assert csch(0) is zoo
  262. assert csch(-1) == -csch(1)
  263. assert csch(-x) == -csch(x)
  264. assert csch(-pi) == -csch(pi)
  265. assert csch(-2**1024 * E) == -csch(2**1024 * E)
  266. assert csch(pi*I) is zoo
  267. assert csch(-pi*I) is zoo
  268. assert csch(2*pi*I) is zoo
  269. assert csch(-2*pi*I) is zoo
  270. assert csch(-3*10**73*pi*I) is zoo
  271. assert csch(7*10**103*pi*I) is zoo
  272. assert csch(pi*I/2) == -I
  273. assert csch(-pi*I/2) == I
  274. assert csch(pi*I*Rational(5, 2)) == -I
  275. assert csch(pi*I*Rational(7, 2)) == I
  276. assert csch(pi*I/3) == -2/sqrt(3)*I
  277. assert csch(pi*I*Rational(-2, 3)) == 2/sqrt(3)*I
  278. assert csch(pi*I/4) == -sqrt(2)*I
  279. assert csch(-pi*I/4) == sqrt(2)*I
  280. assert csch(pi*I*Rational(7, 4)) == sqrt(2)*I
  281. assert csch(pi*I*Rational(-3, 4)) == sqrt(2)*I
  282. assert csch(pi*I/6) == -2*I
  283. assert csch(-pi*I/6) == 2*I
  284. assert csch(pi*I*Rational(7, 6)) == 2*I
  285. assert csch(pi*I*Rational(-7, 6)) == -2*I
  286. assert csch(pi*I*Rational(-5, 6)) == 2*I
  287. assert csch(pi*I/105) == -1/sin(pi/105)*I
  288. assert csch(-pi*I/105) == 1/sin(pi/105)*I
  289. assert csch(x*I) == -1/sin(x)*I
  290. assert csch(k*pi*I) is zoo
  291. assert csch(17*k*pi*I) is zoo
  292. assert csch(k*pi*I/2) == -1/sin(k*pi/2)*I
  293. assert csch(n).is_real is True
  294. assert expand_trig(csch(x + y)) == 1/(sinh(x)*cosh(y) + cosh(x)*sinh(y))
  295. def test_csch_series():
  296. x = Symbol('x')
  297. assert csch(x).series(x, 0, 10) == \
  298. 1/ x - x/6 + 7*x**3/360 - 31*x**5/15120 + 127*x**7/604800 \
  299. - 73*x**9/3421440 + O(x**10)
  300. def test_csch_fdiff():
  301. x = Symbol('x')
  302. raises(ArgumentIndexError, lambda: csch(x).fdiff(2))
  303. def test_sech():
  304. x, y = symbols('x, y')
  305. k = Symbol('k', integer=True)
  306. n = Symbol('n', positive=True)
  307. assert sech(nan) is nan
  308. assert sech(zoo) is nan
  309. assert sech(oo) == 0
  310. assert sech(-oo) == 0
  311. assert sech(0) == 1
  312. assert sech(-1) == sech(1)
  313. assert sech(-x) == sech(x)
  314. assert sech(pi*I) == sec(pi)
  315. assert sech(-pi*I) == sec(pi)
  316. assert sech(-2**1024 * E) == sech(2**1024 * E)
  317. assert sech(pi*I/2) is zoo
  318. assert sech(-pi*I/2) is zoo
  319. assert sech((-3*10**73 + 1)*pi*I/2) is zoo
  320. assert sech((7*10**103 + 1)*pi*I/2) is zoo
  321. assert sech(pi*I) == -1
  322. assert sech(-pi*I) == -1
  323. assert sech(5*pi*I) == -1
  324. assert sech(8*pi*I) == 1
  325. assert sech(pi*I/3) == 2
  326. assert sech(pi*I*Rational(-2, 3)) == -2
  327. assert sech(pi*I/4) == sqrt(2)
  328. assert sech(-pi*I/4) == sqrt(2)
  329. assert sech(pi*I*Rational(5, 4)) == -sqrt(2)
  330. assert sech(pi*I*Rational(-5, 4)) == -sqrt(2)
  331. assert sech(pi*I/6) == 2/sqrt(3)
  332. assert sech(-pi*I/6) == 2/sqrt(3)
  333. assert sech(pi*I*Rational(7, 6)) == -2/sqrt(3)
  334. assert sech(pi*I*Rational(-5, 6)) == -2/sqrt(3)
  335. assert sech(pi*I/105) == 1/cos(pi/105)
  336. assert sech(-pi*I/105) == 1/cos(pi/105)
  337. assert sech(x*I) == 1/cos(x)
  338. assert sech(k*pi*I) == 1/cos(k*pi)
  339. assert sech(17*k*pi*I) == 1/cos(17*k*pi)
  340. assert sech(n).is_real is True
  341. assert expand_trig(sech(x + y)) == 1/(cosh(x)*cosh(y) + sinh(x)*sinh(y))
  342. def test_sech_series():
  343. x = Symbol('x')
  344. assert sech(x).series(x, 0, 10) == \
  345. 1 - x**2/2 + 5*x**4/24 - 61*x**6/720 + 277*x**8/8064 + O(x**10)
  346. def test_sech_fdiff():
  347. x = Symbol('x')
  348. raises(ArgumentIndexError, lambda: sech(x).fdiff(2))
  349. def test_asinh():
  350. x, y = symbols('x,y')
  351. assert unchanged(asinh, x)
  352. assert asinh(-x) == -asinh(x)
  353. #at specific points
  354. assert asinh(nan) is nan
  355. assert asinh( 0) == 0
  356. assert asinh(+1) == log(sqrt(2) + 1)
  357. assert asinh(-1) == log(sqrt(2) - 1)
  358. assert asinh(I) == pi*I/2
  359. assert asinh(-I) == -pi*I/2
  360. assert asinh(I/2) == pi*I/6
  361. assert asinh(-I/2) == -pi*I/6
  362. # at infinites
  363. assert asinh(oo) is oo
  364. assert asinh(-oo) is -oo
  365. assert asinh(I*oo) is oo
  366. assert asinh(-I *oo) is -oo
  367. assert asinh(zoo) is zoo
  368. #properties
  369. assert asinh(I *(sqrt(3) - 1)/(2**Rational(3, 2))) == pi*I/12
  370. assert asinh(-I *(sqrt(3) - 1)/(2**Rational(3, 2))) == -pi*I/12
  371. assert asinh(I*(sqrt(5) - 1)/4) == pi*I/10
  372. assert asinh(-I*(sqrt(5) - 1)/4) == -pi*I/10
  373. assert asinh(I*(sqrt(5) + 1)/4) == pi*I*Rational(3, 10)
  374. assert asinh(-I*(sqrt(5) + 1)/4) == pi*I*Rational(-3, 10)
  375. # Symmetry
  376. assert asinh(Rational(-1, 2)) == -asinh(S.Half)
  377. # inverse composition
  378. assert unchanged(asinh, sinh(Symbol('v1')))
  379. assert asinh(sinh(0, evaluate=False)) == 0
  380. assert asinh(sinh(-3, evaluate=False)) == -3
  381. assert asinh(sinh(2, evaluate=False)) == 2
  382. assert asinh(sinh(I, evaluate=False)) == I
  383. assert asinh(sinh(-I, evaluate=False)) == -I
  384. assert asinh(sinh(5*I, evaluate=False)) == -2*I*pi + 5*I
  385. assert asinh(sinh(15 + 11*I)) == 15 - 4*I*pi + 11*I
  386. assert asinh(sinh(-73 + 97*I)) == 73 - 97*I + 31*I*pi
  387. assert asinh(sinh(-7 - 23*I)) == 7 - 7*I*pi + 23*I
  388. assert asinh(sinh(13 - 3*I)) == -13 - I*pi + 3*I
  389. p = Symbol('p', positive=True)
  390. assert asinh(p).is_zero is False
  391. assert asinh(sinh(0, evaluate=False), evaluate=False).is_zero is True
  392. def test_asinh_rewrite():
  393. x = Symbol('x')
  394. assert asinh(x).rewrite(log) == log(x + sqrt(x**2 + 1))
  395. assert asinh(x).rewrite(atanh) == atanh(x/sqrt(1 + x**2))
  396. assert asinh(x).rewrite(asin) == asinh(x)
  397. assert asinh(x*(1 + I)).rewrite(asin) == -I*asin(I*x*(1+I))
  398. assert asinh(x).rewrite(acos) == I*(-I*asinh(x) + pi/2) - I*pi/2
  399. def test_asinh_leading_term():
  400. x = Symbol('x')
  401. assert asinh(x).as_leading_term(x, cdir=1) == x
  402. # Tests concerning branch points
  403. assert asinh(x + I).as_leading_term(x, cdir=1) == I*pi/2
  404. assert asinh(x - I).as_leading_term(x, cdir=1) == -I*pi/2
  405. assert asinh(1/x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  406. assert asinh(1/x).as_leading_term(x, cdir=-1) == log(x) - log(2) - I*pi
  407. # Tests concerning points lying on branch cuts
  408. assert asinh(x + 2*I).as_leading_term(x, cdir=1) == I*asin(2)
  409. assert asinh(x + 2*I).as_leading_term(x, cdir=-1) == -I*asin(2) + I*pi
  410. assert asinh(x - 2*I).as_leading_term(x, cdir=1) == -I*pi + I*asin(2)
  411. assert asinh(x - 2*I).as_leading_term(x, cdir=-1) == -I*asin(2)
  412. # Tests concerning re(ndir) == 0
  413. assert asinh(2*I + I*x - x**2).as_leading_term(x, cdir=1) == log(2 - sqrt(3)) + I*pi/2
  414. assert asinh(2*I + I*x - x**2).as_leading_term(x, cdir=-1) == log(2 - sqrt(3)) + I*pi/2
  415. def test_asinh_series():
  416. x = Symbol('x')
  417. assert asinh(x).series(x, 0, 8) == \
  418. x - x**3/6 + 3*x**5/40 - 5*x**7/112 + O(x**8)
  419. t5 = asinh(x).taylor_term(5, x)
  420. assert t5 == 3*x**5/40
  421. assert asinh(x).taylor_term(7, x, t5, 0) == -5*x**7/112
  422. def test_asinh_nseries():
  423. x = Symbol('x')
  424. # Tests concerning branch points
  425. assert asinh(x + I)._eval_nseries(x, 4, None) == I*pi/2 + \
  426. sqrt(x)*(1 - I) + x**(S(3)/2)*(S(1)/12 + I/12) + x**(S(5)/2)*(-S(3)/160 + 3*I/160) + \
  427. x**(S(7)/2)*(-S(5)/896 - 5*I/896) + O(x**4)
  428. assert asinh(x - I)._eval_nseries(x, 4, None) == -I*pi/2 + \
  429. sqrt(x)*(1 + I) + x**(S(3)/2)*(S(1)/12 - I/12) + x**(S(5)/2)*(-S(3)/160 - 3*I/160) + \
  430. x**(S(7)/2)*(-S(5)/896 + 5*I/896) + O(x**4)
  431. # Tests concerning points lying on branch cuts
  432. assert asinh(x + 2*I)._eval_nseries(x, 4, None, cdir=1) == I*asin(2) - \
  433. sqrt(3)*I*x/3 + sqrt(3)*x**2/9 + sqrt(3)*I*x**3/18 + O(x**4)
  434. assert asinh(x + 2*I)._eval_nseries(x, 4, None, cdir=-1) == I*pi - I*asin(2) + \
  435. sqrt(3)*I*x/3 - sqrt(3)*x**2/9 - sqrt(3)*I*x**3/18 + O(x**4)
  436. assert asinh(x - 2*I)._eval_nseries(x, 4, None, cdir=1) == I*asin(2) - I*pi + \
  437. sqrt(3)*I*x/3 + sqrt(3)*x**2/9 - sqrt(3)*I*x**3/18 + O(x**4)
  438. assert asinh(x - 2*I)._eval_nseries(x, 4, None, cdir=-1) == -I*asin(2) - \
  439. sqrt(3)*I*x/3 - sqrt(3)*x**2/9 + sqrt(3)*I*x**3/18 + O(x**4)
  440. # Tests concerning re(ndir) == 0
  441. assert asinh(2*I + I*x - x**2)._eval_nseries(x, 4, None) == I*pi/2 + log(2 - sqrt(3)) - \
  442. sqrt(3)*x/3 + x**2*(sqrt(3)/9 - sqrt(3)*I/3) + x**3*(-sqrt(3)/18 + 2*sqrt(3)*I/9) + O(x**4)
  443. def test_asinh_fdiff():
  444. x = Symbol('x')
  445. raises(ArgumentIndexError, lambda: asinh(x).fdiff(2))
  446. def test_acosh():
  447. x = Symbol('x')
  448. assert unchanged(acosh, -x)
  449. #at specific points
  450. assert acosh(1) == 0
  451. assert acosh(-1) == pi*I
  452. assert acosh(0) == I*pi/2
  453. assert acosh(S.Half) == I*pi/3
  454. assert acosh(Rational(-1, 2)) == pi*I*Rational(2, 3)
  455. assert acosh(nan) is nan
  456. # at infinites
  457. assert acosh(oo) is oo
  458. assert acosh(-oo) is oo
  459. assert acosh(I*oo) == oo + I*pi/2
  460. assert acosh(-I*oo) == oo - I*pi/2
  461. assert acosh(zoo) is zoo
  462. assert acosh(I) == log(I*(1 + sqrt(2)))
  463. assert acosh(-I) == log(-I*(1 + sqrt(2)))
  464. assert acosh((sqrt(3) - 1)/(2*sqrt(2))) == pi*I*Rational(5, 12)
  465. assert acosh(-(sqrt(3) - 1)/(2*sqrt(2))) == pi*I*Rational(7, 12)
  466. assert acosh(sqrt(2)/2) == I*pi/4
  467. assert acosh(-sqrt(2)/2) == I*pi*Rational(3, 4)
  468. assert acosh(sqrt(3)/2) == I*pi/6
  469. assert acosh(-sqrt(3)/2) == I*pi*Rational(5, 6)
  470. assert acosh(sqrt(2 + sqrt(2))/2) == I*pi/8
  471. assert acosh(-sqrt(2 + sqrt(2))/2) == I*pi*Rational(7, 8)
  472. assert acosh(sqrt(2 - sqrt(2))/2) == I*pi*Rational(3, 8)
  473. assert acosh(-sqrt(2 - sqrt(2))/2) == I*pi*Rational(5, 8)
  474. assert acosh((1 + sqrt(3))/(2*sqrt(2))) == I*pi/12
  475. assert acosh(-(1 + sqrt(3))/(2*sqrt(2))) == I*pi*Rational(11, 12)
  476. assert acosh((sqrt(5) + 1)/4) == I*pi/5
  477. assert acosh(-(sqrt(5) + 1)/4) == I*pi*Rational(4, 5)
  478. assert str(acosh(5*I).n(6)) == '2.31244 + 1.5708*I'
  479. assert str(acosh(-5*I).n(6)) == '2.31244 - 1.5708*I'
  480. # inverse composition
  481. assert unchanged(acosh, Symbol('v1'))
  482. assert acosh(cosh(-3, evaluate=False)) == 3
  483. assert acosh(cosh(3, evaluate=False)) == 3
  484. assert acosh(cosh(0, evaluate=False)) == 0
  485. assert acosh(cosh(I, evaluate=False)) == I
  486. assert acosh(cosh(-I, evaluate=False)) == I
  487. assert acosh(cosh(7*I, evaluate=False)) == -2*I*pi + 7*I
  488. assert acosh(cosh(1 + I)) == 1 + I
  489. assert acosh(cosh(3 - 3*I)) == 3 - 3*I
  490. assert acosh(cosh(-3 + 2*I)) == 3 - 2*I
  491. assert acosh(cosh(-5 - 17*I)) == 5 - 6*I*pi + 17*I
  492. assert acosh(cosh(-21 + 11*I)) == 21 - 11*I + 4*I*pi
  493. assert acosh(cosh(cosh(1) + I)) == cosh(1) + I
  494. assert acosh(1, evaluate=False).is_zero is True
  495. def test_acosh_rewrite():
  496. x = Symbol('x')
  497. assert acosh(x).rewrite(log) == log(x + sqrt(x - 1)*sqrt(x + 1))
  498. assert acosh(x).rewrite(asin) == sqrt(x - 1)*(-asin(x) + pi/2)/sqrt(1 - x)
  499. assert acosh(x).rewrite(asinh) == sqrt(x - 1)*(-asin(x) + pi/2)/sqrt(1 - x)
  500. assert acosh(x).rewrite(atanh) == \
  501. (sqrt(x - 1)*sqrt(x + 1)*atanh(sqrt(x**2 - 1)/x)/sqrt(x**2 - 1) +
  502. pi*sqrt(x - 1)*(-x*sqrt(x**(-2)) + 1)/(2*sqrt(1 - x)))
  503. x = Symbol('x', positive=True)
  504. assert acosh(x).rewrite(atanh) == \
  505. sqrt(x - 1)*sqrt(x + 1)*atanh(sqrt(x**2 - 1)/x)/sqrt(x**2 - 1)
  506. def test_acosh_leading_term():
  507. x = Symbol('x')
  508. # Tests concerning branch points
  509. assert acosh(x).as_leading_term(x) == I*pi/2
  510. assert acosh(x + 1).as_leading_term(x) == sqrt(2)*sqrt(x)
  511. assert acosh(x - 1).as_leading_term(x) == I*pi
  512. assert acosh(1/x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  513. assert acosh(1/x).as_leading_term(x, cdir=-1) == -log(x) + log(2) + 2*I*pi
  514. # Tests concerning points lying on branch cuts
  515. assert acosh(I*x - 2).as_leading_term(x, cdir=1) == acosh(-2)
  516. assert acosh(-I*x - 2).as_leading_term(x, cdir=1) == -2*I*pi + acosh(-2)
  517. assert acosh(x**2 - I*x + S(1)/3).as_leading_term(x, cdir=1) == -acosh(S(1)/3)
  518. assert acosh(x**2 - I*x + S(1)/3).as_leading_term(x, cdir=-1) == acosh(S(1)/3)
  519. assert acosh(1/(I*x - 3)).as_leading_term(x, cdir=1) == -acosh(-S(1)/3)
  520. assert acosh(1/(I*x - 3)).as_leading_term(x, cdir=-1) == acosh(-S(1)/3)
  521. # Tests concerning im(ndir) == 0
  522. assert acosh(-I*x**2 + x - 2).as_leading_term(x, cdir=1) == log(sqrt(3) + 2) - I*pi
  523. assert acosh(-I*x**2 + x - 2).as_leading_term(x, cdir=-1) == log(sqrt(3) + 2) - I*pi
  524. def test_acosh_series():
  525. x = Symbol('x')
  526. assert acosh(x).series(x, 0, 8) == \
  527. -I*x + pi*I/2 - I*x**3/6 - 3*I*x**5/40 - 5*I*x**7/112 + O(x**8)
  528. t5 = acosh(x).taylor_term(5, x)
  529. assert t5 == - 3*I*x**5/40
  530. assert acosh(x).taylor_term(7, x, t5, 0) == - 5*I*x**7/112
  531. def test_acosh_nseries():
  532. x = Symbol('x')
  533. # Tests concerning branch points
  534. assert acosh(x + 1)._eval_nseries(x, 4, None) == sqrt(2)*sqrt(x) - \
  535. sqrt(2)*x**(S(3)/2)/12 + 3*sqrt(2)*x**(S(5)/2)/160 - 5*sqrt(2)*x**(S(7)/2)/896 + O(x**4)
  536. # Tests concerning points lying on branch cuts
  537. assert acosh(x - 1)._eval_nseries(x, 4, None) == I*pi - \
  538. sqrt(2)*I*sqrt(x) - sqrt(2)*I*x**(S(3)/2)/12 - 3*sqrt(2)*I*x**(S(5)/2)/160 - \
  539. 5*sqrt(2)*I*x**(S(7)/2)/896 + O(x**4)
  540. assert acosh(I*x - 2)._eval_nseries(x, 4, None, cdir=1) == acosh(-2) - \
  541. sqrt(3)*I*x/3 + sqrt(3)*x**2/9 + sqrt(3)*I*x**3/18 + O(x**4)
  542. assert acosh(-I*x - 2)._eval_nseries(x, 4, None, cdir=1) == acosh(-2) - \
  543. 2*I*pi + sqrt(3)*I*x/3 + sqrt(3)*x**2/9 - sqrt(3)*I*x**3/18 + O(x**4)
  544. assert acosh(1/(I*x - 3))._eval_nseries(x, 4, None, cdir=1) == -acosh(-S(1)/3) + \
  545. sqrt(2)*x/12 + 17*sqrt(2)*I*x**2/576 - 443*sqrt(2)*x**3/41472 + O(x**4)
  546. assert acosh(1/(I*x - 3))._eval_nseries(x, 4, None, cdir=-1) == acosh(-S(1)/3) - \
  547. sqrt(2)*x/12 - 17*sqrt(2)*I*x**2/576 + 443*sqrt(2)*x**3/41472 + O(x**4)
  548. # Tests concerning im(ndir) == 0
  549. assert acosh(-I*x**2 + x - 2)._eval_nseries(x, 4, None) == -I*pi + log(sqrt(3) + 2) - \
  550. sqrt(3)*x/3 + x**2*(-sqrt(3)/9 + sqrt(3)*I/3) + x**3*(-sqrt(3)/18 + 2*sqrt(3)*I/9) + O(x**4)
  551. def test_acosh_fdiff():
  552. x = Symbol('x')
  553. raises(ArgumentIndexError, lambda: acosh(x).fdiff(2))
  554. def test_asech():
  555. x = Symbol('x')
  556. assert unchanged(asech, -x)
  557. # values at fixed points
  558. assert asech(1) == 0
  559. assert asech(-1) == pi*I
  560. assert asech(0) is oo
  561. assert asech(2) == I*pi/3
  562. assert asech(-2) == 2*I*pi / 3
  563. assert asech(nan) is nan
  564. # at infinites
  565. assert asech(oo) == I*pi/2
  566. assert asech(-oo) == I*pi/2
  567. assert asech(zoo) == I*AccumBounds(-pi/2, pi/2)
  568. assert asech(I) == log(1 + sqrt(2)) - I*pi/2
  569. assert asech(-I) == log(1 + sqrt(2)) + I*pi/2
  570. assert asech(sqrt(2) - sqrt(6)) == 11*I*pi / 12
  571. assert asech(sqrt(2 - 2/sqrt(5))) == I*pi / 10
  572. assert asech(-sqrt(2 - 2/sqrt(5))) == 9*I*pi / 10
  573. assert asech(2 / sqrt(2 + sqrt(2))) == I*pi / 8
  574. assert asech(-2 / sqrt(2 + sqrt(2))) == 7*I*pi / 8
  575. assert asech(sqrt(5) - 1) == I*pi / 5
  576. assert asech(1 - sqrt(5)) == 4*I*pi / 5
  577. assert asech(-sqrt(2*(2 + sqrt(2)))) == 5*I*pi / 8
  578. # properties
  579. # asech(x) == acosh(1/x)
  580. assert asech(sqrt(2)) == acosh(1/sqrt(2))
  581. assert asech(2/sqrt(3)) == acosh(sqrt(3)/2)
  582. assert asech(2/sqrt(2 + sqrt(2))) == acosh(sqrt(2 + sqrt(2))/2)
  583. assert asech(2) == acosh(S.Half)
  584. # asech(x) == I*acos(1/x)
  585. # (Note: the exact formula is asech(x) == +/- I*acos(1/x))
  586. assert asech(-sqrt(2)) == I*acos(-1/sqrt(2))
  587. assert asech(-2/sqrt(3)) == I*acos(-sqrt(3)/2)
  588. assert asech(-S(2)) == I*acos(Rational(-1, 2))
  589. assert asech(-2/sqrt(2)) == I*acos(-sqrt(2)/2)
  590. # sech(asech(x)) / x == 1
  591. assert expand_mul(sech(asech(sqrt(6) - sqrt(2))) / (sqrt(6) - sqrt(2))) == 1
  592. assert expand_mul(sech(asech(sqrt(6) + sqrt(2))) / (sqrt(6) + sqrt(2))) == 1
  593. assert (sech(asech(sqrt(2 + 2/sqrt(5)))) / (sqrt(2 + 2/sqrt(5)))).simplify() == 1
  594. assert (sech(asech(-sqrt(2 + 2/sqrt(5)))) / (-sqrt(2 + 2/sqrt(5)))).simplify() == 1
  595. assert (sech(asech(sqrt(2*(2 + sqrt(2))))) / (sqrt(2*(2 + sqrt(2))))).simplify() == 1
  596. assert expand_mul(sech(asech(1 + sqrt(5))) / (1 + sqrt(5))) == 1
  597. assert expand_mul(sech(asech(-1 - sqrt(5))) / (-1 - sqrt(5))) == 1
  598. assert expand_mul(sech(asech(-sqrt(6) - sqrt(2))) / (-sqrt(6) - sqrt(2))) == 1
  599. # numerical evaluation
  600. assert str(asech(5*I).n(6)) == '0.19869 - 1.5708*I'
  601. assert str(asech(-5*I).n(6)) == '0.19869 + 1.5708*I'
  602. def test_asech_leading_term():
  603. x = Symbol('x')
  604. # Tests concerning branch points
  605. assert asech(x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  606. assert asech(x).as_leading_term(x, cdir=-1) == -log(x) + log(2) + 2*I*pi
  607. assert asech(x + 1).as_leading_term(x, cdir=1) == sqrt(2)*I*sqrt(x)
  608. assert asech(1/x).as_leading_term(x, cdir=1) == I*pi/2
  609. # Tests concerning points lying on branch cuts
  610. assert asech(x - 1).as_leading_term(x, cdir=1) == I*pi
  611. assert asech(I*x + 3).as_leading_term(x, cdir=1) == -asech(3)
  612. assert asech(-I*x + 3).as_leading_term(x, cdir=1) == asech(3)
  613. assert asech(I*x - 3).as_leading_term(x, cdir=1) == -asech(-3)
  614. assert asech(-I*x - 3).as_leading_term(x, cdir=1) == asech(-3)
  615. assert asech(I*x - S(1)/3).as_leading_term(x, cdir=1) == -2*I*pi + asech(-S(1)/3)
  616. assert asech(I*x - S(1)/3).as_leading_term(x, cdir=-1) == asech(-S(1)/3)
  617. # Tests concerning im(ndir) == 0
  618. assert asech(-I*x**2 + x - 3).as_leading_term(x, cdir=1) == log(-S(1)/3 + 2*sqrt(2)*I/3)
  619. assert asech(-I*x**2 + x - 3).as_leading_term(x, cdir=-1) == log(-S(1)/3 + 2*sqrt(2)*I/3)
  620. def test_asech_series():
  621. x = Symbol('x')
  622. assert asech(x).series(x, 0, 9, cdir=1) == log(2) - log(x) - x**2/4 - 3*x**4/32 \
  623. - 5*x**6/96 - 35*x**8/1024 + O(x**9)
  624. assert asech(x).series(x, 0, 9, cdir=-1) == I*pi + log(2) - log(-x) - x**2/4 - \
  625. 3*x**4/32 - 5*x**6/96 - 35*x**8/1024 + O(x**9)
  626. t6 = asech(x).taylor_term(6, x)
  627. assert t6 == -5*x**6/96
  628. assert asech(x).taylor_term(8, x, t6, 0) == -35*x**8/1024
  629. def test_asech_nseries():
  630. x = Symbol('x')
  631. # Tests concerning branch points
  632. assert asech(x + 1)._eval_nseries(x, 4, None) == sqrt(2)*sqrt(-x) + 5*sqrt(2)*(-x)**(S(3)/2)/12 + \
  633. 43*sqrt(2)*(-x)**(S(5)/2)/160 + 177*sqrt(2)*(-x)**(S(7)/2)/896 + O(x**4)
  634. # Tests concerning points lying on branch cuts
  635. assert asech(x - 1)._eval_nseries(x, 4, None) == I*pi + sqrt(2)*sqrt(x) + \
  636. 5*sqrt(2)*x**(S(3)/2)/12 + 43*sqrt(2)*x**(S(5)/2)/160 + 177*sqrt(2)*x**(S(7)/2)/896 + O(x**4)
  637. assert asech(I*x + 3)._eval_nseries(x, 4, None) == -asech(3) + sqrt(2)*x/12 - \
  638. 17*sqrt(2)*I*x**2/576 - 443*sqrt(2)*x**3/41472 + O(x**4)
  639. assert asech(-I*x + 3)._eval_nseries(x, 4, None) == asech(3) + sqrt(2)*x/12 + \
  640. 17*sqrt(2)*I*x**2/576 - 443*sqrt(2)*x**3/41472 + O(x**4)
  641. assert asech(I*x - 3)._eval_nseries(x, 4, None) == -asech(-3) - sqrt(2)*x/12 - \
  642. 17*sqrt(2)*I*x**2/576 + 443*sqrt(2)*x**3/41472 + O(x**4)
  643. assert asech(-I*x - 3)._eval_nseries(x, 4, None) == asech(-3) - sqrt(2)*x/12 + \
  644. 17*sqrt(2)*I*x**2/576 + 443*sqrt(2)*x**3/41472 + O(x**4)
  645. # Tests concerning im(ndir) == 0
  646. assert asech(-I*x**2 + x - 2)._eval_nseries(x, 3, None) == 2*I*pi/3 + sqrt(3)*I*x/6 + \
  647. x**2*(sqrt(3)/6 + 7*sqrt(3)*I/72) + O(x**3)
  648. def test_asech_rewrite():
  649. x = Symbol('x')
  650. assert asech(x).rewrite(log) == log(1/x + sqrt(1/x - 1) * sqrt(1/x + 1))
  651. assert asech(x).rewrite(acosh) == acosh(1/x)
  652. assert asech(x).rewrite(asinh) == sqrt(-1 + 1/x)*(-asin(1/x) + pi/2)/sqrt(1 - 1/x)
  653. assert asech(x).rewrite(atanh) == \
  654. sqrt(x + 1)*sqrt(1/(x + 1))*atanh(sqrt(1 - x**2)) + I*pi*(-sqrt(x)*sqrt(1/x) + 1 - I*sqrt(x**2)/(2*sqrt(-x**2)) - I*sqrt(-x)/(2*sqrt(x)))
  655. def test_asech_fdiff():
  656. x = Symbol('x')
  657. raises(ArgumentIndexError, lambda: asech(x).fdiff(2))
  658. def test_acsch():
  659. x = Symbol('x')
  660. assert unchanged(acsch, x)
  661. assert acsch(-x) == -acsch(x)
  662. # values at fixed points
  663. assert acsch(1) == log(1 + sqrt(2))
  664. assert acsch(-1) == - log(1 + sqrt(2))
  665. assert acsch(0) is zoo
  666. assert acsch(2) == log((1+sqrt(5))/2)
  667. assert acsch(-2) == - log((1+sqrt(5))/2)
  668. assert acsch(I) == - I*pi/2
  669. assert acsch(-I) == I*pi/2
  670. assert acsch(-I*(sqrt(6) + sqrt(2))) == I*pi / 12
  671. assert acsch(I*(sqrt(2) + sqrt(6))) == -I*pi / 12
  672. assert acsch(-I*(1 + sqrt(5))) == I*pi / 10
  673. assert acsch(I*(1 + sqrt(5))) == -I*pi / 10
  674. assert acsch(-I*2 / sqrt(2 - sqrt(2))) == I*pi / 8
  675. assert acsch(I*2 / sqrt(2 - sqrt(2))) == -I*pi / 8
  676. assert acsch(-I*2) == I*pi / 6
  677. assert acsch(I*2) == -I*pi / 6
  678. assert acsch(-I*sqrt(2 + 2/sqrt(5))) == I*pi / 5
  679. assert acsch(I*sqrt(2 + 2/sqrt(5))) == -I*pi / 5
  680. assert acsch(-I*sqrt(2)) == I*pi / 4
  681. assert acsch(I*sqrt(2)) == -I*pi / 4
  682. assert acsch(-I*(sqrt(5)-1)) == 3*I*pi / 10
  683. assert acsch(I*(sqrt(5)-1)) == -3*I*pi / 10
  684. assert acsch(-I*2 / sqrt(3)) == I*pi / 3
  685. assert acsch(I*2 / sqrt(3)) == -I*pi / 3
  686. assert acsch(-I*2 / sqrt(2 + sqrt(2))) == 3*I*pi / 8
  687. assert acsch(I*2 / sqrt(2 + sqrt(2))) == -3*I*pi / 8
  688. assert acsch(-I*sqrt(2 - 2/sqrt(5))) == 2*I*pi / 5
  689. assert acsch(I*sqrt(2 - 2/sqrt(5))) == -2*I*pi / 5
  690. assert acsch(-I*(sqrt(6) - sqrt(2))) == 5*I*pi / 12
  691. assert acsch(I*(sqrt(6) - sqrt(2))) == -5*I*pi / 12
  692. assert acsch(nan) is nan
  693. # properties
  694. # acsch(x) == asinh(1/x)
  695. assert acsch(-I*sqrt(2)) == asinh(I/sqrt(2))
  696. assert acsch(-I*2 / sqrt(3)) == asinh(I*sqrt(3) / 2)
  697. # acsch(x) == -I*asin(I/x)
  698. assert acsch(-I*sqrt(2)) == -I*asin(-1/sqrt(2))
  699. assert acsch(-I*2 / sqrt(3)) == -I*asin(-sqrt(3)/2)
  700. # csch(acsch(x)) / x == 1
  701. assert expand_mul(csch(acsch(-I*(sqrt(6) + sqrt(2)))) / (-I*(sqrt(6) + sqrt(2)))) == 1
  702. assert expand_mul(csch(acsch(I*(1 + sqrt(5)))) / (I*(1 + sqrt(5)))) == 1
  703. assert (csch(acsch(I*sqrt(2 - 2/sqrt(5)))) / (I*sqrt(2 - 2/sqrt(5)))).simplify() == 1
  704. assert (csch(acsch(-I*sqrt(2 - 2/sqrt(5)))) / (-I*sqrt(2 - 2/sqrt(5)))).simplify() == 1
  705. # numerical evaluation
  706. assert str(acsch(5*I+1).n(6)) == '0.0391819 - 0.193363*I'
  707. assert str(acsch(-5*I+1).n(6)) == '0.0391819 + 0.193363*I'
  708. def test_acsch_infinities():
  709. assert acsch(oo) == 0
  710. assert acsch(-oo) == 0
  711. assert acsch(zoo) == 0
  712. def test_acsch_leading_term():
  713. x = Symbol('x')
  714. assert acsch(1/x).as_leading_term(x) == x
  715. # Tests concerning branch points
  716. assert acsch(x + I).as_leading_term(x) == -I*pi/2
  717. assert acsch(x - I).as_leading_term(x) == I*pi/2
  718. # Tests concerning points lying on branch cuts
  719. assert acsch(x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  720. assert acsch(x).as_leading_term(x, cdir=-1) == log(x) - log(2) - I*pi
  721. assert acsch(x + I/2).as_leading_term(x, cdir=1) == -I*pi - acsch(I/2)
  722. assert acsch(x + I/2).as_leading_term(x, cdir=-1) == acsch(I/2)
  723. assert acsch(x - I/2).as_leading_term(x, cdir=1) == -acsch(I/2)
  724. assert acsch(x - I/2).as_leading_term(x, cdir=-1) == acsch(I/2) + I*pi
  725. # Tests concerning re(ndir) == 0
  726. assert acsch(I/2 + I*x - x**2).as_leading_term(x, cdir=1) == log(2 - sqrt(3)) - I*pi/2
  727. assert acsch(I/2 + I*x - x**2).as_leading_term(x, cdir=-1) == log(2 - sqrt(3)) - I*pi/2
  728. def test_acsch_series():
  729. x = Symbol('x')
  730. assert acsch(x).series(x, 0, 9) == log(2) - log(x) + x**2/4 - 3*x**4/32 \
  731. + 5*x**6/96 - 35*x**8/1024 + O(x**9)
  732. t4 = acsch(x).taylor_term(4, x)
  733. assert t4 == -3*x**4/32
  734. assert acsch(x).taylor_term(6, x, t4, 0) == 5*x**6/96
  735. def test_acsch_nseries():
  736. x = Symbol('x')
  737. # Tests concerning branch points
  738. assert acsch(x + I)._eval_nseries(x, 4, None) == -I*pi/2 + I*sqrt(x) + \
  739. sqrt(x) + 5*I*x**(S(3)/2)/12 - 5*x**(S(3)/2)/12 - 43*I*x**(S(5)/2)/160 - \
  740. 43*x**(S(5)/2)/160 - 177*I*x**(S(7)/2)/896 + 177*x**(S(7)/2)/896 + O(x**4)
  741. assert acsch(x - I)._eval_nseries(x, 4, None) == I*pi/2 - I*sqrt(x) + \
  742. sqrt(x) - 5*I*x**(S(3)/2)/12 - 5*x**(S(3)/2)/12 + 43*I*x**(S(5)/2)/160 - \
  743. 43*x**(S(5)/2)/160 + 177*I*x**(S(7)/2)/896 + 177*x**(S(7)/2)/896 + O(x**4)
  744. # Tests concerning points lying on branch cuts
  745. assert acsch(x + I/2)._eval_nseries(x, 4, None, cdir=1) == -acsch(I/2) - \
  746. I*pi + 4*sqrt(3)*I*x/3 - 8*sqrt(3)*x**2/9 - 16*sqrt(3)*I*x**3/9 + O(x**4)
  747. assert acsch(x + I/2)._eval_nseries(x, 4, None, cdir=-1) == acsch(I/2) - \
  748. 4*sqrt(3)*I*x/3 + 8*sqrt(3)*x**2/9 + 16*sqrt(3)*I*x**3/9 + O(x**4)
  749. assert acsch(x - I/2)._eval_nseries(x, 4, None, cdir=1) == -acsch(I/2) - \
  750. 4*sqrt(3)*I*x/3 - 8*sqrt(3)*x**2/9 + 16*sqrt(3)*I*x**3/9 + O(x**4)
  751. assert acsch(x - I/2)._eval_nseries(x, 4, None, cdir=-1) == I*pi + \
  752. acsch(I/2) + 4*sqrt(3)*I*x/3 + 8*sqrt(3)*x**2/9 - 16*sqrt(3)*I*x**3/9 + O(x**4)
  753. # TODO: Tests concerning re(ndir) == 0
  754. assert acsch(I/2 + I*x - x**2)._eval_nseries(x, 4, None) == -I*pi/2 + \
  755. log(2 - sqrt(3)) + 4*sqrt(3)*x/3 + x**2*(-8*sqrt(3)/9 + 4*sqrt(3)*I/3) + \
  756. x**3*(16*sqrt(3)/9 - 16*sqrt(3)*I/9) + O(x**4)
  757. def test_acsch_rewrite():
  758. x = Symbol('x')
  759. assert acsch(x).rewrite(log) == log(1/x + sqrt(1/x**2 + 1))
  760. assert acsch(x).rewrite(asinh) == asinh(1/x)
  761. assert acsch(x).rewrite(atanh) == (sqrt(-x**2)*(-sqrt(-(x**2 + 1)**2)
  762. *atanh(sqrt(x**2 + 1))/(x**2 + 1)
  763. + pi/2)/x)
  764. def test_acsch_fdiff():
  765. x = Symbol('x')
  766. raises(ArgumentIndexError, lambda: acsch(x).fdiff(2))
  767. def test_atanh():
  768. x = Symbol('x')
  769. #at specific points
  770. assert atanh(0) == 0
  771. assert atanh(I) == I*pi/4
  772. assert atanh(-I) == -I*pi/4
  773. assert atanh(1) is oo
  774. assert atanh(-1) is -oo
  775. assert atanh(nan) is nan
  776. # at infinites
  777. assert atanh(oo) == -I*pi/2
  778. assert atanh(-oo) == I*pi/2
  779. assert atanh(I*oo) == I*pi/2
  780. assert atanh(-I*oo) == -I*pi/2
  781. assert atanh(zoo) == I*AccumBounds(-pi/2, pi/2)
  782. #properties
  783. assert atanh(-x) == -atanh(x)
  784. assert atanh(I/sqrt(3)) == I*pi/6
  785. assert atanh(-I/sqrt(3)) == -I*pi/6
  786. assert atanh(I*sqrt(3)) == I*pi/3
  787. assert atanh(-I*sqrt(3)) == -I*pi/3
  788. assert atanh(I*(1 + sqrt(2))) == pi*I*Rational(3, 8)
  789. assert atanh(I*(sqrt(2) - 1)) == pi*I/8
  790. assert atanh(I*(1 - sqrt(2))) == -pi*I/8
  791. assert atanh(-I*(1 + sqrt(2))) == pi*I*Rational(-3, 8)
  792. assert atanh(I*sqrt(5 + 2*sqrt(5))) == I*pi*Rational(2, 5)
  793. assert atanh(-I*sqrt(5 + 2*sqrt(5))) == I*pi*Rational(-2, 5)
  794. assert atanh(I*(2 - sqrt(3))) == pi*I/12
  795. assert atanh(I*(sqrt(3) - 2)) == -pi*I/12
  796. assert atanh(oo) == -I*pi/2
  797. # Symmetry
  798. assert atanh(Rational(-1, 2)) == -atanh(S.Half)
  799. # inverse composition
  800. assert unchanged(atanh, tanh(Symbol('v1')))
  801. assert atanh(tanh(-5, evaluate=False)) == -5
  802. assert atanh(tanh(0, evaluate=False)) == 0
  803. assert atanh(tanh(7, evaluate=False)) == 7
  804. assert atanh(tanh(I, evaluate=False)) == I
  805. assert atanh(tanh(-I, evaluate=False)) == -I
  806. assert atanh(tanh(-11*I, evaluate=False)) == -11*I + 4*I*pi
  807. assert atanh(tanh(3 + I)) == 3 + I
  808. assert atanh(tanh(4 + 5*I)) == 4 - 2*I*pi + 5*I
  809. assert atanh(tanh(pi/2)) == pi/2
  810. assert atanh(tanh(pi)) == pi
  811. assert atanh(tanh(-3 + 7*I)) == -3 - 2*I*pi + 7*I
  812. assert atanh(tanh(9 - I*2/3)) == 9 - I*2/3
  813. assert atanh(tanh(-32 - 123*I)) == -32 - 123*I + 39*I*pi
  814. def test_atanh_rewrite():
  815. x = Symbol('x')
  816. assert atanh(x).rewrite(log) == (log(1 + x) - log(1 - x)) / 2
  817. assert atanh(x).rewrite(asinh) == \
  818. pi*x/(2*sqrt(-x**2)) - sqrt(-x)*sqrt(1 - x**2)*sqrt(1/(x**2 - 1))*asinh(sqrt(1/(x**2 - 1)))/sqrt(x)
  819. def test_atanh_leading_term():
  820. x = Symbol('x')
  821. assert atanh(x).as_leading_term(x) == x
  822. # Tests concerning branch points
  823. assert atanh(x + 1).as_leading_term(x, cdir=1) == -log(x)/2 + log(2)/2 - I*pi/2
  824. assert atanh(x + 1).as_leading_term(x, cdir=-1) == -log(x)/2 + log(2)/2 + I*pi/2
  825. assert atanh(x - 1).as_leading_term(x, cdir=1) == log(x)/2 - log(2)/2
  826. assert atanh(x - 1).as_leading_term(x, cdir=-1) == log(x)/2 - log(2)/2
  827. assert atanh(1/x).as_leading_term(x, cdir=1) == -I*pi/2
  828. assert atanh(1/x).as_leading_term(x, cdir=-1) == I*pi/2
  829. # Tests concerning points lying on branch cuts
  830. assert atanh(I*x + 2).as_leading_term(x, cdir=1) == atanh(2) + I*pi
  831. assert atanh(-I*x + 2).as_leading_term(x, cdir=1) == atanh(2)
  832. assert atanh(I*x - 2).as_leading_term(x, cdir=1) == -atanh(2)
  833. assert atanh(-I*x - 2).as_leading_term(x, cdir=1) == -I*pi - atanh(2)
  834. # Tests concerning im(ndir) == 0
  835. assert atanh(-I*x**2 + x - 2).as_leading_term(x, cdir=1) == -log(3)/2 - I*pi/2
  836. assert atanh(-I*x**2 + x - 2).as_leading_term(x, cdir=-1) == -log(3)/2 - I*pi/2
  837. def test_atanh_series():
  838. x = Symbol('x')
  839. assert atanh(x).series(x, 0, 10) == \
  840. x + x**3/3 + x**5/5 + x**7/7 + x**9/9 + O(x**10)
  841. def test_atanh_nseries():
  842. x = Symbol('x')
  843. # Tests concerning branch points
  844. assert atanh(x + 1)._eval_nseries(x, 4, None, cdir=1) == -I*pi/2 + log(2)/2 - \
  845. log(x)/2 + x/4 - x**2/16 + x**3/48 + O(x**4)
  846. assert atanh(x + 1)._eval_nseries(x, 4, None, cdir=-1) == I*pi/2 + log(2)/2 - \
  847. log(x)/2 + x/4 - x**2/16 + x**3/48 + O(x**4)
  848. assert atanh(x - 1)._eval_nseries(x, 4, None, cdir=1) == -log(2)/2 + log(x)/2 + \
  849. x/4 + x**2/16 + x**3/48 + O(x**4)
  850. assert atanh(x - 1)._eval_nseries(x, 4, None, cdir=-1) == -log(2)/2 + log(x)/2 + \
  851. x/4 + x**2/16 + x**3/48 + O(x**4)
  852. # Tests concerning points lying on branch cuts
  853. assert atanh(I*x + 2)._eval_nseries(x, 4, None, cdir=1) == I*pi + atanh(2) - \
  854. I*x/3 - 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  855. assert atanh(I*x + 2)._eval_nseries(x, 4, None, cdir=-1) == atanh(2) - I*x/3 - \
  856. 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  857. assert atanh(I*x - 2)._eval_nseries(x, 4, None, cdir=1) == -atanh(2) - I*x/3 + \
  858. 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  859. assert atanh(I*x - 2)._eval_nseries(x, 4, None, cdir=-1) == -atanh(2) - I*pi - \
  860. I*x/3 + 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  861. # Tests concerning im(ndir) == 0
  862. assert atanh(-I*x**2 + x - 2)._eval_nseries(x, 4, None) == -I*pi/2 - log(3)/2 - x/3 + \
  863. x**2*(-S(1)/4 + I/2) + x**2*(S(1)/36 - I/6) + x**3*(-S(1)/6 + I/2) + x**3*(S(1)/162 - I/18) + O(x**4)
  864. def test_atanh_fdiff():
  865. x = Symbol('x')
  866. raises(ArgumentIndexError, lambda: atanh(x).fdiff(2))
  867. def test_acoth():
  868. x = Symbol('x')
  869. #at specific points
  870. assert acoth(0) == I*pi/2
  871. assert acoth(I) == -I*pi/4
  872. assert acoth(-I) == I*pi/4
  873. assert acoth(1) is oo
  874. assert acoth(-1) is -oo
  875. assert acoth(nan) is nan
  876. # at infinites
  877. assert acoth(oo) == 0
  878. assert acoth(-oo) == 0
  879. assert acoth(I*oo) == 0
  880. assert acoth(-I*oo) == 0
  881. assert acoth(zoo) == 0
  882. #properties
  883. assert acoth(-x) == -acoth(x)
  884. assert acoth(I/sqrt(3)) == -I*pi/3
  885. assert acoth(-I/sqrt(3)) == I*pi/3
  886. assert acoth(I*sqrt(3)) == -I*pi/6
  887. assert acoth(-I*sqrt(3)) == I*pi/6
  888. assert acoth(I*(1 + sqrt(2))) == -pi*I/8
  889. assert acoth(-I*(sqrt(2) + 1)) == pi*I/8
  890. assert acoth(I*(1 - sqrt(2))) == pi*I*Rational(3, 8)
  891. assert acoth(I*(sqrt(2) - 1)) == pi*I*Rational(-3, 8)
  892. assert acoth(I*sqrt(5 + 2*sqrt(5))) == -I*pi/10
  893. assert acoth(-I*sqrt(5 + 2*sqrt(5))) == I*pi/10
  894. assert acoth(I*(2 + sqrt(3))) == -pi*I/12
  895. assert acoth(-I*(2 + sqrt(3))) == pi*I/12
  896. assert acoth(I*(2 - sqrt(3))) == pi*I*Rational(-5, 12)
  897. assert acoth(I*(sqrt(3) - 2)) == pi*I*Rational(5, 12)
  898. # Symmetry
  899. assert acoth(Rational(-1, 2)) == -acoth(S.Half)
  900. def test_acoth_rewrite():
  901. x = Symbol('x')
  902. assert acoth(x).rewrite(log) == (log(1 + 1/x) - log(1 - 1/x)) / 2
  903. assert acoth(x).rewrite(atanh) == atanh(1/x)
  904. assert acoth(x).rewrite(asinh) == \
  905. x*sqrt(x**(-2))*asinh(sqrt(1/(x**2 - 1))) + I*pi*(sqrt((x - 1)/x)*sqrt(x/(x - 1)) - sqrt(x/(x + 1))*sqrt(1 + 1/x))/2
  906. def test_acoth_leading_term():
  907. x = Symbol('x')
  908. # Tests concerning branch points
  909. assert acoth(x + 1).as_leading_term(x, cdir=1) == -log(x)/2 + log(2)/2
  910. assert acoth(x + 1).as_leading_term(x, cdir=-1) == -log(x)/2 + log(2)/2
  911. assert acoth(x - 1).as_leading_term(x, cdir=1) == log(x)/2 - log(2)/2 + I*pi/2
  912. assert acoth(x - 1).as_leading_term(x, cdir=-1) == log(x)/2 - log(2)/2 - I*pi/2
  913. # Tests concerning points lying on branch cuts
  914. assert acoth(x).as_leading_term(x, cdir=-1) == I*pi/2
  915. assert acoth(x).as_leading_term(x, cdir=1) == -I*pi/2
  916. assert acoth(I*x + 1/2).as_leading_term(x, cdir=1) == acoth(1/2)
  917. assert acoth(-I*x + 1/2).as_leading_term(x, cdir=1) == acoth(1/2) + I*pi
  918. assert acoth(I*x - 1/2).as_leading_term(x, cdir=1) == -I*pi - acoth(1/2)
  919. assert acoth(-I*x - 1/2).as_leading_term(x, cdir=1) == -acoth(1/2)
  920. # Tests concerning im(ndir) == 0
  921. assert acoth(-I*x**2 - x - S(1)/2).as_leading_term(x, cdir=1) == -log(3)/2 + I*pi/2
  922. assert acoth(-I*x**2 - x - S(1)/2).as_leading_term(x, cdir=-1) == -log(3)/2 + I*pi/2
  923. def test_acoth_series():
  924. x = Symbol('x')
  925. assert acoth(x).series(x, 0, 10) == \
  926. -I*pi/2 + x + x**3/3 + x**5/5 + x**7/7 + x**9/9 + O(x**10)
  927. def test_acoth_nseries():
  928. x = Symbol('x')
  929. # Tests concerning branch points
  930. assert acoth(x + 1)._eval_nseries(x, 4, None) == log(2)/2 - log(x)/2 + x/4 - \
  931. x**2/16 + x**3/48 + O(x**4)
  932. assert acoth(x - 1)._eval_nseries(x, 4, None, cdir=1) == I*pi/2 - log(2)/2 + \
  933. log(x)/2 + x/4 + x**2/16 + x**3/48 + O(x**4)
  934. assert acoth(x - 1)._eval_nseries(x, 4, None, cdir=-1) == -I*pi/2 - log(2)/2 + \
  935. log(x)/2 + x/4 + x**2/16 + x**3/48 + O(x**4)
  936. # Tests concerning points lying on branch cuts
  937. assert acoth(I*x + S(1)/2)._eval_nseries(x, 4, None, cdir=1) == acoth(S(1)/2) + \
  938. 4*I*x/3 - 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  939. assert acoth(I*x + S(1)/2)._eval_nseries(x, 4, None, cdir=-1) == I*pi + \
  940. acoth(S(1)/2) + 4*I*x/3 - 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  941. assert acoth(I*x - S(1)/2)._eval_nseries(x, 4, None, cdir=1) == -acoth(S(1)/2) - \
  942. I*pi + 4*I*x/3 + 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  943. assert acoth(I*x - S(1)/2)._eval_nseries(x, 4, None, cdir=-1) == -acoth(S(1)/2) + \
  944. 4*I*x/3 + 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  945. # Tests concerning im(ndir) == 0
  946. assert acoth(-I*x**2 - x - S(1)/2)._eval_nseries(x, 4, None) == I*pi/2 - log(3)/2 - \
  947. 4*x/3 + x**2*(-S(8)/9 + 2*I/3) - 2*I*x**2 + x**3*(S(104)/81 - 16*I/9) - 8*x**3/3 + O(x**4)
  948. def test_acoth_fdiff():
  949. x = Symbol('x')
  950. raises(ArgumentIndexError, lambda: acoth(x).fdiff(2))
  951. def test_inverses():
  952. x = Symbol('x')
  953. assert sinh(x).inverse() == asinh
  954. raises(AttributeError, lambda: cosh(x).inverse())
  955. assert tanh(x).inverse() == atanh
  956. assert coth(x).inverse() == acoth
  957. assert asinh(x).inverse() == sinh
  958. assert acosh(x).inverse() == cosh
  959. assert atanh(x).inverse() == tanh
  960. assert acoth(x).inverse() == coth
  961. assert asech(x).inverse() == sech
  962. assert acsch(x).inverse() == csch
  963. def test_leading_term():
  964. x = Symbol('x')
  965. assert cosh(x).as_leading_term(x) == 1
  966. assert coth(x).as_leading_term(x) == 1/x
  967. for func in [sinh, tanh]:
  968. assert func(x).as_leading_term(x) == x
  969. for func in [sinh, cosh, tanh, coth]:
  970. for ar in (1/x, S.Half):
  971. eq = func(ar)
  972. assert eq.as_leading_term(x) == eq
  973. for func in [csch, sech]:
  974. eq = func(S.Half)
  975. assert eq.as_leading_term(x) == eq
  976. def test_complex():
  977. a, b = symbols('a,b', real=True)
  978. z = a + b*I
  979. for func in [sinh, cosh, tanh, coth, sech, csch]:
  980. assert func(z).conjugate() == func(a - b*I)
  981. for deep in [True, False]:
  982. assert sinh(z).expand(
  983. complex=True, deep=deep) == sinh(a)*cos(b) + I*cosh(a)*sin(b)
  984. assert cosh(z).expand(
  985. complex=True, deep=deep) == cosh(a)*cos(b) + I*sinh(a)*sin(b)
  986. assert tanh(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
  987. a)/(cos(b)**2 + sinh(a)**2) + I*sin(b)*cos(b)/(cos(b)**2 + sinh(a)**2)
  988. assert coth(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
  989. a)/(sin(b)**2 + sinh(a)**2) - I*sin(b)*cos(b)/(sin(b)**2 + sinh(a)**2)
  990. assert csch(z).expand(complex=True, deep=deep) == cos(b) * sinh(a) / (sin(b)**2\
  991. *cosh(a)**2 + cos(b)**2 * sinh(a)**2) - I*sin(b) * cosh(a) / (sin(b)**2\
  992. *cosh(a)**2 + cos(b)**2 * sinh(a)**2)
  993. assert sech(z).expand(complex=True, deep=deep) == cos(b) * cosh(a) / (sin(b)**2\
  994. *sinh(a)**2 + cos(b)**2 * cosh(a)**2) - I*sin(b) * sinh(a) / (sin(b)**2\
  995. *sinh(a)**2 + cos(b)**2 * cosh(a)**2)
  996. def test_complex_2899():
  997. a, b = symbols('a,b', real=True)
  998. for deep in [True, False]:
  999. for func in [sinh, cosh, tanh, coth]:
  1000. assert func(a).expand(complex=True, deep=deep) == func(a)
  1001. def test_simplifications():
  1002. x = Symbol('x')
  1003. assert sinh(asinh(x)) == x
  1004. assert sinh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1)
  1005. assert sinh(atanh(x)) == x/sqrt(1 - x**2)
  1006. assert sinh(acoth(x)) == 1/(sqrt(x - 1) * sqrt(x + 1))
  1007. assert cosh(asinh(x)) == sqrt(1 + x**2)
  1008. assert cosh(acosh(x)) == x
  1009. assert cosh(atanh(x)) == 1/sqrt(1 - x**2)
  1010. assert cosh(acoth(x)) == x/(sqrt(x - 1) * sqrt(x + 1))
  1011. assert tanh(asinh(x)) == x/sqrt(1 + x**2)
  1012. assert tanh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) / x
  1013. assert tanh(atanh(x)) == x
  1014. assert tanh(acoth(x)) == 1/x
  1015. assert coth(asinh(x)) == sqrt(1 + x**2)/x
  1016. assert coth(acosh(x)) == x/(sqrt(x - 1) * sqrt(x + 1))
  1017. assert coth(atanh(x)) == 1/x
  1018. assert coth(acoth(x)) == x
  1019. assert csch(asinh(x)) == 1/x
  1020. assert csch(acosh(x)) == 1/(sqrt(x - 1) * sqrt(x + 1))
  1021. assert csch(atanh(x)) == sqrt(1 - x**2)/x
  1022. assert csch(acoth(x)) == sqrt(x - 1) * sqrt(x + 1)
  1023. assert sech(asinh(x)) == 1/sqrt(1 + x**2)
  1024. assert sech(acosh(x)) == 1/x
  1025. assert sech(atanh(x)) == sqrt(1 - x**2)
  1026. assert sech(acoth(x)) == sqrt(x - 1) * sqrt(x + 1)/x
  1027. def test_issue_4136():
  1028. assert cosh(asinh(Integer(3)/2)) == sqrt(Integer(13)/4)
  1029. def test_sinh_rewrite():
  1030. x = Symbol('x')
  1031. assert sinh(x).rewrite(exp) == (exp(x) - exp(-x))/2 \
  1032. == sinh(x).rewrite('tractable')
  1033. assert sinh(x).rewrite(cosh) == -I*cosh(x + I*pi/2)
  1034. tanh_half = tanh(S.Half*x)
  1035. assert sinh(x).rewrite(tanh) == 2*tanh_half/(1 - tanh_half**2)
  1036. coth_half = coth(S.Half*x)
  1037. assert sinh(x).rewrite(coth) == 2*coth_half/(coth_half**2 - 1)
  1038. def test_cosh_rewrite():
  1039. x = Symbol('x')
  1040. assert cosh(x).rewrite(exp) == (exp(x) + exp(-x))/2 \
  1041. == cosh(x).rewrite('tractable')
  1042. assert cosh(x).rewrite(sinh) == -I*sinh(x + I*pi/2)
  1043. tanh_half = tanh(S.Half*x)**2
  1044. assert cosh(x).rewrite(tanh) == (1 + tanh_half)/(1 - tanh_half)
  1045. coth_half = coth(S.Half*x)**2
  1046. assert cosh(x).rewrite(coth) == (coth_half + 1)/(coth_half - 1)
  1047. def test_tanh_rewrite():
  1048. x = Symbol('x')
  1049. assert tanh(x).rewrite(exp) == (exp(x) - exp(-x))/(exp(x) + exp(-x)) \
  1050. == tanh(x).rewrite('tractable')
  1051. assert tanh(x).rewrite(sinh) == I*sinh(x)/sinh(I*pi/2 - x)
  1052. assert tanh(x).rewrite(cosh) == I*cosh(I*pi/2 - x)/cosh(x)
  1053. assert tanh(x).rewrite(coth) == 1/coth(x)
  1054. def test_coth_rewrite():
  1055. x = Symbol('x')
  1056. assert coth(x).rewrite(exp) == (exp(x) + exp(-x))/(exp(x) - exp(-x)) \
  1057. == coth(x).rewrite('tractable')
  1058. assert coth(x).rewrite(sinh) == -I*sinh(I*pi/2 - x)/sinh(x)
  1059. assert coth(x).rewrite(cosh) == -I*cosh(x)/cosh(I*pi/2 - x)
  1060. assert coth(x).rewrite(tanh) == 1/tanh(x)
  1061. def test_csch_rewrite():
  1062. x = Symbol('x')
  1063. assert csch(x).rewrite(exp) == 1 / (exp(x)/2 - exp(-x)/2) \
  1064. == csch(x).rewrite('tractable')
  1065. assert csch(x).rewrite(cosh) == I/cosh(x + I*pi/2)
  1066. tanh_half = tanh(S.Half*x)
  1067. assert csch(x).rewrite(tanh) == (1 - tanh_half**2)/(2*tanh_half)
  1068. coth_half = coth(S.Half*x)
  1069. assert csch(x).rewrite(coth) == (coth_half**2 - 1)/(2*coth_half)
  1070. def test_sech_rewrite():
  1071. x = Symbol('x')
  1072. assert sech(x).rewrite(exp) == 1 / (exp(x)/2 + exp(-x)/2) \
  1073. == sech(x).rewrite('tractable')
  1074. assert sech(x).rewrite(sinh) == I/sinh(x + I*pi/2)
  1075. tanh_half = tanh(S.Half*x)**2
  1076. assert sech(x).rewrite(tanh) == (1 - tanh_half)/(1 + tanh_half)
  1077. coth_half = coth(S.Half*x)**2
  1078. assert sech(x).rewrite(coth) == (coth_half - 1)/(coth_half + 1)
  1079. def test_derivs():
  1080. x = Symbol('x')
  1081. assert coth(x).diff(x) == -sinh(x)**(-2)
  1082. assert sinh(x).diff(x) == cosh(x)
  1083. assert cosh(x).diff(x) == sinh(x)
  1084. assert tanh(x).diff(x) == -tanh(x)**2 + 1
  1085. assert csch(x).diff(x) == -coth(x)*csch(x)
  1086. assert sech(x).diff(x) == -tanh(x)*sech(x)
  1087. assert acoth(x).diff(x) == 1/(-x**2 + 1)
  1088. assert asinh(x).diff(x) == 1/sqrt(x**2 + 1)
  1089. assert acosh(x).diff(x) == 1/(sqrt(x - 1)*sqrt(x + 1))
  1090. assert acosh(x).diff(x) == acosh(x).rewrite(log).diff(x).together()
  1091. assert atanh(x).diff(x) == 1/(-x**2 + 1)
  1092. assert asech(x).diff(x) == -1/(x*sqrt(1 - x**2))
  1093. assert acsch(x).diff(x) == -1/(x**2*sqrt(1 + x**(-2)))
  1094. def test_sinh_expansion():
  1095. x, y = symbols('x,y')
  1096. assert sinh(x+y).expand(trig=True) == sinh(x)*cosh(y) + cosh(x)*sinh(y)
  1097. assert sinh(2*x).expand(trig=True) == 2*sinh(x)*cosh(x)
  1098. assert sinh(3*x).expand(trig=True).expand() == \
  1099. sinh(x)**3 + 3*sinh(x)*cosh(x)**2
  1100. def test_cosh_expansion():
  1101. x, y = symbols('x,y')
  1102. assert cosh(x+y).expand(trig=True) == cosh(x)*cosh(y) + sinh(x)*sinh(y)
  1103. assert cosh(2*x).expand(trig=True) == cosh(x)**2 + sinh(x)**2
  1104. assert cosh(3*x).expand(trig=True).expand() == \
  1105. 3*sinh(x)**2*cosh(x) + cosh(x)**3
  1106. def test_cosh_positive():
  1107. # See issue 11721
  1108. # cosh(x) is positive for real values of x
  1109. k = symbols('k', real=True)
  1110. n = symbols('n', integer=True)
  1111. assert cosh(k, evaluate=False).is_positive is True
  1112. assert cosh(k + 2*n*pi*I, evaluate=False).is_positive is True
  1113. assert cosh(I*pi/4, evaluate=False).is_positive is True
  1114. assert cosh(3*I*pi/4, evaluate=False).is_positive is False
  1115. def test_cosh_nonnegative():
  1116. k = symbols('k', real=True)
  1117. n = symbols('n', integer=True)
  1118. assert cosh(k, evaluate=False).is_nonnegative is True
  1119. assert cosh(k + 2*n*pi*I, evaluate=False).is_nonnegative is True
  1120. assert cosh(I*pi/4, evaluate=False).is_nonnegative is True
  1121. assert cosh(3*I*pi/4, evaluate=False).is_nonnegative is False
  1122. assert cosh(S.Zero, evaluate=False).is_nonnegative is True
  1123. def test_real_assumptions():
  1124. z = Symbol('z', real=False)
  1125. assert sinh(z).is_real is None
  1126. assert cosh(z).is_real is None
  1127. assert tanh(z).is_real is None
  1128. assert sech(z).is_real is None
  1129. assert csch(z).is_real is None
  1130. assert coth(z).is_real is None
  1131. def test_sign_assumptions():
  1132. p = Symbol('p', positive=True)
  1133. n = Symbol('n', negative=True)
  1134. assert sinh(n).is_negative is True
  1135. assert sinh(p).is_positive is True
  1136. assert cosh(n).is_positive is True
  1137. assert cosh(p).is_positive is True
  1138. assert tanh(n).is_negative is True
  1139. assert tanh(p).is_positive is True
  1140. assert csch(n).is_negative is True
  1141. assert csch(p).is_positive is True
  1142. assert sech(n).is_positive is True
  1143. assert sech(p).is_positive is True
  1144. assert coth(n).is_negative is True
  1145. assert coth(p).is_positive is True