Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bd95e61
Add reactive view example catalogue and research scaffolding
cristianoc Dec 1, 2025
3e41076
Add DCE formalization and clarify reduce semantics
cristianoc Dec 1, 2025
83f6d15
Document reducer calculus and layer-2 non-reducer analysis
cristianoc Dec 1, 2025
32d5eaf
Expand reactive calculus notes with JSON ordering, add test harnesses
cristianoc Dec 2, 2025
430d9a3
Add examples primitives analysis with detailed deep dives
cristianoc Dec 2, 2025
857a774
fix example 6.3
cristianoc Dec 2, 2025
3c6bbf9
Clarify DBToaster equivalence claims in examples analysis
cristianoc Dec 2, 2025
b51c3de
Move DBToaster discussion to Example 6.3 (Yannakakis joins)
cristianoc Dec 2, 2025
b5458b1
Split Lean DCE Layer2 and align TeX with reactive/incremental split
cristianoc Dec 3, 2025
7a3ea68
Clarify incremental DCE correctness invariant
cristianoc Dec 3, 2025
9b13fa3
Add research note: Incremental Fixpoint Computation - Two-Level Archi…
cristianoc Dec 3, 2025
48e4b96
Add Level 1 formalization: IncrementalFixpoint.lean
cristianoc Dec 3, 2025
4db0301
Formalize counting-based cascade algorithm and overall correctness
cristianoc Dec 3, 2025
3954bb4
Add well-founded derivations for contraction completeness
cristianoc Dec 3, 2025
12a0462
Complete well-founded cascade proofs
cristianoc Dec 3, 2025
562febb
Add helper lemmas for semi-naive expansion proof
cristianoc Dec 3, 2025
69d8418
Clean up: remove unused definitions and lemmas from Lean and TeX
cristianoc Dec 3, 2025
f9d01f9
Complete all Lean proofs - no more sorry
cristianoc Dec 3, 2025
5bd297a
Add implementable API with explicit ranks and concrete pseudo-code
cristianoc Dec 3, 2025
a4cfb2b
Clean up Level 1 API section with clear structure
cristianoc Dec 3, 2025
28e44ad
Simplify API: make stepInv optional, document two API levels
cristianoc Dec 3, 2025
6b289f8
detailed DCE example
cristianoc Dec 3, 2025
d670a7c
Add incremental fixpoint combinator with two-level API
cristianoc Dec 3, 2025
2d556a9
Fix Js.typeof deprecation warnings and minor whitespace
cristianoc Dec 3, 2025
7260995
Simplify dce_reactive_view.tex to reference generic fixpoint
cristianoc Dec 3, 2025
d5584e3
Add Datalog/database references to incremental fixpoint notes
cristianoc Dec 4, 2025
19c09ba
Refactor Fixpoint to use native JS collections and fix stale ranks bug
cristianoc Dec 4, 2025
dc67126
Update AGENTS.md
cristianoc Dec 5, 2025
c7673df
Fix linter warnings in IncrementalFixpoint.lean
cristianoc Dec 8, 2025
68af0e6
Add concrete anti-join examples to paper and analysis
cristianoc Dec 8, 2025
2d886b5
Update REACTIVE_CALCULUS_NOTES.md: clarify local vs global calculi
cristianoc Dec 8, 2025
25ce807
Add anti-join examples and refine example classifications
cristianoc Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ lib/
*.cmj
*.cmi
*.rei
reduce.aux
reduce.log

# LaTeX build artifacts
*.aux
*.log
*.toc
125 changes: 125 additions & 0 deletions REACTIVE_CALCULUS_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Towards a Reactive Calculus

This note sketches a possible “reactive calculus” that could sit underneath Skip’s combinators for building reactive views.
Reducers are the most algebraically subtle part of this story, so they get most of the attention here, but the intent is not to express everything as a reducer—only to make the complex pieces *good by construction* rather than something users or authors must prove case‑by‑case.

It is intentionally informal and future‑looking; the goal is to capture design directions, not to fix a concrete formal system yet.

## 1. Core vision

- A small, typed calculus of *reactive combinators* for building views:
- collections as first‑class values, and
- reducers as structured, reusable update operators on those collections.
- Well‑formedness of reducers is enforced by typing rules and algebraic closure properties.
- Every reducer term that type‑checks in the calculus either:
- is guaranteed to satisfy the Skip well‑formedness law, or
- is explicitly classified as partial / “fallback to recompute”.
- The calculus plays the same role for reactive views that:
- relational algebra plays for SQL, and
- change structures / incremental λ‑calculus play for derivative‑based incrementalization.

## 2. Basic semantic types

At the semantic level, the calculus works with the same objects as the paper:

- `Multiset V` (`𝓜(V)`): finite multisets over values `V`, with union `⊎` and multiset difference.
- `Collection K V`: functions `K → 𝓜(V)`; this is the semantic type for Skip collections.
- `Reducer V A`: triples `R = (ι, ⊕, ⊖)` with:
- `ι : A` – initial accumulator,
- `⊕ : A × V → A` – add,
- `⊖ : A × V → A` or partial `A × V → A + {⊥}` – remove.

