WolframResearch/WolframClientForPython

Truncation of exponents

Closed this issue · 2 comments

The package yields different results when done in python compared to mathematica.
Here's a working example.

from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr

session = WolframLanguageSession()

sys1 = '{-4.0*t0*t1 - 4.0*t0*t2 - 8.0*t0*t4 + 4.0*t1*t3 + 4.0*t2*t3 + 8.0*t3*t4, 4.0*t0*t2 - 4.0*t0*t3 - 8.0*t0*t4 + 8.0*t1*t2 + 4.0*t1*t3 + 8.0*t1*t4 + 8.0*t2*t3 + 12.0*t2*t4 + 4.0*t4^2, 8.0*t0*t4 - 4.0*t1*t3 + 4.0*t1*t4 - 4.0*t2*t3 + 4.0*t2*t4 + 8.0*t4^2, 4.0*t0*t1 - 4.0*t0*t2 + 4.0*t1*t3 + 4.0*t1*t4 - 4.0*t2*t3 - 4.0*t2*t4, 4.0*t0*t2 + 4.0*t0*t3 + 8.0*t0*t4 - 8.0*t1*t2 - 8.0*t1*t3 - 16.0*t1*t4 - 4.0*t2*t3 - 12.0*t2*t4 - 8.0*t3*t4 - 12.0*t4^2}'
sys2 = str(['t'+str(i)+'> 1' for i in range(5)]).replace('\'', '').replace('[','{').replace(']', '}')
variables =str(['t'+str(i) for i in range(5)]).replace('\'', '').replace('[','{').replace(']', '}')

expression = 'NMinimize[Join[{{Plus @@ (#^2 & /@ {})}}, '.format(sys1)
expression += '{}],'.format(sys2)
expression += '{}, AccuracyGoal -> 20, PrecisionGoal -> 20, WorkingPrecision -> 20]'.format(variables)

optimize = wlexpr(expression)
results = session.evaluate(optimize)
results

yields

(Decimal('4.590261537982443550669979993291708325478875'),
 (Rule[Global`t0, Decimal('6.06493241687450887611738251710439317786')],
  Rule[Global`t1, Decimal('1.49023396370430740218122509461758089564')],
  Rule[Global`t2, Decimal('1.49023396380763117160348778583728320911')],
  Rule[Global`t3, Decimal('6.06493241776108712714104622341693698113')],
  Rule[Global`t4, Decimal('1.05028414801046224445183878123997337742')]))

Now, running the same code in a mathematica kernel

In[1] := NMinimize[Join[{Plus @@ (#^2 & /@ {-4.0*t0*t1 - 4.0*t0*t2 - 8.0*t0*t4 + 4.0*t1*t3 + 4.0*t2*t3 + 8.0*t3*t4, 4.0*t0*t2 - 4.0*t0*t3 - 8.0*t0*t4 + 8.0*t1*t2 + 4.0*t1*t3 + 8.0*t1*t4 + 8.0*t2*t3 + 12.0*t2*t4 + 4.0*t4^2, 8.0*t0*t4 - 4.0*t1*t3 + 4.0*t1*t4 - 4.0*t2*t3 + 4.0*t2*t4 + 8.0*t4^2, 4.0*t0*t1 - 4.0*t0*t2 + 4.0*t1*t3 + 4.0*t1*t4 - 4.0*t2*t3 - 4.0*t2*t4, 4.0*t0*t2 + 4.0*t0*t3 + 8.0*t0*t4 - 8.0*t1*t2 - 8.0*t1*t3 - 16.0*t1*t4 - 4.0*t2*t3 - 12.0*t2*t4 - 8.0*t3*t4 - 12.0*t4^2})}, {t0> 1, t1> 1, t2> 1, t3> 1, t4> 1}],{t0, t1, t2, t3, t4}, AccuracyGoal -> 20, PrecisionGoal -> 20, WorkingPrecision -> 20]
Out[1]= {4.5902615379824435507 10^-16   , 
 
>    {t0 -> 6.0649324168745088761, t1 -> 1.4902339637043074022, 
 
>     t2 -> 1.4902339638076311716, t3 -> 6.0649324177610871271, 
 
>     t4 -> 1.0502841480104622445}}

shows that the 10^-16 has been lost. The same holds true for exponents in the variabes ti if they occur.

Hi, it's indeed a bug in big real deserialization. Here is a minimal example:

from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr
session = WolframLanguageSession()

session.evaluate('4.5902615379824435507 10^-16')

The exponent is dropped.

Fixed in 1.1.4:

>>> session.evaluate('4.5902615379824435507 10^-16')
Decimal('4.590261537982443550699999999999999999999281E-16')