[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread kcrisman

>
> Thanks for the link! This is quite instructive.
>
>
Indeed.  Perhaps we should point this out in our documentation for `abs`. 

 

> Le mardi 16 septembre 2014 11:41:42 UTC+2, Peter Bruin a écrit :
>>
>> PS: the following message from the Maxima mailing list (found via a 
>> different sqrt-related report in the Maxima bug tracker) is quite 
>> useful: 
>>
>> https://www.ma.utexas.edu/pipermail/maxima/2011/025213.html 
>>
>> From that page: 
>>
>> * abs is a mathematical function which has simplification rules.  It 
>> assumes by default that it is operating over the reals, so that for 
>> example 
>> abs(sqrt(x)) => sqrt(x) -- because sqrt is treated as a real-to-real 
>> function with domain and range 0..inf.  But if there is an explicitly 
>> complex quantity (%i or a variable declared complex), that assumption is 
>> invalidated, so abs(z^2) => abs(z)^2, where declare(z,complex). 
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread Eric Gourgoulhon
Thanks for the link! This is quite instructive.

Eric. 

Le mardi 16 septembre 2014 11:41:42 UTC+2, Peter Bruin a écrit :
>
> PS: the following message from the Maxima mailing list (found via a 
> different sqrt-related report in the Maxima bug tracker) is quite 
> useful: 
>
> https://www.ma.utexas.edu/pipermail/maxima/2011/025213.html 
>
> From that page: 
>
> * abs is a mathematical function which has simplification rules.  It 
> assumes by default that it is operating over the reals, so that for 
> example 
> abs(sqrt(x)) => sqrt(x) -- because sqrt is treated as a real-to-real 
> function with domain and range 0..inf.  But if there is an explicitly 
> complex quantity (%i or a variable declared complex), that assumption is 
> invalidated, so abs(z^2) => abs(z)^2, where declare(z,complex). 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread Peter Bruin
PS: the following message from the Maxima mailing list (found via a
different sqrt-related report in the Maxima bug tracker) is quite
useful:

https://www.ma.utexas.edu/pipermail/maxima/2011/025213.html

>From that page:

* abs is a mathematical function which has simplification rules.  It
assumes by default that it is operating over the reals, so that for example
abs(sqrt(x)) => sqrt(x) -- because sqrt is treated as a real-to-real
function with domain and range 0..inf.  But if there is an explicitly
complex quantity (%i or a variable declared complex), that assumption is
invalidated, so abs(z^2) => abs(z)^2, where declare(z,complex).

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread Peter Bruin
Hello,

> PS: in the above code, I've simply cut and paste lines from
> Expression._maxima_(). In the present case, the super is not necessary
> and the code can be simplified to
>
> In Sage 6.2:
>
> sage:  from sage.calculus.calculus import maxima
> sage: abs(1/sqrt(x))._interface_(maxima)
> 1/sqrt(x)
> while in Sage 6.3:
>
> sage:  from sage.calculus.calculus import maxima
> sage: abs(1/sqrt(x))._interface_(maxima)
> abs(1/sqrt(_SAGE_VAR_x))

I see; actually I didn't test it in an older version of Maxima since I
only had 5.34.0 installed.  Maybe it is because of #16224 instead?  This
fixed a bug in the Maxima interface that changed (among other things)
which Sage function corresponds to Maxima's abs().

Anyway, a bit more experimenting shows that this behaviour can be fixed
using "declare(x, complex)":

(%i1) display2d: false;
(%o1) false
(%i2) abs(sqrt(x));
(%o2) sqrt(x)
(%i3) declare(x, complex);
(%o3) done
(%i4) abs(sqrt(x));
(%o4) abs(sqrt(x))
(%i5) abs(1/sqrt(x));
(%o5) abs(1/sqrt(x))

Peter

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread Eric Gourgoulhon
PS2 : so Karl-Dieter Crisman was right: the change in behavior is due to 
the introduction of unique names for Sage variables in the interface. 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread Eric Gourgoulhon

PS: in the above code, I've simply cut and paste lines from 
Expression._maxima_(). In the present case, the super is not necessary and 
the code can be simplified to

In Sage 6.2:

sage: from sage.calculus.calculus import maxima
sage: abs(1/sqrt(x))._interface_(maxima)
1/sqrt(x)

while in Sage 6.3:

sage: from sage.calculus.calculus import maxima
sage: abs(1/sqrt(x))._interface_(maxima)
abs(1/sqrt(_SAGE_VAR_x))


-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread Eric Gourgoulhon
Hi,

Le mardi 16 septembre 2014 09:30:23 UTC+2, Peter Bruin a écrit :
>
>
> This is probably due to Maxima.  The following happens with and without 
> the "domain: complex" setting: 
>
> Maxima 5.34.0 http://maxima.sourceforge.net 
> using Lisp ECL 12.12.1 
> Distributed under the GNU Public License. See the file COPYING. 
> Dedicated to the memory of William Schelter. 
> The function bug_report() provides bug reporting information. 
> (%i1) domain: complex; 
> (%o1)   complex 
> (%i2) abs(sqrt(x)); 
> (%o2)   sqrt(x) 
> (%i3) abs(1/sqrt(x)); 
>!   1   ! 
> (%o3)  !---! 
>!sqrt(x)! 
>
> I guess the first answer should be left alone (or at most changed to 
> sqrt(abs(x))) when "domain: complex" is set, which is what Sage does. 
>
> Peter 
>
>
Actually, this is not due to Maxima: with Maxima 5.29.1 shipped with Sage 
6.2, the behavior is exactly the same as the one shown above for Maxima 
5.34.0. The change is due to the interface between Sage and Maxima:

In Sage 6.2:

sage: from sage.calculus.calculus import maxima
sage: super(Expression, abs(1/sqrt(x)))._interface_(maxima)
1/sqrt(x)

while in Sage 6.3:

sage: from sage.calculus.calculus import maxima
sage: super(Expression, abs(1/sqrt(x)))._interface_(maxima)
abs(1/sqrt(_SAGE_VAR_x))

If x is complex, the change in the interface is clearly an improvement !

Eric.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-16 Thread Peter Bruin
Hello,

> I've noticed the following change in simplifications between Sage 6.3 and
> preceeding versions:
>
> In Sage 6.2 (and preceeding):
>
> sage: simplify( abs(sqrt(x))  )
> sqrt(x)
> sage: simplify( abs(1/sqrt(x))  )
> 1/sqrt(x)
> while in Sage 6.3:
>
> sage: simplify( abs(sqrt(x))  )
> sqrt(x)
> sage: simplify( abs(1/sqrt(x))  )
> abs(1/sqrt(x))
> The behavior in Sage <= 6.2 is coherent and correct for x real (but not
> for x complex !), while that in Sage 6.3 is not coherent (why simplifying
> abs(sqrt(x)) and not abs(1/sqrt(x)) ?). Is there any reason for this ?
> Shall this be considered as a bug ?

This is probably due to Maxima.  The following happens with and without
the "domain: complex" setting:

Maxima 5.34.0 http://maxima.sourceforge.net
using Lisp ECL 12.12.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) domain: complex;
(%o1)   complex
(%i2) abs(sqrt(x));
(%o2)   sqrt(x)
(%i3) abs(1/sqrt(x));
   !   1   !
