[sage-support] Re: simplification options

2019-03-11 Thread Simon King
Hi Michael,

On 2019-03-11, Michael Beeson  wrote:
> I tried various simplification functions.I suppose I could start over, 
>  not using "symbolic expressions" but 
> declaring K to be a suitable field or ring, maybe a quadratic extension of 
> the field of rational functions in a. 
> That is probably the "right" way to do it.

Probably!

> But I wish there were a simpler way.

Why do you think using a sub-optimal far too general tool (e.g., symbolic
variables when in fact the problem is about polynomial) is "simpler"?

Best regards,
Simon

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


[sage-support] Re: simplification options

2019-03-11 Thread Eric Gourgoulhon
Le lundi 11 mars 2019 19:05:04 UTC+1, Michael Beeson a écrit :
>
>  I appreciate Eric's post,  and I do use subs  sometimes,  but it makes me 
> nervous since
> it will happily substitute any old thing you tell it to,  even an 
> incorrect thing.  So,  if your idea
> is to check a computation, it is a dangerous thing. 
>

In order to minimize the error risk in the substitution, note that you can 
use the Python variable b defined as
b = sqrt(1-a^2)
in the argument of subs(), thereby avoiding any duplicate code. The whole 
code becomes then

sage: var('p,q,r,a')  # note: no b at this stage
(p, q, r, a)
sage: b = sqrt(1-a^2) 
sage: eq = (p*a+r*b+q)^2
sage: eq = eq.expand(); eq
a^2*p^2 - a^2*r^2 + 2*sqrt(-a^2 + 1)*a*p*r + 2*a*p*q + 2*sqrt(-a^2 + 1)*q*r 
+ q^2 + r^2
sage: eq.subs({b: SR.var('b')})
a^2*p^2 + 2*a*b*p*r - a^2*r^2 + 2*a*p*q + 2*b*q*r + q^2 + r^2



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


[sage-support] Re: simplification options

2019-03-11 Thread Nils Bruin
On Monday, March 11, 2019 at 11:05:04 AM UTC-7, Michael Beeson wrote:
>
>  I appreciate Eric's post,  and I do use subs  sometimes,  but it makes me 
> nervous since
> it will happily substitute any old thing you tell it to,  even an 
> incorrect thing.  So,  if your idea
> is to check a computation, it is a dangerous thing.  True,  if you put 
> only correct equations in, 
> you'll usually get correct ones out.  
>

Checking a result is usually much easier: Take the original form of the 
equation, subtract the simplified form, and check that the difference is 
divisible by the relations you impose, such as b^2-(1-a^2). No special 
normal forms are required, just a divisibility test. This gets more 
complicated when there are more relations, because then you'll need an 
ideal membership test, but then you can just present that as "the 
computational tool" (plus, with a bit of luck you can extract the way in 
which the difference can be expressed in terms of the generating relations. 
The algorithm in principle encounters that information on the way) 

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


[sage-support] Re: simplification options

2019-03-11 Thread Michael Beeson
 I appreciate Eric's post,  and I do use subs  sometimes,  but it makes me 
nervous since
it will happily substitute any old thing you tell it to,  even an incorrect 
thing.  So,  if your idea
is to check a computation, it is a dangerous thing.  True,  if you put only 
correct equations in, 
you'll usually get correct ones out.  

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


[sage-support] Re: simplification options

2019-03-11 Thread Eric Gourgoulhon
What about something like

sage: var('p,q,r,a')
(p, q, r, a)
sage: b = sqrt(1-a^2)
sage: eq = (p*a+r*b+q)^2
sage: eq = eq.expand(); eq
a^2*p^2 - a^2*r^2 + 2*sqrt(-a^2 + 1)*a*p*r + 2*a*p*q + 2*sqrt(-a^2 + 1)*q*r 
+ q^2 + r^2
sage: b = var('b')
sage: eq.subs({sqrt(1-a^2): b})
a^2*p^2 + 2*a*b*p*r - a^2*r^2 + 2*a*p*q + 2*b*q*r + q^2 + r^2

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


[sage-support] Re: simplification of symbolic expressions

2013-11-24 Thread Robert Dodier
On 2013-11-22, John Cremona john.crem...@gmail.com wrote:

 1. It is a fact that if a^2+b^2=1 then arcsin(a)+arcsin(b)=pi/2, but
 how can I get this to happen automatically?  I have an expression
 which comes out as

 arcsin(1/3*sqrt(3)*sqrt(2)) + arcsin(1/3*sqrt(3))

 which I would like to get simplified in this way.

I think this can be achieved via simplification rules in Maxima. I don't
know if there are other ways to get the same result elsewhere in Sage
(if so I am interested to hear about it -- I wouldn't mind adopting
some ideas into Maxima). Here's what I have.

matchdeclare (aa, lambda ([e], not atom(e) and op(e) = nounify(asin)));
matchdeclare (xx, lambda ([e], atom(e) or op(e) # nounify(asin)));
tellsimpafter (aa + xx, xx + FOO1 (aa));
FOO1(a):=if op(a) = + then FOO2 (a) else a;
FOO2(a):=(a:args(a),
 for i thru length(a) do
 (for j from i + 1 thru length(a) do
  if a[i] # 0
  then (FOO3 (a[i], a[j]),
if %% # false then [a[i], a[j]] : [%%, 0])),
 apply (+, a));
FOO3(u,v):=if is (equal (args(u)[1]^2 + args(v)[1]^2, 1)) = true then %pi/2;

If there are any asin terms, call FOO1 on them. If there's more than one,
FOO1 gets an expression like asin(u) + asin(v) + ... (otherwise it's just
asin(u)), so call FOO2 on the + expression. FOO2 marches thru the list
of asin terms and tries to combine them two by two (via FOO3).

With that I get the following:

(%i9) asin(sqrt(3)*sqrt(2)/3) + asin(sqrt(3)/3);
(%o9) %pi/2
(%i10) asin(sqrt(3)*sqrt(2)/3) + asin(sqrt(3)/3) - 1;
(%o10) %pi/2-1
(%i11) asin(sqrt(3)*sqrt(2)/3) + asin(sqrt(3)/3) - x + y;
(%o11) y-x+%pi/2
(%i12) asin(sqrt(3)*sqrt(2)/3) + asin(sqrt(3)/3) - asin(x) + u;
(%o12) -asin(x)+u+%pi/2
(%i13) asin(sqrt(3)*sqrt(2)/3) + asin(sqrt(3)/3) + asin(sqrt(1 - u^2)) + 
asin (u);
(%o13) %pi

This is just what I got from some half-hearted hacking; I'm sure there
are serious limitations.

Good luck, have fun,  hope this helps.

Robert Dodier

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


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-22 Thread Mark Rahner
On Feb 22, 2:37 am, JamesHDavenport j.h.davenp...@bath.ac.uk wrote:
Canonical form and simplify aren't the same thing (necessarily).
See Carette,J., Understanding Expression Simplification.  Proc. ISSAC
2004 (ed. J. Gutierrez), ACM Press, New York, 2004, pp. 72-79.
I don't have access to that source but I completely agree, noting that
the passage you quoted discusses the results of full_simplify().
What I've reported is primarily a bug in Sage simplification.
 However, the underlying cause appears to be an issue with the GiNaC
canonical form, which apparently tends to proliferate radicals of
small integers.  Given Sage's dependence upon GiNaC's canonical form,
unless Sage aggressively simplifies such expressions, Sage users will
see many more expressions like
-(3*sqrt(-2/3*(2*(3*sqrt(-2*sqrt(5) + 5) - 2*sqrt(5) +3)/
(sqrt(-2*sqrt(5) + 5) - sqrt(5) + 2) - 3)*el + 1/9*(3*sqrt(-2*sqrt(5)+
5) - 2*sqrt(5) + 3)^2/(sqrt(-2*sqrt(5) + 5) - sqrt(5) + 2)^2) -
(3*sqrt(-2*sqrt(5) + 5) - 2*sqrt(5) + 3)/(sqrt(-2*sqrt(5) + 5) -
sqrt(5)+ 2))/(2*(3*sqrt(-2*sqrt(5) + 5) - 2*sqrt(5) + 3)/
(sqrt(-2*sqrt(5) + 5)- sqrt(5) + 2) - 3)
My system engineering gut feel is that it would be desirable to
address this particular simplification issue closer to the source
rather than to try to engineer around it on the simplification end.
 When I get some free time, I'm going to raise this issue on GiNaC-
list.  I'm not sure how soon that will be though.
-Mark

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-22 Thread JamesHDavenport
Try
http://www.cas.mcmaster.ca/~carette/publications/simplification.pdf
The real point is that GiNaC's canonical form has different goals from
a 'simplify' command in the sense of minimal complexity.
One really needs to separate the two, and I don;t know how easy that
is with the current design.
James
On Feb 22, 5:18 pm, Mark Rahner rah...@alum.mit.edu wrote:
 On Feb 22, 2:37 am, JamesHDavenport j.h.davenp...@bath.ac.uk wrote:
 Canonical form and simplify aren't the same thing (necessarily).
 See Carette,J., Understanding Expression Simplification.  Proc. ISSAC
 2004 (ed. J. Gutierrez), ACM Press, New York, 2004, pp. 72-79.
 I don't have access to that source but I completely agree, noting that
 the passage you quoted discusses the results of full_simplify().
 What I've reported is primarily a bug in Sage simplification.
  However, the underlying cause appears to be an issue with the GiNaC
 canonical form, which apparently tends to proliferate radicals of
 small integers.  Given Sage's dependence upon GiNaC's canonical form,
 unless Sage aggressively simplifies such expressions, Sage users will
 see many more expressions like
 -(3*sqrt(-2/3*(2*(3*sqrt(-2*sqrt(5) + 5) - 2*sqrt(5) +3)/
 (sqrt(-2*sqrt(5) + 5) - sqrt(5) + 2) - 3)*el + 1/9*(3*sqrt(-2*sqrt(5)+
 5) - 2*sqrt(5) + 3)^2/(sqrt(-2*sqrt(5) + 5) - sqrt(5) + 2)^2) -
 (3*sqrt(-2*sqrt(5) + 5) - 2*sqrt(5) + 3)/(sqrt(-2*sqrt(5) + 5) -
 sqrt(5)+ 2))/(2*(3*sqrt(-2*sqrt(5) + 5) - 2*sqrt(5) + 3)/
 (sqrt(-2*sqrt(5) + 5)- sqrt(5) + 2) - 3)
 My system engineering gut feel is that it would be desirable to
 address this particular simplification issue closer to the source
 rather than to try to engineer around it on the simplification end.
  When I get some free time, I'm going to raise this issue on GiNaC-
 list.  I'm not sure how soon that will be though.
 -Mark

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-21 Thread Mark Rahner
 So once it comes back to Sage, its internal representation goes back to the 
 Ginac one.
Doh!  So much for a possible workaround involving maxima.

Dox, I was using full_simplify() and also the handful of simplify
methods it invokes.  Evaluate a.full_simplify? to see their names.

Nils, trivial comparison is a major reason to use a canonical form but
it isn't an argument that favors a particular canonical form.  For
example, to simplify your example expressions, I would factor the 6
inside the radical and continue with substitutions as I recommended.
 The resulting expressions would be easy to compare because they would
be identical:

2/sqrt(6) - 2/(sqrt(3)*sqrt(2)) - sqrt(2)/sqrt(3)

sqrt(6)/3 - (sqrt(3)*sqrt(2))/3 - sqrt(2)/sqrt(3)

My initial problem was the severe obfuscation that resulted when extra
factors added by the canonical form refused to cancel and then
replicated geometrically.  Severe obfuscation is obviously a bad
thing.  It grows out of simple obfuscation of much simpler
expressions.  Should ( 1/7 * sqrt(21) ).full_simplify() produce
1/7*sqrt(3)*sqrt(7) when sqrt(3)/sqrt(7) is an option?  Having
fewer factors is an important part of being simpler.  In the more
complicated expression, the factors involving 7s aren't even
adjacent.  I don't know if the more complicated forms are required for
GiNaC to perform efficiently.  However, from an interactive user's
perspective, this issue is perplexing because it only involves the
representation of constants.  What could be simpler?  (pun intended)

-Mark

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-21 Thread JamesHDavenport
On Feb 21, 9:36 pm, Mark Rahner rah...@alum.mit.edu wrote:
  So once it comes back to Sage, its internal representation goes back to the 
  Ginac one.
 My initial problem was the severe obfuscation that resulted when extra
 factors added by the canonical form refused to cancel and then
 replicated geometrically.  Severe obfuscation is obviously a bad
 thing.  It grows out of simple obfuscation of much simpler
 expressions.  Should ( 1/7 * sqrt(21) ).full_simplify() produce
 1/7*sqrt(3)*sqrt(7) when sqrt(3)/sqrt(7) is an option?  Having
 fewer factors is an important part of being simpler.  In the more
 complicated expression, the factors involving 7s aren't even
 adjacent.  I don't know if the more complicated forms are required for
 GiNaC to perform efficiently.  However, from an interactive user's
 perspective, this issue is perplexing because it only involves the
 representation of constants.  What could be simpler?  (pun intended)
Canonical form and simplify aren't the same thing (necessarily).
See Carette,J.,
Understanding Expression Simplification.
Proc. ISSAC 2004 (ed. J. Gutierrez), ACM Press, New York, 2004, pp.
72-79.

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-20 Thread kcrisman


On Feb 18, 8:24 pm, Mark Rahner rah...@alum.mit.edu wrote:
 I appreciate that background info.  I hadn't tried invoking maxima
 because I read somewhere that simplify() used maxima.  I must've been
 reading outdated material.  As you stated, maxima does the correct
 thing.  Because Sage can invoke maxima, perhaps I have a work around.

Well, it *does* use maxima, but in this case it just sends it to
Maxima and back.  So once it comes back to Sage, its internal
representation goes back to the Ginac one.

 You're right that this issue should be considered in the context of
 powers.  In that context, I think it is even more clear that
 5^(-1/2) is simpler than (1/5) * 5^(1/2).  Leaving the additional
 term doesn't seem like a big deal, but by preventing subsequent
 simplifications, and by combining and recombining with other large
 expressions, it can have highly undesirable effects.
 I took a quick look at ginsh, the GiNaC interactive shell.  It
 converts 1/sqrt(5) to 1/5*sqrt(5) so I suspect that this issue can be
 traced to the GiNaC canonical form.  I'm not a CAS expert but I know a

Great, then that solves it.  I haven't had a working ginsh for a
while, so I didn't check to make sure.

 fair amount about computer system interfaces and I'm sure this issue
 adversely impacts the user experience.  Nobody would select equation
 obfuscation mode given the choice.

However, there may be other reasons for this choice.  I hesitate to
critique either the GiNaC or Maxima folks (or anyone else) on thorny
canonicalization of simplification questions.

 I think this issue should be taken up with the GiNaC folks.  Do they
 hang out in this group?

One or two are on the sage-devel list.Or you can ask on
https://www.ginac.de/mailman/listinfo/ginac-devel, I think.

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-20 Thread Nils Bruin
On Feb 18, 5:24 pm, Mark Rahner rah...@alum.mit.edu wrote:
 converts 1/sqrt(5) to 1/5*sqrt(5) so I suspect that this issue can be
 traced to the GiNaC canonical form.

Yes, it does so for a very good reason: By simplifying expressions
this way, you're sure to recognize equal expressions. Compare 2/
sqrt(6) and sqrt(6)/3, for instance. You'll easily recognize they're
equal if you remove sqrts from the denominator. By sacrificing the
apparent simplicity of 1/sqrt(5) to get 1/5*sqrt(5), one big problem
in deciding if algebraic numbers are equal disappears completely
(there are still other ones, due to the fact that expressions line
sqrt(1+sqrt(2)) are ambiguous). It's a standard convention to deal
with fractions involving roots. It's often taught in schools.

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-18 Thread Mark Rahner
I appreciate that background info.  I hadn't tried invoking maxima
because I read somewhere that simplify() used maxima.  I must've been
reading outdated material.  As you stated, maxima does the correct
thing.  Because Sage can invoke maxima, perhaps I have a work around.
You're right that this issue should be considered in the context of
powers.  In that context, I think it is even more clear that
5^(-1/2) is simpler than (1/5) * 5^(1/2).  Leaving the additional
term doesn't seem like a big deal, but by preventing subsequent
simplifications, and by combining and recombining with other large
expressions, it can have highly undesirable effects.
I took a quick look at ginsh, the GiNaC interactive shell.  It
converts 1/sqrt(5) to 1/5*sqrt(5) so I suspect that this issue can be
traced to the GiNaC canonical form.  I'm not a CAS expert but I know a
fair amount about computer system interfaces and I'm sure this issue
adversely impacts the user experience.  Nobody would select equation
obfuscation mode given the choice.
I think this issue should be taken up with the GiNaC folks.  Do they
hang out in this group?
-Mark

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification Issue Implicates Canonical Form

2012-02-17 Thread kcrisman
In some previous incarnation, where Sage used Maxima for things like
this, your simplification happened.


(%i1) 1/sqrt(5);
   1
(%o1)   ---
sqrt(5)
(%i2) sqrt(5)/5;
   1
(%o2)   ---
sqrt(5)


Now we use Ginac for basic symbolic stuff.  Once in a while we (i.e.,
Burcin) changes some internal representation, or Ginac does.   But in
general I think it just goes for positive powers - you may want to
read its documentation.  In particular, sqrt is not a builtin
function (square root (not a GiNaC function, rather an alias for
pow(x, numeric(1, 2, so the behavior is analogous to

sage: 1/5^(1/3)
1/5*5^(2/3)

Naturally, GiNaC is Not a CAS, so perhaps that is one reason for the
distinction.  You are also right about black arts!  So I don't pretend
to judge Maxima *or* Ginac on this one.

I'm sorry if that doesn't help, but it might give you some background,
at least.

- kcrisman

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification / Latex question

2010-06-30 Thread kcrisman

 As far as I understand from your previous comments, a way to extract the
 exponential functions from the expression is all you need. You don't
 really need to walk through the tree. Here is one way to do this:

 sage: t = exp(x+y)*(x-y)*(exp(y)+exp(z-y))
 sage: t
 (e^(-y + z) + e^y)*(x - y)*e^(x + y)
 sage: w = SR.wild()
 sage: t.find(exp(w))
 [e^(-y + z), e^(x + y), e^y]

 You can then change the expressions in the given array and substitute
 new values for them:

Did you define res in between?  Maybe this?  Just a guess.

sage: res = t.find(exp(w))


 sage: t.subs({res[1]: sin(res[1].operands()[0])})
 (e^(-y + z) + e^y)*(x - y)*sin(x + y)

 The .operands()[0] syntax is really cumbersome. We need a shortcut for
 this. I thought .op(0) worked for pynac expressions before we switched
 from the maxima backend.


-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification / Latex question

2010-06-26 Thread Jason Grout

On 6/24/10 6:15 AM, kcrisman wrote:


Right. This crops up in the middle of a more complicated
expression. If I could figure out how to break the expression
up in the right way, then I guess I could search for parts
that are exponential functions, take the log of those, and
then simplify the logs. I know how to ultimately find all
the pieces of the function with .operands(), but I don't
then know any way to put them back together with the
proper operators. Maybe there's a way to access the parsed


I believe there is, but I can't figure out how to do it without going
through fast_callable, which doesn't seem right.  This information is
in Pynac, but I can't find a method or underscore method that accesses
it.  This is now http://trac.sagemath.org/sage_trac/ticket/9329 .



See http://sagenb.org/home/pub/1760/ for an example of creating an 
expression tree (in that worksheet, the expression tree is used to make 
a mathematica expression...)


Thanks,

Jason

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Simplification / Latex question

2010-06-26 Thread Mike Witt

On 06/26/2010 03:26:06 PM, Jason Grout wrote:

On 6/24/10 6:15 AM, kcrisman wrote:


Right. This crops up in the middle of a more complicated
expression. If I could figure out how to break the expression
up in the right way, then I guess I could search for parts
that are exponential functions, take the log of those, and
then simplify the logs. I know how to ultimately find all
the pieces of the function with .operands(), but I don't
then know any way to put them back together with the
proper operators. Maybe there's a way to access the parsed


I believe there is, but I can't figure out how to do it without going
through fast_callable, which doesn't seem right.  This information is
in Pynac, but I can't find a method or underscore method that  
accesses

it.  This is now http://trac.sagemath.org/sage_trac/ticket/9329 .



See http://sagenb.org/home/pub/1760/ for an example of creating an  
expression tree (in that worksheet, the expression tree is used to  
make a mathematica expression...)


Hey, that's really cool. Thanks!

BTW, at this point, after the further Latex discussion, I realize
that my original problem was really more related to Ticket #9314
than to the expression itself (at least, that's what I'm currently
speculating). But, especially with that example,
it's pretty clear to me what to do if I need to parse an expression.
I believe that Ticket #9329 was generated in response to my original
post, before I understood that there was a Latex issue involved.
I believe that Ticket #9329 should be deleted (closed or whatever).

-Mike

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification / Latex question

2010-06-26 Thread kcrisman

 I believe that Ticket #9329 was generated in response to my original
 post, before I understood that there was a Latex issue involved.
 I believe that Ticket #9329 should be deleted (closed or whatever).

But part of your question was also to try to simplify more complicated
expressions, and it does seem reasonable that we could provide a full
nested expression tree for symbolic expressions (rather than having to
iterate something by hand), since we do so for fast_callable (I
think?).  Just because we might not do it anytime soon doesn't mean we
can't have a ticket for it!  We usually only close tickets it is clear
are duplicates or things we won't fix or are too vague; things which
no one is motivated to provide just stay that way until someone shows
up (and you'd be surprised how many stay open for  1 year and all of
a sudden get someone working on them).

I do hope the LaTeX issue gets resolved for you soon, though.

- kcrisman

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Simplification / Latex question

2010-06-26 Thread Mike Witt

On 06/26/2010 05:21:21 PM, kcrisman wrote:


 I believe that Ticket #9329 was generated in response to my original
 post, before I understood that there was a Latex issue involved.
 I believe that Ticket #9329 should be deleted (closed or whatever).

But part of your question was also to try to simplify more complicated
expressions, and it does seem reasonable that we could provide a full
nested expression tree for symbolic expressions (rather than having to
iterate something by hand), since we do so for fast_callable (I
think?).  Just because we might not do it anytime soon doesn't mean we
can't have a ticket for it!  We usually only close tickets it is clear
are duplicates or things we won't fix or are too vague; things which
no one is motivated to provide just stay that way until someone shows
up (and you'd be surprised how many stay open for  1 year and all of
a sudden get someone working on them).


OK, sure, that makes sense.


I do hope the LaTeX issue gets resolved for you soon, though.


My current theory is that it will be resolved if Ticket #9314
gets fixed. But I don't really know that for sure :-)


- kcrisman

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to  
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at  
http://groups.google.com/group/sage-support

URL: http://www.sagemath.org






--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification / Latex question

2010-06-25 Thread kcrisman
Dear Mike,

Just to follow up:

There is further discussion at http://trac.sagemath.org/sage_trac/ticket/9329
if you are interested in saying exactly what sort of data structure
would enable you to perform the simplifications you would like to
without having to create a custom Maxima simplification routine.

- kcrisman

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Simplification / Latex question

2010-06-25 Thread Mike Witt

On 06/25/2010 06:07:02 AM, kcrisman wrote:

Dear Mike,

Just to follow up:

There is further discussion at  
http://trac.sagemath.org/sage_trac/ticket/9329

if you are interested in saying exactly what sort of data structure
would enable you to perform the simplifications you would like to
without having to create a custom Maxima simplification routine.

- kcrisman


Well ... I can see how one might work one's way
through the expression, using the operator() and operands()
functions. And, I suppose, I can see how one could then build
up the equivalent expression, having modified one of the
operands in a certain way. So, I don't suppose that there is
actually any need for a custom data structure to do this.

I guess it's really just a question of whether the way
these expressions sometimes display in latex bothers me
enough to do something about it, other than just complain.

Although ... I guess I'm still a bit confused as to why
this happens, even given the form of the exponential.

sage: f = e^(2*I*pi*n*x - 2*I*pi*n)
sage: latex(f)
e^{\left(\left(2 I\right) \, \pi n x + \left(-2 I\right) \, \pi  
n\right)}


Still, I shouldn't really get +(-2i) right? I think you
mentioned something about Pynac (another program I know
nothing about). It seems like trying to fix this just
involves learning too much of a learning curve for me
to contemplate.

-Mike

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification / Latex question

2010-06-24 Thread kcrisman


   sage: n=var('n')
   sage: f=e^(i*x*pi*n-i*2*pi*n)
   sage: f.simplify_full()
   e^(I*pi*n*x - 2*I*pi*n)

   # Is there a way I can get this to simplify?

  This apparently isn't even that easy in Maxima.

  Maxima 5.21.1http://maxima.sourceforge.net
  using Lisp ECL 10.4.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.
  (%i5) radcan(%e^(%pi*n-2*%pi));
                                    %pi n - 2 %pi
  (%o5)                           %e
  (%i6) expand(%e^(%pi*n-2*%pi));
                                    %pi n - 2 %pi
  (%o6)                           %e

  There are several Maxima experts on the list, though, who may know
  about a flag to set in such a case to factor the exponent first.  I
  couldn't find one in the simplification documentation for Maxima, but
  it may be elsewhere.

 Well, I hope to hear from one of these Maxima experts!

  Of course, you can do this ahead of time:

  sage: e^((n*pi-pi*2).factor())
  e^((n - 2)*pi)

  but this is probably not what you want.

 Right. This crops up in the middle of a more complicated
 expression. If I could figure out how to break the expression
 up in the right way, then I guess I could search for parts
 that are exponential functions, take the log of those, and
 then simplify the logs. I know how to ultimately find all
 the pieces of the function with .operands(), but I don't
 then know any way to put them back together with the
 proper operators. Maybe there's a way to access the parsed

I believe there is, but I can't figure out how to do it without going
through fast_callable, which doesn't seem right.  This information is
in Pynac, but I can't find a method or underscore method that accesses
it.  This is now http://trac.sagemath.org/sage_trac/ticket/9329 .

 tree of the expression? But of course that's crazy.
 There must be a normal way to simplify it!


I don't know about that.  Many other discussions about 'obvious'
simplifications have led me to agree that this is a much harder
problem than one thinks.

On the other hand, it can be hard to find references to additional
packages in Maxima that might do this; it turns out that lots of
things one wants to do are not automatically available.  Try
http://maxima.sourceforge.net/docs/manual/en/maxima_71.html#SEC298 for
ways you might be able to do this directly in Maxima, though I
couldn't see for sure if that is part of its functionality.

sage: maxima_console()

(%i4) demo(facexp);

Annoyingly, it continues this thing of asking whether 2*%pi is an
integer which one often sees...

I hope this helps.

- kcrisman

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Simplification / Latex question

2010-06-24 Thread Mike Witt

On 06/24/2010 06:15:52 AM, kcrisman wrote:



   sage: n=var('n')
   sage: f=e^(i*x*pi*n-i*2*pi*n)
   sage: f.simplify_full()
   e^(I*pi*n*x - 2*I*pi*n)

   # Is there a way I can get this to simplify?

  This apparently isn't even that easy in Maxima.

  Maxima 5.21.1http://maxima.sourceforge.net
  using Lisp ECL 10.4.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.
  (%i5) radcan(%e^(%pi*n-2*%pi));
                                    %pi n - 2 %pi
  (%o5)                           %e
  (%i6) expand(%e^(%pi*n-2*%pi));
                                    %pi n - 2 %pi
  (%o6)                           %e

  There are several Maxima experts on the list, though, who may know
  about a flag to set in such a case to factor the exponent first.  
 I
  couldn't find one in the simplification documentation for Maxima,  
but

  it may be elsewhere.

 Well, I hope to hear from one of these Maxima experts!

  Of course, you can do this ahead of time:

  sage: e^((n*pi-pi*2).factor())
  e^((n - 2)*pi)

  but this is probably not what you want.

 Right. This crops up in the middle of a more complicated
 expression. If I could figure out how to break the expression
 up in the right way, then I guess I could search for parts
 that are exponential functions, take the log of those, and
 then simplify the logs. I know how to ultimately find all
 the pieces of the function with .operands(), but I don't
 then know any way to put them back together with the
 proper operators. Maybe there's a way to access the parsed

I believe there is, but I can't figure out how to do it without going
through fast_callable, which doesn't seem right.  This information is
in Pynac, but I can't find a method or underscore method that accesses
it.  This is now http://trac.sagemath.org/sage_trac/ticket/9329 .

 tree of the expression? But of course that's crazy.
 There must be a normal way to simplify it!


I don't know about that.  Many other discussions about 'obvious'
simplifications have led me to agree that this is a much harder
problem than one thinks.

On the other hand, it can be hard to find references to additional
packages in Maxima that might do this; it turns out that lots of
things one wants to do are not automatically available.  Try
http://maxima.sourceforge.net/docs/manual/en/maxima_71.html#SEC298 for
ways you might be able to do this directly in Maxima, though I
couldn't see for sure if that is part of its functionality.

sage: maxima_console()

(%i4) demo(facexp);

Annoyingly, it continues this thing of asking whether 2*%pi is an
integer which one often sees...

I hope this helps.

- kcrisman


This is all good information, thanks. It helps to at least know
that I'm not missing something obvious. It's the combination with
that latex issue that results in some really ugly output.

I've noticed too about how maxima continues to ask things that
(it would seem) you have already told it. I guess it would be
in my best interests to learn more about maxima.

Thanks again,

-Mike






--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification / Latex question

2010-06-24 Thread kcrisman

 I've noticed too about how maxima continues to ask things that
 (it would seem) you have already told it. I guess it would be
 in my best interests to learn more about maxima.


If you are serious about doing symbolic manipulation that you can
control from within Sage, yes.  That said, various people will note
that things it would seem you told it are often things that are
provably undecidable or something like that.

Good luck!

- kcrisman

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] Re: Simplification / Latex question

2010-06-23 Thread Mike Witt

On 06/22/2010 12:41:17 PM, kcrisman wrote:


 sage: n=var('n')
 sage: f=e^(i*x*pi*n-i*2*pi*n)
 sage: f.simplify_full()
 e^(I*pi*n*x - 2*I*pi*n)

 # Is there a way I can get this to simplify?

This apparently isn't even that easy in Maxima.

Maxima 5.21.1 http://maxima.sourceforge.net
using Lisp ECL 10.4.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.
(%i5) radcan(%e^(%pi*n-2*%pi));
  %pi n - 2 %pi
(%o5)   %e
(%i6) expand(%e^(%pi*n-2*%pi));
  %pi n - 2 %pi
(%o6)   %e

There are several Maxima experts on the list, though, who may know
about a flag to set in such a case to factor the exponent first.  I
couldn't find one in the simplification documentation for Maxima, but
it may be elsewhere.


Well, I hope to hear from one of these Maxima experts!


Of course, you can do this ahead of time:

sage: e^((n*pi-pi*2).factor())
e^((n - 2)*pi)

but this is probably not what you want.


Right. This crops up in the middle of a more complicated
expression. If I could figure out how to break the expression
up in the right way, then I guess I could search for parts
that are exponential functions, take the log of those, and
then simplify the logs. I know how to ultimately find all
the pieces of the function with .operands(), but I don't
then know any way to put them back together with the
proper operators. Maybe there's a way to access the parsed
tree of the expression? But of course that's crazy.
There must be a normal way to simplify it!


 sage: latex(f)
 e^{\left(I \, \pi n x + \left(-2 I\right) \, \pi n\right)}

 # Why the extra parentheses around -2I ?

No idea.  Pynac usually handles these sorts of things; I'm not sure
whether I would call it a bug, though it does seem strange.  Perhaps
Pynac represents this as a complex internally and so this happens?
Burcin will know :)

- kcrisman

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to  
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at  
http://groups.google.com/group/sage-support

URL: http://www.sagemath.org









--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification / Latex question

2010-06-22 Thread kcrisman

 sage: n=var('n')
 sage: f=e^(i*x*pi*n-i*2*pi*n)
 sage: f.simplify_full()
 e^(I*pi*n*x - 2*I*pi*n)

 # Is there a way I can get this to simplify?

This apparently isn't even that easy in Maxima.

Maxima 5.21.1 http://maxima.sourceforge.net
using Lisp ECL 10.4.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.
(%i5) radcan(%e^(%pi*n-2*%pi));
  %pi n - 2 %pi
(%o5)   %e
(%i6) expand(%e^(%pi*n-2*%pi));
  %pi n - 2 %pi
(%o6)   %e

There are several Maxima experts on the list, though, who may know
about a flag to set in such a case to factor the exponent first.  I
couldn't find one in the simplification documentation for Maxima, but
it may be elsewhere.

Of course, you can do this ahead of time:

sage: e^((n*pi-pi*2).factor())
e^((n - 2)*pi)

but this is probably not what you want.

 sage: latex(f)
 e^{\left(I \, \pi n x + \left(-2 I\right) \, \pi n\right)}

 # Why the extra parentheses around -2I ?

No idea.  Pynac usually handles these sorts of things; I'm not sure
whether I would call it a bug, though it does seem strange.  Perhaps
Pynac represents this as a complex internally and so this happens?
Burcin will know :)

- kcrisman

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: Simplification

2009-05-14 Thread mabshoff



On May 14, 3:57 am, Laurent moky.m...@gmail.com wrote:
 Hello

Hi Laurent,

 

 x,y=var('x,y')
 s = x*y2 + x*(-y2 - x2 + 1) + x3 - x
 print simplify(s)

 Answer :

                            2         2    2         3
                         x y  + x (- y  - x  + 1) + x  - x

 +

 I'm quite disappointed that Sage do not notice that s=0. Do I miss
 something ?
 Btw, the function simplify_full does not exist ... so I suppose that I
 *do* miss something.

Yes, it does exist for me :)

--
| Sage Version 3.4.2, Release Date: 2009-05-04   |
| Type notebook() for the GUI, and license() for information.|
--
sage: x,y=var('x,y')
sage: s = x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x; s
x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x
sage: s.simplify()
x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x
sage: s.simplify_full()
0


 My version is extracted from the tar.gz downloaded from the website :

 | Sage Version 3.4.1, Release Date: 2009-04-21                       |
 | Type notebook() for the GUI, and license() for information.        |
 --

 Should I install some additional proposed packages 
 ?http://www.sagemath.org/download-packages.html

 Thanks
 Laurent

Cheers,

Michael
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification

2009-05-14 Thread simon . king

Dear Laurent,

On May 14, 12:57 pm, Laurent moky.m...@gmail.com wrote:
 Btw, the function simplify_full does not exist ... so I suppose that I
 *do* miss something.

Yes. simplify_full is not a function but a method (after all, python
is object oriented).

So, you can do:
sage: x,y=var('x,y')
sage: s = x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x
sage: s
x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x
sage: s.simplify_full()
0

Btw, for getting a list of methods, the TAB-Key helps. For example,
type in
sage: s.sim
and press the TAB-key. Then a list appears:
  s.simplify   s.simplify_log   s.simplify_trig
  s.simplify_exp   s.simplify_radical
  s.simplify_full  s.simplify_rational

And these are all attributes/methods of s whose names start with
'sim'.

Best regards,
Simon

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification

2009-05-14 Thread Robert Bradshaw

On May 14, 2009, at 3:57 AM, Laurent wrote:


 Hello

 

 x,y=var('x,y')
 s = x*y2 + x*(-y2 - x2 + 1) + x3 - x
 print simplify(s)

 Answer :

2 22 3
 x y  + x (- y  - x  + 1) + x  - x



 +

 I'm quite disappointed that Sage do not notice that s=0. Do I miss
 something ?
 Btw, the function simplify_full does not exist ... so I suppose that I
 *do* miss something.


Simplification doesn't expand by default. This is by design (e.g. one  
might argue that (1+x)^100 is more simplified than its expanded  
form). However, Sage is able to tell that this is zero:

sage: var('x,y')
(x, y)
sage: s = x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x
sage: s.simplify()
x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x
sage: s.simplify_full()
0
sage: s.simplify_rational()
0
sage: s.expand()
0

Or over the (orders of magnitude faster) polynomial ring:

sage: R.x,y = QQ[]
sage: s = x*y^2 + x*(-y^2 - x^2 + 1) + x^3 - x; s
0

- Robert

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification

2009-05-14 Thread Laurent


 On May 14, 12:57 pm, Laurent moky.m...@gmail.com wrote:
   
 Btw, the function simplify_full does not exist ... so I suppose that I
 *do* miss something.
 

 Yes. simplify_full is not a function but a method (after all, python
 is object oriented).
   

Thanks all.
Indeed, simplify_all(s) provokes an error while s.simplify_all() 
provides 0. Quite logical.
I still have some psychological inability to speak with Sage as I speak 
with my python interpreter ;)

Good afternoon
Laurent


--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread Tim Lahey

On Nov 24, 2008, at 8:45 PM, William Stein wrote:


 On Mon, Nov 24, 2008 at 4:46 PM, Tim Lahey [EMAIL PROTECTED]  
 wrote:

 Hi,

 Is there a specific way to add rules (and apply them) to rewrite
 expressions in Sage?

 Such as, log(a)-log(b) = log(a/b)

 I need this (and others) in order to properly compare the integration
 results from Sage to the list of integrals I have. I'm trying to put
 together a suite of integration tests for both correctness and  
 timing.

 I don't know if one can do the above (maybe with pynac it is  
 possible).
 However, in the meantime could you at least improperly compare
 the results for pseudo-correctness by evaluating both answers
 at a bunch of randomly chosen points and see if they differ by a  
 constant?


I'll check the maxima docs. Unfortunately, at the moment, it doesn't
look like one can use the new symbolics with the standard (maxima)  
integration.

If I do, I get:

sage: var('x,a,b',ns=1)
(x, a, b)
sage: f16 = x/(a*x+b)^3
sage: f16.integrate(x)
---
AttributeErrorTraceback (most recent call  
last)

/Users/tjlahey/ipython console in module()

AttributeError: 'sage.symbolic.expression.Expression' object has no  
attribute 'integrate'


I can easily run timing comparisons between maxima and FriCAS, but  
because
of how sympy does things (with its separate variables), I'll have to run
them separately. Comparing maxima and FriCAS, the timings are pretty  
close on
both for most of the ones I've tried. A few were much longer in FriCAS.

I have a pretty long list of integrals to go through and I've only  
done 16.

Cheers,

Tim.

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread William Stein

On Mon, Nov 24, 2008 at 6:03 PM, Tim Lahey [EMAIL PROTECTED] wrote:

 On Nov 24, 2008, at 8:45 PM, William Stein wrote:


 On Mon, Nov 24, 2008 at 4:46 PM, Tim Lahey [EMAIL PROTECTED]
 wrote:

 Hi,

 Is there a specific way to add rules (and apply them) to rewrite
 expressions in Sage?

 Such as, log(a)-log(b) = log(a/b)

 I need this (and others) in order to properly compare the integration
 results from Sage to the list of integrals I have. I'm trying to put
 together a suite of integration tests for both correctness and
 timing.

 I don't know if one can do the above (maybe with pynac it is
 possible).
 However, in the meantime could you at least improperly compare
 the results for pseudo-correctness by evaluating both answers
 at a bunch of randomly chosen points and see if they differ by a
 constant?


 I'll check the maxima docs. Unfortunately, at the moment, it doesn't
 look like one can use the new symbolics with the standard (maxima)
 integration.

