Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hold symbolic powers unevaluated if evaluation fails #21758

Open
rwst opened this issue Oct 24, 2016 · 8 comments
Open

Hold symbolic powers unevaluated if evaluation fails #21758

rwst opened this issue Oct 24, 2016 · 8 comments

Comments

@rwst
Copy link

rwst commented Oct 24, 2016

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 TypeErrors in the first case and automatically uses the second form, to allow:

            sage: SR(2) ^ SR(QQbar(sqrt(2)))
            2^1.414213562373095?

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

@rwst rwst added this to the sage-7.5 milestone Oct 24, 2016
@rwst
Copy link
Author

rwst commented Oct 24, 2016

@rwst
Copy link
Author

rwst commented Oct 24, 2016

Author: Ralf Stephan

@rwst
Copy link
Author

rwst commented Oct 24, 2016

Commit: 49ab133

@rwst
Copy link
Author

rwst commented Oct 24, 2016

New commits:

49ab13321758: Hold symbolic powers unevaluated if evaluation fails

@videlec
Copy link
Contributor

videlec commented Oct 30, 2016

comment:3
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>

@videlec
Copy link
Contributor

videlec commented Oct 30, 2016

comment:4

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

@rwst
Copy link
Author

rwst commented Oct 31, 2016

comment:5

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.

@rwst
Copy link
Author

rwst commented Nov 6, 2016

comment:6

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.
pynac/pynac#208

@mkoeppe mkoeppe removed this from the sage-7.5 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants