## Phase 106: Kalika Integration — Cross-Domain, SDK, Database, Apps, Benchmarks & Research Workflows

Final integration phase: connects all Kalika libraries into a cohesive platform,
builds the application layer (web UI, API services, SDK), establishes the
database schema, implements end-to-end research workflows, and creates
comprehensive benchmarks proving Kalika meets or exceeds every SOTA system
identified in the design research.

---

### 106.1 Database & Persistence (`@kalika/database`)

#### 106.1.1 Schema Design

- [x] **106.1.1.1** Design and implement PostgreSQL schema for `kalika`
      database: tables for notebooks (id, title, owner, cells JSONB, metadata,
      created_at, updated_at), computations (id, notebook_id, cell_id,
      input_expr, output_expr, derivation_chain JSONB, verification_status,
      execution_time_ms, created_at), citations (id, bibtex, doi, arxiv_id,
      metadata JSONB), knowledge_graph_nodes (id, type, name, description,
      properties JSONB), knowledge_graph_edges (source_id, target_id,
      relationship_type, properties JSONB), user_preferences (user_id, settings
      JSONB), and computation_cache (input_hash, output, created_at,
      access_count)
- [x] **106.1.1.2** Implement database migrations: use Drizzle ORM or Kysely for
      type-safe schema management, with forward-only migrations, seed data for
      physical constants and particle data, and rollback support
- [x] **106.1.1.3** Implement vector search integration: store embeddings of
      theorems, concepts, and paper abstracts in Qdrant (via
      @shared/infrastructure or Sophia integration), enabling semantic search
      across the knowledge base — "find theorems similar to the Atiyah-Singer
      index theorem"
- [x] **106.1.1.4** Implement computation cache with content-addressed storage:
      hash the input expression + parameters + library version -> if cache hit,
      return stored result immediately (with verification that cached result is
      still valid) — dramatically speeding up repeated computations in notebooks

#### 106.1.2 Data Import/Export

- [x] **106.1.2.1** Implement LMFDB data import: L-functions and Modular Forms
      Database — import elliptic curve data, modular form data, number field
      data, and L-function zeros for use in @kalika/number-theory computations
- [x] **106.1.2.2** Implement HEPData import: import published experimental
      results (cross-sections, distributions, correlation matrices) from
      HEPData.net for comparison with theoretical predictions
- [x] **106.1.2.3** Implement SXS waveform catalog import: import numerical
      relativity gravitational waveforms from the SXS collaboration for use in
      @kalika/gravitational-waves
- [x] **106.1.2.4** Implement Kreuzer-Skarke database integration: access the
      database of 473,800,776 reflexive polytopes in 4D for
      @kalika/string-theory Calabi-Yau computations
- [x] **106.1.2.5** Implement OEIS API client: query the Online Encyclopedia of
      Integer Sequences for sequence identification and cross-referencing
- [x] **106.1.2.6** Implement KnotInfo/LinkInfo database integration: import
      knot invariant data for @kalika/topology knot theory computations

---

### 106.2 Application Layer (`apps/kalika/`)

#### 106.2.1 Compute Service (`apps/kalika/svc-compute`)

- [x] **106.2.1.1** Implement compute service: Express/Fastify HTTP server
      exposing CAS operations as REST/WebSocket APIs — endpoints for: symbolic
      computation (simplify, differentiate, integrate, solve, series, limit),
      numerical evaluation, matrix operations, tensor operations, and batch
      computation (submit multiple expressions, get results as they complete)
- [x] **106.2.1.2** Implement WebSocket streaming: for long-running computations
      (Groebner basis, large simplification, numerical simulation), stream
      progress updates and partial results to the client — with cancellation
      support
- [x] **106.2.1.3** Implement computation queue: Redis-backed job queue for
      CPU-intensive computations (IBP reduction, lattice MC), with worker pool,
      priority levels (interactive > batch > background), timeout management,
      and result caching
- [x] **106.2.1.4** Implement WASM-in-browser mode: for lightweight
      computations, run the CAS engine directly in the browser via WASM (no
      server round-trip), falling back to server for heavy computations —
      providing sub-millisecond response for simple operations

#### 106.2.2 Agent Service (`apps/kalika/svc-agents`)

- [x] **106.2.2.1** Implement agent service: manages autonomous research agents
      (from @kalika/research-agents), handles agent lifecycle (create, run,
      pause, resume, terminate), resource allocation (API keys for Claude,
      compute budget), and result persistence
- [x] **106.2.2.2** Implement agent API: REST endpoints for: creating research
      tasks, monitoring agent progress, reviewing intermediate results,
      providing human feedback, and retrieving final reports with citations and
      proofs