True.


 If I do, I get:

 sage: var('x,a,b',ns=1)
 (x, a, b)
 sage: f16 = x/(a*x+b)^3
 sage: f16.integrate(x)
 ---
 AttributeErrorTraceback (most recent call
 last)

 /Users/tjlahey/ipython console in module()

 AttributeError: 'sage.symbolic.expression.Expression' object has no
 attribute 'integrate'

Yep, that's not implemented.

 I can easily run timing comparisons between maxima and FriCAS, but
 because
 of how sympy does things (with its separate variables), I'll have to run
 them separately. Comparing maxima and FriCAS, the timings are pretty
 close on
 both for most of the ones I've tried. A few were much longer in FriCAS.

 I have a pretty long list of integrals to go through and I've only
 done 16.

Many thanks for doing this!

William

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread Tim Lahey


On Nov 24, 2008, at 9:05 PM, William Stein wrote:

 I can easily run timing comparisons between maxima and FriCAS, but
 because
 of how sympy does things (with its separate variables), I'll have  
 to run
 them separately. Comparing maxima and FriCAS, the timings are pretty
 close on
 both for most of the ones I've tried. A few were much longer in  
 FriCAS.

 I have a pretty long list of integrals to go through and I've only
 done 16.

 Many thanks for doing this!

 William


