The Universe As A Value

Malcolm Sparks

Created: 2016-09-10 Sat 12:44

The Universe As A Value

Capacity requirements

  • 1080 particles (Wikipedia)
  • position, velocity, time
  • age of universe: 4.35 * 1017 seconds
  • estimated lifetime: 3 x 10107 seconds
  • Planck's constant (β„Ž) = 10-43
  • instants = 10150
  • * 1080 (particle vectors)
  • approx. 10230 datoms (per Universe)

Include all time too

An observer

(def observer (atom {:universe u :time t}))




π•Œ is the set of all possible observable universes

Function for selecting the 'next' universe

(defn next-u
  "Given an observed universe u,
  return a possible 'next' universe."
  [u t]
  (rand-nth (filter #(consistent? % u t) π•Œ)))

Observing the 'next' universe

(defn switch-universe!
  "Put the given observer in another universe"
    (fn [{:keys [universe time]}]
      {:universe (next-u universe time)
       :time (inc time)})

The illusion of time

(defn run-observer
  "Run the observer, giving them the impression
  of passing time"
  (dorun (iterate switch-universe! observer)))

Quantum Mechanics: Lazy evaluation

– From

The Simulation Hypothesis

"The odds that we are in base-reality is one in billions" β€” Elon Musk

"Odds are 50-50" β€” Niel deGrasse Tyson

Question: Is Mathematics Real?

Evidence to the contrary





  • Om
  • Reagent
// The app 'universe'
(def app-state
    {:drawer {:items [{:name "ear-plugs"}]}
        [{:name "Coffee" :quantity 2}
         {:name "Milk" :quantity 2}
         {:name "Bird seed" :quantity :lots}]}}))

The browser's 'universe as a value'

We dereference the app-state to get a value

(deref app-state)


  1. Consistency: In the render phase, the value we render is constant
  2. Concurrency: We can take our time, nobody is waiting for us!

Object Orientation: Lots of changing state, scattered around.

Like all websites, we have some state.

  • Configuration: port numbers, user/roles, access keys for Stripe, Twilio, Mailgun, OAuth2, etc.
  • Templates and template model data
  • Blog meta-data and content
  • News
  • People profiles
  • Radar data
  • XT16 ticket prices and coupons
  • Datomic

AppState record

(defrecord AppState [data-sources]
  (deref [this]
    (skip/refresh! this)
    ; Return the 'universe as a value'

@ Dereferencing the AppState

Sorry, your browser does not support SVG.

  • We dereference at the start of an observation, e.g. HTTP request
  • A deref causes a refresh, walking the dependency tree
  • Any stale data is detected and updated

Optimizing the refresh

  • Git SHA1 (Merkel trees)
  • Databases supporting time travel (Datomic, Oracle Flashback Technology)
  • HTTP Entity Tags
  • Snapshot filesystems (zfs, btrfs)

Background watchers

Sorry, your browser does not support SVG.

The Result

  • Instant feedback
  • Feels more like a REPL
  • No build! (or rather, the incremental build is embedded into the system)
  • No 'Continuous Integration' or 'Continuous Delivery'
  • Zero tests so no test suite! (or rather, the site tests itself)

C versus Lisp

It seems to me that there have been two really clean, consistent models of programming so far: the C model and the Lisp model.

β€” Paul Graham

C versus Lisp

"Devops: like programming, but with a 15min REPL"

β€” Bob Stuttaford

"You're not constructing it like making a ton of source code and compiling it periodically, you're constructing it the way you construct a city: build some of it, it's running all the time, so it's kind of like a live programming language."

β€” Dick Gabriel On Lisp, Software Engineering Radio Episode 84

Closing thought

As Lisp programmers, can we build systems that better exploit the advantages of our language heritage?

Recommended places in the simulation

XT16 - 6th October, 2016. Near London.


Some tickets remaining. or Google for 'XT16'.

Thank you!