Additional standard type constructors:

- Products `A₁ × A₂`, sums, and perhaps function spaces as needed.
- Simple collection‑level operators: `map`, `slice`, `merge`, etc., which are algebraically straightforward.

## 3. Well‑formedness as a typing judgement

In the paper, well‑formedness is a semantic property of `R = (ι, ⊕, ⊖)`:

- `⊕` must be pairwise‑commutative (multiset fold is independent of order).
- `⊖` must be a left inverse of `⊕` on reachable accumulator states (the main theorem’s condition).

In the calculus, this can become an explicit judgement:

- `Γ ⊢ R : Reducer V A` – `R` is syntactically a reducer.
- `Γ ⊢ R : WFReducer V A` – `R` is well‑formed; it satisfies the semantic correctness law.
- Optionally, `Γ ⊢ R : PartialReducer V A` – `R` may fall back to recomputation.

The goal is to arrange the rules so that:

- Base primitives are declared well‑formed by assumption.
- Combinators on reducers *preserve* well‑formedness, so complex reducers built from well‑formed pieces remain well‑formed automatically.

## 4. Algebra of reducers

Within the broader reactive calculus, we can turn common constructions on reducers into typed combinators, along lines such as:

- **Product of reducers**
- Given `Γ ⊢ R₁ : WFReducer V A₁` and `Γ ⊢ R₂ : WFReducer V A₂`,
- define `R₁ ⊗ R₂ : WFReducer V (A₁ × A₂)` with
- `(ι₁, ⊕₁, ⊖₁)` and `(ι₂, ⊕₂, ⊖₂)` combined componentwise.
- The calculus includes a rule stating that `⊗` preserves well‑formedness.

- **Mapping value types**
- Given a function `f : V' → V` and `Γ ⊢ R : WFReducer V A`,
- define `mapValue f R : WFReducer V' A`, which simply pre‑composes inputs with `f`.

- **State enrichment / refinement**
- E.g., going from `min` over `ℝ` to a reducer over a richer state `(min, secondMin, count)` that makes the remove operation invertible.
- The calculus could expose generic combinators for pairing a reducer with auxiliary state, where the corresponding closure rule tracks whether invertibility is preserved.

Each such operation comes with a small metatheorem: if the premises are well‑formed, the result is well‑formed. Together, they give a “good by construction” algebra of reducers.

## 5. Complexity annotations

In the current paper, well‑formedness implies a complexity contract: under the Skip semantics, well‑formed reducers admit `O(1)` per‑key updates.

The calculus could refine the typing judgement to track complexity:

- `Γ ⊢ R : WFReducer[V, A, O(1)]`
- `Γ ⊢ R : PartialReducer[V, A, fallback]`

and give rules such as:

- Product of two `O(1)` reducers is `O(1)`.
- Product of an `O(1)` reducer with a partial reducer is partial.

This turns the calculus into a discipline not just for correctness but also for incremental performance guarantees.

## 6. Expressivity and examples

A key research question is: how expressive can such a calculus be while keeping the rules simple and checkable?

Potential sources of “real” reducers to test expressivity:

- Existing Skip service graphs: per‑key metrics, dashboards, alerts.
- Streaming/windowed analytics: counts, sums, averages, histograms, per‑session stats.
- Domain‑specific examples: incremental graph metrics, per‑user quotas, shopping carts, etc.

The hypothesis is that:

- A small set of primitive well‑formed reducers (sum, count, min/max with enriched state, average with (sum,count) state, etc.), plus algebraic combinators (product, mapping, grouping), may cover a large fraction of real‑world reducers used in reactive back‑ends.
- Systematically validating this hypothesis is future work.

## 7. User‑facing layer

The calculus is intended as a foundation, not necessarily the surface language.

Two possible user‑facing stories:

- **Embedded combinator library**
- Export the calculus directly as a small set of combinators in ReScript/TypeScript (e.g., `Reducer.product`, `Reducer.mapValue`, etc.).
- Developers build reducers using these combinators; the type system and library design ensure well‑formedness and known complexity where advertised.

- **Higher‑level “view query” DSL**
- Define a more intuitive DSL for derived views, analogous to SQL over collections.
- The compiler lowers this DSL into terms of the reactive calculus, choosing specific reducer constructions.
- Correctness and complexity guarantees are inherited from the calculus, just as SQL inherits guarantees from relational algebra.

In both cases, the long‑term goal is that:

- Developers mostly compose *well‑formed* reducers using high‑level constructs.
- The runtime’s correctness theorem applies automatically to anything expressible in the calculus (or in the DSL compiled to it).
- Only a small, clearly marked “escape hatch” is needed for ad‑hoc reducers that fall outside the calculus, and those carry explicit “partial / may recompute” semantics.
Binary file added dce_reactive_view.pdf
Binary file not shown.
Loading