OK, that was a bad example.  I tried to come up with an example that
demonstrated all the ways that constants could simplify, but as a
result, I made something that can't really be simplified.

The example in the issue has C1**3 and C1**6.  Clearly, this should be
simplified to C1 and C1**2.  We could also do things like pull out
common factors, like 4*C1, 6*C1 => 2*C1, 3*C1.  And I guess sometimes
removing terms from an Add can be beneficial, like C1 + 1, C1 + 2 =>
C1, C1 + 1.

It looks like your condense function already has much of the needed
machinery here, namely, computing the mapping.  All that is needed now
I guess is to compute all the mappings (maybe with some heuristics,
like gcds), and use something expression size heuristics to find the
simplest one. The logic also needs to be modified a little for
dsolve(), because I think that constants should no longer be
renumbered (except maybe to put them in order in an expression).  See
the issue I linked to.

Aaron Meurer

On Wed, Mar 14, 2012 at 11:47 PM, Chris Smith <smi...@gmail.com> wrote:
>
>
> On Thu, Mar 15, 2012 at 9:59 AM, Aaron Meurer <asmeu...@gmail.com> wrote:
>>
>> Hi.
>>
>> I just created http://code.google.com/p/sympy/issues/detail?id=3148.
>> The issue is related to constantsimp() in the ODE module.  Basically,
>> right now, it converts things like 2*C1 + C1**2*x + (C1 + 1)*x**2 into
>> C1 + C2*x + C3*x**2.  In other words, it absorbs C1, C2, ... constants
>> into other constants and into each other, and then renumbers them,
>> because they are no longer the same constant.
>>
>> I think this is a bad idea, because it makes it look like C1, C2, and
>> C3 are independent of each other, when they really aren't (because, in
>> this example, C2 = C1**2/4 and C3 = C1/4 + 1).  What I think it should
>> do instead is return something like C1 + C1**2/2**2 + (C1/4 + 1)*x**2.
>>  In other words, simplify one constant, and rewrite the others in
>> terms of it.
>>
>
> What is simpler about that, though? Now you have C1/4 where before you had
> 2*C1.
>
> <work below comes from my model branch which was pull request 598>
>
>     >>> var('C:4')
>     (C0, C1, C2, C3)
>     >>> condense(S('2*C1 + C1**2*x + (C1 + 1)*x**2'),x)
>     (C0 + C1*x + C2*x**2, {C2: C1 + 1, C0: 2*C1, C1: C1**2})
>
> There is only 1 constant on the right; additive and multiplicative absorbing
> occurred in defining C0 and C2 so we are free to re-write the C0-C2 in term
> of C1 from either of those expressions:
>
>     >>> e, r = _
>     >>> ri=r.items()
>     >>> e.subs([(o,n.subs(C1,solve(Eq(*ri[0]),C1)[0])) for o,n in ri])
>     C2*x**2 + 2*C2 + x*(C2 - 1)**2 - 2
>     >>> e.subs([(o,n.subs(C1,solve(Eq(*ri[1]),C1)[0])) for o,n in ri])
>     C0**2*x/4 + C0 + x**2*(C0/2 + 1)
>
> Again...neither of these is really simpler than you started with, are they?
>
> /c
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to sympy@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to