Ask Your Question
1

Does a subtraction symbolic expression actually exist?

asked 2012-12-18 22:28:15 +0100

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>
edit retag flag offensive close merge delete

Comments

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

kcrisman gravatar imagekcrisman ( 2012-12-18 22:45:09 +0100 )edit

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

benjaminfjones gravatar imagebenjaminfjones ( 2012-12-19 00:40:46 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-12-19 05:06:16 +0100

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.

edit flag offensive delete link more

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: 2012-12-18 22:28:15 +0100

Seen: 758 times

Last updated: Dec 19 '12