No problem. Once it's done it should help as automated tests for both
monitoring performance and correctness. I'll be happy to donate them
to the cause. It's going to take a while.

The timeit routines give results that look like:
5 loops, best of 3: 50 ms per loop

Does anybody have something to pull out the specific time (50ms)?

Cheers,

Tim.

---
Tim Lahey
PhD Candidate, Systems Design Engineering
University of Waterloo

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread mabshoff



On Nov 24, 6:17 pm, Tim Lahey [EMAIL PROTECTED] wrote:
 On Nov 24, 2008, at 9:05 PM, William Stein wrote:

Hi,

  I can easily run timing comparisons between maxima and FriCAS, but
  because
  of how sympy does things (with its separate variables), I'll have  
  to run
  them separately. Comparing maxima and FriCAS, the timings are pretty
  close on
  both for most of the ones I've tried. A few were much longer in  
  FriCAS.

  I have a pretty long list of integrals to go through and I've only
  done 16.

  Many thanks for doing this!

  William

 No problem. Once it's done it should help as automated tests for both
 monitoring performance and correctness. I'll be happy to donate them
 to the cause. It's going to take a while.

 The timeit routines give results that look like:
 5 loops, best of 3: 50 ms per loop

 Does anybody have something to pull out the specific time (50ms)?

