[sage-devel] Re: limits in SAGE

2007-10-03 Thread Ondrej Certik
> 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

[sage-devel] Re: limits in SAGE

2007-10-02 Thread Mike Hansen
> > 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

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Ondrej Certik
> 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

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Mike Hansen
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

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Ondrej Certik
> 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

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Mike Hansen
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

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Ondrej Certik
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

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Ondrej Certik
> 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*

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Mike Hansen
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

[sage-devel] Re: limits in SAGE

2007-10-01 Thread Ondrej Certik
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) >

[sage-devel] Re: limits in SAGE

2007-09-30 Thread Mike Hansen
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