lantern

functor-contract-law-to-wanderland

Functor: Contract Law Evolution → Wanderland Document Management

A structure-preserving map demonstrating the streams-with-gaps invariant in legal systems


The Claim

Contract law evolution and document workflow in Wanderland are not merely analogous—they are categorically isomorphic. A functor F maps the legal domain to the document domain while preserving all compositional structure.

This isn't metaphor. It's math.


Category: ContractLaw

Objects (States)

Object Description
Draft Initial contract template with undefined terms
Negotiation Parties exchanging proposed fills for clause slots
Executed Signed agreement with all terms resolved
Disputed Ambiguity or breach creates new gaps
Litigated Court proceeding to resolve dispute
Precedent Ruling becomes pattern for future cases

Morphisms (Transformations)

Draft ──propose──→ Negotiation ──accept──→ Executed
                        │                      │
                    reject                  breach
                        ↓                      ↓
                     Draft              Disputed
                                           │
                                        file
                                           ↓
                                      Litigated
                                           │
                                        rule
                                           ↓
                                      Precedent

The Gaps

Gap Type Legal Manifestation
Undefined term "Reasonable time" - what counts?
Novel fact pattern No precedent covers this situation
Ambiguous clause Multiple valid interpretations
Changed circumstances Original intent vs. new reality
Jurisdictional void No statute addresses this issue

The Fills

Fill Operation Legal Manifestation
Negotiation Parties agree on term definition
Judicial ruling Court interprets ambiguous clause
Legislation Statute fills regulatory gap
Settlement Parties resolve without precedent
Amendment Contract modified to address gap

Category: WanderlandDoc

Objects (States)

Object Description
Template Document with unresolved fences/placeholders
Drafting Author filling slots, adding content
Rendered All fences executed, document complete
Stale Upstream data changed, cache invalid
Reviewing Examining diffs, validating changes
Versioned Committed state becomes referenceable

Morphisms (Transformations)

Template ──poke──→ Drafting ──render──→ Rendered
                      │                     │
                   revert               invalidate
                      ↓                     ↓
                  Template               Stale
                                           │
                                        peek
                                           ↓
                                      Reviewing
                                           │
                                       commit
                                           ↓
                                      Versioned

The Gaps

Gap Type Wanderland Manifestation
Fence placeholder ${fence:data-source} unexecuted
Unresolved reference ${node:missing-node} not found
Template slot {{party_name}} awaiting value
Stale cache L4 result outdated, needs re-execution
Missing component Referenced component doesn't exist

The Fills

Fill Operation Wanderland Manifestation
Fence execution Python/SQL/API returns data
Poke operation Value written to slot
Component render Nested document expands
Cache refresh Re-execute, update L4
Node creation Missing reference now exists

The Functor F: ContractLaw → WanderlandDoc

Object Mapping

F(Draft):       Template
F(Negotiation): Drafting  
F(Executed):    Rendered
F(Disputed):    Stale
F(Litigated):   Reviewing
F(Precedent):   Versioned

Morphism Mapping

F(propose):     poke      # Fill a slot with proposed value
F(accept):      render    # All slots filled, generate output
F(reject):      revert    # Discard proposed fills, return to template
F(breach):      invalidate # Cached agreement no longer valid
F(file):        peek      # Examine the disputed state
F(rule):        commit    # Authoritative resolution becomes permanent

Preservation Proofs

Identity preservation:

F(id_Draft) = id_Template  ✓

Doing nothing to a draft = doing nothing to a template.

Composition preservation:

F(accept ∘ propose) = F(accept) ∘ F(propose)
F(accept ∘ propose) = render ∘ poke

Proposing then accepting = poking then rendering. Same result: gaps filled, document complete.

F(rule ∘ file) = F(rule) ∘ F(file)
F(rule ∘ file) = commit ∘ peek

Filing then ruling = peeking then committing. Same result: dispute examined, resolution versioned.


The Streams-with-Gaps Invariant

Both categories implement LOOKUP → FETCH → SPLICE → CONTINUE:

Step ContractLaw WanderlandDoc
LOOKUP Identify undefined term or disputed clause Find unresolved fence or placeholder
FETCH Consult precedent, statute, or negotiate Execute fence, query data source
SPLICE Insert agreed term or judicial ruling Inject result into document stream
CONTINUE Proceed to next clause or issue Advance to next token or fence

Worked Example: Employment Contract Lifecycle

Legal Domain

1. HR uses standard employment template
   State: Draft
   Gaps: [salary, start_date, job_title, benefits_tier]

2. Candidate negotiates salary
   Morphism: propose(salary := 150000)
   State: Negotiation

3. Company counteroffers
   Morphism: propose(salary := 140000, signing_bonus := 10000)
   State: Negotiation

4. All terms agreed
   Morphism: accept
   State: Executed
   Gaps: [] (all filled)

5. Dispute over "remote work flexibility" clause
   Morphism: breach
   State: Disputed
   Gaps: [remote_work_interpretation]

6. Arbitration filed
   Morphism: file
   State: Litigated

7. Arbitrator rules: "minimum 3 days/week remote"
   Morphism: rule
   State: Precedent
   # This interpretation now applies to all similar clauses

Wanderland Domain (via Functor F)

1. Create employment contract from template node
   State: Template
   Fences: [${salary}, ${start_date}, ${job_title}, ${benefits_tier}]

2. Poke salary value
   Morphism: poke(path="terms.salary", value=150000)
   State: Drafting

3. Poke revised values
   Morphism: poke(path="terms.salary", value=140000)
   Morphism: poke(path="terms.signing_bonus", value=10000)
   State: Drafting