We have a timeit doctest framework that is supposed to hunt for speed
regressions. It is merged in 3.2, but we need infrastructure to
compare the output from several runs.

But I guess you are asking if timeit('foo') could return the time so
that one can do something with the data? I am not sure how that is
possible, but the timeit doctesting framework somehow does it.

 Cheers,

 Tim.

Cheers,

Michael

 ---
 Tim Lahey
 PhD Candidate, Systems Design Engineering
 University of Waterloo
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread Tim Lahey


On Nov 24, 2008, at 9:21 PM, mabshoff wrote:

 We have a timeit doctest framework that is supposed to hunt for speed
 regressions. It is merged in 3.2, but we need infrastructure to
 compare the output from several runs.

 But I guess you are asking if timeit('foo') could return the time so
 that one can do something with the data? I am not sure how that is
 possible, but the timeit doctesting framework somehow does it.


I know I could parse the output, but I thought someone might have done
it and it sounds like the timeit doctest framework might do it.

Where can I find this in the source so I can see how it is doing it?

Thanks,

Tim.

---
Tim Lahey
PhD Candidate, Systems Design Engineering
University of Waterloo

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread Mike Hansen

On Mon, Nov 24, 2008 at 6:31 PM, Tim Lahey [EMAIL PROTECTED] wrote:
 I know I could parse the output, but I thought someone might have done
 it and it sounds like the timeit doctest framework might do it.

 Where can I find this in the source so I can see how it is doing it?

