Possible bug in the mathematica interface

24 views
Skip to first unread message

Emmanuel Charpentier

unread,
Jul 9, 2023, 9:01:23 PM7/9/23
to sage-support

Inspiration : this ask.sagemath.org question.

Using the Wolfram engine gives me a curious and nonsensical conversion. Compare :

sage: mathematica("Sum[%s, %s]"%tuple(map(lambda u:repr(mathematica(u)), ((1+(-1)^k)*x^k, [k , 0, oo])))) -2/(-1 + x^2) # Correct sage: mathematica.Sum(*map(mathematica, ((1+(-1)^k)*x^k, [k , 0, oo]))) {(1 + (-1)^k)*k*x^k, 0, (1 + (-1)^k)*x^k*Infinity} # Nonsensical

I think that this signs a bug in the Mathematica conversion of sum. Can someone check me with the “full blown” Mathematica interpreter before I open an new issue ?

Thanks in advance…

Jan Groenewald

unread,
Jul 9, 2023, 9:45:59 PM7/9/23
to sage-s...@googlegroups.com
Debian 12, Sage 9.5 (debian package), Mathematica 13.3

sage: mathematica("Sum[%s, %s]"%tuple(map(lambda u:repr(mathematica(u)), ((1+(-1
....: )^k)*x^k, [k , 0, oo]))))
-2/(-1 + x^2)

sage: mathematica.Sum(*map(mathematica, ((1+(-1)^k)*x^k, [k , 0, oo])))
{(1 + (-1)^k)*k*x^k, 0, (1 + (-1)^k)*x^k*Infinity}

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/03eb02e5-6872-4479-8f30-ee2e92606b2an%40googlegroups.com.

Emmanuel Charpentier

unread,
Jul 10, 2023, 6:25:45 PM7/10/23
to sage-support

Well, it’s a bit more intricate than I thought initially :

sage: reset() sage: k = var("k") sage: Ex = (1 + (-1)^k)*x^k sage: sum(Ex, k, 0, oo) sum(((-1)^k + 1)*x^k, k, 0, +Infinity)

Sage (i. e. Maxima) can’t solve it.

sage: sum(Ex, k, 0, oo, algorithm="giac") 1/(x + 1) - 1/(x - 1)

Giac does

sage: sum(Ex, k, 0, oo)._sympy_().doit() Piecewise((1/(1 - x), Abs(x) < 1), (Sum(x**k, (k, 0, oo)), True)) + Piecewise((1/(x + 1), Abs(x) < 1), (Sum((-1)**k*x**k, (k, 0, oo)), True))

Sympy does, gives an important precision (radius of convergence), but this answer can’t (yet) be (automatically) translated to Sage

sage: Ex._mathematica_().Sum(mathematica([k, 0, oo])) {(1 + (-1)^k)*k*x^k, 0, (1 + (-1)^k)*x^k*Infinity}

Applying the Sum (Mathematica) method to the Ex object (automatically translated to Mathematica) gives a nonsensical answer

sage: mathematica.Sum(*map(mathematica, (Ex, [k, 0, oo]))) {(1 + (-1)^k)*k*x^k, 0, (1 + (-1)^k)*x^k*Infinity}

Ditto when calling the mathematica.Sum function to the (manually translated) arguments.

sage: mathematica("Sum[%s, %s]"%tuple(map(lambda u:repr(mathematica(u)), (Ex, [k, 0, oo])))) -2/(-1 + x^2)

But passing to the interpreter a (manually built) string representting the function call works.

Not obvious to report…

Reply all
Reply to author
Forward
0 new messages