Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Inconsistent/incorrect value of limit involving tan and tanh

Out of sheer curiosity I tried to compute $\lim_{x \rightarrow \infty} \frac{d}{dx} \log \tan (\frac \pi 2 \tanh x)$, and found that the maxima engine disagrees on how to take the limit. I am not particularly great at math but I thought it would be interesting to "compare" the horizontal and vertical asymptotes of tanh and tan like this.

It returns something different for the original expression within the limit versus simplify_full, reduce_trig, and exponentialize. Other algorithms variously either fail or return 2, but maxima will confidently report 0 if the expression is not simplified. Presumably it is tempted by the division-by-infinity and multiplication-by-zero, but isn't that the point of taking limits?

sage: fun = diff(log(tan(pi/2 * tanh(x))), x)
sage: simplifications = [lambda x: x, attrcall('simplify_full'), attrcall('reduce_trig'), attrcall('exponentialize')]
sage: algorithms = ['maxima', 'giac', 'fricas', 'mathematica_free']
sage: for simplification in simplifications:
....:     simplified = simplification(fun)
....:     print("Simplified:", simplified)
....:     for algorithm in algorithms:
....:         print(algorithm, limit(simplified, x=infinity, algorithm=algorithm))
....:     print()
....: 
Simplified: -1/2*pi*(tan(1/2*pi*tanh(x))^2 + 1)*(tanh(x)^2 - 1)/tan(1/2*pi*tanh(x))
maxima 0
giac 2
fricas failed
mathematica_free 2

Simplified: 1/2*pi/(cos(1/2*pi*sinh(x)/cosh(x))*cosh(x)^2*sin(1/2*pi*sinh(x)/cosh(x)))
maxima 1/2*pi*limit(1/(cos(1/2*pi*sinh(x)/cosh(x))*cosh(x)^2*sin(1/2*pi*sinh(x)/cosh(x))), x, +Infinity)
giac 2
fricas failed
mathematica_free 2

Simplified: 1/2*pi*cot(1/2*pi*tanh(x))*sec(1/2*pi*tanh(x))^2*sech(x)^2
maxima und
giac 2
fricas failed
mathematica_free 2

Simplified: -1/2*pi*((e^(-x) - e^x)^2/(e^(-x) + e^x)^2 - 1)*((I*e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) - I*e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))^2/(e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) + e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))^2 + 1)*(e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) + e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))/(I*e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) - I*e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))
maxima 2
giac 2
fricas failed
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [105], line 5
      3 print("Simplified:", simplified)
      4 for algorithm in algorithms:
----> 5     print(algorithm, limit(simplified, x=infinity, algorithm=algorithm))
      6 print()

File /usr/lib/python3.10/site-packages/sage/calculus/calculus.py:1461, in limit(ex, dir, taylor, algorithm, **argv)
   1459         l = libgiac.limit(ex, v, a, -1).sage()
   1460 elif algorithm == 'mathematica_free':
-> 1461     return mma_free_limit(ex, v, a, dir)
   1462 else:
   1463     raise ValueError("Unknown algorithm: %s" % algorithm)

File /usr/lib/python3.10/site-packages/sage/calculus/calculus.py:1510, in mma_free_limit(expression, v, a, dir)
   1508     raise ValueError('wrong input for limit')
   1509 json_page_data = request_wolfram_alpha(input)
-> 1510 all_outputs = parse_moutput_from_json(json_page_data)
   1511 if not all_outputs:
   1512     raise ValueError("no outputs found in the answer from Wolfram Alpha")

File /usr/lib/python3.10/site-packages/sage/interfaces/mathematica.py:1284, in parse_moutput_from_json(page_data, verbose)
   1282 queryresult = page_data['queryresult']
   1283 if not queryresult['success']:
-> 1284     raise ValueError('asking wolframalpha.com was not successful')
   1285 if 'pods' not in queryresult:
   1286     raise ValueError('json object contains no pods')

ValueError: asking wolframalpha.com was not successful

The sympy algorithm was excluded from the above because it seems to be much worse behaved than the others. For the same suite of simplifications above, it respectively returns [hangs forever], 2, "conversion to SageMath is not implemented", "maximum recursion depth exceeded".

Is the maxima behaviour here a bug, and if so, where should I report it? (And if anyone off the top of their head knows any interesting identities around this expression, that would be cool too 🙂)

Inconsistent/incorrect value of limit involving tan and tanh

