Repository Public MIT
1<!--2ORIX Calc3File: docs/architecture/workspace.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->7# Workspace engine (`ORIXWorkspace`)89A workspace is an ordered list of cells. Formula cells may define a variable (`NPV = …`) or a function (`f(x) = …`);10live parameters define a variable driven by a slider; tables and graphs read variables.1112```mermaid13flowchart LR14 Investment --> NPV15 DiscountRate(("DiscountRate<br/>live parameter")) --> NPV16 CashFlow1 --> NPV17 CashFlow2 --> NPV18 CashFlow3 --> NPV19 NPV --> Decision20 DiscountRate --> Graph["graph cell"]21 DiscountRate --> Table["table cell"]22```2324## Recalculation25261. **Parse** every cell (two passes: function names are collected first so that `f(2)` in another cell is a call).272. **Resolve names**: the first definition of a name wins; a later duplicate is an error on that cell.283. **Topological order** (Kahn's algorithm in document order). Cells that cannot be ordered are in a cycle: each gets a29 `circularReference` error with the actual path (`a → b → c → a`). Nothing loops.304. **Evaluate** in order. A cell whose dependency failed gets "Depends on “x”, which has an error".315. **Incremental updates**: editing a cell or moving a slider re-evaluates only that cell and its transitive dependents32 (`lastRecalculated` lists them). Changes that alter names, the set of functions or the error structure trigger a full pass.3334Cell order in the document does not matter for evaluation: `c = a + b` may appear above `a = 5`.3536## Exports3738Plain text, Markdown, CSV (machine-readable full-precision values), LaTeX (a complete `article` document using `amsmath`),39and the native `.orixcalc` file. Every export ends with the assumptions that the numbers depend on: angle mode, percent40convention, complex mode, arithmetic model. Unit labels travel with their cells.4142## File format4344`.orixcalc` is JSON: `{ checksum, format, version, workspace }`. The checksum is the SHA-256 of the canonical encoding of45the document. On load: wrong format → rejected; newer version → rejected with a clear message; checksum mismatch → reported46as damaged, with the readable content returned for recovery; truncated file → reported as damaged.47