tellsimp & truncate



On 9/17/07, Barton Willis <willisb at unk.edu> wrote:

> These are OK, But with CVS maxima
>
>  (%i1) tellsimp(truncate(x), 5);
> (%o1) [truncaterule1,simp-truncate]
>
>   (%i2) truncate(x);
>   (%o2) truncate(x);
>
>   (%i3) truncate(-x);
>   (%o3) -5

Looks like noun/verb confusion. There are at least 2 sources of
strangeness here. (1) A rule defined for a noun doesn't usually
apply to the verb, and vice versa. Here's what I was able to puzzle
out about tellsimpafter.

     The treatment of noun and verb forms is slightly confused. If a
     rule is defined for a noun (or verb) form and a rule for the
     corresponding verb (or noun) form already exists, the
     newly-defined rule applies to both forms (noun and verb).  If a
     rule for the corresponding verb (or noun) form does not exist, the
     newly-defined rule applies only to the noun (or verb) form.

Dunno if tellsimp acts the same. I'm sure this confusion wasn't
intentional. (2) SIMP-TRUNCATE which is attached to the noun
%TRUNCATE returns a verb $TRUNCATE. This makes it pretty
difficult to define a rule for the noun (assuming we could get
tellsimp/tellsimpafter to cooperate otherwise).

I guess (2) seems odd. Shouldn't SIMP-TRUNCATE return a noun
if applied to %TRUNCATE ?? Here's a patch to make it do that.
I find that with the patched SIMP-TRUNCATE, I can define a rule
which seems to do something predictable.

tellsimp ('truncate (x), 1234);
truncate (x);
 => 1234

A tangential bit of strangeness is that %TRUNCATE doesn't have
the simplification properties, instead $TRUNCATE has them.
Isn't that unlike other noun/verb pairs in Maxima? Oh well.

truncate (- x)
 => truncate(- x)
:lisp (setf (get '%truncate 'reflection-rule) (get '$truncate 'reflection-rule))
 => #<COMPILED-FUNCTION ODD-FUNCTION-REFLECT>
truncate (- x);
 => - 1234

FWIW

Robert

PS.
--- src/nummod.lisp     18 May 2007 16:13:10 -0000      1.13
+++ src/nummod.lisp     18 Sep 2007 06:01:14 -0000
@@ -291,8 +291,8 @@
 (setf (get '$truncate 'reflection-rule) #'odd-function-reflect)

 (defun simp-truncate (e yy z)
-  (declare (ignore yy))
   (oneargcheck e)
+  (setq yy (caar e)) ;; find a use for the otherwise unused YY.
   (setq e (simplifya (specrepcheck (second e)) z))
   (cond (($featurep e '$integer) e) ;; takes care of
truncate(truncate(x)) --> truncate(x).
        ((memq e '($inf $minf $und $ind)) e)
@@ -300,6 +300,6 @@
         (let ((sgn (csign e)))
           (cond ((memq sgn '($neg $nz)) (take '($ceiling) e))
                 ((memq sgn '($zero $pz $pos)) (take '($floor) e))
-                ((apply-reflection-simp '$truncate e t))
-                (t `(($truncate simp) ,e)))))))
+                ((apply-reflection-simp yy e t))
+                (t `((,yy simp) ,e)))))))