Out of sheer curiosity I tried to compute $\lim_{x \rightarrow \infty} \frac{d}{dx} \log \tan (\frac \pi 2 \tanh x)$, and found that the maxima engine disagrees on how to take the limit. I am not particularly great at math but I thought it would be interesting to "compare" the horizontal and vertical asymptotes of tanh and tan like this.

It returns something different for the original expression within the limit versus simplify_full, reduce_trig, and exponentialize. Other algorithms variously either fail or return 2, but maxima will confidently report 0 if the expression is not simplified. Presumably it is tempted by the division-by-infinity and multiplication-by-zero, but isn't that the point of taking limits?

sage: fun = diff(log(tan(pi/2 * tanh(x))), x)
sage: simplifications = [lambda x: x, attrcall('simplify_full'), attrcall('reduce_trig'), attrcall('exponentialize')]
sage: algorithms = ['maxima', 'giac', 'fricas', 'mathematica_free']
sage: for simplification in simplifications:
....:     simplified = simplification(fun)
....:     print("Simplified:", simplified)
....:     for algorithm in algorithms:
....:         print(algorithm, limit(simplified, x=infinity, algorithm=algorithm))
....:     print()
....: 
Simplified: -1/2*pi*(tan(1/2*pi*tanh(x))^2 + 1)*(tanh(x)^2 - 1)/tan(1/2*pi*tanh(x))
maxima 0
giac 2
fricas failed
mathematica_free 2

Simplified: 1/2*pi/(cos(1/2*pi*sinh(x)/cosh(x))*cosh(x)^2*sin(1/2*pi*sinh(x)/cosh(x)))
maxima 1/2*pi*limit(1/(cos(1/2*pi*sinh(x)/cosh(x))*cosh(x)^2*sin(1/2*pi*sinh(x)/cosh(x))), x, +Infinity)
giac 2
fricas failed
mathematica_free 2

Simplified: 1/2*pi*cot(1/2*pi*tanh(x))*sec(1/2*pi*tanh(x))^2*sech(x)^2
maxima und
giac 2
fricas failed
mathematica_free 2

Simplified: -1/2*pi*((e^(-x) - e^x)^2/(e^(-x) + e^x)^2 - 1)*((I*e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) - I*e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))^2/(e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) + e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))^2 + 1)*(e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) + e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))/(I*e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) - I*e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))
maxima 2
giac 2
fricas failed
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [105], line 5
      3 print("Simplified:", simplified)
      4 for algorithm in algorithms:
----> 5     print(algorithm, limit(simplified, x=infinity, algorithm=algorithm))
      6 print()

File /usr/lib/python3.10/site-packages/sage/calculus/calculus.py:1461, in limit(ex, dir, taylor, algorithm, **argv)
   1459         l = libgiac.limit(ex, v, a, -1).sage()
   1460 elif algorithm == 'mathematica_free':
-> 1461     return mma_free_limit(ex, v, a, dir)
   1462 else:
   1463     raise ValueError("Unknown algorithm: %s" % algorithm)

File /usr/lib/python3.10/site-packages/sage/calculus/calculus.py:1510, in mma_free_limit(expression, v, a, dir)
   1508     raise ValueError('wrong input for limit')
   1509 json_page_data = request_wolfram_alpha(input)
-> 1510 all_outputs = parse_moutput_from_json(json_page_data)
   1511 if not all_outputs:
   1512     raise ValueError("no outputs found in the answer from Wolfram Alpha")

File /usr/lib/python3.10/site-packages/sage/interfaces/mathematica.py:1284, in parse_moutput_from_json(page_data, verbose)
   1282 queryresult = page_data['queryresult']
   1283 if not queryresult['success']:
-> 1284     raise ValueError('asking wolframalpha.com was not successful')
   1285 if 'pods' not in queryresult:
   1286     raise ValueError('json object contains no pods')

ValueError: asking wolframalpha.com was not successful

The sympy algorithm was excluded from the above because it seems to be much worse behaved than the others. For the same suite of simplifications above, it respectively returns [hangs forever], 2, "conversion to SageMath is not implemented", "maximum recursion depth exceeded".

Is the maxima behaviour here a bug, and if so, where should I report it? (And if anyone off the top of their head knows any interesting identities around this expression, that would be cool too 🙂)

Inconsistent/incorrect value of limit involving tan and tanh

