Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

ch6 tests behave differently depending on seemingly equivalent series g/- #151

@sritchie

Description

@sritchie

Here's a reproduction. You can make this test fail by redefining the existing seq:- in series.cljc:

(defn- seq:- [f g]
  (seq:+ f (seq:negate g)))

to:

(defn- seq:- [f g]
  (map g/- f g))

Which should be equivalent. Here's the check:

(deftest ch6-repro
  "Evaluate this in sicmutils.sicm.ch6_test.cljc. If you defined g/- for series
  as `(map g/- f g)`, this test will return a different result than if you
  define it as `(g/+ f (g/negate g))`."
  (let [L (e/Lie-derivative
           (fn [[_ theta ptheta]]
             (/ (* -1 'a 'b (sin theta))
                ptheta)))
        H (e/series
           (fn [[_ _ ptheta]]
             (/ (square ptheta)
                (* 2 'a)))
           (fn [[_ theta _]]
             (* -1 'e 'b (cos theta))))
        E (((exp (* 'e L)) H) (up 't 'theta 'p_theta))]
    (is (= '((/ (expt p_theta 2) (* 2 a))
             0
             (/ (* a (expt b 2) (expt e 2) (expt (sin theta) 2))
                (* 2 (expt p_theta 2))))
           (take 3 (simplify E))))))

With the existing definition, the 3rd sequence entry is

(/ (* a (expt b 2) (expt e 2) (expt (sin theta) 2)) (* 2 (expt p_theta 2)))

If you use the new g/- based definition, you pick up a factor of 3 in the third term:

(/ (* 3N a (expt b 2) (expt e 2) (expt (sin theta) 2)) (* 2 (expt p_theta 2)))

Seems like a bug with the simplifier.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions