From 172129d24dfb1b74ea98a404da9dc5e4da83df7d Mon Sep 17 00:00:00 2001 From: Sam Ritchie Date: Thu, 8 Aug 2024 09:30:15 -0400 Subject: [PATCH] rename diff --- src/emmy/abstract/function.cljc | 6 +-- src/emmy/calculus/derivative.cljc | 6 +-- src/emmy/collection.cljc | 2 +- src/emmy/{differential.cljc => dual.cljc} | 10 ++--- src/emmy/function.cljc | 2 +- src/emmy/matrix.cljc | 2 +- src/emmy/numerical/derivative.cljc | 2 +- src/emmy/operator.cljc | 2 +- src/emmy/polynomial.cljc | 2 +- src/emmy/quaternion.cljc | 2 +- src/emmy/sci.cljc | 2 +- src/emmy/series.cljc | 2 +- src/emmy/structure.cljc | 2 +- src/emmy/tape.cljc | 40 +++++++++---------- test/emmy/calculus/derivative_test.cljc | 4 +- test/emmy/collection_test.cljc | 2 +- ...{differential_test.cljc => dual_test.cljc} | 18 ++++----- test/emmy/generators.cljc | 4 +- test/emmy/polynomial_test.cljc | 2 +- test/emmy/tape_test.cljc | 2 +- 20 files changed, 57 insertions(+), 57 deletions(-) rename src/emmy/{differential.cljc => dual.cljc} (98%) rename test/emmy/{differential_test.cljc => dual_test.cljc} (96%) diff --git a/src/emmy/abstract/function.cljc b/src/emmy/abstract/function.cljc index c3e3abe8..283ed972 100644 --- a/src/emmy/abstract/function.cljc +++ b/src/emmy/abstract/function.cljc @@ -12,7 +12,7 @@ (:refer-clojure :exclude [name]) (:require #?(:clj [clojure.pprint :as pprint]) [emmy.abstract.number :as an] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generic :as g] [emmy.matrix :as m] @@ -262,7 +262,7 @@ And returns a folding function (designed for use with [[emmy.structure/fold-chain]]) that - generates a new [[emmy.differential/Dual]] by applying the chain rule and + generates a new [[emmy.dual/Dual]] by applying the chain rule and summing the partial derivatives for each perturbed argument in the input structure." [f primal-s tag] @@ -309,7 +309,7 @@ and generates the proper return value for `((D f) xs)`. - In forward-mode AD this is a new [[emmy.differential/Dual]] generated by + In forward-mode AD this is a new [[emmy.dual/Dual]] generated by applying the chain rule and summing the partial derivatives for each perturbed argument in the input structure. diff --git a/src/emmy/calculus/derivative.cljc b/src/emmy/calculus/derivative.cljc index 53f616e2..334854a1 100644 --- a/src/emmy/calculus/derivative.cljc +++ b/src/emmy/calculus/derivative.cljc @@ -7,7 +7,7 @@ "This namespace implements a number of differential operators like [[D]], and the machinery to apply [[D]] to various structures." (:refer-clojure :exclude [partial]) - (:require [emmy.differential :as d] + (:require [emmy.dual :as d] [emmy.expression :as x] [emmy.function :as f] [emmy.generic :as g] @@ -22,7 +22,7 @@ ;; ## Single and Multivariable Calculus ;; ;; These functions put together the pieces laid out -;; in [[emmy.differential]] and declare an interface for taking +;; in [[emmy.dual]] and declare an interface for taking ;; derivatives. (defn derivative @@ -34,7 +34,7 @@ see [[emmy.numerical.derivative/D-numeric]]. `f` must be built out of generic operations that know how to - handle [[emmy.differential/Differential]] inputs in addition to any types that + handle [[emmy.dual/Dual]] inputs in addition to any types that a normal `(f x)` call would present. This restriction does _not_ apply to operations like putting `x` into a container or destructuring; just primitive function calls." diff --git a/src/emmy/collection.cljc b/src/emmy/collection.cljc index c07af1e2..85698e2c 100644 --- a/src/emmy/collection.cljc +++ b/src/emmy/collection.cljc @@ -7,7 +7,7 @@ "This namespace contains implementations of various Emmy protocols for native Clojure collections." (:require [clojure.set :as cs] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generic :as g] [emmy.util :as u] diff --git a/src/emmy/differential.cljc b/src/emmy/dual.cljc similarity index 98% rename from src/emmy/differential.cljc rename to src/emmy/dual.cljc index 013427b7..67fe8892 100644 --- a/src/emmy/differential.cljc +++ b/src/emmy/dual.cljc @@ -3,7 +3,7 @@ ^#:nextjournal.clerk {:toc true :visibility :hide-ns} -(ns emmy.differential +(ns emmy.dual "This namespace contains an implementation of [[Dual]], a type that forms the basis for the forward-mode automatic differentiation implementation in emmy. @@ -15,8 +15,8 @@ ;; ## Differentials, Dual Numbers and Automatic Differentiation ;; -;; This namespace develops an implementation of a type called [[Differential]]. -;; A [[Differential]] is a generalization of a type called a ["dual +;; This namespace develops an implementation of a type called [[Dual]]. +;; A [[Dual]] is a generalization of a type called a ["dual ;; number"](https://en.wikipedia.org/wiki/Dual_number). ;; ;; As we'll discuss, passing these numbers as arguments to some function $f$ @@ -236,7 +236,7 @@ ;; ;; The solution is to introduce a new $\varepsilon$ for every level, and allow ;; different $\varepsilon$ instances to multiply without annihilating. Each -;; $\varepsilon$ is called a "tag". [[Differential]] (implemented below) is a +;; $\varepsilon$ is called a "tag". [[Dual]] (implemented below) is a ;; generalized dual number that can track many tags at once, allowing nested ;; derivatives like the one described above to work. ;; @@ -256,7 +256,7 @@ ;; ### What Return Values are Allowed? ;; ;; Before we discuss the implementation of dual -;; numbers (called [[Differential]]), [[emmy.tape/lift-1]], [[emmy.tape/lift-2]] +;; numbers (called [[Dual]]), [[emmy.tape/lift-1]], [[emmy.tape/lift-2]] ;; and the rest of the machinery that makes this all possible; what sorts of ;; objects is `f` allowed to return? ;; diff --git a/src/emmy/function.cljc b/src/emmy/function.cljc index 737594ac..73ab33eb 100644 --- a/src/emmy/function.cljc +++ b/src/emmy/function.cljc @@ -10,7 +10,7 @@ (:refer-clojure :exclude [get get-in memoize with-meta name]) (:require [clojure.core :as core] [clojure.core.match :refer [match]] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.generic :as g] [emmy.util :as u] [emmy.value :as v]) diff --git a/src/emmy/matrix.cljc b/src/emmy/matrix.cljc index 56b006a3..fcdbbb52 100644 --- a/src/emmy/matrix.cljc +++ b/src/emmy/matrix.cljc @@ -8,7 +8,7 @@ to the [[Matrix]] datatype." (:refer-clojure :exclude [get-in some]) (:require [clojure.core :as core] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generic :as g] [emmy.polynomial :as poly] diff --git a/src/emmy/numerical/derivative.cljc b/src/emmy/numerical/derivative.cljc index e96d0fd6..7e3b7ac8 100644 --- a/src/emmy/numerical/derivative.cljc +++ b/src/emmy/numerical/derivative.cljc @@ -14,7 +14,7 @@ For an implementation of [forward-mode automatic differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation), - see [[emmy.differential]] (for the backing implementation) + see [[emmy.dual]] (for the backing implementation) and [[emmy.calculus.derivative]] (for the [[emmy.operator/Operator]] instances that make it pleasant to use this method.)" (:require [emmy.abstract.function :as af] diff --git a/src/emmy/operator.cljc b/src/emmy/operator.cljc index b9883ff5..d25daa83 100644 --- a/src/emmy/operator.cljc +++ b/src/emmy/operator.cljc @@ -3,7 +3,7 @@ (ns emmy.operator (:refer-clojure :exclude [get identity name]) (:require [clojure.core :as core] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generic :as g] [emmy.pattern.rule :refer [rule-simplifier]] diff --git a/src/emmy/polynomial.cljc b/src/emmy/polynomial.cljc index 2f459a56..e4ab83f5 100644 --- a/src/emmy/polynomial.cljc +++ b/src/emmy/polynomial.cljc @@ -8,7 +8,7 @@ (:require [clojure.set :as set] [clojure.string :as cs] [emmy.collection] - [emmy.differential :as sd] + [emmy.dual :as sd] [emmy.expression :as x] [emmy.expression.analyze :as a] [emmy.function :as f] diff --git a/src/emmy/quaternion.cljc b/src/emmy/quaternion.cljc index e38dc915..17fa976b 100644 --- a/src/emmy/quaternion.cljc +++ b/src/emmy/quaternion.cljc @@ -12,7 +12,7 @@ and [[emmy.numbers]]." (:refer-clojure :exclude [zero?]) (:require [emmy.complex :as sc] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generic :as g] [emmy.matrix :as m] diff --git a/src/emmy/sci.cljc b/src/emmy/sci.cljc index fe883723..98d57b3b 100644 --- a/src/emmy/sci.cljc +++ b/src/emmy/sci.cljc @@ -13,7 +13,7 @@ minimal SCI environment should select their desired namespaces from this map." {'emmy.algebra.fold (copy-ns emmy.algebra.fold (sci/create-ns 'emmy.algebra.fold)) 'emmy.complex (copy-ns emmy.complex (sci/create-ns 'emmy.complex)) - 'emmy.differential (copy-ns emmy.differential (sci/create-ns 'emmy.differential)) + 'emmy.dual (copy-ns emmy.dual (sci/create-ns 'emmy.dual)) 'emmy.env (copy-ns emmy.env (sci/create-ns 'emmy.env)) 'emmy.expression (copy-ns emmy.expression (sci/create-ns 'emmy.expression)) 'emmy.function (copy-ns emmy.function (sci/create-ns 'emmy.function)) diff --git a/src/emmy/series.cljc b/src/emmy/series.cljc index f2cc8268..10559332 100644 --- a/src/emmy/series.cljc +++ b/src/emmy/series.cljc @@ -22,7 +22,7 @@ Doug also has a 10-line version in Haskell on [his website](https://www.cs.dartmouth.edu/~doug/powser.html)." (:refer-clojure :exclude [identity]) - (:require [emmy.differential :as d] + (:require [emmy.dual :as d] [emmy.expression] ;; for the effect of the defmethod of zero? for Literals [emmy.function :as f] [emmy.generic :as g] diff --git a/src/emmy/structure.cljc b/src/emmy/structure.cljc index 83a6131a..8ef21c15 100644 --- a/src/emmy/structure.cljc +++ b/src/emmy/structure.cljc @@ -6,7 +6,7 @@ (ns emmy.structure (:require [clojure.string :refer [join]] [emmy.collection] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generic :as g] [emmy.numsymb] diff --git a/src/emmy/tape.cljc b/src/emmy/tape.cljc index e2d0bbf1..2d565a5a 100644 --- a/src/emmy/tape.cljc +++ b/src/emmy/tape.cljc @@ -9,7 +9,7 @@ AD! Don't nest [[gradient]] calls inside [[emmy.env/D]] calls." (:refer-clojure :exclude [compare zero?]) (:require #?(:clj [clojure.pprint :as pprint]) - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generic :as g] [emmy.matrix :as matrix] @@ -26,7 +26,7 @@ ;; ;; This namespace develops an implementation of "reverse-mode" automatic ;; differentation, in contrast with the forward mode AD implementation -;; in [[emmy.differential]]. These two are closely related, and the +;; in [[emmy.dual]]. These two are closely related, and the ;; implementations could merge once I get around to reading and ;; implementing [the YOLO paper](https://arxiv.org/abs/2204.10923). ;; @@ -58,7 +58,7 @@ ;; First, wrap all inputs to the function in an instance of a type called ;; a [[TapeCell]]. This type holds ;; -;; - a "tag", used as in [[emmy.differential]] to prevent confusion +;; - a "tag", used as in [[emmy.dual]] to prevent confusion ;; between [[TapeCell]] instances created for different nested runs of ;; differentation ;; - a unique ID, used to de-duplicate work in the reverse pass @@ -331,7 +331,7 @@ [ ] - containing the tag and instance of [[emmy.differential/Dual]] or [[TapeCell]] + containing the tag and instance of [[emmy.dual/Dual]] or [[TapeCell]] associated with the inner-most call to [[with-active-tag]] in the current call stack. @@ -358,7 +358,7 @@ (defn deep-primal "Version of [[tape-primal]] that will descend recursively into any perturbation - instance returned by [[tape-primal]] or [[emmy.differential/primal]] until + instance returned by [[tape-primal]] or [[emmy.dual/primal]] until encountering a non-perturbation. Given a non-perturbation, acts as identity." @@ -535,7 +535,7 @@ ;; ;; TODO [[->partials]] really should depend on `fmap`, as should so many other ;; things in the library. Without this we can't generically support output -;; values like maps or quaternions. [[emmy.differential/extract-tangent]] does +;; values like maps or quaternions. [[emmy.dual/extract-tangent]] does ;; this for forward-mode, I believe. (declare ->partials) @@ -643,7 +643,7 @@ ;; output-walking. ;; ;; I am sure we are going to need to glom on to the [[replace-tag]] machinery as -;; well. [[emmy.differential/extract-tangent]] is similar to what we want. Maybe +;; well. [[emmy.dual/extract-tangent]] is similar to what we want. Maybe ;; we can share? (defn ^:no-doc interpret @@ -718,12 +718,12 @@ ;; ## Lifted Functions ;; [[lift-1]] and [[lift-2]] "lift", or augment, unary or binary functions with -;; the ability to handle [[emmy.differential/Dual]] and [[TapeCell]] instances +;; the ability to handle [[emmy.dual/Dual]] and [[TapeCell]] instances ;; in addition to whatever other types they previously supported. ;; -;; Forward-mode support for [[emmy.differential/Dual]] is an implementation of +;; Forward-mode support for [[emmy.dual/Dual]] is an implementation of ;; the single and multivariable Taylor series expansion methods discussed at the -;; beginning of [[emmy.differential]]. +;; beginning of [[emmy.dual]]. ;; ;; To support reverse-mode automatic differentiation, When a unary or binary ;; function `f` encounters a [[TapeCell]] `x` (and `y` in the binary case) it @@ -745,12 +745,12 @@ ;; There is a subtlety here, noted in the docstrings below. [[lift-1]] ;; and [[lift-2]] really are able to lift functions like [[clojure.core/+]] that -;; can't accept [[emmy.differential/Dual]] and [[TapeCell]]s. But the +;; can't accept [[emmy.dual/Dual]] and [[TapeCell]]s. But the ;; first-order derivatives that you have to supply _do_ have to be able to take ;; instances of these types. ;; -;; This is because, for example, the [[emmy.differential/tangent]] of [[Dual]] -;; might still be a [[Dual]], and will hit the first-order derivative via the +;; This is because, for example, the [[emmy.dual/tangent]] of [[emmy.dual/Dual]] +;; might still be a [[emmy.dual/Dual]], and will hit the first-order derivative via the ;; chain rule. ;; ;; Magically this will all Just Work if you pass an already-lifted function, or @@ -764,14 +764,14 @@ single argument Returns a new unary function that operates on both the original type of - `f`, [[TapeCell]] and [[emmy.differential/Dual]] instances. + `f`, [[TapeCell]] and [[emmy.dual/Dual]] instances. If called without `df:dx`, `df:dx` defaults to `(f :dfdx)`; this will return the derivative registered to a generic function defined with [[emmy.util.def/defgeneric]]. NOTE: `df:dx` has to ALREADY be able to handle [[TapeCell]] - and [[emmy.differential/Dual]] instances. The best way to accomplish this is + and [[emmy.dual/Dual]] instances. The best way to accomplish this is by building `df:dx` out of already-lifted functions, and declaring them by forward reference if you need to." ([f] @@ -804,10 +804,10 @@ - a function `df:dy`, similar to `df:dx` for the second arg Returns a new binary function that operates on both the original type of - `f`, [[TapeCell]] and [[emmy.differential/Differential]] instances. + `f`, [[TapeCell]] and [[emmy.dual/Dual]] instances. NOTE: `df:dx` and `df:dy` have to ALREADY be able to handle [[TapeCell]] - and [[emmy.differential/Dual]] instances. The best way to accomplish this is + and [[emmy.dual/Dual]] instances. The best way to accomplish this is by building `df:dx` and `df:dy` out of already-lifted functions, and declaring them by forward reference if you need to." ([f] @@ -860,7 +860,7 @@ first and second args in the binary case Returns a new any-arity function that operates on both the original type of - `f`, [[TapeCell]] and [[emmy.differential/Dual]] instances. + `f`, [[TapeCell]] and [[emmy.dual/Dual]] instances. NOTE: The n-ary case of `f` is populated by nested calls to the binary case. That means that this is NOT an appropriate lifting method for an n-ary @@ -890,7 +890,7 @@ `differential-op` (defaults to `(lift-1 generic-op)`) installs an appropriate unary implementation of `generic-op` for `::tape` and - `:emmy.differential/dual` instances." + `:emmy.dual/dual` instances." ([generic-op] (defunary generic-op (lift-1 generic-op))) ([generic-op differential-op] @@ -905,7 +905,7 @@ `differential-op` (defaults to `(lift-2 generic-op)`) installs an appropriate binary implementation of `generic-op` between - `::tape`, `::emmy.differential/dual` and `::v/scalar` instances." + `::tape`, `::emmy.dual/dual` and `::v/scalar` instances." ([generic-op] (defbinary generic-op (lift-2 generic-op))) ([generic-op differential-op] diff --git a/test/emmy/calculus/derivative_test.cljc b/test/emmy/calculus/derivative_test.cljc index 86d84175..dcde5052 100644 --- a/test/emmy/calculus/derivative_test.cljc +++ b/test/emmy/calculus/derivative_test.cljc @@ -7,7 +7,7 @@ [emmy.abstract.number :refer [literal-number]] [emmy.calculus.derivative :as d :refer [D partial]] [emmy.complex :as c] - [emmy.differential :as sd] + [emmy.dual :as sd] [emmy.expression :as x] [emmy.function :as f] [emmy.generic :as g :refer [acos asin atan cos sin tan @@ -1342,7 +1342,7 @@ ;; space. ;; ;; Doing work inside a continuation means you're actually working - ;; with [[emmy.differential/Differential]] instances whose tangents can + ;; with [[emmy.dual/Dual]] instances whose tangents can ;; interact. Once you break out of the continuation, as in "bug two", the ;; two components separately drop their tangents, so they can't talk ;; anymore. diff --git a/test/emmy/collection_test.cljc b/test/emmy/collection_test.cljc index f7bb48d2..febcfdd5 100644 --- a/test/emmy/collection_test.cljc +++ b/test/emmy/collection_test.cljc @@ -7,7 +7,7 @@ [emmy.calculus.derivative :refer [D]] [emmy.collection :as collection] [emmy.complex :refer [complex I]] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.function :as f] [emmy.generators :as sg] [emmy.generic :as g] diff --git a/test/emmy/differential_test.cljc b/test/emmy/dual_test.cljc similarity index 96% rename from test/emmy/differential_test.cljc rename to test/emmy/dual_test.cljc index 9ee0bce2..34b5d86f 100644 --- a/test/emmy/differential_test.cljc +++ b/test/emmy/dual_test.cljc @@ -1,11 +1,11 @@ #_"SPDX-License-Identifier: GPL-3.0" -(ns emmy.differential-test +(ns emmy.dual-test (:require #?(:cljs [emmy.util :as u]) [clojure.test :refer [is deftest testing use-fixtures]] [clojure.test.check.generators :as gen] [com.gfredericks.test.chuck.clojure-test :refer [checking]] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.generators :as sg] [emmy.generic :as g] [emmy.numerical.derivative :refer [D-numeric]] @@ -18,7 +18,7 @@ (defn- derivative "A bare-bones derivative implementation, used for testing the functionality made - available by [[Dual]]. The real version lives + available by [[emmy.dual/Dual]]. The real version lives at [[emmy.calculus.derivative/derivative]]" [f] (let [tag (d/fresh-tag)] @@ -59,7 +59,7 @@ ;; friends. Once we implement `v/<` we can duplicate this test for those ;; overridden versions, which should piggyback on compare. (let [real-minus-rationals (gen/one-of [sg/any-integral (sg/reasonable-double)])] - (checking "[[Dual]] is transparent to native comparison operators" 100 + (checking "[[emmy.dual/Dual]] is transparent to native comparison operators" 100 [[l-num r-num] (gen/vector real-minus-rationals 2)] (let [compare-bit (v/compare l-num r-num)] (doseq [l [l-num (d/bundle-element l-num 1 0)] @@ -150,7 +150,7 @@ "d/eq handles equality") (is (not (d/eq (d/bundle-element n 1 0) (d/bundle-element n 2 0))) - "d/eq is false for [[Dual]]s with diff tags")) + "d/eq is false for [[emmy.dual/Dual]]s with diff tags")) (checking "compare ignores tangent" 100 [l sg/real, r sg/real] @@ -174,12 +174,12 @@ (checking "compare-full takes tags into account" 100 [l sg/real] (is (pos? (d/compare-full (d/bundle-element l 1 0) l)) - "a [[Dual]] with a positive tangent is ALWAYS - greater than a non-[[Dual]] whatever the tangent.") + "a [[emmy.dual/Dual]] with a positive tangent is ALWAYS + greater than a non-[[emmy.dual/Dual]] whatever the tangent.") (is (neg? (d/compare-full l (d/bundle-element l 1 0))) - "a [[Dual]] with a positive tangent is ALWAYS - greater than a non-[[Dual]] whatever the tangent.")) + "a [[emmy.dual/Dual]] with a positive tangent is ALWAYS + greater than a non-[[emmy.dual/Dual]] whatever the tangent.")) (testing "freeze, simplify, str" (let [not-simple (g/square diff --git a/test/emmy/generators.cljc b/test/emmy/generators.cljc index 8887781a..f6c22c34 100644 --- a/test/emmy/generators.cljc +++ b/test/emmy/generators.cljc @@ -8,7 +8,7 @@ #?(:cljs [emmy.bigfraction :refer [Fraction]]) [emmy.complex :as c] #?(:cljs [emmy.complex.impl :refer [Complex]]) - [emmy.differential :as d] + [emmy.dual :as d] [emmy.generic :as g] [emmy.matrix :as m] [emmy.modint :as mi] @@ -284,7 +284,7 @@ (defn dual "Returns a generator that produces proper instances - of [[emmy.differential/Dual]]." + of [[emmy.dual/Dual]]." ([] (dual real)) ([primal-gen] (gen/let [tag gen/nat diff --git a/test/emmy/polynomial_test.cljc b/test/emmy/polynomial_test.cljc index fc3ddea8..47c9984e 100644 --- a/test/emmy/polynomial_test.cljc +++ b/test/emmy/polynomial_test.cljc @@ -6,7 +6,7 @@ [com.gfredericks.test.chuck.clojure-test :refer [checking]] [emmy.abstract.number :as an] [emmy.calculus.derivative :refer [D]] - [emmy.differential :as sd] + [emmy.dual :as sd] [emmy.expression :as x :refer [variables-in expression-of]] [emmy.expression.analyze :as a] [emmy.function :as f] diff --git a/test/emmy/tape_test.cljc b/test/emmy/tape_test.cljc index 54d1472a..16e26967 100644 --- a/test/emmy/tape_test.cljc +++ b/test/emmy/tape_test.cljc @@ -6,7 +6,7 @@ [clojure.test.check.generators :as gen] [com.gfredericks.test.chuck.clojure-test :refer [checking]] [emmy.calculus.derivative :refer [D]] - [emmy.differential :as d] + [emmy.dual :as d] [emmy.expression.analyze :as a] [emmy.generators :as sg] [emmy.generic :as g]