4. Render complete document
   Morphism: render
   State: Rendered
   Fences: [] (all executed)

5. Upstream policy node changes, invalidating interpretation
   Morphism: invalidate
   State: Stale
   Fences: [${remote_work_policy}] (needs re-resolution)

6. Peek at the stale content and diff
   Morphism: peek(level="L3")
   State: Reviewing

7. Commit authoritative interpretation
   Morphism: commit(version=2, comment="Clarified remote policy")
   State: Versioned
   # This version now referenceable by future documents

The functor preserves structure perfectly. Each legal operation maps to exactly one document operation. The composition of legal steps maps to the composition of document steps.


The Deep Isomorphism

Precedent = Versioned Node

A judicial precedent is a versioned, immutable resolution that future cases can reference. In Wanderland, a committed node version is a versioned, immutable state that future documents can reference.

# Legal citation
Smith v. Jones, 2024 WL 12345 at ¶47
# ≅
# Wanderland reference  
${node:smith-v-jones@v2#ruling}

Both are: identifier@version#section

Stare Decisis = Cache Semantics

Stare decisis ("let the decision stand") means courts follow precedent unless there's compelling reason to overturn.

Cache semantics means the system uses cached results unless explicitly invalidated.

Legal Principle Cache Equivalent
Follow precedent Return cached value
Distinguish on facts Cache miss (different key)
Overturn precedent Cache invalidation
Dictum (non-binding) Soft cache (advisory, not authoritative)

Contract Template = Document Template

A contract template with blanks:

This Agreement is entered into by {{party_a}} and {{party_b}}
on {{effective_date}} for the provision of {{services}}.

A Wanderland document template:

# Service Agreement

This Agreement is entered into by ${party_a} and ${party_b}
on ${effective_date} for the provision of ${services}.

Identical structure. The legal practice of contract drafting IS document rendering. Law firms have been doing bidirectional mail merge for centuries.


Natural Transformations

η: ContractLaw → WanderlandDoc (Digitization)

The natural transformation η takes a legal process and produces its document workflow equivalent:

η_Draft: physical template → Template node
η_Negotiation: email thread → Drafting session with poke history
η_Executed: signed PDF → Rendered + cryptographic signature fence
η_Precedent: case reporter → Versioned node in legal knowledge graph

ε: WanderlandDoc → ContractLaw (Interpretation)

The inverse transformation ε interprets document operations as legal acts:

ε_poke: filling a field → making an offer
ε_render: generating output → executing the agreement
ε_invalidate: cache bust → material breach
ε_commit: version lock → entering into record

These form an adjunction. Digitization and interpretation are adjoint functors—they're the "best approximation" of each other across the category boundary.


Implementation: Contract Workflow in Wanderland

# contract-workflow.md

## Contract Template

```yaml[fence:contract-data execute:false]
parties:
  client: ${input:client_name}
  provider: ${input:provider_name}
terms:
  effective_date: ${input:effective_date}
  value: ${input:contract_value}
  duration_months: ${input:duration}
clauses:
  - id: payment
    text: "Payment of ${terms.value} due within 30 days of invoice."
  - id: termination  
    text: "Either party may terminate with ${input:notice_days} days notice."
  - id: governing_law
    text: "Governed by the laws of ${input:jurisdiction}."

Negotiation History

- timestamp: 2025-01-03T10:00:00Z
  party: client
  action: propose
  changes:
    notice_days: 30
    
- timestamp: 2025-01-03T14:30:00Z
  party: provider
  action: counter
  changes:
    notice_days: 60
    
- timestamp: 2025-01-04T09:00:00Z
  party: client
  action: accept
  changes: {}
  status: executed

Rendered Agreement

${fence:contract-data | template:contract-template.md | sign:both}

Dispute Resolution

  • No active disputes
query: "termination notice period disputes"
jurisdiction: ${clauses.governing_law}
relevance_threshold: 0.8

---

## Why This Matters

### For Legal Tech

The functor proves that **document automation IS legal reasoning**, not a convenience layer on top of it. Systems like Wanderland aren't simulating legal workflows—they're implementing the same algorithm that legal systems implement.

This means:
- Legal AI can use document-graph techniques directly
- Contract lifecycle management is a solved problem (it's fence execution)
- Precedent databases are knowledge graphs with the same semantics as Wanderland

### For the Thesis

Legal systems evolved over millennia to solve the streams-with-gaps problem in human agreements. They converged on the same algorithm because **there is no other algorithm**.

The functor from ContractLaw to WanderlandDoc isn't a clever mapping—it's evidence that both systems discovered the same mandatory structure for embedded observers trying to build coherent state from incomplete information.

**Bedrock applies to law.**

---

## Provenance

### Document
- **Status**: 🔴 Unverified
- **Source**: Derived from reading list analysis identifying legal systems as uncovered domain
- **Date**: 2025-01-05

## North

```yaml
slots:
- slug: streams-with-gaps-invariant
  context:
  - Functor demonstrates invariant in legal domain
- slug: capability-from-recognition
  context:
  - Legal precedent is CFR - recognition of pattern creates applicable capability

East

slots:
- context:
  - Legal systems as evidence of convergent evolution to the mandatory algorithm
  slug: bedrock
- context:
  - Legal systems as evidence of convergent evolution to the mandatory algorithm
  slug: bedrock

North

slots:
- context:
  - Functor demonstrates the invariant in legal domain - linking to parent thesis
  slug: streams-with-gaps-invariant

West

slots:
- context:
  - Legal precedent is CFR - recognition of pattern creates applicable capability
  slug: capability-from-recognition