> Hey Ondrej,
>
> Yeah, I don't think the symbolic stuff was really designed with that
> in mind. Your best bet would be to go through the symbolic types in
> calculus/calculus.py and add a _recursive_sub_expression(self,
> to_match, replacement).
I see. Unfortunately I don't have time at the m
>
> That does the job. But now I found a harder problem. Now I need to
> substitute a subexpression of "e", by some other expression. Example
>
>
> e = exp(x)+1
> f=e.subs(exp(x), w)
>
> so f will be w+1. Is that possible in SAGE? I fear it's only possible
> to substitute for a symbol. I am attach
> Oh, I was thinking of proper subexpressions.
>
> sage: def subexpressions(e):
> : res = [e]
> : if not hasattr(e, '_operands'):
> : return res
> : for op in e._operands:
> : res += subexpressions(op)
> : return res
> :
> sage: subexpress
Oh, I was thinking of proper subexpressions.
sage: def subexpressions(e):
: res = [e]
: if not hasattr(e, '_operands'):
: return res
: for op in e._operands:
: res += subexpressions(op)
: return res
:
sage: subexpressions(exp(x)+1)
[e^x
> Here is some code that I think will do the trick.
>
> sage: def subexpressions(e):
> : res = []
> : if not hasattr(e, '_operands'):
> : return []
> : for op in e._operands:
> : res.append(op)
> : res += subexpressions(op)
> : re
Here is some code that I think will do the trick.
sage: def subexpressions(e):
: res = []
: if not hasattr(e, '_operands'):
: return []
: for op in e._operands:
: res.append(op)
: res += subexpressions(op)
: return res
:
sage
Hi,
I was curious, so I started to port the algorithm. Now I have this problem:
sage: e = exp(x)+1
sage: f = exp(x)
I need to check, that f is a subexpression of e. In SymPy, I do:
e.subs(f, Symbol("x", dummy=True))==e
i.e. I substitute f for some dummy variable and compare if the
expression
> The operators are defined in the standard Python module 'operator'.
>
> sage: import operator
> sage: (x+y)._operator is operator.add
> True
> sage: (x*y)._operator is operator.add
> False
> sage: (x*y)._operator is operator.mul
> True
> sage: (x**y)._operator is operator.mul
> False
> sage: (x*
The operators are defined in the standard Python module 'operator'.
sage: import operator
sage: (x+y)._operator is operator.add
True
sage: (x*y)._operator is operator.add
False
sage: (x*y)._operator is operator.mul
True
sage: (x**y)._operator is operator.mul
False
sage: (x**y)._operator is operat
On 10/1/07, Mike Hansen <[EMAIL PROTECTED]> wrote:
>
> Hey Ondrej,
>
> While the correspondence is not exact, this should be enough to work:
>
> sage: e = x*y
> sage: type(e)
>
> sage: e._operands
> [x, y]
> sage: e._operator
>
> sage: e = exp(y)
> sage: e._operands
> [exp, y]
> sage: type(e)
>
Hey Ondrej,
While the correspondence is not exact, this should be enough to work:
sage: e = x*y
sage: type(e)
sage: e._operands
[x, y]
sage: e._operator
sage: e = exp(y)
sage: e._operands
[exp, y]
sage: type(e)
sage: var('z')
z
sage: f = x+y*z
sage: f._operands
[x, y*z]
sage: (y*z)._operands
11 matches
Mail list logo