You can do this in 3.2:

sage: s = timeit.eval(2+3)
sage: s
625 loops, best of 3: 942 ns per loop
sage: s.stats
(625, 3, 3, 942.230224609375, 'ns')

The code is in sage/misc/sage_timeit.py and sage/misc/sage_timeit_class.py.

--Mike

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread mabshoff



On Nov 24, 7:03 pm, Tim Lahey [EMAIL PROTECTED] wrote:
 On Nov 24, 2008, at 9:51 PM, Mike Hansen wrote:



  You can do this in 3.2:

  sage: s = timeit.eval(2+3)
  sage: s
  625 loops, best of 3: 942 ns per loop
  sage: s.stats
  (625, 3, 3, 942.230224609375, 'ns')

  The code is in sage/misc/sage_timeit.py and sage/misc/
  sage_timeit_class.py.

 Thanks a lot. This will definitely help.

Yep.

 Cheers,

You should consider creating one or a couple large files with the
integrals for doctesting and stuff them into $SAGE_ROOT/devel/tests.
Hopefully it can be arranged to feed the input into Maxima/Axiom/Maple/
MMA/sympy and so on and compare the result as well as performance. If
you find a bunch of integrals the OS programs cannot do or where a
result is incorrect I am sure those projects will be more than happy
to get bug reports.

 Tim.

