Opened 4 years ago
Last modified 4 years ago
#21758 needs_work enhancement
Hold symbolic powers unevaluated if evaluation fails
Reported by: | rws | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-7.5 |
Component: | symbolics | Keywords: | |
Cc: | vdelecroix | Merged in: | |
Authors: | Ralf Stephan | Reviewers: | |
Report Upstream: | N/A | Work issues: | |
Branch: | u/rws/hold_symbolic_powers_unevaluated_if_evaluation_fails (Commits) | Commit: | 49ab13301f5b44f946701f3fdcaff6c4613c0de7 |
Dependencies: | Stopgaps: |
Description
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:
sage: SR(2) ^ SR(QQbar(sqrt(2))) Traceback (most recent call last): ... TypeError: no canonical coercion ... sage: SR(2).power(SR(QQbar(sqrt(2))), hold=True) 2^1.414213562373095?
The ticket catches TypeError
s in the first case and automatically uses the second form, to allow:
sage: SR(2) ^ SR(QQbar(sqrt(2))) 2^1.414213562373095?
Change History (6)
comment:1 Changed 4 years ago by
- Branch set to u/rws/hold_symbolic_powers_unevaluated_if_evaluation_fails
comment:2 Changed 4 years ago by
- Cc vdelecroix added
- Commit set to 49ab13301f5b44f946701f3fdcaff6c4613c0de7
- Status changed from new to needs_review
comment:3 follow-up: ↓ 6 Changed 4 years ago by
- Status changed from needs_review to needs_work
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>
comment:4 follow-up: ↓ 5 Changed 4 years ago by
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
comment:5 in reply to: ↑ 4 Changed 4 years ago by
Replying to vdelecroix:
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.
comment:6 in reply to: ↑ 3 Changed 4 years ago by
Replying to vdelecroix:
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
New commits:
21758: Hold symbolic powers unevaluated if evaluation fails