Opened 3 years ago

Last modified 5 months ago

#24428 needs_work defect

Substitution should be the same as numerical evaluation — at Version 12

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-8.2
Component: symbolics Keywords:
Cc: rws, slelievre Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by slelievre)

It is very surprising that these do not give the same result:

sage: arccosh(0.9)


sage: arccosh(x).subs(x=0.9)

The second result is more useful, so the first should probably return a complex number too.

See also

sage: arccosh(RDF(0.9))

Change History (12)

comment:1 Changed 3 years ago by jdemeyer

  • Description modified (diff)

comment:2 Changed 3 years ago by rws

I'm not decided on which result is correct. But see also #15344.

comment:3 Changed 3 years ago by rws

so the first should probably return a complex number too

This would mean either 1. changing general evaluation of f(arg) to not try arg.f() first or, 2. changing the interface to mpfr_acosh() (which is responsible for the NaN), i.e. RR.arccosh(), and some others too.

I'm in favor of the latter.

comment:4 Changed 3 years ago by rws

Note that RBF(0.9).arccosh() returns nan as well.

comment:5 Changed 3 years ago by mantepse

Does an expression in SR (like acosh) come with a notion of domain and codomain?

comment:6 Changed 3 years ago by rws

Symbolic function expressions have internal restrictions as to their arguments but there is no information associated regarding domains. The function code in sage/functions and in Pynac raises stock Python exceptions and runtime errors if nonsensical arguments are encountered, but just yesterday I wished I could catch them specifically, e.g. by inheriting from domain error---it would enable much better random testing.

comment:7 Changed 3 years ago by mantepse

It might be important to note that this is a regression:

sage: arccosh(0.9)
sage: arccosh(x).subs(x=0.9)
sage: version()
'SageMath version 8.1.beta5, Release Date: 2017-09-11'

comment:8 Changed 3 years ago by mantepse

in fact, the change must have been introduced in 8.2.beta1, because in 8.2.beta0 it still gives the expected result.

comment:9 Changed 3 years ago by rws

That is no surprise as I changed FP evaluation in the commit

It might not be a bug. Still, the necessity of being consistent demands some fix somewhere.

comment:10 Changed 3 years ago by rws

For example

sage: arccos(1.1)
sage: arccos(x).subs(x=1.1)


So one of arccos/arccosh should be changed.

Last edited 3 years ago by rws (previous) (diff)

comment:11 Changed 3 years ago by mantepse

Changes in symbolics code are quite likely to produce doctest differences in the fricas interface, so it might make sense to make sure that these doctests are run.

In the case at hand, I guess it would be very important to specify domain and codomain of expressions which can be evaluated numerically, otherwise it will never be clear whether something is a bug or a feature.

Besides, I think that arccosh is terrible language :-)

comment:12 Changed 3 years ago by slelievre

  • Cc slelievre added
  • Description modified (diff)

Adding an example:

sage: arccosh(RDF(0.9))
Note: See TracTickets for help on using tickets.