Opened 3 months ago

Last modified 3 weeks ago

#31282 new defect

Allow to take the sign of a callable symbolic expression

Reported by: rburing Owned by: gh-bmlivin
Priority: major Milestone: sage-9.4
Component: symbolics Keywords: sign, callablesymbolicexpression
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

Reported in Ask SageMath question #55417:

sage: f(x) = x^2
sage: cos(f)
x |--> cos(x^2)
sage: log(f)
x |--> log(x^2)
sage: sign(x^2)
sgn(x^2)
sage: sign(f)
...
TypeError: cannot coerce arguments: no canonical coercion from Callable function ring with argument x to Symbolic Ring

Change History (5)

comment:1 Changed 3 months ago by vdelecroix

Moreover, one can build the object in sage

sage: sgn(x^2).function(x)
x |--> sgn(x^2)

comment:2 follow-up: Changed 2 months ago by gh-bmlivin

  • Owner changed from (none) to gh-bmlivin

I think this can be fixed by renaming the sage.symbolics.expression.Expression.csgn method to sgn and giving it the @property decorator. I'm going to test that out and see if it breaks anything.

comment:3 in reply to: ↑ 2 Changed 2 months ago by gh-bmlivin

Replying to gh-bmlivin:

I think this can be fixed by renaming the sage.symbolics.expression.Expression.csgn method to sgn and giving it the @property decorator. I'm going to test that out and see if it breaks anything.

Never mind. That broke a number of tests, and it doesn't appear to do what it should anyway. I will continue to look for other ways to do this.

comment:4 Changed 2 months ago by gh-bmlivin

So I've attempted to make a sage.symbolic.expression.Expression.sgn method which returns giac.sgn(self). This causes one of the tests in src.sage.symbolic.expression to fail:

sage: unicode_art(SR(1.3 - I)) should return 1.3 - ⅈ, but it instead returns 1.3 - 1.0⋅ⅈ. I'm not sure whether this really matters, especially since there are other tests in that same method which return 1.0⋅x instead of x, but is a test that technically fails.

I have a feeling there may some other formatting tests that this may cause to fail, and I'm not sure why.

comment:5 Changed 3 weeks ago by mkoeppe

  • Milestone changed from sage-9.3 to sage-9.4

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review of ticket status, priority, and last modification date.

Note: See TracTickets for help on using tickets.