## Phase 105: Kalika Research Platform — Computational Notebooks, Visualization, LaTeX Typesetting, Knowledge Graph, Citations & Reproducibility

Implements the user-facing research infrastructure that turns raw computation
into a complete research workflow. Targets parity with or exceeding: Jupyter
(notebooks), Mathematica (integrated notebook + CAS), Overleaf (LaTeX
collaboration), Zotero/Mendeley (citation management), ObservableHQ (reactive
notebooks), and emerging AI-augmented research platforms.

---

### 105.1 Computational Notebooks (`@kalika/notebooks`)

#### 105.1.1 Notebook Engine

- [x] **105.1.1.1** Implement notebook document model: ordered list of cells,
      each with type (code, markdown, LaTeX math, visualization, prose),
      content, execution state (idle, running, completed, errored), output
      (text, rich HTML, SVG, image, interactive widget), execution count, and
      metadata (creation time, last modified, tags) — stored as JSON (.kalika-nb
      format) with optional plain-text export
- [x] **105.1.1.2** Implement **reactive execution engine** (matching
      Pluto.jl/Marimo): automatic dependency tracking between cells (parse
      variable reads/writes, build dependency DAG), automatic re-execution of
      downstream cells when an upstream cell changes, topological sort for
      execution order, cycle detection with clear error messages — exceeding
      Jupyter's manual execute-in-order model
- [x] **105.1.1.3** Implement CAS kernel: cells can contain Kalika expressions
      (symbolic math), which are parsed, evaluated by the CAS engine, and
      rendered with LaTeX-quality typesetting. Support mixed code (TypeScript) +
      math (Kalika DSL) cells, with seamless variable sharing between code and
      math contexts
- [x] **105.1.1.4** Implement cell execution: sandboxed execution of TypeScript
      code cells (V8 isolate or worker thread), CAS expression evaluation (via
      @kalika/cas-engine WASM), Python code execution (via Python subprocess for
      ML/PINN cells), and Lean 4 tactic execution (via
      @kalika/formal-verification) — with timeout management, memory limits, and
      graceful cancellation
- [x] **105.1.1.5** Implement rich output rendering: LaTeX-rendered math (KaTeX
      or MathJax), interactive plots (via @kalika/renderer), data tables, images
      (PNG/SVG), HTML widgets, and custom MIME type handlers — output is
      deterministic and reproducible
- [x] **105.1.1.6** Implement notebook versioning: git-friendly format (cells
      stored as separate chunks, diffs show per-cell changes), version history
      within the notebook (undo/redo), and notebook diffing/merging tools
- [x] **105.1.1.7** Implement **AI notebook assistant**: inline AI suggestions
      (via Claude API) for: completing partial expressions, suggesting next
      computation steps, explaining results in natural language, debugging
      errors, proposing alternative approaches — matching Google Colab AI and
      Jupyter AI extensions but specialized for mathematical research
- [x] **105.1.1.8** Implement Jupyter interoperability: import .ipynb notebooks
      (convert cells to Kalika format), export to .ipynb (for sharing with
      Jupyter users), and support for running Jupyter kernels (Python, Julia, R)
      as alternative cell execution backends

#### 105.1.2 Collaborative Notebooks

