On Friday 9 February 2024 at 08:16:03 UTC-8 Georgi Guninski wrote:

When I try to extract digits of tanh(91) via floor, I still get error 

sage: floor(10^4*tanh(91)) 
ValueError 

The sage code doesn't use gp for this. The error you're encountering 
happens in

sage.functions.other._eval_floor_ceil

and it happens because the system tries to evaluate the expression using 
interval arithmetic. It iteratively increases the precision until it find 
an interval that doesn't straddle an integer or it gives up after a set 
number of trials. You're hitting that second condition. You don't make it 
easier by multiplying by 10^4. In fact, you make it harder: you now need 
more digits to get the interval to not include an integer.

Without more information, this code basically has to give up after a fixed 
number of tries: it could be evaluating an expression that actually does 
evaluate to 1. In that case, no amount of increased precision will result 
in an interval that doesn't contain an integer. It's a well-known problem 
in numerical approximation: discontinuous functions are basically not 
computable in that model.
 

gp computes it both ways :) 

sage: gp.default('realprecision',10^5) 
0 
sage: gp('floor(tanh(91))') 
0 


so does sage if you tell it to use the same approach gp uses:

 sage: tanh(91).n(30).floor()
1
sage: tanh(91).n(300).floor()
0

-- 
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/7c4fbdd1-b925-48ed-b9e4-4b1a970d4b3en%40googlegroups.com.

Reply via email to