Cheers,

Michael
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread Tim Lahey


On Nov 24, 2008, at 10:07 PM, mabshoff wrote:

 You should consider creating one or a couple large files with the
 integrals for doctesting and stuff them into $SAGE_ROOT/devel/tests.
 Hopefully it can be arranged to feed the input into Maxima/Axiom/ 
 Maple/
 MMA/sympy and so on and compare the result as well as performance. If
 you find a bunch of integrals the OS programs cannot do or where a
 result is incorrect I am sure those projects will be more than happy
 to get bug reports.

Initially, I'm using the integrals set I got from Tim Daly at the Axiom
project. His are from the Schaum's integral tables. He has a total of
25 separate files. I've finished the first file. So, I'm not checking
those results, just performance. I will be checking both Maxima and  
Sympy
for correctness, though. I've already found one integral that Axiom and
Sympy get correct, but Maxima fails because it requests additional
information during the integration:

var('x,a,b,n')
f22 = (a*x+b)^n
aa = f22.integrate(x)

In fact, SymPy gets the same answer as Schaum's while FriCAS needs
a rewrite rule applied to the results to match Schaum's.

Cheers,

Tim.

---
Tim Lahey
PhD Candidate, Systems Design Engineering
University of Waterloo

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Simplification/Rewrite Rules?

