Skip to content

Instantly share code, notes, and snippets.

View sritchie's full-sized avatar
🎯
Focusing

Sam Ritchie sritchie

🎯
Focusing
View GitHub Profile

Chapter 5: Integration

We know how to integrate real-valued functions of a real variable. We want to extend this idea to manifolds, in such a way that the integral is independent of the coordinate system used to compute it.

The integral of a real-valued function of a real variable is the limit of a sum of products of the values of the function on subintervals and the lengths of the increments of the independent variable in those subintervals:

@sritchie
sritchie / deps.edn
Created November 19, 2021 05:11
Double Pendulum in Clerk
;; here were the deps I needed for this... I don't know enough vega-lite to go without the Hanami example I had
;; already built, so excuse me there!
{:paths ["dev"]
:deps {io.github.nextjournal/clerk {:local/root "../clerk"}
notespace-sicmutils {:mvn/version "0.16.2"}
aerial.hanami/aerial.hanami {:mvn/version "0.12.7"}
sicmutils/sicmutils {:git/url "https://github.com/sicmutils/sicmutils"
:sha "8658c0c8883b8225a742b9422061f40b852f375d"}}}
@sritchie
sritchie / extend.clj
Created November 18, 2021 14:43
Print writer extensions for functions.
(defn install-fn-printers!
"NOTE: If you are using Emacs + cider-nrepl, these two `print-method`
implementations will not be installed. I'm currently working on a fix to get
this enabled in the Emacs environment... But if you want to test this feature
out, simply execute these forms.
https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/print_method.clj#L42-L71
TODO write a with-methods instead to do this..."
[]
#?(:clj
(defn ^:no-doc careful-def [ns]
#?(:cljs
(fn [sym form]
`(def ~sym ~form))
:clj
(let [ns-sym (ns-name ns)
nsm (ns-map ns)
remote? (fn [sym]
(when-let [v (nsm sym)]
shadow-cljs - running: lein run -m shadow.cljs.devtools.cli --npm clj-repl
Syntax error (UnsatisfiedLinkError) compiling at (/private/var/folders/xw/0lq56zhn4hb4lknppw_k086c0000gn/T/form-init10880055894866318920.clj:1:126).
/private/var/folders/xw/0lq56zhn4hb4lknppw_k086c0000gn/T/jna5901602065421044698.tmp: dlopen(/private/var/folders/xw/0lq56zhn4hb4lknppw_k086c0000gn/T/jna5901602065421044698.tmp, 1): no suitable image found. Did find:
/private/var/folders/xw/0lq56zhn4hb4lknppw_k086c0000gn/T/jna5901602065421044698.tmp: no matching architecture in universal wrapper
/private/var/folders/xw/0lq56zhn4hb4lknppw_k086c0000gn/T/jna5901602065421044698.tmp: no matching architecture in universal wrapper
Full report at:
/var/folders/xw/0lq56zhn4hb4lknppw_k086c0000gn/T/clojure-14930451110325842276.edn
@sritchie
sritchie / 50th.scm
Created April 28, 2021 14:25
50th derivative
(/
(+ (* -717897987691852588770249/1125899906842624 (expt x 74) (sqrt x) (cos (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* -17947449692296314719256225/562949953421312 (expt x 73) (sqrt x) (cos (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* -412791342922815238542893175/1125899906842624 (expt x 73) (sin (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* -879425034922519421243555025/1125899906842624 (expt x 72) (sqrt x) (cos (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* -19640492446602933741106062225/1125899906842624 (expt x 72) (sin (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* 23549048157369686724410751225/281474976710656 (expt x 71) (sqrt x) (cos (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* -57162627269963762380831076625/140737488355328 (expt x 71) (sin (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* 1180872394115405245080929164125/281474976710656 (expt x 70) (sqrt x) (cos (+ (* x (sqrt x)) (* 3 (sqrt x)))))
(* 80027678177949267333163507275/8796093022208 (expt x 70) (sin (+ (* x (sqrt x)) (* 3 (sqrt x)))))
@sritchie
sritchie / multivariate.cljc
Last active January 18, 2021 11:47
multivariate redo attempt...
;;
;; [[jacobian]] handles this main logic. [[jacobian]] can only take a structural
;; input. [[euclidean]] and [[multivariate]] below widen handle, respectively,
;; optionally-structural and multivariable arguments.
(defn- jacobian
"Takes:
- some function `f` of a single [[s/structure?]] argument
- the unperturbed structural `input`
(define ((replace-differential-tag oldtag newtag) object)
(cond ((differential? object)
(terms->differential
(map (lambda (term)
(let ((terms (differential-tags term)))
(cond ((and (memv oldtag terms)
(memv newtag terms))
(make-differential-term
(remove-differential-tag newtag (remove-differential-tag oldtag terms))
:zero))
@sritchie
sritchie / bug.scm
Last active December 30, 2020 20:40
;; Here is the smoking gun...
(define (f x)
(lambda (cont)
(cont (lambda (y) (* x y))
(lambda (g) (g x)))))
;; (D f) is:
(lambda (cont)
(ns sicmutils.sci
(:require [sicmutils.env :as env]
[sci.core :as sci]))
(defn ns-bindings
"Returns a pair of
- `(ns-publics sym)` fn entries
- `(ns-publics sym)` macro entries"
[sym]