Out of sheer curiosity I tried to compute $\lim_{x \rightarrow \infty} \frac{d}{dx} \log \tan (\frac \pi 2 \tanh x)$, and found that the maxima engine disagrees on how to take the limit. I am not particularly great at math but I thought it would be interesting to "compare" the horizontal and vertical asymptotes of tanh and tan like this.

It returns something different for the original expression within the limit versus simplify_full, reduce_trig, and exponentialize. Other algorithms variously either fail or return 2, but maxima will confidently report 0 if the expression is not simplified. Presumably it is tempted by the division-by-infinity and multiplication-by-zero, but isn't that the point of taking limits?

sage: fun = diff(log(tan(pi/2 * tanh(x))), x)
sage: simplifications = [lambda x: x, attrcall('simplify_full'), attrcall('reduce_trig'), attrcall('exponentialize')]
sage: algorithms = ['maxima', 'giac', 'fricas', 'mathematica_free']
sage: for simplification in simplifications:
....:     simplified = simplification(fun)
....:     print("Simplified:", simplified)
....:     for algorithm in algorithms:
....:         print(algorithm, limit(simplified, x=infinity, algorithm=algorithm))
....:     print()
....: 
Simplified: -1/2*pi*(tan(1/2*pi*tanh(x))^2 + 1)*(tanh(x)^2 - 1)/tan(1/2*pi*tanh(x))
maxima 0
giac 2
fricas failed
mathematica_free 2

Simplified: 1/2*pi/(cos(1/2*pi*sinh(x)/cosh(x))*cosh(x)^2*sin(1/2*pi*sinh(x)/cosh(x)))
maxima 1/2*pi*limit(1/(cos(1/2*pi*sinh(x)/cosh(x))*cosh(x)^2*sin(1/2*pi*sinh(x)/cosh(x))), x, +Infinity)
giac 2
fricas failed
mathematica_free 2

Simplified: 1/2*pi*cot(1/2*pi*tanh(x))*sec(1/2*pi*tanh(x))^2*sech(x)^2
maxima und
giac 2
fricas failed
mathematica_free 2

Simplified: -1/2*pi*((e^(-x) - e^x)^2/(e^(-x) + e^x)^2 - 1)*((I*e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) - I*e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))^2/(e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) + e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))^2 + 1)*(e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) + e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))/(I*e^(1/2*I*pi*e^(-x)/(e^(-x) + e^x) - 1/2*I*pi*e^x/(e^(-x) + e^x)) - I*e^(-1/2*I*pi*e^(-x)/(e^(-x) + e^x) + 1/2*I*pi*e^x/(e^(-x) + e^x)))
maxima 2
giac 2
fricas failed
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [105], line 5
      3 print("Simplified:", simplified)
      4 for algorithm in algorithms:
----> 5     print(algorithm, limit(simplified, x=infinity, algorithm=algorithm))
      6 print()

File /usr/lib/python3.10/site-packages/sage/calculus/calculus.py:1461, in limit(ex, dir, taylor, algorithm, **argv)
   1459         l = libgiac.limit(ex, v, a, -1).sage()
   1460 elif algorithm == 'mathematica_free':
-> 1461     return mma_free_limit(ex, v, a, dir)
   1462 else:
   1463     raise ValueError("Unknown algorithm: %s" % algorithm)

File /usr/lib/python3.10/site-packages/sage/calculus/calculus.py:1510, in mma_free_limit(expression, v, a, dir)
   1508     raise ValueError('wrong input for limit')
   1509 json_page_data = request_wolfram_alpha(input)
-> 1510 all_outputs = parse_moutput_from_json(json_page_data)
   1511 if not all_outputs:
   1512     raise ValueError("no outputs found in the answer from Wolfram Alpha")

File /usr/lib/python3.10/site-packages/sage/interfaces/mathematica.py:1284, in parse_moutput_from_json(page_data, verbose)
   1282 queryresult = page_data['queryresult']
   1283 if not queryresult['success']:
-> 1284     raise ValueError('asking wolframalpha.com was not successful')
   1285 if 'pods' not in queryresult:
   1286     raise ValueError('json object contains no pods')

ValueError: asking wolframalpha.com was not successful

The sympy algorithm was excluded from the above because it seems to be much worse behaved than the others. For the same suite of simplifications above, it respectively returns [hangs forever], 2, "conversion to SageMath is not implemented", "maximum recursion depth exceeded".

Is the maxima behaviour here a bug, and if so, where should I report it? (And if anyone off the top of their head knows any interesting identities around this expression, that would be cool too 🙂)