Skip to content

Instantly share code, notes, and snippets.


Sam Ritchie sritchie

View GitHub Profile
sritchie / 50th.scm
Created Apr 28, 2021
50th derivative
View 50th.scm
(+ (* -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 / multivariate.cljc
Last active Jan 18, 2021
multivariate redo attempt...
View multivariate.cljc
;; [[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
- some function `f` of a single [[s/structure?]] argument
- the unperturbed structural `input`
View replace_tag.scm
(define ((replace-differential-tag oldtag newtag) object)
(cond ((differential? object)
(map (lambda (term)
(let ((terms (differential-tags term)))
(cond ((and (memv oldtag terms)
(memv newtag terms))
(remove-differential-tag newtag (remove-differential-tag oldtag terms))
View bug.scm
;; Here is the smoking gun...
(define (f x)
(lambda (cont)
(cont (lambda (y) (* x y))
(lambda (g) (g x)))))
;; (D f) is:
(lambda (cont)
View sci.cljc
(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"
sritchie / refman.adoc
Created Dec 12, 2020
SICMUtils Reference Manual (ported from the original)
View refman.adoc

SICMUTILS Reference Manual

This is a port of the original reference manual for scmutils over to Clojure and the SICMUtils API. The goal here is to host an annotated version of the original refman.txt, highlighting any difference in functionality, behavior and naming so that folks can transition between the systems. The code here assumes that you’re working at a REPL initialized to the the sicmutils.env namespace.
sritchie /
Created Dec 12, 2020
v0.14.0: tons of new generic operations, refman ported!
  • we have a great documentation site now! cljdoc now hosts a full port of the original scmutils reference manual. All code snippets in the ported refman now work. I've also distributed many of the sections in the reference manual into more topically organized sections in the cljdoc site, so give those a browse and keep your eye out for more expansion there.

Okay, on to the beefy changelog.

A quick note: After the work below, v/nullity? renamed to v/zero?, and v/unity? renamed to v/one? #180. This affects the names listed in the CHANGELOG entries below.

New Generic Functions

This release brings us closer to the interface provided by scmutils.

View adaptive.clj
(defn adaptive
"Accepts two 'integrator' functions of:
- `f`: some integrand
- `a` and `b`: the lower and upper endpoints of integration
- `opts`, a dictionary of configuration options
And returns a new function of the same signature that adaptively subdivides
the region $a, b$ into intervals if integration fails to converge."
([integrator] (adaptive integrator integrator))
sritchie / minimize.cljc
Last active Sep 3, 2020
Nelder-Mead multidimensional minimization in Clojure, based on Colin Smith's excellent work!
View minimize.cljc
(ns sicmutils.numerical.minimize
"Implementations of minimization algorithms for single and multiple dimensions."
(:require [sicmutils.util :as u]
[sicmutils.util.stopwatch :as us]
[taoensso.timbre :as log])
(:import (org.apache.commons.math3.optim.univariate

Exercise 1.15: Equivalence

This is one of the more important exercises in the chapter. The problem asks for a proof that it's possible to absorb a coordinate transformation directly into the Lagrangian. If you can do this, you can express your paths and your forces in whatever coordinates you like, so long as you can transition between them.

I also found that this exposed, and repaired, my weakness with the functional notation that Sussman and Wisdom have used in the book.

The problem states:

Show by direct calculation that the Lagrange equations for $L'$ are satisfied if the Lagrange equations for $L$ are satisfied.