WolframModel

The Wolfram Model is a rule-based computational framework in which a system is represented by a hypergraph that evolves through simple, local rewriting rules. Even with simple rules, the model can generate rich, emergent behavior and is used to explore complex systems.

This repository contains a full-featured Elixir implementation of the Wolfram Model, providing:

Installation

def deps do
  [
    {:wolfram_model, "~> 1.3.0"}
  ]
end

Key Features

Evolution Rules

Causal Networks

Multiway Evolution

Emergent Structure Analysis

Visualization

Rule Analysis

Example Usage

# Create a simple universe
universe = WolframModel.Example.simple_universe()

# Evolve it for 10 steps (default :first ordering)
evolved = WolframModel.evolve_steps(universe, 10)

# Use leftmost or random ordering
WolframModel.evolve_step(universe, ordering: :leftmost)
WolframModel.evolve_step(universe, ordering: :random)

# Apply all non-conflicting matches in one parallel step
WolframModel.evolve_parallel(universe)

# Evolve until no rules apply (fixpoint)
final = WolframModel.evolve_until_fixpoint(universe)
WolframModel.fixpoint?(final)  # => true

# Analyze what emerged
WolframModel.print_stats(evolved)

# Explore multiway evolution as a tree...
multiway_tree = WolframModel.multiway_explore(universe, 3)

# ...or as a proper DAG where converging branches share nodes
dag = WolframModel.multiway_explore_dag(universe, 3)
# dag.nodes :: %{canonical_key => %WolframModel{}}
# dag.edges :: MapSet of {from_key, to_key}

# Analyze causality
causality = WolframModel.Analytics.analyze_causality(evolved)

# Compute spacelike foliations
layers = WolframModel.foliations(evolved)

# Explore the branchial graph of conflicting branches
bg = WolframModel.branchial_graph(universe)

# Check causal invariance (tests both overlapping and non-overlapping pairs)
WolframModel.causally_invariant?(universe)
WolframModel.causally_invariant?(universe, 3)  # depth-3 Church-Rosser check

# Estimate the emergent spatial dimension (uses hypergraph geodesics)
dim = WolframModel.Analytics.estimate_dimension(evolved.hypergraph)

# Estimate Ricci scalar curvature (positive → sphere-like, negative → hyperbolic)
r_scalar = WolframModel.Analytics.estimate_ricci_scalar(evolved.hypergraph)

# Detect conserved quantities across evolution history
conserved = WolframModel.Analytics.detect_conserved_quantities(evolved)
# => %{conserved: [:edge_count_parity, ...], vertex_count_history: [...], ...}

# Use classic Wolfram Physics Project benchmark rules
rules = WolframModel.RuleSet.rule_set(:wolfram, :rule_1)

# Parse rules from standard Wolfram notation
rule = WolframModel.Rule.parse("{{1,2},{1,3}} -> {{2,3},{1,4}}")
WolframModel.Rule.to_string(rule)
# => "{{1,2},{1,3}} -> {{2,3},{1,4}}"

# Inspect rule properties
alias WolframModel.RuleAnalysis
RuleAnalysis.reversible?(rule)
RuleAnalysis.introduces_new_vertices?(rule)
RuleAnalysis.hyperedge_delta(rule)
RuleAnalysis.canonical_form(rule)
RuleAnalysis.equivalent?(rule_a, rule_b)

# SVG visualizations
alias WolframModel.{HypergraphSVG, MultiwayGraphSVG, BranchialGraphSVG, GeodesicPlotSVG, CausalGraphSVG}

# Render the current hypergraph
evolved.hypergraph
|> HypergraphSVG.to_svg(title: "Step #{evolved.generation}")
|> then(&File.write!("hypergraph.svg", &1))

# Render the full evolution as a strip of panels
evolved
|> HypergraphSVG.evolution_to_svg(max_snapshots: 8, panel_size: 200)
|> then(&File.write!("evolution.svg", &1))

# Render the multiway DAG
dag = WolframModel.multiway_explore_dag(universe, 3)
dag
|> MultiwayGraphSVG.to_svg()
|> then(&File.write!("multiway.svg", &1))

# Render the branchial graph
WolframModel.branchial_graph(universe)
|> BranchialGraphSVG.to_svg(title: "Branchial graph")
|> then(&File.write!("branchial.svg", &1))

# Render the causal graph
evolved
|> WolframModel.causal_network_data()
|> CausalGraphSVG.to_svg()
|> then(&File.write!("causal.svg", &1))

# Render the geodesic ball growth plot with dimension estimate
evolved.hypergraph
|> GeodesicPlotSVG.to_svg(seeds: 5, title: "Geodesic dimension")
|> then(&File.write!("geodesic.svg", &1))

Interactive Livebook

For a step-by-step guided tour — including theory, worked examples, visualisations, and curvature analysis — open wolfram_model.livemd in Livebook:

livebook server wolfram_model.livemd

The notebook covers:

  1. Wolfram Physics background and core concepts
  2. Building and evolving universes
  3. Update orderings and parallel evolution
  4. Causal networks, foliations, and causal invariance
  5. Multiway evolution and branchial graphs
  6. Emergent spatial dimension and Ricci scalar curvature
  7. Classic Wolfram benchmark rules
  8. Rule analysis and conservation law detection

References