+
Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,61 @@

## unreleased

- #503:

- Changes the default implementation of `square` and `cube` for differentials
to use `(expt <> 2)` etc instead of `(* <> <>)`.

This is a _big deal!_ For certain expressions there's a huge blowup when you
square a big symbolic term, and taking the derivative of it TWICE is very
messy.

With this change, differentials use the chain rule to calculuate the
derivative of $x^2$ as $2x*x'$, instead of using the product rule and
achieving a SECOND differentiatation of the same form and another
multiplication: $xx' + x'x$.

Before a judicious `simplify` call I added, this change dropped the runtime
of the `sicmutils.sicm.ch3-test` suite down by 6x. After the simplify change
in `sicmutils.examples.top` the tests were still 40% faster in that
namespace.

- Fixes a bug where the `RationalFunction` cube implementation actually called
`square`.

- adds `sicmutils.mechanics.lagrange/Lagrangian` for building function
signatures of Lagrangians.

- adds the `sicmutils.mechanics.time-evolution` namespace

- adds `sicmutils.mechanics.lagrange/L-axisymmetric-top`, more efficient than
the version in `sicmutils.examples.top`

- Fleshes out `sicmutils.mechanics.hamilton`:

- New functions: `H-state?`, `compatible-H-state?`, `state->p`, `momenta`,
`P`, `literal-Hamiltonian-state`, `L-state->H-state`, `H-state->L-state`,
`H-state->matrix`, `matrix->H-state`, `make-Hamiltonian`, `D-phase-space`,
`Hamiltonian->Lagrangian-procedure`, `Hamiltonian->Lagrangian`,
`flow-derivative`, `flow-transform`, `standard-map-inverse`, `F->K`,
`J-func`, `T-func`, `canonical-H?`, `canonical-K?`,
`linear-function->multiplier`, `Phi`, `Phi*`, `qp-canonical?`,
`polar-canonical-inverse`, `two-particle-center-of-mass` ,
`two-particle-center-of-mass-canonical`, `transpose-function`,
`multiplicative-transpose`, `symplectic-two-form`, `canonical-transform?`,
`J-matrix`, `symplectic?`

- `F->CH` moves to `F->CT` (`F->CT` is now an alias)

- `Legendre-transform-fn` becomes `Legendre-transform-procedure` and gains
more correctness tests, toggled on and off by the
`*validate-Legendre-transform?*` dynamic variable.

- #508 adds `sicmutils.mechanics.noether` namespace, with `Noether-integral`.

- #506 tidies up the build by removing unneeded reader conditionals and
replacing renames like `core-=` with a proper require of `clojure.core`.

- #502 begins the port of the remaining items in the scmutils `mechanics`
package over the Clojure. This PR focuses on `sicmutils.mechanics.lagrange`,
which contains functions from many files in the original `mechanics` folder.
Expand Down
57 changes: 28 additions & 29 deletions src/sicmutils/calculus/covariant.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,34 @@
;; This comes from `Lie.scm`.

