<span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; "><pre><font class="Apple-style-span" face="'Times New Roman'"><span class="Apple-style-span" style="white-space: normal;">></span></font>Hello,
>On Tue, Sep 21, 2010 at 12:01 AM, Jose Antonio Garcia Peiro
><<a href="https://www.cebix.net/mailman/listinfo/ginac-list">jgpeiro at gmail.com</a>> wrote:
>><i> I think that the problem is at internal representation or at internal order. When
</i>>><i> I debug the code, same expression prints differ.
</i>>><i> ex test = pow(log(x),2)/x;
</i>>><i> cout << test;
</i>>><i> // sometimes x^(-1)*log(x)^2
</i>>><i> // other sometimes log(x)^2*x^(-1)
</i>
>Works as designed. This behavior is documented in the manual
>(section 5.7.2, titled as 'Expanding and collecting'): "Again,
>since the canonical form in GiNaC is not easy to guess you
>should be prepared to see different orderings of terms in such
>sums!". Also it has been explained on this mailing list several
>(quite a number, actually) times, see e.g.
> <a href="http://www.cebix.net/pipermail/ginac-list/2010-April/001598.html">http://www.cebix.net/pipermail/ginac-list/2010-April/001598.html</a>
> <a href="http://www.ginac.de/pipermail/ginac-list/2008-August/001403.html">h</a><a href="http://www.ginac.de/pipermail/ginac-list/2008-August/001403.html">ttp://www.ginac.de/pipermail/ginac-list/2008-August/001403.html</a></pre>
<pre>>><i> How I can force GiNaC to unique representation?
</i>
>You can't. And there's no need to do so. Instead fix the (buggy)
>code which makes assuptions about term ordering.
>><i> I am try to test expressions with "match", but it not works
</i>>><i> always with the same expression.
</i>
>Could you please post the actual expression and the pattern,
>so I can make a (more) specific suggestion?
>Best regards,
> Alexei</pre><pre><br></pre><pre><span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal; "><pre>>You can't. And there's no need to do so. Instead fix the (buggy)
>code which makes assuptions about term ordering.
</pre><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><i>mmm, I write about 50 lines with these assumptions, and i think that is
not easy to correct....:-(</i></span></font></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><br></i></span></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-style: normal; white-space: normal; "><pre>
>Could you please post the actual expression and the pattern,
>so I can make a (more) specific suggestion?
</pre><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i>The code try to find the integral of a function. The code include all basic integration rules, for the function log(x)^2*x^(-1) apply these rule.</i></span></div>
<div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><br></i></span></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i>ex f = pow(log(x),2)/x;</i></span><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><i><i>        // case a: f = x^(-1)*log(x)^2, case b: </i></i></i></span><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><i><i><i>log(x)^2*</i></i></i></i></span><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><i><i><i><i>x^(-1)</i></i></i></i></i></span></div>
</span></i></span></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><i>ex w0, w1, w2;</i></span></font></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><i>exmap m;</i></span></font></div>
<div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><i><br></i></span></font></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i>if( f.match( pow(wild(0),wild(1))*wild(2), m ) || f.match( pow(wild(0),wild(1)), m ) ){
        </i></span><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><i>// int( f^c*f', x) = f^(c+1)/(c+1) or ln(f) if c == -1</i></i></span></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><i>        </i>w2 = 1;
        for( exmap::const_iterator i=m.begin(); i!=m.end(); ++i){
                if        (i->first.is_equal(wild(0)) )        w0 = i->second; // f
                else if        (i->first.is_equal(wild(1)) )        w1 = i->second; // c
                else if        (i->first.is_equal(wild(2)) )        w2 = i->second; // f'
        }                
<span class="Apple-style-span" style="font-style: normal; "><i>        </i></span>if( has(w0,x) && !has(w1,x) ){ // f depends on x and c is constant
                ex dw0 = w0.diff(x,1);
                if( !dw0.is_equal(0) ){ // prevents division by 0
                        if( !has(w2/dw0,x) ){
                                 if( w1.is_equal(-1) ){ //check if c == -1
                                        return log( w0 ) * (w2/dw0);
                                }else{
                                        return pow( w0, w1+1 )/(w1+1) * (w2/dw0);
                                }
                        }
                }
        }
}
</i></span></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i><br></i></span></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><i>In case a: f = x, c = -1, and f' = log(x)^2, the code cannot compute the integral because f'/df = w2/dw0 = (log(x)^2)/(-x^-2) has the term 'x' and it cannot move out of integral.</i></span></div>
<div><i><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;">In case b: f = log(x), c = 2, f' = x^(-1), the code can compute integral because f'/df = w2/dw0 = x^(-1)/x^(-1) do not have the term 'x' and it can move out of integral.</span></font></i></div>
</span></pre><pre><span class="Apple-style-span" style="font-family: 'Times New Roman'; white-space: normal; "><pre>The code fails because I assume that the product w2 dont have powers. </pre></span></pre></span>