sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.47k stars 487 forks source link

Held symbolic powers cannot be approximated numerically #21754

Open rwst opened 8 years ago

rwst commented 8 years ago

Maybe a bit obscure but still a bug:

sage: SR(2).power(SR(QQbar(3).sqrt() + QQbar(2).sqrt()), hold=True)
2^3.146264369941973?
sage: _.n()
...
TypeError: no canonical coercion from Algebraic Field to Rational Field

Reason is that in Expression.n() the special sum treatment via class DefiniteSumExpander(ExpressionTreeWalker) leaves arithmetic operations to the superclass where (if all numeric) they are reduced to their non-symbolic calls, i.e. here, 2^QQbar(...) which gives the error (correctly, see https://groups.google.com/forum/?hl=en#!topic/sage-support/_7eGYj92Igw).

As we want to hold the power until later numerical conversion we want to override arithmetic in DefiniteSumExpander.

Component: symbolics

Author: Ralf Stephan

Branch/Commit: u/rws/held_symbolic_powers_cannot_be_approximated_numerically @ e1279df

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/21754

rwst commented 8 years ago

Branch: u/rws/held_symbolic_powers_cannot_be_approximated_numerically

rwst commented 8 years ago

Author: Ralf Stephan

rwst commented 8 years ago

Commit: e1279df

rwst commented 8 years ago

New commits:

e1279df21754: Held symbolic powers cannot be approximated numerically
videlec commented 8 years ago

Reviewer: Vincent Delecroix

videlec commented 8 years ago
comment:3

You added a method without neither documentation nor tests.

The following still fails

sage: SR(2) ^ SR(QQbar(3).sqrt() + QQbar(2).sqrt())

Would it be possible to hold the power automatically when there is no simplification?

rwst commented 8 years ago
comment:4

Replying to @videlec:

You added a method without neither documentation nor tests.

In a locally used class, come on, show me one example where this is done in Sage. It won't show in coverage, either:

ralf@ark:~/sage> ./sage -coverage src/sage/symbolic/expression.pyx
------------------------------------------------------------------------
SCORE src/sage/symbolic/expression.pyx: 100.0% (220 of 220)
------------------------------------------------------------------------

The test is in the containing function, of course.

The following still fails

sage: SR(2) ^ SR(QQbar(3).sqrt() + QQbar(2).sqrt())

Would it be possible to hold the power automatically when there is no simplification?

I can catch the type error, but then I will catch all type errors. Is this desireable?

rwst commented 8 years ago
comment:5

Replying to @rwst:

The following still fails

sage: SR(2) ^ SR(QQbar(3).sqrt() + QQbar(2).sqrt())

Would it be possible to hold the power automatically when there is no simplification?

I can catch the type error, but then I will catch all type errors. Is this desireable?

See #21758.