- [x] **105.1.2.1** Implement real-time collaboration: CRDT-based concurrent
      editing (Yjs or Automerge), cursor presence (see other users' positions),
      cell locking (prevent simultaneous execution of the same cell), and
      conflict-free merge of independent edits — matching Google Colab/Deepnote
      collaboration
- [x] **105.1.2.2** Implement commenting system: inline comments on cells,
      threaded discussions, @mentions, and resolution workflow — for
      collaborative research review
- [x] **105.1.2.3** Implement sharing and permissions: public/private/team
      notebooks, read/execute/edit permission levels, shareable links with
      optional expiration, and embedding in external web pages

---

### 105.2 Visualization (`@kalika/renderer`)

#### 105.2.1 2D Plotting

- [x] **105.2.1.1** Implement function plotting: plot y = f(x) for symbolic
      expressions with automatic domain detection (avoid poles/branch cuts),
      adaptive sampling (more points near rapid changes), axis scaling
      (linear/log/symlog), multiple functions on same axes, parametric plots
      (x(t), y(t)), implicit plots (F(x,y) = 0 via marching squares), and
      contour plots (level curves of F(x,y))
- [x] **105.2.1.2** Implement complex function visualization: domain coloring
      (hue = argument, brightness = modulus), phase portraits, conformal mapping
      visualization (grid transformation), Riemann surface 3D rendering, and
      pole/zero/branch cut annotation
- [x] **105.2.1.3** Implement data plotting: scatter plots, line plots, error
      bars, histograms, bar charts, box plots, violin plots, heatmaps — all with
      LaTeX-quality labels, customizable styles, and export to SVG/PDF/PNG

#### 105.2.2 3D Visualization

- [x] **105.2.2.1** Implement 3D surface plotting: z = f(x,y) with adaptive
      meshing, parametric surfaces (x(u,v), y(u,v), z(u,v)), implicit surfaces
      (F(x,y,z) = 0 via marching cubes), coloring by value/curvature/normal,
      wireframe/solid/transparent modes, and interactive rotation/zoom (via
      WebGL/wgpu)
- [x] **105.2.2.2** Implement 3D manifold visualization: embed 2D manifolds in
      R^3 (torus, Klein bottle, Mobius strip, Boy's surface), geodesic
      visualization on curved surfaces, curvature coloring (Gaussian curvature
      map), and parallel transport visualization
- [x] **105.2.2.3** Implement vector field visualization: 2D/3D vector field
      plots (arrow fields, streamlines, LIC — line integral convolution), flow
      visualization, critical point detection and classification (sources,
      sinks, saddles, centers), and phase portrait visualization for dynamical
      systems

#### 105.2.3 Physics-Specific Visualization

- [x] **105.2.3.1** Implement Feynman diagram renderer: input a FeynmanDiagram
      object (from @kalika/feynman), output publication-quality SVG/PDF diagrams
      with: straight/wavy/dashed/curly lines for different particle types
      (fermion/boson/scalar/gluon), vertex dots, external leg labels (particle
      name + momentum), loop labels, proper line routing to avoid crossings —
      matching TikZ-Feynman quality
- [x] **105.2.3.2** Implement Penrose-Carter diagram renderer: input a spacetime
      metric, output the conformal diagram with: null infinities (I+, I-),
      spatial infinity (i0), timelike infinities (i+, i-), horizons,
      singularities (zigzag lines), light cones, geodesic trajectories, and
      region labels — for Schwarzschild, Kerr, Reissner-Nordstrom, FLRW, de
      Sitter, and custom spacetimes
- [x] **105.2.3.3** Implement Dynkin diagram renderer: given a Lie algebra,
      render its Dynkin diagram with: filled/unfilled nodes (for root lengths),
      single/double/triple bonds (for root angle), arrows (for
      non-simply-laced), extended Dynkin nodes, and folding visualizations
- [x] **105.2.3.4** Implement Young diagram/tableau renderer: given a partition
      or Young tableau, render it as a box diagram with entries, with
      highlighting for semistandard condition, and skew diagram support
- [x] **105.2.3.5** Implement lattice visualization: 2D/3D lattice
      configurations with colored sites (spin up/down for Ising), bond coloring
      for gauge fields, plaquette highlighting, Wilson loop visualization, and
      animation of Monte Carlo evolution
- [x] **105.2.3.6** Implement tensor network diagram renderer: MPS/MERA/PEPS
      diagrams with: tensors as shapes (circles/squares), bonds as lines with
      bond dimension labels, contraction order highlighting, and canonical form
      indication
- [x] **105.2.3.7** Implement spacetime diagram renderer: Minkowski diagrams
      (with light cones, worldlines, simultaneity surfaces), embedding diagrams
      (Flamm's paraboloid for Schwarzschild), and gravitational wave strain
      visualization (h\_+(t), h_x(t) waveforms)
- [x] **105.2.3.8** Implement quantum circuit renderer: circuit diagrams with
      gate boxes, control dots, measurement symbols, multi-qubit gates,
      barriers, and classical output wires — matching Qiskit's circuit drawer

#### 105.2.4 Animation & Interactivity

- [x] **105.2.4.1** Implement parameter sliders: interactive widgets that vary a
      parameter in a symbolic expression and update the plot in real-time (e.g.,
      vary potential depth in quantum well, watch energy levels change), with
      configurable range, step size, and animation playback (auto-sweep
      parameter over time)
- [x] **105.2.4.2** Implement time evolution animation: for time-dependent
      systems (wavefunction evolution, field configuration evolution, orbit
      animation, gravitational wave propagation), render frame-by-frame
      animations with play/pause/speed controls and export to GIF/MP4/WebM

---

### 105.3 LaTeX Typesetting (`@kalika/typesetting`)

- [x] **105.3.1.1** Implement Expr-to-LaTeX converter: convert any Kalika
      expression tree to publication-quality LaTeX, with: proper fraction
      rendering (\frac), integral/sum/product with limits, matrix/determinant
      environments, automatic parenthesization (minimal parentheses based on
      operator precedence), tensor index placement (superscript/subscript with
      comma separation), and configurable notation style (physicist's vs
      mathematician's conventions)
- [x] **105.3.1.2** Implement LaTeX equation numbering and cross-referencing:
      automatic equation numbering, \label/\ref support, equation arrays (align,
      gather, multline environments), and sub-equation numbering — matching
      standard LaTeX math environments
- [x] **105.3.1.3** Implement paper drafting engine: given notebook cells marked
      for publication, generate a complete LaTeX document with:
      title/author/abstract, sections/subsections, equations (from CAS cells),
      figures (from visualization cells), tables (from data cells), bibliography
      (from citation cells), and appendices — outputting compilable .tex files
      matching journal templates (RevTeX for physics, amsart for math)
- [x] **105.3.1.4** Implement derivation typesetting: given a ProvenResult with
      derivation chain, generate a typeset proof/derivation in LaTeX with:
      numbered steps, justifications for each step (theorem name, rule applied),
      and connecting text ("Applying the chain rule...", "By the Bianchi
      identity...") — for inclusion in papers
- [x] **105.3.1.5** Implement LaTeX import: parse LaTeX math expressions
      (\frac{}, \int, \sum, etc.) and convert to Kalika `Expr` AST — enabling
      users to paste LaTeX from papers and immediately compute with the
      expressions

---

### 105.4 Knowledge Graph (`@kalika/knowledge-graph`)

- [x] **105.4.1.1** Implement physics/mathematics ontology: hierarchical concept
      taxonomy (Mathematics > Algebra > Group Theory > Finite Groups > Symmetric
      Groups), property definitions (every group has an order, every manifold
      has a dimension), relationship types (generalizes, specializes,
      is-instance-of, proves, uses, contradicts, is-dual-to)
- [x] **105.4.1.2** Implement theorem dependency graph: for every
      theorem/lemma/proposition in Kalika's library (and those imported from
      Mathlib), track: statement, proof dependencies (which other theorems are
      used), applications (which theorems use this one), domain tags, difficulty
      rating, and historical information (discoverer, year, original paper)
- [x] **105.4.1.3** Implement concept linking: automatically link mathematical
      concepts across domains — e.g., "the Laplacian" links to: differential
      geometry (Laplace-Beltrami operator), PDE theory (Laplace equation),
      quantum mechanics (kinetic energy operator), graph theory (graph
      Laplacian), spectral theory (eigenvalues of Laplacian) — enabling
      cross-domain discovery
- [x] **105.4.1.4** Implement knowledge graph queries: "What are the
      prerequisites for understanding the Atiyah-Singer index theorem?", "What
      theorems connect algebraic topology to quantum field theory?", "What open
      problems exist in the intersection of number theory and physics?" —
      powered by graph traversal + LLM reasoning over the knowledge graph
- [x] **105.4.1.5** Implement knowledge graph persistence: store in Neo4j (when
      `graph` Docker profile is active) with Cypher queries, or in PostgreSQL
      with JSONB + recursive CTEs as fallback — with full-text search on theorem
      statements and concept descriptions

---

### 105.5 Citations (`@kalika/citations`)

- [x] **105.5.1.1** Implement citation manager: import citations from BibTeX,
      RIS, CSL-JSON, and DOI (automatic metadata retrieval from
      CrossRef/DataCite), store in structured database, search by
      author/title/year/keyword/DOI/arXiv ID, and export to BibTeX/RIS/CSL-JSON
- [x] **105.5.1.2** Implement in-notebook citations: cite papers directly in
      notebook cells using \cite{key} syntax, automatic bibliography generation
      at end of notebook, citation style selection (APS, AIP, IEEE, Chicago,
      APA, nature, science), and hyperlinks to paper URLs (DOI, arXiv)
- [x] **105.5.1.3** Implement automatic citation suggestion: when a notebook
      uses a theorem, algorithm, or technique, suggest relevant citations from
      the citation database and from arXiv/INSPIRE search — ensuring proper
      attribution in generated papers
- [x] **105.5.1.4** Implement citation graph visualization: for a given paper,
      show its citation network (papers it cites, papers that cite it,
      co-citation clusters), with interactive exploration (click to expand,
      filter by year/topic/citation count)

---

### 105.6 Reproducibility Framework

- [x] **105.6.1.1** Implement computation reproducibility: every notebook
      execution records the complete environment (Kalika version, CAS engine
      version, library versions, random seeds, system architecture), enabling
      bit-exact reproduction of all results — matching Code Ocean's capsule
      approach
- [x] **105.6.1.2** Implement dependency locking: lock all package versions used
      in a notebook computation, generate a lockfile that pins exact versions,
      and support running old notebooks with their original locked dependencies
      — matching Nix-style reproducibility
- [x] **105.6.1.3** Implement computation provenance: for every output cell,
      track the complete computation chain (input data + code + library
      versions + hardware -> output), stored as a DAG, enabling "how was this
      result computed?" queries
- [x] **105.6.1.4** Implement export to reproducible formats: export notebooks
      to Docker containers (with all dependencies), Binder-compatible
      repositories (repo2docker), and standalone HTML (with embedded WASM CAS
      engine for in-browser reproduction) — enabling one-click reproducibility
      for reviewers and readers

---

### 105.7 Tests

- [x] **105.7.1.1** Write notebook engine tests: verify reactive execution
      (changing cell A re-executes dependent cells B, C), cycle detection,
      sandboxed execution (code cells can't access filesystem), CAS cell
      evaluation, and output rendering — minimum 100 test cases
- [x] **105.7.1.2** Write visualization tests: verify function plots match
      expected output for standard functions (sin, exp, Bessel), Feynman diagram
      rendering correctness, Penrose diagram topology, and export to SVG/PDF —
      minimum 50 test cases (snapshot testing)
- [x] **105.7.1.3** Write typesetting tests: verify Expr-to-LaTeX conversion for
      100+ expression types (fractions, integrals, sums, matrices, tensors,
      Dirac notation), verify LaTeX-to-Expr round-trip, verify paper generation
      compiles with pdflatex — minimum 120 test cases
- [x] **105.7.1.4** Write citation tests: verify BibTeX/RIS import, DOI metadata
      retrieval, citation style formatting for APS/AIP/nature, and bibliography
      generation — minimum 30 test cases
