Message Boards Message Boards

0
|
701 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Using wolframclient and arbitrary precision numbers

Posted 1 year ago

Hello, I am using wolframclient for a project, and I have gotten the hang of it. However, I want to use it for arbitrary precision arithmetic, which means passing arbitrary precision numbers between python and the Mathematica kernel and back. Is there a way to do this. Some stuff I have tried already:

with WolframLanguageSession() as session:
    x = session.evaluate(wl.ToString(wl.N(1/3, 100)))
    print(x)

which gives 0.333333

I have also tried passing the numbers to a function from an external .m package, without success:

with WolframLanguageSession() as session:
    session.evaluate(wl.SetDirectory("mathematica_files"))
    session.evaluate(wl.Needs('MyPackage`'))
    session.evaluate(wl.ResetDirectory())

    a = wl.N(33/100, 100)
    b = wl.N(24/100, 100)

    res = session.evaluate(
        wl.MyPackage.MyFunction(a,b)
    )

    print(res)

which again gives a less-than-machine-prec number.

Is there any way to serialize some python library type which would allow me to make use of high-precision arithmetic in Mathematica?

POSTED BY: Deyan Mihaylov

In Mathematica, I can easily use arbitrary precision arithmetic with my function:

In[79]:= N[MyFunction[33/100, 24/100], 100]

Out[79]= 1.88738779815070197734299179845518640219851026216604601501806249175530\
1802345986221767363158187993378
POSTED BY: Deyan Mihaylov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract