First time here? Check out the FAQ!

Ask Your Question
1

Does a subtraction symbolic expression actually exist?

asked 12 years ago

rmp251 gravatar image

Can someone please give me an example of a symbolic expression in sage of the subtraction variety? (by subtraction variety I mean using the subtraction operator)

Precisely: how can I create an object o of type sage.symbolic.expression.Expression such that o.operator() is operator.sub? It seems that subtraction expressions are always converted to additions.

For example:

sage: x = var('x')
sage: (x-1).operator()
<built-in function add>
Preview: (hide)

Comments

Apparently we don't use this, though ginac does seem to have a `sub` subtraction thing. Interesting.

kcrisman gravatar imagekcrisman ( 12 years ago )

subtraction is not a nice operator; it's not associative!

benjaminfjones gravatar imagebenjaminfjones ( 12 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 12 years ago

We only use add, mul and pow operations in the expression tree. Subtraction is represented as addition with an appropriate coefficient and division is multiplication with an appropriate exponent. This makes it easier to handle expressions since you don't need to worry about handling these cases separately.

For example:

sage: var('x,y')
(x, y)
sage: ex = x+y-1
sage: ex.operator()
<built-in function add>
sage: ex.operands()
[x, y, -1]

You can read more about the internal representation of expressions in the relevant part of the GiNaC tutorial.

The patch attached to ticket #13738 wraps some internal GiNaC functions to view the expression tree.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 12 years ago

Seen: 783 times

Last updated: Dec 19 '12