Menu

#4639 dim-%antideriv: a partial fix for a bug in widths

None
open
nobody
None
5
2025-11-30
2025-11-30
No

These are the messages M1 and M2, about "dim-%antideriv":

M1: https://sourceforge.net/p/maxima/mailman/message/59178281/
M2: https://sourceforge.net/p/maxima/mailman/message/59266596/

M1 is by Robert Dodier, in which he sent the code for
"dim-%antideriv", and M2 is by me, in which I showed that by adding
one line to Robert's code we can make it calculate the width correctly
in most - but not all - cases.

Robert asked me to send the code and the screenshots to the bug
tracker, so here it goes. The code is below, with the "setq" that I
added marked with ";; Edrx:", and with my tests in the comments at the
end. The screenshot named "without-setq-width.png" shows that the
widths were incorrect in all the four tests - o1, o2, o3, and o4 - and
the screenshot named "with-setq-width.png" shows that after my fix the
tests o1, o2, and o4 are good, but the width in o3 still has a one-off
error.

--snip--snip--

(if (not (fboundp 'display2d-unicode-enabled))
    (defun display2d-unicode-enabled () nil))


(defun dim-%antideriv (form result)

  (unless (= (length (cdr form)) 4)
    (return-from dim-%antideriv (dimension-function form result)))

  (let*
    ((args (rest form))
     (expr (first args))
     (my-var (second args))
     (lower-val (third args))
     (upper-val (fourth args))
     (lower-eqn (list '(mequal) my-var lower-val))
     (upper-eqn (list '(mequal) my-var upper-val))
     (vertical-bar-char (if (display2d-unicode-enabled)
                            at-char-unicode
                          (car (coerce $absboxchar 'list))))
     vertical-bar
     expr-result  
     lower-result
     upper-result
     expr-w  expr-h  expr-d
     lower-w lower-h lower-d
     upper-w upper-h upper-d)
    (declare (ignorable expr-w expr-h expr-d
                        lower-w lower-h lower-d
                        upper-w upper-h upper-d))

    (setq expr-result (dimension expr nil 'mparen 'mparen nil 0)
          expr-w width
          expr-h height
          expr-d depth)

    (setq lower-result (dimension-infix lower-eqn nil)
          lower-w width
          lower-h height
          lower-d depth)

    (setq upper-result (dimension-infix upper-eqn nil)
          upper-w width
          upper-h height
          upper-d depth)

    (setq vertical-bar (list 'd-vbar
                             (1+ (max expr-h upper-d))
                             (max (1+ expr-d) lower-h)
                             vertical-bar-char))

    (setq result (append (list (append (list (- lower-w) (max expr-h upper-d)) upper-result)
                               (append (list 0 (- (max (1+ expr-d) lower-h))) lower-result)
                               vertical-bar
                               (append (list 0 0) expr-result))
                         result))

    (setq height (+ 1 (max expr-h upper-d) upper-h)
          depth (+ (max (1+ expr-d) lower-h) lower-d))

    ;; Edrx:
    (setq width (+ expr-w 1 (max upper-w lower-w)))

    (update-heights height depth)

    result))

(setf (get '%antideriv 'dimension) 'dim-%antideriv)
(setf (get '$antideriv 'dimension) 'dim-%antideriv) ; Edrx

#|
 (eepitch-maxima)
 (eepitch-kill)
 (eepitch-maxima)
load ("dim-antideriv.lisp");
mybox(o) := [box(o)];

o1 : antideriv (F(u), u, a, b);
o2 : antideriv (F(u[k]), u[k], a[k], b[k]);
o3 : antideriv (a+b, u, z^2^n+y[k], x^2-z[k]);
o4 : antideriv (a+b, u, z^2^n+y[k], x^2-z[k[l[u]]]);

mybox(o1);
mybox(o2);
mybox(o3);
mybox(o4);

|#

--snip--snip--

Cheers,
Eduardo Ochs
https://anggtwu.net/eev-maxima.html
http://anggtwu.net/MAXIMA/dim-antideriv.lisp.html

2 Attachments

Discussion


Log in to post a comment.