Skip to content

Commit 7a0adfb

Browse files
authored
Rename emmy.differential => emmy.dual (#180)
1 parent 87ee402 commit 7a0adfb

21 files changed

+61
-58
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
## [unreleased]
44

5-
This PR:
5+
- #180 renames `emmy.differential` to `emmy.dual`, since the file now contains a
6+
proper dual number implementation, not a truncated multivariate power series.
7+
8+
- #179:
69

710
- Moves the `IPerturbed` implementation for functions to `emmy.function`, out
811
of `emmy.calculus.derivative`

src/emmy/abstract/function.cljc

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(:refer-clojure :exclude [name])
1313
(:require #?(:clj [clojure.pprint :as pprint])
1414
[emmy.abstract.number :as an]
15-
[emmy.differential :as d]
15+
[emmy.dual :as d]
1616
[emmy.function :as f]
1717
[emmy.generic :as g]
1818
[emmy.matrix :as m]
@@ -262,7 +262,7 @@
262262
And returns a folding function (designed for use
263263
with [[emmy.structure/fold-chain]]) that
264264
265-
generates a new [[emmy.differential/Dual]] by applying the chain rule and
265+
generates a new [[emmy.dual/Dual]] by applying the chain rule and
266266
summing the partial derivatives for each perturbed argument in the input
267267
structure."
268268
[f primal-s tag]
@@ -309,7 +309,7 @@
309309
310310
and generates the proper return value for `((D f) xs)`.
311311
312-
In forward-mode AD this is a new [[emmy.differential/Dual]] generated by
312+
In forward-mode AD this is a new [[emmy.dual/Dual]] generated by
313313
applying the chain rule and summing the partial derivatives for each perturbed
314314
argument in the input structure.
315315

src/emmy/calculus/derivative.cljc

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"This namespace implements a number of differential operators like [[D]], and
88
the machinery to apply [[D]] to various structures."
99
(:refer-clojure :exclude [partial])
10-
(:require [emmy.differential :as d]
10+
(:require [emmy.dual :as d]
1111
[emmy.expression :as x]
1212
[emmy.function :as f]
1313
[emmy.generic :as g]
@@ -22,7 +22,7 @@
2222
;; ## Single and Multivariable Calculus
2323
;;
2424
;; These functions put together the pieces laid out
25-
;; in [[emmy.differential]] and declare an interface for taking
25+
;; in [[emmy.dual]] and declare an interface for taking
2626
;; derivatives.
2727

2828
(defn derivative
@@ -34,7 +34,7 @@
3434
see [[emmy.numerical.derivative/D-numeric]].
3535
3636
`f` must be built out of generic operations that know how to
37-
handle [[emmy.differential/Differential]] inputs in addition to any types that
37+
handle [[emmy.dual/Dual]] inputs in addition to any types that
3838
a normal `(f x)` call would present. This restriction does _not_ apply to
3939
operations like putting `x` into a container or destructuring; just primitive
4040
function calls."

src/emmy/collection.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"This namespace contains implementations of various Emmy protocols for
88
native Clojure collections."
99
(:require [clojure.set :as cs]
10-
[emmy.differential :as d]
10+
[emmy.dual :as d]
1111
[emmy.function :as f]
1212
[emmy.generic :as g]
1313
[emmy.util :as u]

src/emmy/differential.cljc src/emmy/dual.cljc

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
^#:nextjournal.clerk
44
{:toc true
55
:visibility :hide-ns}
6-
(ns emmy.differential
6+
(ns emmy.dual
77
"This namespace contains an implementation of [[Dual]], a type that forms the
88
basis for the forward-mode automatic differentiation implementation in emmy.
99
@@ -15,8 +15,8 @@
1515

1616
;; ## Differentials, Dual Numbers and Automatic Differentiation
1717
;;
18-
;; This namespace develops an implementation of a type called [[Differential]].
19-
;; A [[Differential]] is a generalization of a type called a ["dual
18+
;; This namespace develops an implementation of a type called [[Dual]].
19+
;; A [[Dual]] is a generalization of a type called a ["dual
2020
;; number"](https://en.wikipedia.org/wiki/Dual_number).
2121
;;
2222
;; As we'll discuss, passing these numbers as arguments to some function $f$
@@ -236,7 +236,7 @@
236236
;;
237237
;; The solution is to introduce a new $\varepsilon$ for every level, and allow
238238
;; different $\varepsilon$ instances to multiply without annihilating. Each
239-
;; $\varepsilon$ is called a "tag". [[Differential]] (implemented below) is a
239+
;; $\varepsilon$ is called a "tag". [[Dual]] (implemented below) is a
240240
;; generalized dual number that can track many tags at once, allowing nested
241241
;; derivatives like the one described above to work.
242242
;;
@@ -256,7 +256,7 @@
256256
;; ### What Return Values are Allowed?
257257
;;
258258
;; Before we discuss the implementation of dual
259-
;; numbers (called [[Differential]]), [[emmy.tape/lift-1]], [[emmy.tape/lift-2]]
259+
;; numbers (called [[Dual]]), [[emmy.tape/lift-1]], [[emmy.tape/lift-2]]
260260
;; and the rest of the machinery that makes this all possible; what sorts of
261261
;; objects is `f` allowed to return?
262262
;;

src/emmy/function.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(:refer-clojure :exclude [get get-in memoize with-meta name])
1111
(:require [clojure.core :as core]
1212
[clojure.core.match :refer [match]]
13-
[emmy.differential :as d]
13+
[emmy.dual :as d]
1414
[emmy.generic :as g]
1515
[emmy.util :as u]
1616
[emmy.value :as v])

src/emmy/matrix.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
to the [[Matrix]] datatype."
99
(:refer-clojure :exclude [get-in some])
1010
(:require [clojure.core :as core]
11-
[emmy.differential :as d]
11+
[emmy.dual :as d]
1212
[emmy.function :as f]
1313
[emmy.generic :as g]
1414
[emmy.polynomial :as poly]

src/emmy/numerical/derivative.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
For an implementation of [forward-mode automatic
1616
differentiation](https://en.wikipedia.org/wiki/Automatic_differentiation),
17-
see [[emmy.differential]] (for the backing implementation)
17+
see [[emmy.dual]] (for the backing implementation)
1818
and [[emmy.calculus.derivative]] (for the [[emmy.operator/Operator]]
1919
instances that make it pleasant to use this method.)"
2020
(:require [emmy.abstract.function :as af]

src/emmy/operator.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(ns emmy.operator
44
(:refer-clojure :exclude [get identity name])
55
(:require [clojure.core :as core]
6-
[emmy.differential :as d]
6+
[emmy.dual :as d]
77
[emmy.function :as f]
88
[emmy.generic :as g]
99
[emmy.pattern.rule :refer [rule-simplifier]]

src/emmy/polynomial.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
(:require [clojure.set :as set]
99
[clojure.string :as cs]
1010
[emmy.collection]
11-
[emmy.differential :as sd]
11+
[emmy.dual :as sd]
1212
[emmy.expression :as x]
1313
[emmy.expression.analyze :as a]
1414
[emmy.function :as f]

src/emmy/quaternion.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
and [[emmy.numbers]]."
1313
(:refer-clojure :exclude [zero?])
1414
(:require [emmy.complex :as sc]
15-
[emmy.differential :as d]
15+
[emmy.dual :as d]
1616
[emmy.function :as f]
1717
[emmy.generic :as g]
1818
[emmy.matrix :as m]

src/emmy/sci.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
minimal SCI environment should select their desired namespaces from this map."
1414
{'emmy.algebra.fold (copy-ns emmy.algebra.fold (sci/create-ns 'emmy.algebra.fold))
1515
'emmy.complex (copy-ns emmy.complex (sci/create-ns 'emmy.complex))
16-
'emmy.differential (copy-ns emmy.differential (sci/create-ns 'emmy.differential))
16+
'emmy.dual (copy-ns emmy.dual (sci/create-ns 'emmy.dual))
1717
'emmy.env (copy-ns emmy.env (sci/create-ns 'emmy.env))
1818
'emmy.expression (copy-ns emmy.expression (sci/create-ns 'emmy.expression))
1919
'emmy.function (copy-ns emmy.function (sci/create-ns 'emmy.function))

src/emmy/series.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
Doug also has a 10-line version in Haskell on [his
2323
website](https://www.cs.dartmouth.edu/~doug/powser.html)."
2424
(:refer-clojure :exclude [identity])
25-
(:require [emmy.differential :as d]
25+
(:require [emmy.dual :as d]
2626
[emmy.expression] ;; for the effect of the defmethod of zero? for Literals
2727
[emmy.function :as f]
2828
[emmy.generic :as g]

src/emmy/structure.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(ns emmy.structure
77
(:require [clojure.string :refer [join]]
88
[emmy.collection]
9-
[emmy.differential :as d]
9+
[emmy.dual :as d]
1010
[emmy.function :as f]
1111
[emmy.generic :as g]
1212
[emmy.numsymb]

src/emmy/tape.cljc

+20-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
AD! Don't nest [[gradient]] calls inside [[emmy.env/D]] calls."
1010
(:refer-clojure :exclude [compare zero?])
1111
(:require #?(:clj [clojure.pprint :as pprint])
12-
[emmy.differential :as d]
12+
[emmy.dual :as d]
1313
[emmy.function :as f]
1414
[emmy.generic :as g]
1515
[emmy.matrix :as matrix]
@@ -26,7 +26,7 @@
2626
;;
2727
;; This namespace develops an implementation of "reverse-mode" automatic
2828
;; differentation, in contrast with the forward mode AD implementation
29-
;; in [[emmy.differential]]. These two are closely related, and the
29+
;; in [[emmy.dual]]. These two are closely related, and the
3030
;; implementations could merge once I get around to reading and
3131
;; implementing [the YOLO paper](https://arxiv.org/abs/2204.10923).
3232
;;
@@ -58,7 +58,7 @@
5858
;; First, wrap all inputs to the function in an instance of a type called
5959
;; a [[TapeCell]]. This type holds
6060
;;
61-
;; - a "tag", used as in [[emmy.differential]] to prevent confusion
61+
;; - a "tag", used as in [[emmy.dual]] to prevent confusion
6262
;; between [[TapeCell]] instances created for different nested runs of
6363
;; differentation
6464
;; - a unique ID, used to de-duplicate work in the reverse pass
@@ -331,7 +331,7 @@
331331
332332
[<tag> <tape-or-dual-number>]
333333
334-
containing the tag and instance of [[emmy.differential/Dual]] or [[TapeCell]]
334+
containing the tag and instance of [[emmy.dual/Dual]] or [[TapeCell]]
335335
associated with the inner-most call to [[with-active-tag]] in the current call
336336
stack.
337337
@@ -358,7 +358,7 @@
358358

359359
(defn deep-primal
360360
"Version of [[tape-primal]] that will descend recursively into any perturbation
361-
instance returned by [[tape-primal]] or [[emmy.differential/primal]] until
361+
instance returned by [[tape-primal]] or [[emmy.dual/primal]] until
362362
encountering a non-perturbation.
363363
364364
Given a non-perturbation, acts as identity."
@@ -535,7 +535,7 @@
535535
;;
536536
;; TODO [[->partials]] really should depend on `fmap`, as should so many other
537537
;; things in the library. Without this we can't generically support output
538-
;; values like maps or quaternions. [[emmy.differential/extract-tangent]] does
538+
;; values like maps or quaternions. [[emmy.dual/extract-tangent]] does
539539
;; this for forward-mode, I believe.
540540

541541
(declare ->partials)
@@ -643,7 +643,7 @@
643643
;; output-walking.
644644
;;
645645
;; I am sure we are going to need to glom on to the [[replace-tag]] machinery as
646-
;; well. [[emmy.differential/extract-tangent]] is similar to what we want. Maybe
646+
;; well. [[emmy.dual/extract-tangent]] is similar to what we want. Maybe
647647
;; we can share?
648648

649649
(defn ^:no-doc interpret
@@ -718,12 +718,12 @@
718718
;; ## Lifted Functions
719719

720720
;; [[lift-1]] and [[lift-2]] "lift", or augment, unary or binary functions with
721-
;; the ability to handle [[emmy.differential/Dual]] and [[TapeCell]] instances
721+
;; the ability to handle [[emmy.dual/Dual]] and [[TapeCell]] instances
722722
;; in addition to whatever other types they previously supported.
723723
;;
724-
;; Forward-mode support for [[emmy.differential/Dual]] is an implementation of
724+
;; Forward-mode support for [[emmy.dual/Dual]] is an implementation of
725725
;; the single and multivariable Taylor series expansion methods discussed at the
726-
;; beginning of [[emmy.differential]].
726+
;; beginning of [[emmy.dual]].
727727
;;
728728
;; To support reverse-mode automatic differentiation, When a unary or binary
729729
;; function `f` encounters a [[TapeCell]] `x` (and `y` in the binary case) it
@@ -745,12 +745,12 @@
745745

746746
;; There is a subtlety here, noted in the docstrings below. [[lift-1]]
747747
;; and [[lift-2]] really are able to lift functions like [[clojure.core/+]] that
748-
;; can't accept [[emmy.differential/Dual]] and [[TapeCell]]s. But the
748+
;; can't accept [[emmy.dual/Dual]] and [[TapeCell]]s. But the
749749
;; first-order derivatives that you have to supply _do_ have to be able to take
750750
;; instances of these types.
751751
;;
752-
;; This is because, for example, the [[emmy.differential/tangent]] of [[Dual]]
753-
;; might still be a [[Dual]], and will hit the first-order derivative via the
752+
;; This is because, for example, the [[emmy.dual/tangent]] of [[emmy.dual/Dual]]
753+
;; might still be a [[emmy.dual/Dual]], and will hit the first-order derivative via the
754754
;; chain rule.
755755
;;
756756
;; Magically this will all Just Work if you pass an already-lifted function, or
@@ -764,14 +764,14 @@
764764
single argument
765765
766766
Returns a new unary function that operates on both the original type of
767-
`f`, [[TapeCell]] and [[emmy.differential/Dual]] instances.
767+
`f`, [[TapeCell]] and [[emmy.dual/Dual]] instances.
768768
769769
If called without `df:dx`, `df:dx` defaults to `(f :dfdx)`; this will return
770770
the derivative registered to a generic function defined
771771
with [[emmy.util.def/defgeneric]].
772772
773773
NOTE: `df:dx` has to ALREADY be able to handle [[TapeCell]]
774-
and [[emmy.differential/Dual]] instances. The best way to accomplish this is
774+
and [[emmy.dual/Dual]] instances. The best way to accomplish this is
775775
by building `df:dx` out of already-lifted functions, and declaring them by
776776
forward reference if you need to."
777777
([f]
@@ -804,10 +804,10 @@
804804
- a function `df:dy`, similar to `df:dx` for the second arg
805805
806806
Returns a new binary function that operates on both the original type of
807-
`f`, [[TapeCell]] and [[emmy.differential/Differential]] instances.
807+
`f`, [[TapeCell]] and [[emmy.dual/Dual]] instances.
808808
809809
NOTE: `df:dx` and `df:dy` have to ALREADY be able to handle [[TapeCell]]
810-
and [[emmy.differential/Dual]] instances. The best way to accomplish this is
810+
and [[emmy.dual/Dual]] instances. The best way to accomplish this is
811811
by building `df:dx` and `df:dy` out of already-lifted functions, and declaring
812812
them by forward reference if you need to."
813813
([f]
@@ -860,7 +860,7 @@
860860
first and second args in the binary case
861861
862862
Returns a new any-arity function that operates on both the original type of
863-
`f`, [[TapeCell]] and [[emmy.differential/Dual]] instances.
863+
`f`, [[TapeCell]] and [[emmy.dual/Dual]] instances.
864864
865865
NOTE: The n-ary case of `f` is populated by nested calls to the binary case.
866866
That means that this is NOT an appropriate lifting method for an n-ary
@@ -890,7 +890,7 @@
890890
`differential-op` (defaults to `(lift-1 generic-op)`)
891891
892892
installs an appropriate unary implementation of `generic-op` for `::tape` and
893-
`:emmy.differential/dual` instances."
893+
`:emmy.dual/dual` instances."
894894
([generic-op]
895895
(defunary generic-op (lift-1 generic-op)))
896896
([generic-op differential-op]
@@ -905,7 +905,7 @@
905905
`differential-op` (defaults to `(lift-2 generic-op)`)
906906
907907
installs an appropriate binary implementation of `generic-op` between
908-
`::tape`, `::emmy.differential/dual` and `::v/scalar` instances."
908+
`::tape`, `::emmy.dual/dual` and `::v/scalar` instances."
909909
([generic-op]
910910
(defbinary generic-op (lift-2 generic-op)))
911911
([generic-op differential-op]

test/emmy/calculus/derivative_test.cljc

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[emmy.abstract.number :refer [literal-number]]
88
[emmy.calculus.derivative :as d :refer [D partial]]
99
[emmy.complex :as c]
10-
[emmy.differential :as sd]
10+
[emmy.dual :as sd]
1111
[emmy.expression :as x]
1212
[emmy.function :as f]
1313
[emmy.generic :as g :refer [acos asin atan cos sin tan
@@ -1342,7 +1342,7 @@
13421342
;; space.
13431343
;;
13441344
;; Doing work inside a continuation means you're actually working
1345-
;; with [[emmy.differential/Differential]] instances whose tangents can
1345+
;; with [[emmy.dual/Dual]] instances whose tangents can
13461346
;; interact. Once you break out of the continuation, as in "bug two", the
13471347
;; two components separately drop their tangents, so they can't talk
13481348
;; anymore.

test/emmy/collection_test.cljc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[emmy.calculus.derivative :refer [D]]
88
[emmy.collection :as collection]
99
[emmy.complex :refer [complex I]]
10-
[emmy.differential :as d]
10+
[emmy.dual :as d]
1111
[emmy.function :as f]
1212
[emmy.generators :as sg]
1313
[emmy.generic :as g]

0 commit comments

Comments
 (0)