- [x] **106.2.2.3** Implement agent rate limiting and cost management: track API
      usage (Claude tokens, compute time), enforce per-user budgets, and provide
      cost estimates before starting expensive agent tasks

#### 106.2.3 Notebook Service (`apps/kalika/svc-notebooks`)

- [x] **106.2.3.1** Implement notebook service: CRUD for notebooks, cell
      execution management (queue cells for execution, manage kernel state),
      collaboration state (CRDT synchronization), and notebook export (HTML, PDF
      via LaTeX, .ipynb)
- [x] **106.2.3.2** Implement notebook templates: pre-built notebooks for common
      research workflows — "Getting Started with Quantum Mechanics", "Computing
      Feynman Diagrams", "Exploring Calabi-Yau Manifolds", "Gravitational Wave
      Parameter Estimation", "Number Theory Explorations" — each with runnable
      examples and explanatory text

#### 106.2.4 Web Application (`apps/kalika/web`)

- [x] **106.2.4.1** Implement notebook UI: Monaco-based code editor for
      TypeScript cells, KaTeX-rendered LaTeX for math cells, Markdown editor for
      prose cells, interactive visualization canvas for plot cells, cell
      reordering (drag-and-drop), cell type switching, and keyboard shortcuts
      (Shift+Enter to execute, Ctrl+Enter to execute and advance)
- [x] **106.2.4.2** Implement math input: LaTeX input with real-time preview,
      palette of common symbols/operators/functions, handwriting recognition
      (via ML model for math symbols), and natural language to expression
      conversion ("integrate sin(x) from 0 to pi" -> Integral expression)
- [x] **106.2.4.3** Implement computation explorer: side panel showing the
      derivation chain for any computed result (expandable tree of steps),
      verification status badges (proven/conjectured/numerical), and one-click
      formal verification button
- [x] **106.2.4.4** Implement knowledge graph browser: interactive graph
      visualization of the mathematical knowledge base, with node expansion,
      filtering by domain, search, and navigation to related theorems/concepts
- [x] **106.2.4.5** Implement citation sidebar: search and insert citations,
      view bibliography, manage citation library, and sync with external
      managers (Zotero via API)

#### 106.2.5 BFF (Backend for Frontend)

- [x] **106.2.5.1** Implement BFF layer: aggregate compute, agent, and notebook
      service APIs into a single frontend-optimized API, handle authentication
      (via @shared/auth), session management, user preferences, and WebSocket
      connection management for real-time features

---

### 106.3 SDK (`@kalika/sdk`)

- [x] **106.3.1.1** Implement TypeScript SDK: importable npm package providing
      the full CAS API (symbolic computation, simplification, differentiation,
      integration, solving, tensor operations, physics utilities) for use in
      Node.js/browser applications — zero server dependency (uses WASM engine
      directly)
- [x] **106.3.1.2** Implement Python SDK: Python package wrapping the TypeScript
      SDK via subprocess or REST API calls, providing a SymPy-compatible API
      surface (so researchers familiar with SymPy can switch with minimal code
      changes), plus Kalika-specific capabilities (derivation chains, formal
      verification)
- [x] **106.3.1.3** Implement CLI tool: command-line interface for Kalika
      computations — `kalika eval "integrate(sin(x)^2, x)"`,
      `kalika simplify "..."`, `kalika solve "..."`,
      `kalika notebook run file.kalika-nb` — for scripting and pipeline
      integration
- [x] **106.3.1.4** Implement Jupyter kernel: Kalika computation kernel for
      Jupyter notebooks, enabling Kalika CAS computations from standard Jupyter
      — for users who prefer the Jupyter ecosystem

---

### 106.4 Cross-Domain Integration

#### 106.4.1 Sophia Integration (Research & Knowledge)

- [x] **106.4.1.1** Integrate Kalika knowledge graph with Sophia's document
      ingestion: when Sophia ingests physics/math papers, extract theorems,
      definitions, and conjectures, and add them to Kalika's knowledge graph —
      enriching the mathematical knowledge base from literature
- [x] **106.4.1.2** Integrate Kalika citations with Sophia's citation
      management: share citation database, avoid duplication, and enable
      cross-domain citation search

#### 106.4.2 Metis Integration (Education)

- [x] **106.4.2.1** Integrate Kalika CAS with Metis educational platform: enable
      interactive mathematical exploration in Metis courses — students can
      symbolically solve equations, visualize functions, and verify solutions
      within the learning environment
- [x] **106.4.2.2** Implement step-by-step solution mode: given a problem (e.g.,
      "solve x^2 - 5x + 6 = 0"), show the solution step by step with
      explanations at each step, using the derivation chain to generate
      pedagogically appropriate explanations — matching Mathematica's
      Step-by-Step Solutions and Maple's tutors

