test_hyperbolic.py 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553
  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, PoleError
  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. # reality
  376. assert asinh(S(2)).is_real is True
  377. assert asinh(S(2)).is_finite is True
  378. assert asinh(S(-2)).is_real is True
  379. assert asinh(S(oo)).is_extended_real is True
  380. assert asinh(-S(oo)).is_real is False
  381. assert (asinh(2) - oo) == -oo
  382. assert asinh(symbols('y', real=True)).is_real is True
  383. # Symmetry
  384. assert asinh(Rational(-1, 2)) == -asinh(S.Half)
  385. # inverse composition
  386. assert unchanged(asinh, sinh(Symbol('v1')))
  387. assert asinh(sinh(0, evaluate=False)) == 0
  388. assert asinh(sinh(-3, evaluate=False)) == -3
  389. assert asinh(sinh(2, evaluate=False)) == 2
  390. assert asinh(sinh(I, evaluate=False)) == I
  391. assert asinh(sinh(-I, evaluate=False)) == -I
  392. assert asinh(sinh(5*I, evaluate=False)) == -2*I*pi + 5*I
  393. assert asinh(sinh(15 + 11*I)) == 15 - 4*I*pi + 11*I
  394. assert asinh(sinh(-73 + 97*I)) == 73 - 97*I + 31*I*pi
  395. assert asinh(sinh(-7 - 23*I)) == 7 - 7*I*pi + 23*I
  396. assert asinh(sinh(13 - 3*I)) == -13 - I*pi + 3*I
  397. p = Symbol('p', positive=True)
  398. assert asinh(p).is_zero is False
  399. assert asinh(sinh(0, evaluate=False), evaluate=False).is_zero is True
  400. def test_asinh_rewrite():
  401. x = Symbol('x')
  402. assert asinh(x).rewrite(log) == log(x + sqrt(x**2 + 1))
  403. assert asinh(x).rewrite(atanh) == atanh(x/sqrt(1 + x**2))
  404. assert asinh(x).rewrite(asin) == -I*asin(I*x, evaluate=False)
  405. assert asinh(x*(1 + I)).rewrite(asin) == -I*asin(I*x*(1+I))
  406. assert asinh(x).rewrite(acos) == I*acos(I*x, evaluate=False) - I*pi/2
  407. def test_asinh_leading_term():
  408. x = Symbol('x')
  409. assert asinh(x).as_leading_term(x, cdir=1) == x
  410. # Tests concerning branch points
  411. assert asinh(x + I).as_leading_term(x, cdir=1) == I*pi/2
  412. assert asinh(x - I).as_leading_term(x, cdir=1) == -I*pi/2
  413. assert asinh(1/x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  414. assert asinh(1/x).as_leading_term(x, cdir=-1) == log(x) - log(2) - I*pi
  415. # Tests concerning points lying on branch cuts
  416. assert asinh(x + 2*I).as_leading_term(x, cdir=1) == I*asin(2)
  417. assert asinh(x + 2*I).as_leading_term(x, cdir=-1) == -I*asin(2) + I*pi
  418. assert asinh(x - 2*I).as_leading_term(x, cdir=1) == -I*pi + I*asin(2)
  419. assert asinh(x - 2*I).as_leading_term(x, cdir=-1) == -I*asin(2)
  420. # Tests concerning re(ndir) == 0
  421. assert asinh(2*I + I*x - x**2).as_leading_term(x, cdir=1) == log(2 - sqrt(3)) + I*pi/2
  422. assert asinh(2*I + I*x - x**2).as_leading_term(x, cdir=-1) == log(2 - sqrt(3)) + I*pi/2
  423. def test_asinh_series():
  424. x = Symbol('x')
  425. assert asinh(x).series(x, 0, 8) == \
  426. x - x**3/6 + 3*x**5/40 - 5*x**7/112 + O(x**8)
  427. t5 = asinh(x).taylor_term(5, x)
  428. assert t5 == 3*x**5/40
  429. assert asinh(x).taylor_term(7, x, t5, 0) == -5*x**7/112
  430. def test_asinh_nseries():
  431. x = Symbol('x')
  432. # Tests concerning branch points
  433. assert asinh(x + I)._eval_nseries(x, 4, None) == I*pi/2 - \
  434. sqrt(2)*sqrt(I)*I*sqrt(x) + sqrt(2)*sqrt(I)*x**(S(3)/2)/12 + 3*sqrt(2)*sqrt(I)*I*x**(S(5)/2)/160 - \
  435. 5*sqrt(2)*sqrt(I)*x**(S(7)/2)/896 + O(x**4)
  436. assert asinh(x - I)._eval_nseries(x, 4, None) == -I*pi/2 + \
  437. sqrt(2)*I*sqrt(x)*sqrt(-I) + sqrt(2)*x**(S(3)/2)*sqrt(-I)/12 - \
  438. 3*sqrt(2)*I*x**(S(5)/2)*sqrt(-I)/160 - 5*sqrt(2)*x**(S(7)/2)*sqrt(-I)/896 + O(x**4)
  439. # Tests concerning points lying on branch cuts
  440. assert asinh(x + 2*I)._eval_nseries(x, 4, None, cdir=1) == I*asin(2) - \
  441. sqrt(3)*I*x/3 + sqrt(3)*x**2/9 + sqrt(3)*I*x**3/18 + O(x**4)
  442. assert asinh(x + 2*I)._eval_nseries(x, 4, None, cdir=-1) == I*pi - I*asin(2) + \
  443. sqrt(3)*I*x/3 - sqrt(3)*x**2/9 - sqrt(3)*I*x**3/18 + O(x**4)
  444. assert asinh(x - 2*I)._eval_nseries(x, 4, None, cdir=1) == I*asin(2) - I*pi + \
  445. sqrt(3)*I*x/3 + sqrt(3)*x**2/9 - sqrt(3)*I*x**3/18 + O(x**4)
  446. assert asinh(x - 2*I)._eval_nseries(x, 4, None, cdir=-1) == -I*asin(2) - \
  447. sqrt(3)*I*x/3 - sqrt(3)*x**2/9 + sqrt(3)*I*x**3/18 + O(x**4)
  448. # Tests concerning re(ndir) == 0
  449. assert asinh(2*I + I*x - x**2)._eval_nseries(x, 4, None) == I*pi/2 + log(2 - sqrt(3)) + \
  450. x*(-3 + 2*sqrt(3))/(-6 + 3*sqrt(3)) + x**2*(12 - 36*I + sqrt(3)*(-7 + 21*I))/(-63 + \
  451. 36*sqrt(3)) + x**3*(-168 + sqrt(3)*(97 - 388*I) + 672*I)/(-1746 + 1008*sqrt(3)) + O(x**4)
  452. def test_asinh_fdiff():
  453. x = Symbol('x')
  454. raises(ArgumentIndexError, lambda: asinh(x).fdiff(2))
  455. def test_acosh():
  456. x = Symbol('x')
  457. assert unchanged(acosh, -x)
  458. #at specific points
  459. assert acosh(1) == 0
  460. assert acosh(-1) == pi*I
  461. assert acosh(0) == I*pi/2
  462. assert acosh(S.Half) == I*pi/3
  463. assert acosh(Rational(-1, 2)) == pi*I*Rational(2, 3)
  464. assert acosh(nan) is nan
  465. # at infinites
  466. assert acosh(oo) is oo
  467. assert acosh(-oo) is oo
  468. assert acosh(I*oo) == oo + I*pi/2
  469. assert acosh(-I*oo) == oo - I*pi/2
  470. assert acosh(zoo) is zoo
  471. assert acosh(I) == log(I*(1 + sqrt(2)))
  472. assert acosh(-I) == log(-I*(1 + sqrt(2)))
  473. assert acosh((sqrt(3) - 1)/(2*sqrt(2))) == pi*I*Rational(5, 12)
  474. assert acosh(-(sqrt(3) - 1)/(2*sqrt(2))) == pi*I*Rational(7, 12)
  475. assert acosh(sqrt(2)/2) == I*pi/4
  476. assert acosh(-sqrt(2)/2) == I*pi*Rational(3, 4)
  477. assert acosh(sqrt(3)/2) == I*pi/6
  478. assert acosh(-sqrt(3)/2) == I*pi*Rational(5, 6)
  479. assert acosh(sqrt(2 + sqrt(2))/2) == I*pi/8
  480. assert acosh(-sqrt(2 + sqrt(2))/2) == I*pi*Rational(7, 8)
  481. assert acosh(sqrt(2 - sqrt(2))/2) == I*pi*Rational(3, 8)
  482. assert acosh(-sqrt(2 - sqrt(2))/2) == I*pi*Rational(5, 8)
  483. assert acosh((1 + sqrt(3))/(2*sqrt(2))) == I*pi/12
  484. assert acosh(-(1 + sqrt(3))/(2*sqrt(2))) == I*pi*Rational(11, 12)
  485. assert acosh((sqrt(5) + 1)/4) == I*pi/5
  486. assert acosh(-(sqrt(5) + 1)/4) == I*pi*Rational(4, 5)
  487. assert str(acosh(5*I).n(6)) == '2.31244 + 1.5708*I'
  488. assert str(acosh(-5*I).n(6)) == '2.31244 - 1.5708*I'
  489. # inverse composition
  490. assert unchanged(acosh, Symbol('v1'))
  491. assert acosh(cosh(-3, evaluate=False)) == 3
  492. assert acosh(cosh(3, evaluate=False)) == 3
  493. assert acosh(cosh(0, evaluate=False)) == 0
  494. assert acosh(cosh(I, evaluate=False)) == I
  495. assert acosh(cosh(-I, evaluate=False)) == I
  496. assert acosh(cosh(7*I, evaluate=False)) == -2*I*pi + 7*I
  497. assert acosh(cosh(1 + I)) == 1 + I
  498. assert acosh(cosh(3 - 3*I)) == 3 - 3*I
  499. assert acosh(cosh(-3 + 2*I)) == 3 - 2*I
  500. assert acosh(cosh(-5 - 17*I)) == 5 - 6*I*pi + 17*I
  501. assert acosh(cosh(-21 + 11*I)) == 21 - 11*I + 4*I*pi
  502. assert acosh(cosh(cosh(1) + I)) == cosh(1) + I
  503. assert acosh(1, evaluate=False).is_zero is True
  504. # Reality
  505. assert acosh(S(2)).is_real is True
  506. assert acosh(S(2)).is_extended_real is True
  507. assert acosh(oo).is_extended_real is True
  508. assert acosh(S(2)).is_finite is True
  509. assert acosh(S(1) / 5).is_real is False
  510. assert (acosh(2) - oo) == -oo
  511. assert acosh(symbols('y', real=True)).is_real is None
  512. def test_acosh_rewrite():
  513. x = Symbol('x')
  514. assert acosh(x).rewrite(log) == log(x + sqrt(x - 1)*sqrt(x + 1))
  515. assert acosh(x).rewrite(asin) == sqrt(x - 1)*(-asin(x) + pi/2)/sqrt(1 - x)
  516. assert acosh(x).rewrite(asinh) == sqrt(x - 1)*(I*asinh(I*x, evaluate=False) + pi/2)/sqrt(1 - x)
  517. assert acosh(x).rewrite(atanh) == \
  518. (sqrt(x - 1)*sqrt(x + 1)*atanh(sqrt(x**2 - 1)/x)/sqrt(x**2 - 1) +
  519. pi*sqrt(x - 1)*(-x*sqrt(x**(-2)) + 1)/(2*sqrt(1 - x)))
  520. x = Symbol('x', positive=True)
  521. assert acosh(x).rewrite(atanh) == \
  522. sqrt(x - 1)*sqrt(x + 1)*atanh(sqrt(x**2 - 1)/x)/sqrt(x**2 - 1)
  523. def test_acosh_leading_term():
  524. x = Symbol('x')
  525. # Tests concerning branch points
  526. assert acosh(x).as_leading_term(x) == I*pi/2
  527. assert acosh(x + 1).as_leading_term(x) == sqrt(2)*sqrt(x)
  528. assert acosh(x - 1).as_leading_term(x) == I*pi
  529. assert acosh(1/x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  530. assert acosh(1/x).as_leading_term(x, cdir=-1) == -log(x) + log(2) + 2*I*pi
  531. # Tests concerning points lying on branch cuts
  532. assert acosh(I*x - 2).as_leading_term(x, cdir=1) == acosh(-2)
  533. assert acosh(-I*x - 2).as_leading_term(x, cdir=1) == -2*I*pi + acosh(-2)
  534. assert acosh(x**2 - I*x + S(1)/3).as_leading_term(x, cdir=1) == -acosh(S(1)/3)
  535. assert acosh(x**2 - I*x + S(1)/3).as_leading_term(x, cdir=-1) == acosh(S(1)/3)
  536. assert acosh(1/(I*x - 3)).as_leading_term(x, cdir=1) == -acosh(-S(1)/3)
  537. assert acosh(1/(I*x - 3)).as_leading_term(x, cdir=-1) == acosh(-S(1)/3)
  538. # Tests concerning im(ndir) == 0
  539. assert acosh(-I*x**2 + x - 2).as_leading_term(x, cdir=1) == log(sqrt(3) + 2) - I*pi
  540. assert acosh(-I*x**2 + x - 2).as_leading_term(x, cdir=-1) == log(sqrt(3) + 2) - I*pi
  541. def test_acosh_series():
  542. x = Symbol('x')
  543. assert acosh(x).series(x, 0, 8) == \
  544. -I*x + pi*I/2 - I*x**3/6 - 3*I*x**5/40 - 5*I*x**7/112 + O(x**8)
  545. t5 = acosh(x).taylor_term(5, x)
  546. assert t5 == - 3*I*x**5/40
  547. assert acosh(x).taylor_term(7, x, t5, 0) == - 5*I*x**7/112
  548. def test_acosh_nseries():
  549. x = Symbol('x')
  550. # Tests concerning branch points
  551. assert acosh(x + 1)._eval_nseries(x, 4, None) == sqrt(2)*sqrt(x) - \
  552. 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)
  553. # Tests concerning points lying on branch cuts
  554. assert acosh(x - 1)._eval_nseries(x, 4, None) == I*pi - \
  555. sqrt(2)*I*sqrt(x) - sqrt(2)*I*x**(S(3)/2)/12 - 3*sqrt(2)*I*x**(S(5)/2)/160 - \
  556. 5*sqrt(2)*I*x**(S(7)/2)/896 + O(x**4)
  557. assert acosh(I*x - 2)._eval_nseries(x, 4, None, cdir=1) == acosh(-2) - \
  558. sqrt(3)*I*x/3 + sqrt(3)*x**2/9 + sqrt(3)*I*x**3/18 + O(x**4)
  559. assert acosh(-I*x - 2)._eval_nseries(x, 4, None, cdir=1) == acosh(-2) - \
  560. 2*I*pi + sqrt(3)*I*x/3 + sqrt(3)*x**2/9 - sqrt(3)*I*x**3/18 + O(x**4)
  561. assert acosh(1/(I*x - 3))._eval_nseries(x, 4, None, cdir=1) == -acosh(-S(1)/3) + \
  562. sqrt(2)*x/12 + 17*sqrt(2)*I*x**2/576 - 443*sqrt(2)*x**3/41472 + O(x**4)
  563. assert acosh(1/(I*x - 3))._eval_nseries(x, 4, None, cdir=-1) == acosh(-S(1)/3) - \
  564. sqrt(2)*x/12 - 17*sqrt(2)*I*x**2/576 + 443*sqrt(2)*x**3/41472 + O(x**4)
  565. # Tests concerning im(ndir) == 0
  566. assert acosh(-I*x**2 + x - 2)._eval_nseries(x, 4, None) == -I*pi + log(sqrt(3) + 2) + \
  567. x*(-2*sqrt(3) - 3)/(3*sqrt(3) + 6) + x**2*(-12 + 36*I + sqrt(3)*(-7 + 21*I))/(36*sqrt(3) + \
  568. 63) + x**3*(-168 + 672*I + sqrt(3)*(-97 + 388*I))/(1008*sqrt(3) + 1746) + O(x**4)
  569. def test_acosh_fdiff():
  570. x = Symbol('x')
  571. raises(ArgumentIndexError, lambda: acosh(x).fdiff(2))
  572. def test_asech():
  573. x = Symbol('x')
  574. assert unchanged(asech, -x)
  575. # values at fixed points
  576. assert asech(1) == 0
  577. assert asech(-1) == pi*I
  578. assert asech(0) is oo
  579. assert asech(2) == I*pi/3
  580. assert asech(-2) == 2*I*pi / 3
  581. assert asech(nan) is nan
  582. # at infinites
  583. assert asech(oo) == I*pi/2
  584. assert asech(-oo) == I*pi/2
  585. assert asech(zoo) == I*AccumBounds(-pi/2, pi/2)
  586. assert asech(I) == log(1 + sqrt(2)) - I*pi/2
  587. assert asech(-I) == log(1 + sqrt(2)) + I*pi/2
  588. assert asech(sqrt(2) - sqrt(6)) == 11*I*pi / 12
  589. assert asech(sqrt(2 - 2/sqrt(5))) == I*pi / 10
  590. assert asech(-sqrt(2 - 2/sqrt(5))) == 9*I*pi / 10
  591. assert asech(2 / sqrt(2 + sqrt(2))) == I*pi / 8
  592. assert asech(-2 / sqrt(2 + sqrt(2))) == 7*I*pi / 8
  593. assert asech(sqrt(5) - 1) == I*pi / 5
  594. assert asech(1 - sqrt(5)) == 4*I*pi / 5
  595. assert asech(-sqrt(2*(2 + sqrt(2)))) == 5*I*pi / 8
  596. # properties
  597. # asech(x) == acosh(1/x)
  598. assert asech(sqrt(2)) == acosh(1/sqrt(2))
  599. assert asech(2/sqrt(3)) == acosh(sqrt(3)/2)
  600. assert asech(2/sqrt(2 + sqrt(2))) == acosh(sqrt(2 + sqrt(2))/2)
  601. assert asech(2) == acosh(S.Half)
  602. # reality
  603. assert asech(S(2)).is_real is False
  604. assert asech(-S(1) / 3).is_real is False
  605. assert asech(S(2) / 3).is_finite is True
  606. assert asech(S(0)).is_real is False
  607. assert asech(S(0)).is_extended_real is True
  608. assert asech(symbols('y', real=True)).is_real is None
  609. # asech(x) == I*acos(1/x)
  610. # (Note: the exact formula is asech(x) == +/- I*acos(1/x))
  611. assert asech(-sqrt(2)) == I*acos(-1/sqrt(2))
  612. assert asech(-2/sqrt(3)) == I*acos(-sqrt(3)/2)
  613. assert asech(-S(2)) == I*acos(Rational(-1, 2))
  614. assert asech(-2/sqrt(2)) == I*acos(-sqrt(2)/2)
  615. # sech(asech(x)) / x == 1
  616. assert expand_mul(sech(asech(sqrt(6) - sqrt(2))) / (sqrt(6) - sqrt(2))) == 1
  617. assert expand_mul(sech(asech(sqrt(6) + sqrt(2))) / (sqrt(6) + sqrt(2))) == 1
  618. assert (sech(asech(sqrt(2 + 2/sqrt(5)))) / (sqrt(2 + 2/sqrt(5)))).simplify() == 1
  619. assert (sech(asech(-sqrt(2 + 2/sqrt(5)))) / (-sqrt(2 + 2/sqrt(5)))).simplify() == 1
  620. assert (sech(asech(sqrt(2*(2 + sqrt(2))))) / (sqrt(2*(2 + sqrt(2))))).simplify() == 1
  621. assert expand_mul(sech(asech(1 + sqrt(5))) / (1 + sqrt(5))) == 1
  622. assert expand_mul(sech(asech(-1 - sqrt(5))) / (-1 - sqrt(5))) == 1
  623. assert expand_mul(sech(asech(-sqrt(6) - sqrt(2))) / (-sqrt(6) - sqrt(2))) == 1
  624. # numerical evaluation
  625. assert str(asech(5*I).n(6)) == '0.19869 - 1.5708*I'
  626. assert str(asech(-5*I).n(6)) == '0.19869 + 1.5708*I'
  627. def test_asech_leading_term():
  628. x = Symbol('x')
  629. # Tests concerning branch points
  630. assert asech(x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  631. assert asech(x).as_leading_term(x, cdir=-1) == -log(x) + log(2) + 2*I*pi
  632. assert asech(x + 1).as_leading_term(x, cdir=1) == sqrt(2)*I*sqrt(x)
  633. assert asech(1/x).as_leading_term(x, cdir=1) == I*pi/2
  634. # Tests concerning points lying on branch cuts
  635. assert asech(x - 1).as_leading_term(x, cdir=1) == I*pi
  636. assert asech(I*x + 3).as_leading_term(x, cdir=1) == -asech(3)
  637. assert asech(-I*x + 3).as_leading_term(x, cdir=1) == asech(3)
  638. assert asech(I*x - 3).as_leading_term(x, cdir=1) == -asech(-3)
  639. assert asech(-I*x - 3).as_leading_term(x, cdir=1) == asech(-3)
  640. assert asech(I*x - S(1)/3).as_leading_term(x, cdir=1) == -2*I*pi + asech(-S(1)/3)
  641. assert asech(I*x - S(1)/3).as_leading_term(x, cdir=-1) == asech(-S(1)/3)
  642. # Tests concerning im(ndir) == 0
  643. assert asech(-I*x**2 + x - 3).as_leading_term(x, cdir=1) == log(-S(1)/3 + 2*sqrt(2)*I/3)
  644. assert asech(-I*x**2 + x - 3).as_leading_term(x, cdir=-1) == log(-S(1)/3 + 2*sqrt(2)*I/3)
  645. def test_asech_series():
  646. x = Symbol('x')
  647. assert asech(x).series(x, 0, 9, cdir=1) == log(2) - log(x) - x**2/4 - 3*x**4/32 \
  648. - 5*x**6/96 - 35*x**8/1024 + O(x**9)
  649. assert asech(x).series(x, 0, 9, cdir=-1) == I*pi + log(2) - log(-x) - x**2/4 - \
  650. 3*x**4/32 - 5*x**6/96 - 35*x**8/1024 + O(x**9)
  651. t6 = asech(x).taylor_term(6, x)
  652. assert t6 == -5*x**6/96
  653. assert asech(x).taylor_term(8, x, t6, 0) == -35*x**8/1024
  654. def test_asech_nseries():
  655. x = Symbol('x')
  656. # Tests concerning branch points
  657. assert asech(x + 1)._eval_nseries(x, 4, None) == sqrt(2)*sqrt(-x) + 5*sqrt(2)*(-x)**(S(3)/2)/12 + \
  658. 43*sqrt(2)*(-x)**(S(5)/2)/160 + 177*sqrt(2)*(-x)**(S(7)/2)/896 + O(x**4)
  659. # Tests concerning points lying on branch cuts
  660. assert asech(x - 1)._eval_nseries(x, 4, None) == I*pi + sqrt(2)*sqrt(x) + \
  661. 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)
  662. assert asech(I*x + 3)._eval_nseries(x, 4, None) == -asech(3) + sqrt(2)*x/12 - \
  663. 17*sqrt(2)*I*x**2/576 - 443*sqrt(2)*x**3/41472 + O(x**4)
  664. assert asech(-I*x + 3)._eval_nseries(x, 4, None) == asech(3) + sqrt(2)*x/12 + \
  665. 17*sqrt(2)*I*x**2/576 - 443*sqrt(2)*x**3/41472 + O(x**4)
  666. assert asech(I*x - 3)._eval_nseries(x, 4, None) == -asech(-3) - sqrt(2)*x/12 - \
  667. 17*sqrt(2)*I*x**2/576 + 443*sqrt(2)*x**3/41472 + O(x**4)
  668. assert asech(-I*x - 3)._eval_nseries(x, 4, None) == asech(-3) - sqrt(2)*x/12 + \
  669. 17*sqrt(2)*I*x**2/576 + 443*sqrt(2)*x**3/41472 + O(x**4)
  670. # Tests concerning im(ndir) == 0
  671. assert asech(-I*x**2 + x - 2)._eval_nseries(x, 3, None) == 2*I*pi/3 + \
  672. x*(-sqrt(3) + 3*I)/(6*sqrt(3) + 6*I) + x**2*(36 + sqrt(3)*(7 - 12*I) + 21*I)/(72*sqrt(3) - \
  673. 72*I) + O(x**3)
  674. def test_asech_rewrite():
  675. x = Symbol('x')
  676. assert asech(x).rewrite(log) == log(1/x + sqrt(1/x - 1) * sqrt(1/x + 1))
  677. assert asech(x).rewrite(acosh) == acosh(1/x)
  678. assert asech(x).rewrite(asinh) == sqrt(-1 + 1/x)*(I*asinh(I/x, evaluate=False) + pi/2)/sqrt(1 - 1/x)
  679. assert asech(x).rewrite(atanh) == \
  680. 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)))
  681. def test_asech_fdiff():
  682. x = Symbol('x')
  683. raises(ArgumentIndexError, lambda: asech(x).fdiff(2))
  684. def test_acsch():
  685. x = Symbol('x')
  686. assert unchanged(acsch, x)
  687. assert acsch(-x) == -acsch(x)
  688. # values at fixed points
  689. assert acsch(1) == log(1 + sqrt(2))
  690. assert acsch(-1) == - log(1 + sqrt(2))
  691. assert acsch(0) is zoo
  692. assert acsch(2) == log((1+sqrt(5))/2)
  693. assert acsch(-2) == - log((1+sqrt(5))/2)
  694. assert acsch(I) == - I*pi/2
  695. assert acsch(-I) == I*pi/2
  696. assert acsch(-I*(sqrt(6) + sqrt(2))) == I*pi / 12
  697. assert acsch(I*(sqrt(2) + sqrt(6))) == -I*pi / 12
  698. assert acsch(-I*(1 + sqrt(5))) == I*pi / 10
  699. assert acsch(I*(1 + sqrt(5))) == -I*pi / 10
  700. assert acsch(-I*2 / sqrt(2 - sqrt(2))) == I*pi / 8
  701. assert acsch(I*2 / sqrt(2 - sqrt(2))) == -I*pi / 8
  702. assert acsch(-I*2) == I*pi / 6
  703. assert acsch(I*2) == -I*pi / 6
  704. assert acsch(-I*sqrt(2 + 2/sqrt(5))) == I*pi / 5
  705. assert acsch(I*sqrt(2 + 2/sqrt(5))) == -I*pi / 5
  706. assert acsch(-I*sqrt(2)) == I*pi / 4
  707. assert acsch(I*sqrt(2)) == -I*pi / 4
  708. assert acsch(-I*(sqrt(5)-1)) == 3*I*pi / 10
  709. assert acsch(I*(sqrt(5)-1)) == -3*I*pi / 10
  710. assert acsch(-I*2 / sqrt(3)) == I*pi / 3
  711. assert acsch(I*2 / sqrt(3)) == -I*pi / 3
  712. assert acsch(-I*2 / sqrt(2 + sqrt(2))) == 3*I*pi / 8
  713. assert acsch(I*2 / sqrt(2 + sqrt(2))) == -3*I*pi / 8
  714. assert acsch(-I*sqrt(2 - 2/sqrt(5))) == 2*I*pi / 5
  715. assert acsch(I*sqrt(2 - 2/sqrt(5))) == -2*I*pi / 5
  716. assert acsch(-I*(sqrt(6) - sqrt(2))) == 5*I*pi / 12
  717. assert acsch(I*(sqrt(6) - sqrt(2))) == -5*I*pi / 12
  718. assert acsch(nan) is nan
  719. # properties
  720. # acsch(x) == asinh(1/x)
  721. assert acsch(-I*sqrt(2)) == asinh(I/sqrt(2))
  722. assert acsch(-I*2 / sqrt(3)) == asinh(I*sqrt(3) / 2)
  723. # reality
  724. assert acsch(S(2)).is_real is True
  725. assert acsch(S(2)).is_finite is True
  726. assert acsch(S(-2)).is_real is True
  727. assert acsch(S(oo)).is_extended_real is True
  728. assert acsch(-S(oo)).is_real is True
  729. assert (acsch(2) - oo) == -oo
  730. assert acsch(symbols('y', extended_real=True)).is_extended_real is True
  731. # acsch(x) == -I*asin(I/x)
  732. assert acsch(-I*sqrt(2)) == -I*asin(-1/sqrt(2))
  733. assert acsch(-I*2 / sqrt(3)) == -I*asin(-sqrt(3)/2)
  734. # csch(acsch(x)) / x == 1
  735. assert expand_mul(csch(acsch(-I*(sqrt(6) + sqrt(2)))) / (-I*(sqrt(6) + sqrt(2)))) == 1
  736. assert expand_mul(csch(acsch(I*(1 + sqrt(5)))) / (I*(1 + sqrt(5)))) == 1
  737. assert (csch(acsch(I*sqrt(2 - 2/sqrt(5)))) / (I*sqrt(2 - 2/sqrt(5)))).simplify() == 1
  738. assert (csch(acsch(-I*sqrt(2 - 2/sqrt(5)))) / (-I*sqrt(2 - 2/sqrt(5)))).simplify() == 1
  739. # numerical evaluation
  740. assert str(acsch(5*I+1).n(6)) == '0.0391819 - 0.193363*I'
  741. assert str(acsch(-5*I+1).n(6)) == '0.0391819 + 0.193363*I'
  742. def test_acsch_infinities():
  743. assert acsch(oo) == 0
  744. assert acsch(-oo) == 0
  745. assert acsch(zoo) == 0
  746. def test_acsch_leading_term():
  747. x = Symbol('x')
  748. assert acsch(1/x).as_leading_term(x) == x
  749. # Tests concerning branch points
  750. assert acsch(x + I).as_leading_term(x) == -I*pi/2
  751. assert acsch(x - I).as_leading_term(x) == I*pi/2
  752. # Tests concerning points lying on branch cuts
  753. assert acsch(x).as_leading_term(x, cdir=1) == -log(x) + log(2)
  754. assert acsch(x).as_leading_term(x, cdir=-1) == log(x) - log(2) - I*pi
  755. assert acsch(x + I/2).as_leading_term(x, cdir=1) == -I*pi - acsch(I/2)
  756. assert acsch(x + I/2).as_leading_term(x, cdir=-1) == acsch(I/2)
  757. assert acsch(x - I/2).as_leading_term(x, cdir=1) == -acsch(I/2)
  758. assert acsch(x - I/2).as_leading_term(x, cdir=-1) == acsch(I/2) + I*pi
  759. # Tests concerning re(ndir) == 0
  760. assert acsch(I/2 + I*x - x**2).as_leading_term(x, cdir=1) == log(2 - sqrt(3)) - I*pi/2
  761. assert acsch(I/2 + I*x - x**2).as_leading_term(x, cdir=-1) == log(2 - sqrt(3)) - I*pi/2
  762. def test_acsch_series():
  763. x = Symbol('x')
  764. assert acsch(x).series(x, 0, 9) == log(2) - log(x) + x**2/4 - 3*x**4/32 \
  765. + 5*x**6/96 - 35*x**8/1024 + O(x**9)
  766. t4 = acsch(x).taylor_term(4, x)
  767. assert t4 == -3*x**4/32
  768. assert acsch(x).taylor_term(6, x, t4, 0) == 5*x**6/96
  769. def test_acsch_nseries():
  770. x = Symbol('x')
  771. # Tests concerning branch points
  772. assert acsch(x + I)._eval_nseries(x, 4, None) == -I*pi/2 + \
  773. sqrt(2)*I*sqrt(x)*sqrt(-I) - 5*x**(S(3)/2)*(1 - I)/12 - \
  774. 43*sqrt(2)*I*x**(S(5)/2)*sqrt(-I)/160 + 177*x**(S(7)/2)*(1 - I)/896 + O(x**4)
  775. assert acsch(x - I)._eval_nseries(x, 4, None) == I*pi/2 - \
  776. sqrt(2)*sqrt(I)*I*sqrt(x) - 5*x**(S(3)/2)*(1 + I)/12 + \
  777. 43*sqrt(2)*sqrt(I)*I*x**(S(5)/2)/160 + 177*x**(S(7)/2)*(1 + I)/896 + O(x**4)
  778. # Tests concerning points lying on branch cuts
  779. assert acsch(x + I/2)._eval_nseries(x, 4, None, cdir=1) == -acsch(I/2) - \
  780. I*pi + 4*sqrt(3)*I*x/3 - 8*sqrt(3)*x**2/9 - 16*sqrt(3)*I*x**3/9 + O(x**4)
  781. assert acsch(x + I/2)._eval_nseries(x, 4, None, cdir=-1) == acsch(I/2) - \
  782. 4*sqrt(3)*I*x/3 + 8*sqrt(3)*x**2/9 + 16*sqrt(3)*I*x**3/9 + O(x**4)
  783. assert acsch(x - I/2)._eval_nseries(x, 4, None, cdir=1) == -acsch(I/2) - \
  784. 4*sqrt(3)*I*x/3 - 8*sqrt(3)*x**2/9 + 16*sqrt(3)*I*x**3/9 + O(x**4)
  785. assert acsch(x - I/2)._eval_nseries(x, 4, None, cdir=-1) == I*pi + \
  786. 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)
  787. # Tests concerning re(ndir) == 0
  788. assert acsch(I/2 + I*x - x**2)._eval_nseries(x, 4, None) == -I*pi/2 + \
  789. log(2 - sqrt(3)) + x*(12 - 8*sqrt(3))/(-6 + 3*sqrt(3)) + x**2*(-96 + \
  790. sqrt(3)*(56 - 84*I) + 144*I)/(-63 + 36*sqrt(3)) + x**3*(2688 - 2688*I + \
  791. sqrt(3)*(-1552 + 1552*I))/(-873 + 504*sqrt(3)) + O(x**4)
  792. def test_acsch_rewrite():
  793. x = Symbol('x')
  794. assert acsch(x).rewrite(log) == log(1/x + sqrt(1/x**2 + 1))
  795. assert acsch(x).rewrite(asinh) == asinh(1/x)
  796. assert acsch(x).rewrite(atanh) == (sqrt(-x**2)*(-sqrt(-(x**2 + 1)**2)
  797. *atanh(sqrt(x**2 + 1))/(x**2 + 1)
  798. + pi/2)/x)
  799. def test_acsch_fdiff():
  800. x = Symbol('x')
  801. raises(ArgumentIndexError, lambda: acsch(x).fdiff(2))
  802. def test_atanh():
  803. x = Symbol('x')
  804. # at specific points
  805. assert atanh(0) == 0
  806. assert atanh(I) == I*pi/4
  807. assert atanh(-I) == -I*pi/4
  808. assert atanh(1) is oo
  809. assert atanh(-1) is -oo
  810. assert atanh(nan) is nan
  811. # at infinites
  812. assert atanh(oo) == -I*pi/2
  813. assert atanh(-oo) == I*pi/2
  814. assert atanh(I*oo) == I*pi/2
  815. assert atanh(-I*oo) == -I*pi/2
  816. assert atanh(zoo) == I*AccumBounds(-pi/2, pi/2)
  817. # properties
  818. assert atanh(-x) == -atanh(x)
  819. # reality
  820. assert atanh(S(2)).is_real is False
  821. assert atanh(S(-1)/5).is_real is True
  822. assert atanh(symbols('y', extended_real=True)).is_real is None
  823. assert atanh(S(1)).is_real is False
  824. assert atanh(S(1)).is_extended_real is True
  825. assert atanh(S(-1)).is_real is False
  826. # special values
  827. assert atanh(I/sqrt(3)) == I*pi/6
  828. assert atanh(-I/sqrt(3)) == -I*pi/6
  829. assert atanh(I*sqrt(3)) == I*pi/3
  830. assert atanh(-I*sqrt(3)) == -I*pi/3
  831. assert atanh(I*(1 + sqrt(2))) == pi*I*Rational(3, 8)
  832. assert atanh(I*(sqrt(2) - 1)) == pi*I/8
  833. assert atanh(I*(1 - sqrt(2))) == -pi*I/8
  834. assert atanh(-I*(1 + sqrt(2))) == pi*I*Rational(-3, 8)
  835. assert atanh(I*sqrt(5 + 2*sqrt(5))) == I*pi*Rational(2, 5)
  836. assert atanh(-I*sqrt(5 + 2*sqrt(5))) == I*pi*Rational(-2, 5)
  837. assert atanh(I*(2 - sqrt(3))) == pi*I/12
  838. assert atanh(I*(sqrt(3) - 2)) == -pi*I/12
  839. assert atanh(oo) == -I*pi/2
  840. # Symmetry
  841. assert atanh(Rational(-1, 2)) == -atanh(S.Half)
  842. # inverse composition
  843. assert unchanged(atanh, tanh(Symbol('v1')))
  844. assert atanh(tanh(-5, evaluate=False)) == -5
  845. assert atanh(tanh(0, evaluate=False)) == 0
  846. assert atanh(tanh(7, evaluate=False)) == 7
  847. assert atanh(tanh(I, evaluate=False)) == I
  848. assert atanh(tanh(-I, evaluate=False)) == -I
  849. assert atanh(tanh(-11*I, evaluate=False)) == -11*I + 4*I*pi
  850. assert atanh(tanh(3 + I)) == 3 + I
  851. assert atanh(tanh(4 + 5*I)) == 4 - 2*I*pi + 5*I
  852. assert atanh(tanh(pi/2)) == pi/2
  853. assert atanh(tanh(pi)) == pi
  854. assert atanh(tanh(-3 + 7*I)) == -3 - 2*I*pi + 7*I
  855. assert atanh(tanh(9 - I*2/3)) == 9 - I*2/3
  856. assert atanh(tanh(-32 - 123*I)) == -32 - 123*I + 39*I*pi
  857. def test_atanh_rewrite():
  858. x = Symbol('x')
  859. assert atanh(x).rewrite(log) == (log(1 + x) - log(1 - x)) / 2
  860. assert atanh(x).rewrite(asinh) == \
  861. 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)
  862. def test_atanh_leading_term():
  863. x = Symbol('x')
  864. assert atanh(x).as_leading_term(x) == x
  865. # Tests concerning branch points
  866. assert atanh(x + 1).as_leading_term(x, cdir=1) == -log(x)/2 + log(2)/2 - I*pi/2
  867. assert atanh(x + 1).as_leading_term(x, cdir=-1) == -log(x)/2 + log(2)/2 + I*pi/2
  868. assert atanh(x - 1).as_leading_term(x, cdir=1) == log(x)/2 - log(2)/2
  869. assert atanh(x - 1).as_leading_term(x, cdir=-1) == log(x)/2 - log(2)/2
  870. assert atanh(1/x).as_leading_term(x, cdir=1) == -I*pi/2
  871. assert atanh(1/x).as_leading_term(x, cdir=-1) == I*pi/2
  872. # Tests concerning points lying on branch cuts
  873. assert atanh(I*x + 2).as_leading_term(x, cdir=1) == atanh(2) + I*pi
  874. assert atanh(-I*x + 2).as_leading_term(x, cdir=1) == atanh(2)
  875. assert atanh(I*x - 2).as_leading_term(x, cdir=1) == -atanh(2)
  876. assert atanh(-I*x - 2).as_leading_term(x, cdir=1) == -I*pi - atanh(2)
  877. # Tests concerning im(ndir) == 0
  878. assert atanh(-I*x**2 + x - 2).as_leading_term(x, cdir=1) == -log(3)/2 - I*pi/2
  879. assert atanh(-I*x**2 + x - 2).as_leading_term(x, cdir=-1) == -log(3)/2 - I*pi/2
  880. def test_atanh_series():
  881. x = Symbol('x')
  882. assert atanh(x).series(x, 0, 10) == \
  883. x + x**3/3 + x**5/5 + x**7/7 + x**9/9 + O(x**10)
  884. def test_atanh_nseries():
  885. x = Symbol('x')
  886. # Tests concerning branch points
  887. assert atanh(x + 1)._eval_nseries(x, 4, None, cdir=1) == -I*pi/2 + log(2)/2 - \
  888. log(x)/2 + x/4 - x**2/16 + x**3/48 + O(x**4)
  889. assert atanh(x + 1)._eval_nseries(x, 4, None, cdir=-1) == I*pi/2 + log(2)/2 - \
  890. log(x)/2 + x/4 - x**2/16 + x**3/48 + O(x**4)
  891. assert atanh(x - 1)._eval_nseries(x, 4, None, cdir=1) == -log(2)/2 + log(x)/2 + \
  892. x/4 + x**2/16 + x**3/48 + O(x**4)
  893. assert atanh(x - 1)._eval_nseries(x, 4, None, cdir=-1) == -log(2)/2 + log(x)/2 + \
  894. x/4 + x**2/16 + x**3/48 + O(x**4)
  895. # Tests concerning points lying on branch cuts
  896. assert atanh(I*x + 2)._eval_nseries(x, 4, None, cdir=1) == I*pi + atanh(2) - \
  897. I*x/3 - 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  898. assert atanh(I*x + 2)._eval_nseries(x, 4, None, cdir=-1) == atanh(2) - I*x/3 - \
  899. 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  900. assert atanh(I*x - 2)._eval_nseries(x, 4, None, cdir=1) == -atanh(2) - I*x/3 + \
  901. 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  902. assert atanh(I*x - 2)._eval_nseries(x, 4, None, cdir=-1) == -atanh(2) - I*pi - \
  903. I*x/3 + 2*x**2/9 + 13*I*x**3/81 + O(x**4)
  904. # Tests concerning im(ndir) == 0
  905. assert atanh(-I*x**2 + x - 2)._eval_nseries(x, 4, None) == -I*pi/2 - log(3)/2 - x/3 + \
  906. 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)
  907. def test_atanh_fdiff():
  908. x = Symbol('x')
  909. raises(ArgumentIndexError, lambda: atanh(x).fdiff(2))
  910. def test_acoth():
  911. x = Symbol('x')
  912. #at specific points
  913. assert acoth(0) == I*pi/2
  914. assert acoth(I) == -I*pi/4
  915. assert acoth(-I) == I*pi/4
  916. assert acoth(1) is oo
  917. assert acoth(-1) is -oo
  918. assert acoth(nan) is nan
  919. # at infinites
  920. assert acoth(oo) == 0
  921. assert acoth(-oo) == 0
  922. assert acoth(I*oo) == 0
  923. assert acoth(-I*oo) == 0
  924. assert acoth(zoo) == 0
  925. #properties
  926. assert acoth(-x) == -acoth(x)
  927. assert acoth(I/sqrt(3)) == -I*pi/3
  928. assert acoth(-I/sqrt(3)) == I*pi/3
  929. assert acoth(I*sqrt(3)) == -I*pi/6
  930. assert acoth(-I*sqrt(3)) == I*pi/6
  931. assert acoth(I*(1 + sqrt(2))) == -pi*I/8
  932. assert acoth(-I*(sqrt(2) + 1)) == pi*I/8
  933. assert acoth(I*(1 - sqrt(2))) == pi*I*Rational(3, 8)
  934. assert acoth(I*(sqrt(2) - 1)) == pi*I*Rational(-3, 8)
  935. assert acoth(I*sqrt(5 + 2*sqrt(5))) == -I*pi/10
  936. assert acoth(-I*sqrt(5 + 2*sqrt(5))) == I*pi/10
  937. assert acoth(I*(2 + sqrt(3))) == -pi*I/12
  938. assert acoth(-I*(2 + sqrt(3))) == pi*I/12
  939. assert acoth(I*(2 - sqrt(3))) == pi*I*Rational(-5, 12)
  940. assert acoth(I*(sqrt(3) - 2)) == pi*I*Rational(5, 12)
  941. # reality
  942. assert acoth(S(2)).is_real is True
  943. assert acoth(S(2)).is_finite is True
  944. assert acoth(S(2)).is_extended_real is True
  945. assert acoth(S(-2)).is_real is True
  946. assert acoth(S(1)).is_real is False
  947. assert acoth(S(1)).is_extended_real is True
  948. assert acoth(S(-1)).is_real is False
  949. assert acoth(symbols('y', real=True)).is_real is None
  950. # Symmetry
  951. assert acoth(Rational(-1, 2)) == -acoth(S.Half)
  952. def test_acoth_rewrite():
  953. x = Symbol('x')
  954. assert acoth(x).rewrite(log) == (log(1 + 1/x) - log(1 - 1/x)) / 2
  955. assert acoth(x).rewrite(atanh) == atanh(1/x)
  956. assert acoth(x).rewrite(asinh) == \
  957. 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
  958. def test_acoth_leading_term():
  959. x = Symbol('x')
  960. # Tests concerning branch points
  961. assert acoth(x + 1).as_leading_term(x, cdir=1) == -log(x)/2 + log(2)/2
  962. assert acoth(x + 1).as_leading_term(x, cdir=-1) == -log(x)/2 + log(2)/2
  963. assert acoth(x - 1).as_leading_term(x, cdir=1) == log(x)/2 - log(2)/2 + I*pi/2
  964. assert acoth(x - 1).as_leading_term(x, cdir=-1) == log(x)/2 - log(2)/2 - I*pi/2
  965. # Tests concerning points lying on branch cuts
  966. assert acoth(x).as_leading_term(x, cdir=-1) == I*pi/2
  967. assert acoth(x).as_leading_term(x, cdir=1) == -I*pi/2
  968. assert acoth(I*x + 1/2).as_leading_term(x, cdir=1) == acoth(1/2)
  969. assert acoth(-I*x + 1/2).as_leading_term(x, cdir=1) == acoth(1/2) + I*pi
  970. assert acoth(I*x - 1/2).as_leading_term(x, cdir=1) == -I*pi - acoth(1/2)
  971. assert acoth(-I*x - 1/2).as_leading_term(x, cdir=1) == -acoth(1/2)
  972. # Tests concerning im(ndir) == 0
  973. assert acoth(-I*x**2 - x - S(1)/2).as_leading_term(x, cdir=1) == -log(3)/2 + I*pi/2
  974. assert acoth(-I*x**2 - x - S(1)/2).as_leading_term(x, cdir=-1) == -log(3)/2 + I*pi/2
  975. def test_acoth_series():
  976. x = Symbol('x')
  977. assert acoth(x).series(x, 0, 10) == \
  978. -I*pi/2 + x + x**3/3 + x**5/5 + x**7/7 + x**9/9 + O(x**10)
  979. def test_acoth_nseries():
  980. x = Symbol('x')
  981. # Tests concerning branch points
  982. assert acoth(x + 1)._eval_nseries(x, 4, None) == log(2)/2 - log(x)/2 + x/4 - \
  983. x**2/16 + x**3/48 + O(x**4)
  984. assert acoth(x - 1)._eval_nseries(x, 4, None, cdir=1) == I*pi/2 - log(2)/2 + \
  985. log(x)/2 + x/4 + x**2/16 + x**3/48 + O(x**4)
  986. assert acoth(x - 1)._eval_nseries(x, 4, None, cdir=-1) == -I*pi/2 - log(2)/2 + \
  987. log(x)/2 + x/4 + x**2/16 + x**3/48 + O(x**4)
  988. # Tests concerning points lying on branch cuts
  989. assert acoth(I*x + S(1)/2)._eval_nseries(x, 4, None, cdir=1) == acoth(S(1)/2) + \
  990. 4*I*x/3 - 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  991. assert acoth(I*x + S(1)/2)._eval_nseries(x, 4, None, cdir=-1) == I*pi + \
  992. acoth(S(1)/2) + 4*I*x/3 - 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  993. assert acoth(I*x - S(1)/2)._eval_nseries(x, 4, None, cdir=1) == -acoth(S(1)/2) - \
  994. I*pi + 4*I*x/3 + 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  995. assert acoth(I*x - S(1)/2)._eval_nseries(x, 4, None, cdir=-1) == -acoth(S(1)/2) + \
  996. 4*I*x/3 + 8*x**2/9 - 112*I*x**3/81 + O(x**4)
  997. # Tests concerning im(ndir) == 0
  998. assert acoth(-I*x**2 - x - S(1)/2)._eval_nseries(x, 4, None) == I*pi/2 - log(3)/2 - \
  999. 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)
  1000. def test_acoth_fdiff():
  1001. x = Symbol('x')
  1002. raises(ArgumentIndexError, lambda: acoth(x).fdiff(2))
  1003. def test_inverses():
  1004. x = Symbol('x')
  1005. assert sinh(x).inverse() == asinh
  1006. raises(AttributeError, lambda: cosh(x).inverse())
  1007. assert tanh(x).inverse() == atanh
  1008. assert coth(x).inverse() == acoth
  1009. assert asinh(x).inverse() == sinh
  1010. assert acosh(x).inverse() == cosh
  1011. assert atanh(x).inverse() == tanh
  1012. assert acoth(x).inverse() == coth
  1013. assert asech(x).inverse() == sech
  1014. assert acsch(x).inverse() == csch
  1015. def test_leading_term():
  1016. x = Symbol('x')
  1017. assert cosh(x).as_leading_term(x) == 1
  1018. assert coth(x).as_leading_term(x) == 1/x
  1019. for func in [sinh, tanh]:
  1020. assert func(x).as_leading_term(x) == x
  1021. for func in [sinh, cosh, tanh, coth]:
  1022. for ar in (1/x, S.Half):
  1023. eq = func(ar)
  1024. assert eq.as_leading_term(x) == eq
  1025. for func in [csch, sech]:
  1026. eq = func(S.Half)
  1027. assert eq.as_leading_term(x) == eq
  1028. def test_complex():
  1029. a, b = symbols('a,b', real=True)
  1030. z = a + b*I
  1031. for func in [sinh, cosh, tanh, coth, sech, csch]:
  1032. assert func(z).conjugate() == func(a - b*I)
  1033. for deep in [True, False]:
  1034. assert sinh(z).expand(
  1035. complex=True, deep=deep) == sinh(a)*cos(b) + I*cosh(a)*sin(b)
  1036. assert cosh(z).expand(
  1037. complex=True, deep=deep) == cosh(a)*cos(b) + I*sinh(a)*sin(b)
  1038. assert tanh(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
  1039. a)/(cos(b)**2 + sinh(a)**2) + I*sin(b)*cos(b)/(cos(b)**2 + sinh(a)**2)
  1040. assert coth(z).expand(complex=True, deep=deep) == sinh(a)*cosh(
  1041. a)/(sin(b)**2 + sinh(a)**2) - I*sin(b)*cos(b)/(sin(b)**2 + sinh(a)**2)
  1042. assert csch(z).expand(complex=True, deep=deep) == cos(b) * sinh(a) / (sin(b)**2\
  1043. *cosh(a)**2 + cos(b)**2 * sinh(a)**2) - I*sin(b) * cosh(a) / (sin(b)**2\
  1044. *cosh(a)**2 + cos(b)**2 * sinh(a)**2)
  1045. assert sech(z).expand(complex=True, deep=deep) == cos(b) * cosh(a) / (sin(b)**2\
  1046. *sinh(a)**2 + cos(b)**2 * cosh(a)**2) - I*sin(b) * sinh(a) / (sin(b)**2\
  1047. *sinh(a)**2 + cos(b)**2 * cosh(a)**2)
  1048. def test_complex_2899():
  1049. a, b = symbols('a,b', real=True)
  1050. for deep in [True, False]:
  1051. for func in [sinh, cosh, tanh, coth]:
  1052. assert func(a).expand(complex=True, deep=deep) == func(a)
  1053. def test_simplifications():
  1054. x = Symbol('x')
  1055. assert sinh(asinh(x)) == x
  1056. assert sinh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1)
  1057. assert sinh(atanh(x)) == x/sqrt(1 - x**2)
  1058. assert sinh(acoth(x)) == 1/(sqrt(x - 1) * sqrt(x + 1))
  1059. assert cosh(asinh(x)) == sqrt(1 + x**2)
  1060. assert cosh(acosh(x)) == x
  1061. assert cosh(atanh(x)) == 1/sqrt(1 - x**2)
  1062. assert cosh(acoth(x)) == x/(sqrt(x - 1) * sqrt(x + 1))
  1063. assert tanh(asinh(x)) == x/sqrt(1 + x**2)
  1064. assert tanh(acosh(x)) == sqrt(x - 1) * sqrt(x + 1) / x
  1065. assert tanh(atanh(x)) == x
  1066. assert tanh(acoth(x)) == 1/x
  1067. assert coth(asinh(x)) == sqrt(1 + x**2)/x
  1068. assert coth(acosh(x)) == x/(sqrt(x - 1) * sqrt(x + 1))
  1069. assert coth(atanh(x)) == 1/x
  1070. assert coth(acoth(x)) == x
  1071. assert csch(asinh(x)) == 1/x
  1072. assert csch(acosh(x)) == 1/(sqrt(x - 1) * sqrt(x + 1))
  1073. assert csch(atanh(x)) == sqrt(1 - x**2)/x
  1074. assert csch(acoth(x)) == sqrt(x - 1) * sqrt(x + 1)
  1075. assert sech(asinh(x)) == 1/sqrt(1 + x**2)
  1076. assert sech(acosh(x)) == 1/x
  1077. assert sech(atanh(x)) == sqrt(1 - x**2)
  1078. assert sech(acoth(x)) == sqrt(x - 1) * sqrt(x + 1)/x
  1079. def test_issue_4136():
  1080. assert cosh(asinh(Integer(3)/2)) == sqrt(Integer(13)/4)
  1081. def test_sinh_rewrite():
  1082. x = Symbol('x')
  1083. assert sinh(x).rewrite(exp) == (exp(x) - exp(-x))/2 \
  1084. == sinh(x).rewrite('tractable')
  1085. assert sinh(x).rewrite(cosh) == -I*cosh(x + I*pi/2)
  1086. tanh_half = tanh(S.Half*x)
  1087. assert sinh(x).rewrite(tanh) == 2*tanh_half/(1 - tanh_half**2)
  1088. coth_half = coth(S.Half*x)
  1089. assert sinh(x).rewrite(coth) == 2*coth_half/(coth_half**2 - 1)
  1090. def test_cosh_rewrite():
  1091. x = Symbol('x')
  1092. assert cosh(x).rewrite(exp) == (exp(x) + exp(-x))/2 \
  1093. == cosh(x).rewrite('tractable')
  1094. assert cosh(x).rewrite(sinh) == -I*sinh(x + I*pi/2, evaluate=False)
  1095. tanh_half = tanh(S.Half*x)**2
  1096. assert cosh(x).rewrite(tanh) == (1 + tanh_half)/(1 - tanh_half)
  1097. coth_half = coth(S.Half*x)**2
  1098. assert cosh(x).rewrite(coth) == (coth_half + 1)/(coth_half - 1)
  1099. def test_tanh_rewrite():
  1100. x = Symbol('x')
  1101. assert tanh(x).rewrite(exp) == (exp(x) - exp(-x))/(exp(x) + exp(-x)) \
  1102. == tanh(x).rewrite('tractable')
  1103. assert tanh(x).rewrite(sinh) == I*sinh(x)/sinh(I*pi/2 - x, evaluate=False)
  1104. assert tanh(x).rewrite(cosh) == I*cosh(I*pi/2 - x, evaluate=False)/cosh(x)
  1105. assert tanh(x).rewrite(coth) == 1/coth(x)
  1106. def test_coth_rewrite():
  1107. x = Symbol('x')
  1108. assert coth(x).rewrite(exp) == (exp(x) + exp(-x))/(exp(x) - exp(-x)) \
  1109. == coth(x).rewrite('tractable')
  1110. assert coth(x).rewrite(sinh) == -I*sinh(I*pi/2 - x, evaluate=False)/sinh(x)
  1111. assert coth(x).rewrite(cosh) == -I*cosh(x)/cosh(I*pi/2 - x, evaluate=False)
  1112. assert coth(x).rewrite(tanh) == 1/tanh(x)
  1113. def test_csch_rewrite():
  1114. x = Symbol('x')
  1115. assert csch(x).rewrite(exp) == 1 / (exp(x)/2 - exp(-x)/2) \
  1116. == csch(x).rewrite('tractable')
  1117. assert csch(x).rewrite(cosh) == I/cosh(x + I*pi/2, evaluate=False)
  1118. tanh_half = tanh(S.Half*x)
  1119. assert csch(x).rewrite(tanh) == (1 - tanh_half**2)/(2*tanh_half)
  1120. coth_half = coth(S.Half*x)
  1121. assert csch(x).rewrite(coth) == (coth_half**2 - 1)/(2*coth_half)
  1122. def test_sech_rewrite():
  1123. x = Symbol('x')
  1124. assert sech(x).rewrite(exp) == 1 / (exp(x)/2 + exp(-x)/2) \
  1125. == sech(x).rewrite('tractable')
  1126. assert sech(x).rewrite(sinh) == I/sinh(x + I*pi/2, evaluate=False)
  1127. tanh_half = tanh(S.Half*x)**2
  1128. assert sech(x).rewrite(tanh) == (1 - tanh_half)/(1 + tanh_half)
  1129. coth_half = coth(S.Half*x)**2
  1130. assert sech(x).rewrite(coth) == (coth_half - 1)/(coth_half + 1)
  1131. def test_derivs():
  1132. x = Symbol('x')
  1133. assert coth(x).diff(x) == -sinh(x)**(-2)
  1134. assert sinh(x).diff(x) == cosh(x)
  1135. assert cosh(x).diff(x) == sinh(x)
  1136. assert tanh(x).diff(x) == -tanh(x)**2 + 1
  1137. assert csch(x).diff(x) == -coth(x)*csch(x)
  1138. assert sech(x).diff(x) == -tanh(x)*sech(x)
  1139. assert acoth(x).diff(x) == 1/(-x**2 + 1)
  1140. assert asinh(x).diff(x) == 1/sqrt(x**2 + 1)
  1141. assert acosh(x).diff(x) == 1/(sqrt(x - 1)*sqrt(x + 1))
  1142. assert acosh(x).diff(x) == acosh(x).rewrite(log).diff(x).together()
  1143. assert atanh(x).diff(x) == 1/(-x**2 + 1)
  1144. assert asech(x).diff(x) == -1/(x*sqrt(1 - x**2))
  1145. assert acsch(x).diff(x) == -1/(x**2*sqrt(1 + x**(-2)))
  1146. def test_sinh_expansion():
  1147. x, y = symbols('x,y')
  1148. assert sinh(x+y).expand(trig=True) == sinh(x)*cosh(y) + cosh(x)*sinh(y)
  1149. assert sinh(2*x).expand(trig=True) == 2*sinh(x)*cosh(x)
  1150. assert sinh(3*x).expand(trig=True).expand() == \
  1151. sinh(x)**3 + 3*sinh(x)*cosh(x)**2
  1152. def test_cosh_expansion():
  1153. x, y = symbols('x,y')
  1154. assert cosh(x+y).expand(trig=True) == cosh(x)*cosh(y) + sinh(x)*sinh(y)
  1155. assert cosh(2*x).expand(trig=True) == cosh(x)**2 + sinh(x)**2
  1156. assert cosh(3*x).expand(trig=True).expand() == \
  1157. 3*sinh(x)**2*cosh(x) + cosh(x)**3
  1158. def test_cosh_positive():
  1159. # See issue 11721
  1160. # cosh(x) is positive for real values of x
  1161. k = symbols('k', real=True)
  1162. n = symbols('n', integer=True)
  1163. assert cosh(k, evaluate=False).is_positive is True
  1164. assert cosh(k + 2*n*pi*I, evaluate=False).is_positive is True
  1165. assert cosh(I*pi/4, evaluate=False).is_positive is True
  1166. assert cosh(3*I*pi/4, evaluate=False).is_positive is False
  1167. def test_cosh_nonnegative():
  1168. k = symbols('k', real=True)
  1169. n = symbols('n', integer=True)
  1170. assert cosh(k, evaluate=False).is_nonnegative is True
  1171. assert cosh(k + 2*n*pi*I, evaluate=False).is_nonnegative is True
  1172. assert cosh(I*pi/4, evaluate=False).is_nonnegative is True
  1173. assert cosh(3*I*pi/4, evaluate=False).is_nonnegative is False
  1174. assert cosh(S.Zero, evaluate=False).is_nonnegative is True
  1175. def test_real_assumptions():
  1176. z = Symbol('z', real=False)
  1177. assert sinh(z).is_real is None
  1178. assert cosh(z).is_real is None
  1179. assert tanh(z).is_real is None
  1180. assert sech(z).is_real is None
  1181. assert csch(z).is_real is None
  1182. assert coth(z).is_real is None
  1183. def test_sign_assumptions():
  1184. p = Symbol('p', positive=True)
  1185. n = Symbol('n', negative=True)
  1186. assert sinh(n).is_negative is True
  1187. assert sinh(p).is_positive is True
  1188. assert cosh(n).is_positive is True
  1189. assert cosh(p).is_positive is True
  1190. assert tanh(n).is_negative is True
  1191. assert tanh(p).is_positive is True
  1192. assert csch(n).is_negative is True
  1193. assert csch(p).is_positive is True
  1194. assert sech(n).is_positive is True
  1195. assert sech(p).is_positive is True
  1196. assert coth(n).is_negative is True
  1197. assert coth(p).is_positive is True
  1198. def test_issue_25847():
  1199. x = Symbol('x')
  1200. #atanh
  1201. assert atanh(sin(x)/x).as_leading_term(x) == atanh(sin(x)/x)
  1202. raises(PoleError, lambda: atanh(exp(1/x)).as_leading_term(x))
  1203. #asinh
  1204. assert asinh(sin(x)/x).as_leading_term(x) == log(1 + sqrt(2))
  1205. raises(PoleError, lambda: asinh(exp(1/x)).as_leading_term(x))
  1206. #acosh
  1207. assert acosh(sin(x)/x).as_leading_term(x) == 0
  1208. raises(PoleError, lambda: acosh(exp(1/x)).as_leading_term(x))
  1209. #acoth
  1210. assert acoth(sin(x)/x).as_leading_term(x) == acoth(sin(x)/x)
  1211. raises(PoleError, lambda: acoth(exp(1/x)).as_leading_term(x))
  1212. #asech
  1213. assert asech(sinh(x)/x).as_leading_term(x) == 0
  1214. raises(PoleError, lambda: asech(exp(1/x)).as_leading_term(x))
  1215. #acsch
  1216. assert acsch(sin(x)/x).as_leading_term(x) == log(1 + sqrt(2))
  1217. raises(PoleError, lambda: acsch(exp(1/x)).as_leading_term(x))
  1218. def test_issue_25175():
  1219. x = Symbol('x')
  1220. g1 = 2*acosh(1 + 2*x/3) - acosh(S(5)/3 - S(8)/3/(x + 4))
  1221. g2 = 2*log(sqrt((x + 4)/3)*(sqrt(x + 3)+sqrt(x))**2/(2*sqrt(x + 3) + sqrt(x)))
  1222. assert (g1 - g2).series(x) == O(x**6)