2008-11-24 Thread William Stein

On Mon, Nov 24, 2008 at 6:17 PM, Tim Lahey [EMAIL PROTECTED] wrote:


 On Nov 24, 2008, at 9:05 PM, William Stein wrote:

 I can easily run timing comparisons between maxima and FriCAS, but
 because
 of how sympy does things (with its separate variables), I'll have
 to run
 them separately. Comparing maxima and FriCAS, the timings are pretty
 close on
 both for most of the ones I've tried. A few were much longer in
 FriCAS.

 I have a pretty long list of integrals to go through and I've only
 done 16.

 Many thanks for doing this!

 William


 No problem. Once it's done it should help as automated tests for both
 monitoring performance and correctness. I'll be happy to donate them
 to the cause. It's going to take a while.

 The timeit routines give results that look like:
 5 loops, best of 3: 50 ms per loop

 Does anybody have something to pull out the specific time (50ms)?

In Sage-3.2 somebody (thanks!) nicely refactored the timeit code
somewhat, so that this is well supported.  This is probably related
to the doctest improvements that mabshoff just mentioned.
Anyway, here is an example:

sage: from sage.misc.sage_timeit import sage_timeit
sage: a = sage_timeit('3^1',globals())
sage: a
625 loops, best of 3: 35.2 µs per loop
sage: type(a)
type 'instance'
sage: a.stats
(625, 3, 3, 35.214614868164062, '\xc2\xb5s')
sage:a.__repr__??
def __repr__(self):
return %d loops, best of %d: %.*g %s per loop % self.stats

The stats are:
   (number, repeat, precision, best * scaling[order], units[order])

It would be nice if you contribute some new integration doctests or
something even before you have something massive and
comprehensive.

William

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---