#### 106.4.3 Nyx Integration (Astronomy)

- [x] **106.4.3.1** Integrate Kalika orbital mechanics
      (@kalika/general-relativity geodesics + Newtonian limit) with Nyx
      ephemeris calculations: provide relativistic corrections to Nyx's orbital
      computations where needed (Mercury perihelion precession, GPS relativistic
      corrections, pulsar timing)
- [x] **106.4.3.2** Integrate Kalika gravitational wave computations with Nyx
      event catalog: when Nyx catalogs a gravitational wave event, provide
      theoretical waveform comparison and parameter estimation

#### 106.4.4 Nous Integration (Sovereign AI)

- [x] **106.4.4.1** Register Kalika's research agents with Nous agent framework:
      enable Nous to dispatch mathematical/physics computation tasks to Kalika
      agents, and enable Kalika agents to use Nous's general-purpose AI
      capabilities (language understanding, planning, tool use)
- [x] **106.4.4.2** Integrate Kalika's formal verification pipeline with Nous's
      safety verification: use Lean 4 formal proofs to verify critical AI system
      properties (safety constraints, invariant preservation)

---

### 106.5 End-to-End Research Workflows

- [x] **106.5.1.1** Implement "Compute and Verify" workflow: user enters
      expression -> CAS computes result -> result is numerically spot-checked ->
      optionally formally verified via Lean 4 -> result displayed with
      verification badge and derivation chain — the core workflow for trusted
      computation
- [x] **106.5.1.2** Implement "Literature-Informed Computation" workflow: user
      asks a research question -> literature agent searches arXiv/INSPIRE ->
      computation agent implements relevant techniques from papers -> results
      compared with published values -> discrepancies flagged for investigation
- [x] **106.5.1.3** Implement "Explore and Conjecture" workflow: user specifies
      a mathematical structure -> exploration agent computes invariants and
      properties -> pattern detection identifies regularities -> conjecture
      agent formulates precise conjectures -> proof agent attempts to
      prove/disprove -> results presented as a mini research report
- [x] **106.5.1.4** Implement "Theory-to-Observable" workflow for particle
      physics: user specifies BSM model parameters -> Lagrangian built -> RGE
      running -> spectrum computation -> Feynman diagram generation ->
      cross-section/decay rate computation -> comparison with experimental data
      (PDG, LHC) -> constraints on parameter space — a complete phenomenology
      pipeline matching the FeynRules -> SARAH -> SPheno -> MadGraph ->
      CheckMATE chain
- [x] **106.5.1.5** Implement "Paper Generation" workflow: user selects notebook
      cells for publication -> Kalika generates LaTeX document with equations,
      figures, tables, derivations, bibliography -> user reviews and edits ->
      export to compilable .tex file or submit directly to arXiv via API

---

### 106.6 Comprehensive Benchmarks

#### 106.6.1 CAS Benchmarks (vs Mathematica, SageMath, SymPy, FriCAS)

- [x] **106.6.1.1** Create symbolic integration benchmark: 500+ integrals from
      Bondarenko, Charlwood, Timofeev, Rubi test suites — measure correctness
      (percentage of integrals correctly evaluated) and performance (time per
      integral) — target: exceed SymPy and FriCAS correctness, within 10x of
      Mathematica performance
- [x] **106.6.1.2** Create polynomial algebra benchmark: Groebner basis
      (cyclic-n for n=4..8, Katsura-n for n=5..12), polynomial factorization
      (degree 50/100/500 over Z), polynomial GCD (sparse multivariate, dense
      univariate) — target: match SINGULAR/Magma for GB, match FLINT for GCD
- [x] **106.6.1.3** Create simplification benchmark: 300+ expressions requiring
      trigonometric, exponential, radical, and mixed simplification — compare
      final expression complexity (node count) against Mathematica's
      FullSimplify output — target: equal or better simplification via e-graph
      saturation
- [x] **106.6.1.4** Create ODE/PDE solver benchmark: 200+ differential equations
      from Kamke's catalog (ODEs) and standard PDE test problems — measure
      solvability rate and correctness — target: match Maple for ODEs, exceed
      SymPy for PDEs

#### 106.6.2 Physics Benchmarks (vs FeynCalc, xAct, Package-X, FORM)

- [x] **106.6.2.1** Create QFT benchmark: one-loop QED corrections (vertex,
      vacuum polarization, self-energy), QCD beta function (one/two-loop), top
      quark decay width at NLO — compare analytic results against published
      values and FeynCalc output
- [x] **106.6.2.2** Create GR benchmark: compute all curvature tensors for 20+
      exact solutions (Schwarzschild, Kerr, FLRW, Godel, pp-wave, etc.), verify
      Einstein equation satisfaction, compare against xAct output — target:
      match xAct correctness with comparable or better performance