(defn- vector-field-Lie-derivative [X]
(o/make-operator
(fn [Y]
(cond (f/function? Y) (X Y)
(vf/vector-field? Y) (o/commutator X Y)

(ff/form-field? Y)
(let [k (ff/get-rank Y)
op (fn [& vectors]
(let [vectors (into [] vectors)]
(assert (= k (count vectors))
`(~'≠ ~k ~(count vectors)
~@vectors
~@(map meta vectors)))
(g/- ((g/Lie-derivative X) (apply Y vectors))
(ua/generic-sum
(fn [i]
(let [xs (update vectors i (g/Lie-derivative X))]
(apply Y xs)))
0 k))))
name `((~'Lie-derivative ~(v/freeze X))
~(v/freeze Y))]
(ff/procedure->nform-field op k name))

(s/structure? Y)
(s/mapr (vector-field-Lie-derivative X) Y)

:else (u/unsupported "Bad argument: Lie Derivative")))
`(~'Lie-derivative
~(v/freeze X))))
(let [freeze-X (v/freeze X)
op-name `(~'Lie-derivative ~freeze-X)]
(-> (fn rec [Y]
(cond (f/function? Y) (X Y)
(vf/vector-field? Y) (o/commutator X Y)

(ff/form-field? Y)
(let [k (ff/get-rank Y)
op (fn [& vectors]
(let [vectors (into [] vectors)]
(assert (= k (count vectors))
`(~'≠ ~k ~(count vectors)
~@vectors
~@(map meta vectors)))
(g/- ((g/Lie-derivative X) (apply Y vectors))
(ua/generic-sum
(fn [i]
(let [xs (update vectors i (g/Lie-derivative X))]
(apply Y xs)))
0 k))))
name `((~'Lie-derivative ~freeze-X) ~(v/freeze Y))]
(ff/procedure->nform-field op k name))

(s/structure? Y)
(s/mapr (vector-field-Lie-derivative X) Y)

:else (u/unsupported "Bad argument: Lie Derivative")))
(o/make-operator op-name))))

(defmethod g/Lie-derivative [::vf/vector-field] [V]
(vector-field-Lie-derivative V))
Expand Down
16 changes: 11 additions & 5 deletions src/sicmutils/differential.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1214,11 +1214,18 @@
(defunary g/negate (lift-1 g/negate))
(defbinary g/sub (lift-2 g/sub))

(let [mul (lift-2 g/mul)]
(let [mul (lift-2 g/mul)
expt (lift-2 g/expt)]
(defbinary g/mul mul)
(defunary g/square (fn [x] (mul x x)))
(defunary g/cube (fn [x] (mul x (mul x x))))
(defbinary g/dot-product mul))
(defbinary g/dot-product mul)
(defbinary g/expt expt)

;; NOTE that it's important that these stay exponents vs repeated
;; multiplication. It is cheaper to compute the derivative just once using the
;; chain rule, vs performing a full multiplication and then taking the
;; derivative of the result.
(defunary g/square (fn [x] (expt x 2)))
(defunary g/cube (fn [x] (expt x 3))))

(defunary g/invert (lift-1 g/invert))
(defbinary g/div (lift-2 g/div))
Expand Down Expand Up @@ -1264,7 +1271,6 @@
(defbinary g/solve-linear-right div))

(defunary g/sqrt (lift-1 g/sqrt))
(defbinary g/expt (lift-2 g/expt))
(defunary g/log (lift-1 g/log))
(defunary g/exp (lift-1 g/exp))

Expand Down
2 changes: 1 addition & 1 deletion src/sicmutils/examples/top.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

(defn L
[A B C gMR]
(let [T (rigid/T-rigid-body A B C)
(let [T (comp e/simplify (rigid/T-rigid-body A B C))
V (fn [[_ [theta _ _]]]
(* gMR (cos theta)))]
(- T V)))
Expand Down
8 changes: 4 additions & 4 deletions src/sicmutils/generic.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ defaults to `ln((1 + sqrt(1+x^2)) / x)`."
(if (v/zero? x)
x
(sub (div (cos x) x)
(div (sin x) (* x x)))))})
(div (sin x) (square x)))))})

(defmethod sinc :default [x]
(if (v/zero? x)
Expand Down Expand Up @@ -886,7 +886,7 @@ defaults to `ln((1 + sqrt(1+x^2)) / x)`."
x
(let [sx (sec x)]
(sub (div (* sx sx) x)
(div (tan x) (* x x))))))})
(div (tan x) (square x))))))})

(defmethod tanc :default [x]
(if (v/zero? x)
Expand All @@ -907,7 +907,7 @@ defaults to `ln((1 + sqrt(1+x^2)) / x)`."
(if (v/zero? x)
x
(sub (div (cosh x) x)
(div (sinh x) (* x x)))))})
(div (sinh x) (square x)))))})

(defmethod sinhc :default [x]
(if (v/zero? x)
Expand All @@ -927,7 +927,7 @@ defaults to `ln((1 + sqrt(1+x^2)) / x)`."
x
(let [sx (sech x)]
(sub (div (* sx sx) x)
(div (tanh x) (* x x))))))})
(div (tanh x) (square x))))))})

(defmethod tanhc :default [x]
(if (v/zero? x)
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载