(%o3)  !---!
   !sqrt(x)!

I guess the first answer should be left alone (or at most changed to
sqrt(abs(x))) when "domain: complex" is set, which is what Sage does.

Peter

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] Re: Change in simplification of combined abs & sqrt in Sage 6.3

2014-09-15 Thread kcrisman


On Monday, September 15, 2014 3:24:42 PM UTC-4, Eric Gourgoulhon wrote:
>
> Hi,
>
> I've noticed the following change in simplifications between Sage 6.3 and 
> preceeding versions:
>
> In Sage 6.2 (and preceeding):
>
> sage: simplify( abs(sqrt(x)) )
> sqrt(x)
> sage: simplify( abs(1/sqrt(x)) )
> 1/sqrt(x)
>
> while in Sage 6.3:
>
> sage: simplify( abs(sqrt(x)) )
> sqrt(x)
> sage: simplify( abs(1/sqrt(x)) )
> abs(1/sqrt(x))
>
> The behavior in Sage <= 6.2 is coherent and correct for x real (but not 
> for x complex !), while that in Sage 6.3 is not coherent (why simplifying 
> abs(sqrt(x)) and not abs(1/sqrt(x)) ?). Is there any reason for this ? 
> Shall this be considered as a bug ?
>
>
Remember, under the hood `simplify` just sends to Maxima and back.   I 
can't even get Maxima to return 1/sqrt(x) in this situation with Sage 6.2, 
though, so maybe it fixed a bad translation on our part...  but I don't see 
how the most relevant change of making sure Sage variables are unique could 
have done this, so I assume Maxima changed this behavior, as there was an 
upgrade in between. 

Vincent's ?! example would also be a Maxima thing... well, I guess if abs 
gives you the magnitude of the complex number in question then it must be 
correct!

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.