Open rwst opened 7 years ago
Author: Ralf Stephan
New commits:
49ab133 | 21758: Hold symbolic powers unevaluated if evaluation fails |
sage: a = SR(2) ^ QQbar(3).sqrt()
sage: a
2^1.732050807568878?
sage: b = a + 1
sage: b
<repr(<sage.symbolic.expression.Expression at ...>) failed: TypeError: no canonical coercion from Algebraic Field to Rational Field>
Why algebraic numbers behave differently from pi
?
sage: a = 2 ^ pi.sqrt() + 1
sage: a
2^sqrt(pi) + 1
sage: a.n()
4.41634542118404
And why is pi
not numeric?
sage: pi.is_numeric()
False
Replying to @videlec:
Why algebraic numbers behave differently from
pi
?sage: a = 2 ^ pi.sqrt() + 1 sage: a 2^sqrt(pi) + 1 sage: a.n() 4.41634542118404
Because traditionally in Pynac all Python objects that can't be converted to Pynac objects are wrapped inside a numeric
object. Constants can be converted and are handled correctly. That's why pi is non-numeric.
Replying to @videlec:
sage: a = SR(2) ^ QQbar(3).sqrt() sage: a 2^1.732050807568878? sage: b = a + 1 sage: b <repr(<sage.symbolic.expression.Expression at ...>) failed: TypeError: no canonical coercion from Algebraic Field to Rational Field>
I have opened a Pynac issue although atm I have no idea where exactly to fix. https://github.com/pynac/pynac/issues/208
Automatic evaluation of symbolic expressions of "numerics" prevents construction of such expressions despite them being perfectly numerically approximatable (or otherwise useful) if exact evaluation in the algebraic sense fails. This is usually not a problem with function expressions (because of the easily added
hold=True
), and sums and products (?), but powers have to be constructed awkwardly:The ticket catches
TypeError
s in the first case and automatically uses the second form, to allow:CC: @videlec
Component: symbolics
Author: Ralf Stephan
Branch/Commit: u/rws/hold_symbolic_powers_unevaluated_if_evaluation_fails @
49ab133
Issue created by migration from https://trac.sagemath.org/ticket/21758