On Tuesday, April 18, 2023 at 4:23:10 PM UTC-6 Dima Pasechnik wrote:


1) compute t=e^1.1
2) compute RealLazyField(200)(t)

When you do step 1), you need, in Python, to set a precision, implicitly or 
explicitly. (Same in Mathematica, by the way, you can do SetPrecision[...]).


If Python is evaluating e^1.1, then it is also evaluating e^(11/10), right?

If that's how it worked, we would never be able to get more than 64 correct 
bits from RealLazyField.

But we can: if we send in e^(11/10), we can get any number of correct bits, 
just as expected.

Here's another angle on it:

Python interprets 1.1 and 11/10 to have the same value. In a plain Python 
interpreter, version 3.10, no Sage involved:

1.1=11/10
True

from math import *
pow(e,1.1)==pow(e,11/10)
True

Hence if Python was evaluating e^1.1 and e^(11/10) and sending the result 
to RealLazyField, we should get the same output from RealLazyField. But we 
don't:

RealLazyField()((e^1.1)).numerical_approx(200)
3.0041660239464333947978502692421898245811462402343750000000

RealLazyField()((e^(11/10))).numerical_approx(200)
3.0041660239464331120584079535886723932826810260162727621298

Different answers here mean Sage *is* getting its hands on e^1.1 and 
e^(11/10).

By the way, I'm running these Sage commands in a Jupyter notebook. That 
notebook seems to think 1.1 and e are both Sage types:

type(1.1)
<class 'sage.rings.real_mpfr.RealLiteral'>

type(e)
<class 'sage.symbolic.constants_c.E'>

That makes it look like Sage has complete control over what happens here. 

Is that not true?

If for some reason Sage does not have full control, a workaround would be 
to pass expressions to RealField and RealLazyField as strings, and let 
those functions themselves parse the strings. 

Parsing code for arithmetic expressions is standard and would be simple to 
copy-paste into RealField and RealLazyField, or any other Sage function 
that we want to have full control over how user-supplied expressions are 
interpreted.

By the way, Wolfram Alpha is not affected by this problem, so you can't 
really say it's impossible to do, right?

Alpha:
enter "e^1.1", press "more digits"
3.0041660239464331120584079535886723932826810260162727621297528605...

Sage:
RealLazyField()((e^1.1)).numerical_approx(200)
3.0041660239464333947978502692421898245811462402343750000000

Why is interpreting the 1.1 as 11/10 easy for Alpha, but hard for you guys?

-aw



-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/0a7079bd-414e-4409-9105-7e12816cc62en%40googlegroups.com.

Reply via email to