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 + 1, e^x, exp, x, 1]
sage: exp(x) in subexpressions(exp(x)+1)
True
sage: exp(x) in subexpressions(exp(x))
True


--Mike

On 10/1/07, Ondrej Certik <[EMAIL PROTECTED]> wrote:
>
> > 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: e = exp(x)+1
> > sage: f = exp(x)
> > sage: subexpressions(e)
> > [e^x, exp, x, 1]
> > sage: f in subexpressions(e)
> > True
>
> Thanks for a quick response. It doesn't work well though:
>
> sage: exp(x) in subexpressions(exp(x)+1)
> True
> sage: exp(x) in subexpressions(exp(x))
> False
>
> But both should return True. Unfortunately I need this to work
> reliably, otherwise the algorithm will not work.
>
> Ondrej
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to