[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-07 Thread Stéfan van der Walt
2008/7/7 Ondrej Certik <[EMAIL PROTECTED]>: > The docs are here: > > http://docs.sympy.org/modules/rewriting.html#module-sympy.simplify.cse_main > > Stefan, what is the preferred way to document things in numpy? I mean > what kind of REST markup one should use in docstrings, so that it > looks nic

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-07 Thread Ondrej Certik
On Sun, Jul 6, 2008 at 12:45 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > On Sun, Jul 6, 2008 at 12:36 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Tue, Jul 1, 2008 at 10:38, Ondrej Certik <[EMAIL PROTECTED]> wrote: >>> Any progress on this? I think it's time to make anothe release, let's

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Ondrej Certik
On Sun, Jul 6, 2008 at 2:57 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > > On Sun, Jul 6, 2008 at 07:55, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> >> On Sun, Jul 6, 2008 at 2:19 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >>> >>> On Sun, Jul 6, 2008 at 07:13, Ondrej Certik <[EMAIL PROTECTED]> wro

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Robert Kern
On Sun, Jul 6, 2008 at 07:55, Ondrej Certik <[EMAIL PROTECTED]> wrote: > > On Sun, Jul 6, 2008 at 2:19 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Sun, Jul 6, 2008 at 07:13, Ondrej Certik <[EMAIL PROTECTED]> wrote: >>> diff --git a/sympy/simplify/__init__.py b/sympy/simplify/__init__.py >>

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Ondrej Certik
On Sun, Jul 6, 2008 at 2:19 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > > On Sun, Jul 6, 2008 at 07:13, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> diff --git a/sympy/simplify/__init__.py b/sympy/simplify/__init__.py >> --- a/sympy/simplify/__init__.py >> +++ b/sympy/simplify/__init__.py >> @@ -1

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Robert Kern
On Sun, Jul 6, 2008 at 07:13, Ondrej Certik <[EMAIL PROTECTED]> wrote: > diff --git a/sympy/simplify/__init__.py b/sympy/simplify/__init__.py > --- a/sympy/simplify/__init__.py > +++ b/sympy/simplify/__init__.py > @@ -10,3 +10,5 @@ from rewrite import cancel, trim, apart > from rewrite import can

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Ondrej Certik
> You should also decide where the main cse() function ought to be > exposed. I punted, and didn't expose it in sympy.* or > sympy.simplify.*. I'd add the following patch: # HG changeset patch # User Ondrej Certik <[EMAIL PROTECTED]> # Date 1215346162 -7200 # Node ID a899701f1e4f303dcc41fd4a1e00

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Robert Kern
On Sun, Jul 6, 2008 at 05:45, Ondrej Certik <[EMAIL PROTECTED]> wrote: > > On Sun, Jul 6, 2008 at 12:36 PM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Tue, Jul 1, 2008 at 10:38, Ondrej Certik <[EMAIL PROTECTED]> wrote: >>> Any progress on this? I think it's time to make anothe release, let's

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Ondrej Certik
On Sun, Jul 6, 2008 at 12:36 PM, Robert Kern <[EMAIL PROTECTED]> wrote: > > On Tue, Jul 1, 2008 at 10:38, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> Any progress on this? I think it's time to make anothe release, let's >> say on Monday. If you are busy, I propose to put the code that we have >> i

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-06 Thread Robert Kern
On Tue, Jul 1, 2008 at 10:38, Ondrej Certik <[EMAIL PROTECTED]> wrote: > Any progress on this? I think it's time to make anothe release, let's > say on Monday. If you are busy, I propose to put the code that we have > in (with my patch and a comment how to proceed with fixing it > generally) and w

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-01 Thread Robert Kern
On Tue, Jul 1, 2008 at 10:38, Ondrej Certik <[EMAIL PROTECTED]> wrote: > Any progress on this? I think it's time to make anothe release, let's > say on Monday. If you are busy, I propose to put the code that we have > in (with my patch and a comment how to proceed with fixing it > generally) and w

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-07-01 Thread Ondrej Certik
On Thu, Jun 19, 2008 at 10:10 AM, Ondrej Certik <[EMAIL PROTECTED]> wrote: > On Thu, Jun 19, 2008 at 7:42 AM, Robert Kern <[EMAIL PROTECTED]> wrote: >> >> On Wed, Jun 18, 2008 at 05:44, Ondrej Certik <[EMAIL PROTECTED]> wrote: >>> >>> On Wed, Jun 18, 2008 at 11:50 AM, Robert Kern <[EMAIL PROTECTED

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-19 Thread Ondrej Certik
On Thu, Jun 19, 2008 at 7:42 AM, Robert Kern <[EMAIL PROTECTED]> wrote: > > On Wed, Jun 18, 2008 at 05:44, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> >> On Wed, Jun 18, 2008 at 11:50 AM, Robert Kern <[EMAIL PROTECTED]> wrote: > >>> I can probably implement multiple expression support + unit tests

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Robert Kern
On Wed, Jun 18, 2008 at 05:44, Ondrej Certik <[EMAIL PROTECTED]> wrote: > > On Wed, Jun 18, 2008 at 11:50 AM, Robert Kern <[EMAIL PROTECTED]> wrote: >> I can probably implement multiple expression support + unit tests + >> subtraction preprocessing in a few days time. > > Excellent. In this case,

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Ondrej Certik
On Wed, Jun 18, 2008 at 3:26 PM, Fredrik Johansson <[EMAIL PROTECTED]> wrote: > I've implemented an evaluate=False option for Add, Mul, Pow and > functions (see attachment). This could be useful to suppress default > behavior like Sub(x,y) -> Add(x,Mul(-1,y)) for code generation etc. As > it happe

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Fredrik Johansson
I've implemented an evaluate=False option for Add, Mul, Pow and functions (see attachment). This could be useful to suppress default behavior like Sub(x,y) -> Add(x,Mul(-1,y)) for code generation etc. As it happens, I need something like this for evalf testing as well. Fredrik --~--~-~--~

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Ondrej Certik
On Wed, Jun 18, 2008 at 11:50 AM, Robert Kern <[EMAIL PROTECTED]> wrote: > > On Wed, Jun 18, 2008 at 04:32, Ondrej Certik <[EMAIL PROTECTED]> wrote: > >> 1) commit your patch as is and wait until someone fixes the x-y >> problem in a general way >> 2) commit your patch + my patch + a good comment,

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Robert Kern
On Wed, Jun 18, 2008 at 04:32, Ondrej Certik <[EMAIL PROTECTED]> wrote: > 1) commit your patch as is and wait until someone fixes the x-y > problem in a general way > 2) commit your patch + my patch + a good comment, that adding further > special cases are not acceptable and one should refactor i

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Ondrej Certik
On Wed, Jun 18, 2008 at 11:23 AM, Pearu Peterson <[EMAIL PROTECTED]> wrote: > > > > On Jun 18, 9:13 am, "Ondrej Certik" <[EMAIL PROTECTED]> wrote: >> On Wed, Jun 18, 2008 at 11:03 AM, Pearu Peterson >> >> <[EMAIL PROTECTED]> wrote: >> >> > Hi, >> >> > In sympycore we have Verbatim class that holds

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Pearu Peterson
On Jun 18, 9:13 am, "Ondrej Certik" <[EMAIL PROTECTED]> wrote: > On Wed, Jun 18, 2008 at 11:03 AM, Pearu Peterson > > <[EMAIL PROTECTED]> wrote: > > > Hi, > > > In sympycore we have Verbatim class that holds expressions without > > any evaluation. E.g. it can hold the expression 'x - y' in both

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Ondrej Certik
On Wed, Jun 18, 2008 at 11:03 AM, Pearu Peterson <[EMAIL PROTECTED]> wrote: > > Hi, > > In sympycore we have Verbatim class that holds expressions without > any evaluation. E.g. it can hold the expression 'x - y' in both > forms: Add(x, -y) and Sub(x, y). Converting to Verbatim and back > to the d

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Pearu Peterson
Hi, In sympycore we have Verbatim class that holds expressions without any evaluation. E.g. it can hold the expression 'x - y' in both forms: Add(x, -y) and Sub(x, y). Converting to Verbatim and back to the default representation is relatively cheap. May sympy should implement a similar scheme in

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Robert Kern
On Wed, Jun 18, 2008 at 03:29, Ondrej Certik <[EMAIL PROTECTED]> wrote: >>> It does, but it can be easily fixed, see above. I.e. fixing your >>> algorithm. :) The other option, as you said, is fixing sympy. We would >>> have to introduce a Sub class. >>> But I think it would just make things more

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-18 Thread Ondrej Certik
> It is certainly correct for that representation. However, my claim is > that this representation is suboptimal for the purposes to which one > wants to apply common subexpression elimination. All of the use cases > hold as important one of these two criteria: > > 1. flop count > 2. readability

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-17 Thread Robert Kern
On Tue, Jun 17, 2008 at 02:11, Ondrej Certik <[EMAIL PROTECTED]> wrote: > On Mon, Jun 16, 2008 at 11:41 PM, Luke <[EMAIL PROTECTED]> wrote: >> >> Robert, >> The Mathematica link you provided is exactly what I'm trying to do. >> I haven't tried your python code yet but after reading it I think it >

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-17 Thread Ondrej Certik
On Mon, Jun 16, 2008 at 11:41 PM, Luke <[EMAIL PROTECTED]> wrote: > > Robert, > The Mathematica link you provided is exactly what I'm trying to do. > I haven't tried your python code yet but after reading it I think it I did: http://code.google.com/p/sympy/issues/detail?id=891#c3 > should work

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-16 Thread Luke
Robert, The Mathematica link you provided is exactly what I'm trying to do. I haven't tried your python code yet but after reading it I think it should work great. I really appreciate your comments and your help! Thanks, ~Luke On Jun 16, 12:14 pm, "Robert Kern" <[EMAIL PROTECTED]> wrote: > O

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-16 Thread Robert Kern
On Mon, Jun 16, 2008 at 12:13, Luke <[EMAIL PROTECTED]> wrote: > Essentially what I need to do is parse every equation and identify > subexressions (and then parse those subexpression and identify > subsubexpressions), and introduce variables for any that are used > more than once. If a subex

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-16 Thread Luke
So I think it has become clear what I'm looking to do. There are many levels of subexpressions, and equations may be defined by many different subexpressions. For those of you familiar with classical mechanics, you are probably aware of the explosion of the number of terms that arises as the num

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Robert Kern
On Sun, Jun 15, 2008 at 17:46, Ondrej Certik <[EMAIL PROTECTED]> wrote: > Anyway, I created an issue for this: > > http://code.google.com/p/sympy/issues/detail?id=891 I've attached some nominally working code to the issue. Playing with it, I see some suboptimal results. First, it's quadratic, but

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Friedrich Hagedorn
On Sun, Jun 15, 2008 at 12:00:54PM -0700, Luke wrote: > > I guess what I'm looking for is more an algorithm to > help identify and automatically collect common subexpressions so that > repeated quantities are only calculated once. For each repeated > subexpression in an equation, an intermediate

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Robert Kern
On Sun, Jun 15, 2008 at 17:46, Ondrej Certik <[EMAIL PROTECTED]> wrote: > > On Mon, Jun 16, 2008 at 12:10 AM, Robert Kern <[EMAIL PROTECTED]> wrote: >> Actually, that example is not relevant since there is no repeated >> subexpression. The idea is to reduce the amount of unnecessarily >> repeated

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Ondrej Certik
On Mon, Jun 16, 2008 at 12:10 AM, Robert Kern <[EMAIL PROTECTED]> wrote: > > On Sun, Jun 15, 2008 at 16:11, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> >> Hi Luke, >> >> On Sun, Jun 15, 2008 at 9:00 PM, Luke <[EMAIL PROTECTED]> wrote: >>> >>> Ondrej, >>> I know that Sympy has the capability to do

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Robert Kern
On Sun, Jun 15, 2008 at 16:11, Ondrej Certik <[EMAIL PROTECTED]> wrote: > I don't understand which criteria you use to substitute the > subexpressions --- the most frequent subexpression? Here's some help I got a long time ago when I asked about how to do this with Python ASTs. I never followed u

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Robert Kern
On Sun, Jun 15, 2008 at 16:11, Ondrej Certik <[EMAIL PROTECTED]> wrote: > > Hi Luke, > > On Sun, Jun 15, 2008 at 9:00 PM, Luke <[EMAIL PROTECTED]> wrote: >> >> Ondrej, >> I know that Sympy has the capability to do symbolic replacement like >> you described. I guess what I'm looking for is more a

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Ondrej Certik
Hi Luke, On Sun, Jun 15, 2008 at 9:00 PM, Luke <[EMAIL PROTECTED]> wrote: > > Ondrej, > I know that Sympy has the capability to do symbolic replacement like > you described. I guess what I'm looking for is more an algorithm to > help identify and automatically collect common subexpressions so t

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-15 Thread Luke
Ondrej, I know that Sympy has the capability to do symbolic replacement like you described. I guess what I'm looking for is more an algorithm to help identify and automatically collect common subexpressions so that repeated quantities are only calculated once. For each repeated subexpression i

[sympy] Re: Identifying repeated subexpressions in systems of equations

2008-06-14 Thread Ondrej Certik
Hi Luke! On Fri, Jun 13, 2008 at 8:45 PM, Luke <[EMAIL PROTECTED]> wrote: > > I'm working on some code that symbolically generates equations of > motion for mechanical systems. I would like the equations to be > computationally efficient in that they don't repeatedly calculate > quantities that h