- [x] **106.6.2.3** Create tensor canonicalization benchmark: expressions with
      10/20/50/100 indices and various symmetry groups — measure
      canonicalization time against xPerm — target: within 2x for all cases,
      match for simple symmetries

#### 106.6.3 Numerical Benchmarks (vs LAPACK, PETSc, SUNDIALS)

- [x] **106.6.3.1** Create dense linear algebra benchmark: eigenvalue
      computation for matrices of size 100/500/1000/5000, SVD, matrix
      exponential — compare against OpenBLAS/LAPACK — target: within 3x for
      native, 10x for WASM
- [x] **106.6.3.2** Create sparse solver benchmark: Poisson equation on N x N
      grid (N = 100, 500, 1000, 5000) with CG + AMG preconditioner — compare
      against PETSc — target: within 5x of PETSc for moderate problems
- [x] **106.6.3.3** Create ODE solver benchmark: stiff and non-stiff test
      problems from Hairer-Norsett-Wanner test suite — compare against SUNDIALS
      CVODE — target: match accuracy with comparable performance

#### 106.6.4 AI & Verification Benchmarks

- [x] **106.6.4.1** Create formal verification benchmark: attempt to formally
      verify 100 CAS computation results in Lean 4 — measure success rate
      (percentage verified), average verification time, and types of failures —
      target: >80% automatic verification rate for standard algebraic identities
- [x] **106.6.4.2** Create symbolic regression benchmark: AI Feynman benchmark
      (100 physics equations) — measure correct recovery rate and computational
      time — target: match or exceed PySR's published results
- [x] **106.6.4.3** Create conjecture generation benchmark: given data for known
      mathematical sequences/structures, measure rate of rediscovering known
      results (e.g., Euler's partition theorem, quadratic reciprocity patterns,
      Catalan number formulas) — establishing a baseline for conjecture quality

---

### 106.7 Documentation & Onboarding

- [x] **106.7.1.1** Write API reference documentation: auto-generated TypeDoc
      for all public APIs in all @kalika/\* libraries, with usage examples for
      every major function
- [x] **106.7.1.2** Write tutorial notebooks: 10 tutorial notebooks covering —
      (1) Getting Started (basic CAS operations), (2) Calculus (differentiation,
      integration, series), (3) Linear Algebra, (4) Quantum Mechanics, (5)
      Classical Mechanics (Lagrangian/Hamiltonian), (6) Electrodynamics, (7)
      General Relativity, (8) Quantum Field Theory (Feynman diagrams), (9)
      Number Theory, (10) Formal Verification with Lean 4
- [x] **106.7.1.3** Write domain guide: comprehensive guide to Kalika's
      capabilities, organized by physics/math domain, with pointers to relevant
      libraries and functions for each topic — serving as a "which tool do I use
      for X?" reference
- [x] **106.7.1.4** Write migration guides: for users coming from Mathematica
      (function name mapping, notation differences), SymPy (API comparison),
      SageMath (workflow comparison), and FeynCalc (QFT workflow comparison) —
      reducing the barrier to adoption

---

### 106.8 Final Integration Tests

- [x] **106.8.1.1** End-to-end test: compute hydrogen atom energy levels from
      scratch (define Hamiltonian, solve Schrodinger equation, extract
      eigenvalues) and verify E_n = -13.6/n^2 eV — testing QM + CAS + numerical
      integration
- [x] **106.8.1.2** End-to-end test: compute anomalous magnetic moment of the
      electron at one loop (generate Feynman diagram, evaluate amplitude, take
      trace, evaluate loop integral, renormalize) and verify a_e = alpha/(2\*pi)
      — testing QFT + Feynman engine + loop integrals
- [x] **106.8.1.3** End-to-end test: compute Schwarzschild geodesic precession
      and verify Mercury perihelion advance formula delta_phi =
      6*pi*G*M/(c^2*a\*(1-e^2)) — testing GR + tensor calculus + geodesic solver
- [x] **106.8.1.4** End-to-end test: discover Newton's law of gravitation (F =
      GMm/r^2) from synthetic orbital data via symbolic regression — testing
      AI + symbolic regression pipeline
- [x] **106.8.1.5** End-to-end test: formally verify in Lean 4 that the integral
      of sin(x) from 0 to pi equals 2 — testing CAS + formal verification bridge
- [x] **106.8.1.6** End-to-end test: generate a complete notebook computing
      Ising model critical temperature, visualize phase transition, and export
      as LaTeX paper with bibliography — testing notebooks + statistical
      mechanics + visualization + typesetting + citations
