GiNaC and assumptions on variables?

Richard B. Kreckel kreckel at ThEP.Physik.Uni-Mainz.DE
Mon Jul 31 17:52:49 CEST 2000


On 31 Jul 2000, Paul Grayson wrote:
> Hi, you don't have any sort of a feedback/suggestions/questions
> mailing address, and I didn't know if writing to devel was a good
> idea, so here's my question:

Hi Paul.  Writing to ginac-devel is IMHO a good idea.  It makes ideas
known to others and somebody might have already thought about it, have an
idea how to do this or have a veto against that.  I CC this email there.
(And I should set up mhonarc RSN...)

> I'm an undergraduate in physics at MIT, and I just started taking a
> look at GiNaC after getting frustrated with Mathematica and Maple.
> Needless to say, it was very refreshing to see that I could do math in
> a reasonable programming environment.  Basically I'm interested in
> getting GiNaC to do some classical perturbation theory for me, which
> basically will involve going through a bunch of integration and
> simplification of large expressions.
> 
> The integration I can handle pretty easily myself (all terms are
> prop. to cos(x)^n*sin(x)^m).  In fact, I think GiNaC will do a much
> better job at this than Maple or Mathematica, which both get *really*
> bogged down when I try to integrate ~100 terms with complicated
> constant factors.  When a CAS computation takes forever, I have no way
> to discover why; GiNaC will let me analyze the computation like any
> computer program, and fix it.  For simplification, however I really
> need some way to work with constants that are known to have values in
> a certain range.  For example, given that x is real and x>0, we know
> sqrt(x*x) -> x.  Though this example is trivial, with larger
> expressions in many variables automatic simplifcation *with
> assumptions on variables* can be quite useful.  It's very frustrating
> when the computer doesn't even know that my variables are all *real*!
> 
> Both Maple and Mathematica have added this feature to their most
> recent versions:  In Maple V6, I can type
> 
>   assume(x>0);
>   sqrt(x*x);
> 
> and get 'x' as a result.  I read through the GiNaC documentation, and
> didn't see any obvious way to do this.  However, you make various
> statements in the docs that indicate that there are many hidden ways
> to simplify expressions in GiNaC --- do you have any methods in mind
> for performing these kinds of simplifications?  If not, do you see any
> reason that I shouldn't/couldn't implement this feature?  Would you
> be interested in giving me some guidance so that, if I added this, I
> could get it incorporated back into the main GiNaC distribution?
> 
> Thanks,
> -Paul

What you want to do doesn't sound impossible to me.  However, for my own
part, I don't think I do need this kind of feature and so won't be able to
help much.  Guidance is possible, though.  And no, nothing like this has
been implemented yet.

Adding assumptions to expressions throws up a couple of questions: Where
do you stick assumption-tags?  A pointer to something in class ex might
slow it down somewhat, though this needs to be tested.  I think ex would
be the way where to store it.  The alternative would be a protected
variable in class basic.  You need to think about how to evaluate those
tags.  The trivial example you give suggests that each class' eval()
function should check for members' property-tags, it could read them via
the .info() method.  (The info_flags class might need some careful
restructuring, if this wants to be going into production use.  It is
pretty much hacked together.)  If it gets in the way in the .eval()
function, an alternative would be to add this checking to another
evaluation-method.  It can soon get very involved as soon as more than one
variables are involved.  There is some literature about this and one
should carefully check what Maple does here.  Maybe it is discouraging,
maybe it is stimulating, but please have a look at this Maple session:

zino:~/projects/GiNaC/ginac$ maple
    |\^/|     Maple V Release 4 (Universitaet Mainz)
._|\|   |/|_. Copyright (c) 1981-1996 by Waterloo Maple Inc. All rights
 \  MAPLE  /  reserved. Maple and Maple V are registered trademarks of
 <____ ____>  Waterloo Maple Inc.
      |       Type ? for help.
> interface(version);
               TTY Iris, Release 4, DEC ALPHA UNIX, Apr 28, 1997
> assume(x>0);
> sqrt(x^2);       
                              x~
> assume(y>0);
> about(x+y);
x+y:
Error, (in ConvertProperty) too many levels of recursion
> about(sqrt((x+y)^2));
x+y:
Segmentation fault

I don't know if Maple6 performs better in this respect.  If you are still
interested, I can see if I find some pointers into the literature about
such things and send them to you.  It definitely requires some thinking
before one can start hacking.

Regards
     -richy.
-- 
Richard B. Kreckel
<Richard.Kreckel at Uni-Mainz.DE>
<http://wwwthep.physik.uni-mainz.de/~kreckel/>





More information about the GiNaC-devel mailing list