1 | initial version |
You should think of a symbolic expression as a tree. Unfortunately, the substitution only works for substituing pieces of expression that are subtrees of the given expression.
In the present case:
sage: f.operator()
<function add_vararg at 0x7f52b4cdaf50>
sage: f.operands()
[-mu*x1(t)^2*x2(t), x1(t)]
sage: f.operands()[0].operator()
<function mul_vararg at 0x7f52b4d00050>
sage: f.operands()[0].operands()
[mu, x1(t)^2, x2(t), -1]
So you can think of f
as a tree
__ mu
/
/ __ x1(t)^2
| /
* ____ x2(t)
/ \
+ \__ -1
\
\
\__ x1(t)
So, the smallest subtree that contains x1(t)^2*x2(t)
is actually -mu*x1(t)^2*x2(t)
, and you can see that the following works:
sage: f.subs({-mu*x[0]^2*x[1] : x[2]})
x1(t) + x3(t)
So, what you can do is to substitute the subtree by taking into account what you had to add to get the entire subtree (in this case, you have to multiply by -mu
):
sage: f.subs({-mu*x[0]^2*x[1] : -mu*x[2]})
-mu*x3(t) + x1(t)
Remark: the tree i pictured above can of course be further developped, for example x1(t)^2 is actually:
x1 __ t
/
^
\
2
so that the complete tree is actually:
___ mu
/ x1 __ t
/ /
| ______ ^
| / \
| / 2
| /
* ____ x2 __ t
/ \
+ \__ -1
\
\
\__ x1 __ t
2 | No.2 Revision |
You should think of a symbolic expression as a tree. Unfortunately, the substitution only works for substituing pieces of expression that are subtrees of the given expression.
In the present case:
sage: f.operator()
<function add_vararg at 0x7f52b4cdaf50>
sage: f.operands()
[-mu*x1(t)^2*x2(t), x1(t)]
sage: f.operands()[0].operator()
<function mul_vararg at 0x7f52b4d00050>
sage: f.operands()[0].operands()
[mu, x1(t)^2, x2(t), -1]
So you can think of f
as a treethe tree:
__ mu
/
/ __ x1(t)^2
| /
* ____ x2(t)
/ \
+ \__ -1
\
\
\__ x1(t)
Somahow, it is like mu, x1(t)^2, x2(t), -1
are tied together by a single *
. So, the smallest subtree that contains x1(t)^2*x2(t)
is actually -mu*x1(t)^2*x2(t)
, and you can see that the following works:
sage: f.subs({-mu*x[0]^2*x[1] : x[2]})
x1(t) + x3(t)
So, what you can do is to substitute the subtree by taking into account what you had to add to get the entire subtree (in this case, you have to multiply by -mu
):
sage: f.subs({-mu*x[0]^2*x[1] : -mu*x[2]})
-mu*x3(t) + x1(t)
Remark: the tree i pictured above can of course be further developped, for example x1(t)^2 is actually:
x1 __ t
/
^
\
2
so that the complete tree is actually:
___ mu
/ x1 __ t
/ /
| ______ ^
| / \
| / 2
| /
* ____ x2 __ t
/ \
+ \__ -1
\
\
\__ x1 __ t
3 | No.3 Revision |
You should think of a symbolic expression as a tree. Unfortunately, the substitution only works for substituing pieces of expression that are subtrees of the given expression.
In the present case:
sage: f.operator()
<function add_vararg at 0x7f52b4cdaf50>
sage: f.operands()
[-mu*x1(t)^2*x2(t), x1(t)]
sage: f.operands()[0].operator()
<function mul_vararg at 0x7f52b4d00050>
sage: f.operands()[0].operands()
[mu, x1(t)^2, x2(t), -1]
So you can think of f
as the tree:
__ mu
/
/ __ x1(t)^2
| /
* ____ x2(t)
/ \
+ \__ -1
\
\
\__ x1(t)
Somahow, it is like mu, x1(t)^2, x2(t), -1
are tied together by a single *
. So, the smallest subtree that contains x1(t)^2*x2(t)
is actually -mu*x1(t)^2*x2(t)
, and you can see that the following works:
sage: f.subs({-mu*x[0]^2*x[1] : x[2]})
x1(t) + x3(t)
So, what you can do is to substitute the subtree by taking into account what you had to add to get the entire subtree (in this case, you have to multiply by -mu
):
sage: f.subs({-mu*x[0]^2*x[1] : -mu*x[2]})
-mu*x3(t) + x1(t)
Remark: the tree i pictured above can of course be further developped, for example x1(t)^2 is actually:
x1 __ t
/
^
\
2
so that the complete tree representing f
is actually:
___ mu
/ x1 __ t
/ /
| ______ ^
| / \
| / 2
| /
* ____ x2 __ t
/ \
+ \__ -1
\
\
\__ x1 __ t
4 | No.4 Revision |
You should think of a symbolic expression as a tree. Unfortunately, the substitution only works for substituing pieces of expression that are subtrees of the given expression.
In the present case:
sage: f.operator()
<function add_vararg at 0x7f52b4cdaf50>
sage: f.operands()
[-mu*x1(t)^2*x2(t), x1(t)]
sage: f.operands()[0].operator()
<function mul_vararg at 0x7f52b4d00050>
sage: f.operands()[0].operands()
[mu, x1(t)^2, x2(t), -1]
So you can think of f
as the tree:
__ mu
/
/ __ x1(t)^2
| /
* ____ x2(t)
/ \
+ \__ -1
\
\
\__ x1(t)
Somahow, Somehow, it is like mu,
x1(t)^2, x2(t), -1 are tied together by a single *
. So, the smallest subtree that contains x1(t)^2*x2(t)
is actually -mu*x1(t)^2*x2(t)
, and you can see that the following works:
sage: f.subs({-mu*x[0]^2*x[1] : x[2]})
x1(t) + x3(t)
So, what you can do is to substitute the subtree by taking into account what you had to add to get the entire subtree (in this case, you have to multiply by -mu
):
sage: f.subs({-mu*x[0]^2*x[1] : -mu*x[2]})
-mu*x3(t) + x1(t)
Remark: the tree i pictured above can of course be further developped, for example x1(t)^2 is actually:
x1 __ t
/
^
\
2
so that the complete tree representing f
is actually:
___ mu
/ x1 __ t
/ /
| ______ ^
| / \
| / 2
| /
* ____ x2 __ t
/ \
+ \__ -1
\
\
\__ x1 __ t
5 | No.5 Revision |
You should think of a symbolic expression as a tree. Unfortunately, the substitution only works for substituing pieces of expression that are subtrees of the given expression.
In the present case:
sage: f.operator()
<function add_vararg at 0x7f52b4cdaf50>
sage: f.operands()
[-mu*x1(t)^2*x2(t), x1(t)]
sage: f.operands()[0].operator()
<function mul_vararg at 0x7f52b4d00050>
sage: f.operands()[0].operands()
[mu, x1(t)^2, x2(t), -1]
So you can think of f
as the tree:
__ mu
/
/ __ x1(t)^2
| /
* ____ x2(t)
/ \
+ \__ -1
\
\
\__ x1(t)
Somehow, it is like mu, x1(t)^2, x2(t), -1
are tied together by a single *
. So, the smallest subtree that contains x1(t)^2*x2(t)
is actually -mu*x1(t)^2*x2(t)
, and you can see that the following works:
sage: f.subs({-mu*x[0]^2*x[1] : x[2]})
x1(t) + x3(t)
So, what you can do is to substitute the subtree by taking into account what you had to add to get the entire subtree (in this case, you have to multiply by -mu
):
sage: f.subs({-mu*x[0]^2*x[1] : -mu*x[2]})
-mu*x3(t) + x1(t)
Remark: the tree i pictured above can of course be further developped, for example x1(t)^2 x1(t)^2
is actually:
x1 __ t
/
^
\
2
so that the complete tree representing f
is actually:
___ mu
/ x1 __ t
/ /
| ______ ^
| / \
| / 2
| /
* ____ x2 __ t
/ \
+ \__ -1
\
\
\__ x1 __ t
6 | No.6 Revision |
You should think of a symbolic expression as a tree. Unfortunately, the substitution only works for substituing pieces of expression that are subtrees of the given expression.
In the present case:
sage: f.operator()
<function add_vararg at 0x7f52b4cdaf50>
sage: f.operands()
[-mu*x1(t)^2*x2(t), x1(t)]
sage: f.operands()[0].operator()
<function mul_vararg at 0x7f52b4d00050>
sage: f.operands()[0].operands()
[mu, x1(t)^2, x2(t), -1]
So you can think of f
as the tree:
__ mu
/
/ __ x1(t)^2
| /
* ____ x2(t)
/ \
+ \__ -1
\
\
\__ x1(t)
Somehow, it is like mu, x1(t)^2, x2(t), -1
are tied together by a single *
. (to benefit from the associativity of the product). So, the smallest subtree that contains x1(t)^2*x2(t)
is actually -mu*x1(t)^2*x2(t)
, and you can see that the following works:
sage: f.subs({-mu*x[0]^2*x[1] : x[2]})
x1(t) + x3(t)
So, what you can do is to substitute the subtree by taking into account what you had to add to get the entire subtree (in this case, you have to multiply by -mu
):
sage: f.subs({-mu*x[0]^2*x[1] : -mu*x[2]})
-mu*x3(t) + x1(t)
Remark: the tree i pictured above can of course be further developped, for example x1(t)^2
is actually:
x1 __ t
/
^
\
2
so that the complete tree representing f
is actually:
___ mu
/ x1 __ t
/ /
| ______ ^
| / \
| / 2
| /
* ____ x2 __ t
/ \
+ \__ -1
\
\
\__ x1 __ t