Turning off automatic simplification

Help
Ted Kosan
2011-04-21
2012-11-20
  • Ted Kosan

    Ted Kosan - 2011-04-21

    I sometimes need to work with expressions exactly as they are entered and I would like to know if Reduce has a way to turn off automatic simplification? For example, in the MathPiper CAS the Hold() function is used to prevent an expression from being simplified:

    In> 2/4
    Result: 1/2

    In> zz := Hold(2/4)
    Result: 2/4

    In> zz
    Result: 2/4

    I have looked through four books on Reduce, but I have not been able to locate this information.

    Thanks in advance,

    Ted

     
  • Anthony Hearn

    Anthony Hearn - 2011-04-24

    I haven't tested this very thoroughly, but you might see if this piece of code does what you want.  Numerical expressions still evaluate (e.g., 1+2 -> 3), however, a+a and int(sin x,x) return the results unchanged.


    copyd('revalz,'reval1);

    fluid '(!*revalp);

    switch revalp;

    on revalp;

    symbolic procedure reval1(u,v);
       if null !*revalp then u else revalz(u,v);

     
  • Anthony Hearn

    Anthony Hearn - 2011-04-24

    Ok, I've looked a little further.  The following code (with revalp off) will make 2/4 return the unchanged expression.  It would be easy to turn this into a "hold" function if you prefer that.  You'd simply bind !*revalp within the function and make sure it's nil:

    copyd('revalz,'reval1);

    fluid '(!*revalp);

    switch revalp;

    on revalp;

    symbolic procedure reval1(u,v);
       if null !*revalp then u else revalz(u,v);

    copyd('intexprnpz,'intexprnp);

    symbolic procedure intexprnp u; if !*revalp then intexprnpz u else nil;

     
  • Ted Kosan

    Ted Kosan - 2011-04-24

    The code you posted was very helpful. Here is a small test I did with it that binds an unsimplified expression to zz with revalp off and then verifies that it remains unsimplified when revalp is turned back on:

    In> off revalp;

    In> zz := (x^2 - 36) / (6 - x);

    zz := (x**2 - 36)/(6 - x)$

    In> on revalp;

    In> zz;

    - x - 6$

    In> plist 'zz;

    ((avalue scalar (quotient (difference (expt x 2) 36) (difference 6 x))))

    My next step is to figure out how to process unsimplified expressions like the following MathPiper example shows:

    In> zz := Hold((x+x)/x);
    Result: (x+x)/x

    In> Numerator(zz)
    Result: x+x

    In> Subst(x,y) zz
    Result: (y+y)/y

    In MathPiper, one can specify if function parameters are evaluated or not when the function is defined. I noticed that in the package pm, a file called pmpatch.red defines a function called nosimp which appears to provide this capability for Reduce. I think the code you provided, plus the code in the pm package, should provide me with a good place to start for building the capabilities I need.

    Thanks again for the help.

     
  • Arthur Norman

    Arthur Norman - 2011-04-26

    I have just (I hope) put the "revalp" switch as suggested by Tony into the subversion repository so it should automatically become available to everybody.
              Arthur

     
  • Ted Kosan

    Ted Kosan - 2011-04-27

    I did some more research on this issue and I discovered that Maxima uses a flag called simp to turn off automatic simplification:

    (%i1) (x + x)/x;
    (%o1)                                  2
    (%i2) simp:off;
    (%o2)                                false
    (%i3) zz : (x + x)/x;
                                         x + x
    (%o3)                                -----
                                           x
                                           
    (%i4) num(zz);
    (%o4)                                x + x
    (%i5) subst(y,x,zz);
                                         y + y
    (%o5)                                -----
                                           y
    

    The critical thing that makes Maxima's simp different from revalp is that simp still enables evaluation to occur so that the expression can be processed with functions like denom, etc. Something similar to Maxima's simp flag is what I am interested in using in Reduce.

     
  • James

    James - 2011-05-12

    For what it is worth, I have naively tried entering the code shown above, and I get the following:

    Reduce (Free CSL version), 14-Apr-11 …

    1: (x+x)/x;
    2

    2: off revalp;
    ***** revalp not defined as switch

    3: copyd('revalz,'reval1);
    revalz

    4: fluid '(!*revalp);
    5: switch revalp;
    6: on revalp;
    7: symbolic procedure reval1(u,v);  if null !*revalp then u else revalz(u,v);
    reval1

    8: copyd('intexprnpz,'intexprnp);
    intexprnpz

    9: symbolic procedure intexprnp u; if !*revalp then intexprnpz u else nil;
    intexprnp

    10: off revalp;
    11: (x+x)/x;
    +++ Error too many arguments provided:

    12: on revalp;
    13: (x+x)/x;
    +++ Error too many arguments provided:

    14:

    James

     
  • Thomas Sturm

    Thomas Sturm - 2011-05-12

    intexprnp take 2 arguments. So go:

    symbolic procedure intexprnp(u,v); if !*revalp then intexprnpz(u,v) u else nil;

    The other error:

    2: off revalp;
    ***** revalp not defined as switch

    is because (as the message says) the switch is defined only later at your prompt no. 5

    Arthur: Does not the interpreter know the name of the function at the argument mismatch? If so, as more informative error message might be easy to implement and helpful.

    Thomas

     
  • James

    James - 2011-05-13

    Thanks Thomas.  Naively, again,

    Reduce (Free CSL version), 14-Apr-11 …
    1: copyd('revalz,'reval1);

    revalz

    2: fluid '(!*revalp);
    3: switch revalp;
    4: on revalp;
    5: symbolic procedure reval1(u,v); if null !*revalp then u else revalz(u,v);

    reval1

    6: copyd('intexprnpz,'intexprnp);

    intexprnpz

    7: symbolic procedure intexprnp(u,v); if !*revalp then intexprnpz(u,v) u else nil;

    ***** (intexprnpz u v) invalid as operator

    8:

    James

     
  • Arthur Norman

    Arthur Norman - 2011-05-13

    I had put Tony Hearn's patches into the subversion, so as of some time last week anybody who builds afresh from that ought not to need to be trying to install this switch for themselves…
                Arthur

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks