Opened 9 years ago

Last modified 4 years ago

#10169 new defect

Operands and Operator of symbolic expressions

Reported by: SimonKing Owned by: burcin
Priority: major Milestone: sage-6.4
Component: symbolics Keywords: operator operands symbolics
Cc: eviatarbach Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by SimonKing)

I think that for all symbolic expression s should hold

sage: s == s.operator()(*s.operands())

That currently does not work, for two reasons.

  1. There may be no operator at all:
    sage: print x.operator()
    None
    sage: x.operands()
    []
    

I believe there should instead be an identity operator.

  1. The list of operands may be longer than what the operator accepts:
    sage: s = 0.001*x^2+0.01*x+0.1*sin(1.01*x)+1
    sage: s.operands()
    [0.00100000000000000*x^2, 0.0100000000000000*x,
    0.100000000000000*sin(1.01000000000000*x), 1]
    sage: s.operator()(*s.operands())
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call
    last)
    
    /home/king/<ipython console> in <module>()
    
    TypeError: op_add expected 2 arguments, got 4 
    

Compare this thread at sage-devel.

Change History (10)

comment:1 Changed 9 years ago by SimonKing

  • Milestone set to sage-4.6

comment:2 Changed 9 years ago by SimonKing

  • Description modified (diff)

comment:3 Changed 6 years ago by eviatarbach

  • Cc eviatarbach added

comment:4 Changed 6 years ago by eviatarbach

Note to self: after this is fixed (or at least just the arithmetic operators), simplify_hypergeometric should be added to simplify_full. Now it cannot be added because it will sometimes raise errors due to this bug.

comment:5 Changed 6 years ago by eviatarbach

Burcin, is there a problem with setting the sum operator to Expression.add, for example? I don't understand why we have to define new functions representing the arithmetic operators.

Last edited 6 years ago by eviatarbach (previous) (diff)

comment:6 Changed 6 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:7 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:8 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:9 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:10 Changed 4 years ago by rws

This will not work with some symbolic functions because they may have been called with the hold=True keyword, and calling them again doesn't know about it. See also #17849. The solution of that ticket in line with this one would be to make keywords into operands (strings?, a dedicated class OperatorKeyword?).

Another possible solution would be to abandon the hold keyword and introduce a hold context, see #10035.

Last edited 4 years ago by rws (previous) (diff)
Note: See TracTickets for help on using tickets.