equireduce 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. equireduce-0.1.0/CHANGELOG.md +45 -0
  2. equireduce-0.1.0/LICENSE +21 -0
  3. equireduce-0.1.0/MANIFEST.in +6 -0
  4. equireduce-0.1.0/PKG-INFO +103 -0
  5. equireduce-0.1.0/PROVENANCE.md +18 -0
  6. equireduce-0.1.0/README.md +79 -0
  7. equireduce-0.1.0/docs/algebraic_reduction.md +105 -0
  8. equireduce-0.1.0/docs/api.md +180 -0
  9. equireduce-0.1.0/docs/architecture.md +114 -0
  10. equireduce-0.1.0/docs/artifacts.md +153 -0
  11. equireduce-0.1.0/docs/conf.py +21 -0
  12. equireduce-0.1.0/docs/coordinates.md +88 -0
  13. equireduce-0.1.0/docs/dae.md +178 -0
  14. equireduce-0.1.0/docs/decisions.md +90 -0
  15. equireduce-0.1.0/docs/development.md +127 -0
  16. equireduce-0.1.0/docs/dnipro.md +193 -0
  17. equireduce-0.1.0/docs/examples.md +134 -0
  18. equireduce-0.1.0/docs/glossary.md +32 -0
  19. equireduce-0.1.0/docs/implementation_plan.md +254 -0
  20. equireduce-0.1.0/docs/implicit_dae.md +321 -0
  21. equireduce-0.1.0/docs/index.md +40 -0
  22. equireduce-0.1.0/docs/lean.md +153 -0
  23. equireduce-0.1.0/docs/mathematical_contract.md +108 -0
  24. equireduce-0.1.0/docs/overview.md +69 -0
  25. equireduce-0.1.0/docs/progress.md +190 -0
  26. equireduce-0.1.0/docs/quickstart.md +119 -0
  27. equireduce-0.1.0/docs/reference.md +135 -0
  28. equireduce-0.1.0/docs/requirements.txt +2 -0
  29. equireduce-0.1.0/docs/roadmap.md +97 -0
  30. equireduce-0.1.0/docs/testing.md +129 -0
  31. equireduce-0.1.0/examples/__init__.py +1 -0
  32. equireduce-0.1.0/examples/bjt14.py +39 -0
  33. equireduce-0.1.0/examples/bjt43.py +59 -0
  34. equireduce-0.1.0/examples/coordinate_benchmark.py +44 -0
  35. equireduce-0.1.0/examples/dae_first_order.py +40 -0
  36. equireduce-0.1.0/examples/flow_balance.py +23 -0
  37. equireduce-0.1.0/examples/kinematic.py +24 -0
  38. equireduce-0.1.0/examples/run_formal.py +46 -0
  39. equireduce-0.1.0/lean/lake-manifest.json +117 -0
  40. equireduce-0.1.0/lean/lakefile.toml +7 -0
  41. equireduce-0.1.0/lean/lean-toolchain +1 -0
  42. equireduce-0.1.0/pyproject.toml +44 -0
  43. equireduce-0.1.0/setup.cfg +4 -0
  44. equireduce-0.1.0/src/equireduce/__init__.py +90 -0
  45. equireduce-0.1.0/src/equireduce/_coordinate_lean.py +180 -0
  46. equireduce-0.1.0/src/equireduce/_core.py +1181 -0
  47. equireduce-0.1.0/src/equireduce/_dae_lean.py +346 -0
  48. equireduce-0.1.0/src/equireduce/_implicit_lean.py +782 -0
  49. equireduce-0.1.0/src/equireduce/_lean_calculus.py +140 -0
  50. equireduce-0.1.0/src/equireduce/_lean_export.py +695 -0
  51. equireduce-0.1.0/src/equireduce/_time_coordinate_lean.py +279 -0
  52. equireduce-0.1.0/src/equireduce/_version.py +3 -0
  53. equireduce-0.1.0/src/equireduce/api.py +153 -0
  54. equireduce-0.1.0/src/equireduce/artifacts.py +517 -0
  55. equireduce-0.1.0/src/equireduce/conditions.py +142 -0
  56. equireduce-0.1.0/src/equireduce/coordinates.py +298 -0
  57. equireduce-0.1.0/src/equireduce/dae.py +500 -0
  58. equireduce-0.1.0/src/equireduce/dae_structure.py +298 -0
  59. equireduce-0.1.0/src/equireduce/errors.py +34 -0
  60. equireduce-0.1.0/src/equireduce/implicit.py +305 -0
  61. equireduce-0.1.0/src/equireduce/implicit_artifacts.py +106 -0
  62. equireduce-0.1.0/src/equireduce/implicit_initial.py +313 -0
  63. equireduce-0.1.0/src/equireduce/implicit_reduction.py +353 -0
  64. equireduce-0.1.0/src/equireduce/implicit_search.py +164 -0
  65. equireduce-0.1.0/src/equireduce/lean.py +265 -0
  66. equireduce-0.1.0/src/equireduce/metrics.py +45 -0
  67. equireduce-0.1.0/src/equireduce/provenance.py +77 -0
  68. equireduce-0.1.0/src/equireduce/py.typed +0 -0
  69. equireduce-0.1.0/src/equireduce/resources/artifact-implicit-v1.schema.json +483 -0
  70. equireduce-0.1.0/src/equireduce/resources/artifact-v1.schema.json +441 -0
  71. equireduce-0.1.0/src/equireduce/resources/lake-manifest.json +117 -0
  72. equireduce-0.1.0/src/equireduce/resources/lakefile.toml +7 -0
  73. equireduce-0.1.0/src/equireduce/resources/lean-toolchain +1 -0
  74. equireduce-0.1.0/src/equireduce/result.py +114 -0
  75. equireduce-0.1.0/src/equireduce/search.py +299 -0
  76. equireduce-0.1.0/src/equireduce/smooth.py +125 -0
  77. equireduce-0.1.0/src/equireduce/system.py +134 -0
  78. equireduce-0.1.0/src/equireduce/time_coordinates.py +354 -0
  79. equireduce-0.1.0/src/equireduce.egg-info/PKG-INFO +103 -0
  80. equireduce-0.1.0/src/equireduce.egg-info/SOURCES.txt +102 -0
  81. equireduce-0.1.0/src/equireduce.egg-info/dependency_links.txt +1 -0
  82. equireduce-0.1.0/src/equireduce.egg-info/requires.txt +14 -0
  83. equireduce-0.1.0/src/equireduce.egg-info/top_level.txt +1 -0
  84. equireduce-0.1.0/tests/test_artifacts.py +168 -0
  85. equireduce-0.1.0/tests/test_bjt_coordinates.py +65 -0
  86. equireduce-0.1.0/tests/test_coordinates.py +168 -0
  87. equireduce-0.1.0/tests/test_dae.py +305 -0
  88. equireduce-0.1.0/tests/test_dae_structure.py +133 -0
  89. equireduce-0.1.0/tests/test_dnipro_adapter.py +104 -0
  90. equireduce-0.1.0/tests/test_implicit_artifacts.py +129 -0
  91. equireduce-0.1.0/tests/test_implicit_contract.py +106 -0
  92. equireduce-0.1.0/tests/test_implicit_initial.py +152 -0
  93. equireduce-0.1.0/tests/test_implicit_inputs.py +253 -0
  94. equireduce-0.1.0/tests/test_implicit_lean.py +87 -0
  95. equireduce-0.1.0/tests/test_implicit_reduction.py +217 -0
  96. equireduce-0.1.0/tests/test_implicit_search.py +70 -0
  97. equireduce-0.1.0/tests/test_lean.py +143 -0
  98. equireduce-0.1.0/tests/test_properties.py +60 -0
  99. equireduce-0.1.0/tests/test_reduction.py +159 -0
  100. equireduce-0.1.0/tests/test_regressions.py +76 -0
  101. equireduce-0.1.0/tests/test_search.py +122 -0
  102. equireduce-0.1.0/tests/test_smooth_charges.py +244 -0
  103. equireduce-0.1.0/tests/test_system.py +81 -0
  104. equireduce-0.1.0/tests/test_time_coordinates.py +269 -0
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0.dev0 — in development
4
+
5
+ - Standalone GitHub repository with MIT licensing and SPDX package metadata.
6
+
7
+ - Independent immutable SymPy system model and explicit real domains.
8
+ - Exact affine scalar/block elimination and reconstruction.
9
+ - Certificate replay with source-domain and affinity validation.
10
+ - Pinned Lean compiler backend, strict proof modes, and axiom auditing.
11
+ - JSON AST round trips and reproducible proof directories.
12
+ - Affine coordinate maps, composed certificates, and full Lean 4 → 3 / 14 → 3 regressions.
13
+ - Bounded deterministic coordinate search, Jacobian/DAG metrics and measured Lean benchmarks.
14
+ - Optional Dnipro adapter with explicit real assumptions and stationary projection.
15
+ - Experimental semi-explicit DAE reduction, interval trajectory equivalence,
16
+ exact initial checks, rational chain rules and checked first-rate substitution.
17
+ - Implicit first-order DAE contract, exact rate-affinity analysis, bounded
18
+ symbolic rank certificates and algebraic-block reduction without mass inversion.
19
+ - Dnipro time-domain adapter with immutable source snapshots and row provenance.
20
+ - Exact identity/condition checks avoid `Expr.equals` numerical probing in the
21
+ supported symbolic reduction path.
22
+ - Complete implicit MNA interval proofs with actual derivatives, source poles,
23
+ composite derivative normalization and audited final Lean theorems.
24
+ - Exact pointwise initial consistency with existential missing rates and explicit
25
+ parameter obligations, without assuming nonzero capacitance or inductance.
26
+ - Bounded deterministic partition search with checked blocks and manual overrides.
27
+ - Rational time-dependent affine trajectory charts, both inverse rate maps,
28
+ transported initial data and full composed Lean equivalence proofs.
29
+ - Prescribed differentiable external inputs in implicit reconstruction and
30
+ rational chain rules, explicit Lean regularity and actual input derivatives.
31
+ - Exact input initial samples with separate symbolic placeholders, propagated
32
+ through partition search, time charts and the Dnipro adapter.
33
+ - Algebraic Lean condition export avoids Relational.simplify/equals probing.
34
+ - Explicit unary/binary smooth laws with declared gradients, exact mixed charge
35
+ derivatives and concrete exponential calculus with actual Lean theorems.
36
+ - Ordered Piecewise branch selection, strict interval guards and raw-charge
37
+ derivative proofs; no transitions or implicit branch coverage claims.
38
+ - Concrete NPN/PNP charge regressions for fixed VT, MJE=MJC=0, TF/TR and Early
39
+ effect, including both storage branches and three-terminal charge conservation.
40
+ - Portable implicit/v1 JSON with bounded AST, independent certificate replay,
41
+ checked initial data, search metadata and optional source provenance.
42
+ - Dnipro single-call symbolic time pipeline, original-labelled SymPy results,
43
+ CLI JSON/LaTeX/Lean exports and explicit fresh Lean verification.
44
+
45
+ Acceptance results and unfinished milestones are recorded in `docs/progress.md`.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 konst1970
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ include LICENSE CHANGELOG.md PROVENANCE.md
2
+ recursive-include docs *.md *.py *.txt
3
+ recursive-exclude docs/_build *
4
+ recursive-include examples *.py
5
+ include lean/lean-toolchain lean/lakefile.toml lean/lake-manifest.json
6
+ recursive-include src/equireduce/resources *
@@ -0,0 +1,103 @@
1
+ Metadata-Version: 2.4
2
+ Name: equireduce
3
+ Version: 0.1.0
4
+ Summary: Exact symbolic equation reduction with independently checked certificates
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/konst1970/EquiReduce
7
+ Project-URL: Issues, https://github.com/konst1970/EquiReduce/issues
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: sympy<2,>=1.14
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest>=8; extra == "dev"
14
+ Requires-Dist: hypothesis>=6; extra == "dev"
15
+ Requires-Dist: jsonschema>=4; extra == "dev"
16
+ Requires-Dist: ruff>=0.15; extra == "dev"
17
+ Requires-Dist: mypy>=1.15; extra == "dev"
18
+ Requires-Dist: build>=1.2; extra == "dev"
19
+ Requires-Dist: twine>=6; extra == "dev"
20
+ Provides-Extra: docs
21
+ Requires-Dist: Sphinx<9,>=8; extra == "docs"
22
+ Requires-Dist: myst-parser<5,>=4; extra == "docs"
23
+ Dynamic: license-file
24
+
25
+ # EquiReduce
26
+
27
+ **Exact symbolic reduction of equation systems with formal equivalence
28
+ proofs.** An independent Python library with SymPy input and output,
29
+ and certificate verification in Lean 4 + Mathlib.
30
+
31
+ Source repository: [konst1970/EquiReduce](https://github.com/konst1970/EquiReduce).
32
+
33
+ > Status as of 2026-11-20: development version `0.1.0.dev0` is available.
34
+ > The implementation includes the algebraic core, certificates, Lean backend,
35
+ > portable artifacts, affine coordinates, and bounded search. Lean verifies
36
+ > the 14 → 4, 4 → 3, and 14 → 3 examples. An experimental semi-explicit DAE
37
+ > API provides trajectory correspondence and chain-rule proofs.
38
+ > The implicit MNA pipeline also includes a complete Lean proof, symbolic
39
+ > initial data, partition search, and time-dependent affine charts with derivatives.
40
+ > Prescribed differentiable inputs are supported, including the full chain rule,
41
+ > explicit Lean assumptions, and exact initial value and derivative samples.
42
+ > Smooth charge laws, `exp`, explicit branches, and a concrete NPN/PNP charge
43
+ > profile are supported; implicit JSON artifacts have independent replay.
44
+ > This is not a published release.
45
+
46
+ The library returns reduced equations, reconstruction formulas for eliminated
47
+ variables, validity conditions, a transformation certificate, and its verification
48
+ result. Reduction does not numerically solve the resulting system.
49
+
50
+ The first release covers algebraic systems over the real numbers. Differential-
51
+ algebraic equation (DAE) support is available through a separate experimental
52
+ API for affine algebraic blocks and supported smooth reconstruction.
53
+ The precise limits are given in the [DAE contract](docs/dae.md) and
54
+ [implicit pipeline contract](docs/implicit_dae.md).
55
+
56
+ ## Documentation
57
+
58
+ [Getting started with the implemented library](docs/quickstart.md) ·
59
+ [TDD report and task status](docs/progress.md) ·
60
+ [Python API reference](docs/reference.md).
61
+
62
+ Start with the [contents](docs/index.md), [purpose and current status](docs/overview.md),
63
+ and [implementation roadmap](docs/roadmap.md).
64
+
65
+ For development, read the [detailed ER-01–ER-19 implementation plan](docs/implementation_plan.md).
66
+
67
+ - [Mathematical contract](docs/mathematical_contract.md).
68
+ - [Algebraic reduction algorithms](docs/algebraic_reduction.md).
69
+ - [DAEs: initial implementation limits and proof requirements](docs/dae.md).
70
+ - [Python library architecture](docs/architecture.md).
71
+ - [Target API](docs/api.md) and [examples](docs/examples.md).
72
+ - [Lean verification](docs/lean.md).
73
+ - [Certificate and audit artifact format](docs/artifacts.md).
74
+ - [Testing and quality criteria](docs/testing.md).
75
+ - [Development, packaging, and releases](docs/development.md).
76
+ - [Terminology and notation](docs/glossary.md).
77
+ - [Architecture decision records](docs/decisions.md).
78
+
79
+ ## Building the documentation
80
+
81
+ Clone the standalone repository and install the local package for the API
82
+ reference; Lean and Mathlib are not required to build the documentation:
83
+
84
+ ```bash
85
+ git clone https://github.com/konst1970/EquiReduce.git
86
+ cd EquiReduce
87
+ python3 -m venv .venv
88
+ .venv/bin/python -m pip install -e '.[dev,docs]'
89
+ .venv/bin/python -m sphinx -n -W --keep-going -b html docs docs/_build/html
90
+ ```
91
+
92
+ Open `docs/_build/html/index.html`. You can also read the Markdown files
93
+ directly on GitHub or in an editor without building them.
94
+
95
+ The availability of the distribution name `equireduce` must be checked before
96
+ publication.
97
+
98
+ ## License
99
+
100
+ EquiReduce is distributed under the [MIT License](LICENSE).
101
+ Copyright (c) 2026 konst1970.
102
+ See [code provenance](PROVENANCE.md) for the origin of extracted code.
103
+ Third-party dependencies retain their own licenses.
@@ -0,0 +1,18 @@
1
+ # Code provenance
2
+
3
+ The affine reduction primitives in `src/equireduce/_core.py` and the initial
4
+ exporter in `_lean_export.py` were adapted from the Dnipro prototype
5
+ (`dnipro/analysis/reduction.py` and `lean_reduction.py`, repository commit
6
+ [`f634f73d2880fb1f57b36c506086a0a62980c056`](https://github.com/konst1970/dnipro4/commit/f634f73d2880fb1f57b36c506086a0a62980c056)). The extraction and subsequent
7
+ changes were requested by the project owner in this workspace.
8
+
9
+ EquiReduce adds its own application-independent input contract, domain tracking,
10
+ certificate checks, proof auditing, and portable artifact format. It has no
11
+ runtime import of Dnipro. Third-party dependencies are installed separately;
12
+ their source and compiled caches are not part of this Python distribution.
13
+
14
+ EquiReduce as distributed in this repository is licensed under the MIT License
15
+ (see `LICENSE`), selected by the project owner. This applies to the EquiReduce
16
+ code and documentation distributed here; separately installed dependencies
17
+ retain their own licenses. The development version is not a declaration that
18
+ a stable package release has been published.
@@ -0,0 +1,79 @@
1
+ # EquiReduce
2
+
3
+ **Exact symbolic reduction of equation systems with formal equivalence
4
+ proofs.** An independent Python library with SymPy input and output,
5
+ and certificate verification in Lean 4 + Mathlib.
6
+
7
+ Source repository: [konst1970/EquiReduce](https://github.com/konst1970/EquiReduce).
8
+
9
+ > Status as of 2026-11-20: development version `0.1.0.dev0` is available.
10
+ > The implementation includes the algebraic core, certificates, Lean backend,
11
+ > portable artifacts, affine coordinates, and bounded search. Lean verifies
12
+ > the 14 → 4, 4 → 3, and 14 → 3 examples. An experimental semi-explicit DAE
13
+ > API provides trajectory correspondence and chain-rule proofs.
14
+ > The implicit MNA pipeline also includes a complete Lean proof, symbolic
15
+ > initial data, partition search, and time-dependent affine charts with derivatives.
16
+ > Prescribed differentiable inputs are supported, including the full chain rule,
17
+ > explicit Lean assumptions, and exact initial value and derivative samples.
18
+ > Smooth charge laws, `exp`, explicit branches, and a concrete NPN/PNP charge
19
+ > profile are supported; implicit JSON artifacts have independent replay.
20
+ > This is not a published release.
21
+
22
+ The library returns reduced equations, reconstruction formulas for eliminated
23
+ variables, validity conditions, a transformation certificate, and its verification
24
+ result. Reduction does not numerically solve the resulting system.
25
+
26
+ The first release covers algebraic systems over the real numbers. Differential-
27
+ algebraic equation (DAE) support is available through a separate experimental
28
+ API for affine algebraic blocks and supported smooth reconstruction.
29
+ The precise limits are given in the [DAE contract](docs/dae.md) and
30
+ [implicit pipeline contract](docs/implicit_dae.md).
31
+
32
+ ## Documentation
33
+
34
+ [Getting started with the implemented library](docs/quickstart.md) ·
35
+ [TDD report and task status](docs/progress.md) ·
36
+ [Python API reference](docs/reference.md).
37
+
38
+ Start with the [contents](docs/index.md), [purpose and current status](docs/overview.md),
39
+ and [implementation roadmap](docs/roadmap.md).
40
+
41
+ For development, read the [detailed ER-01–ER-19 implementation plan](docs/implementation_plan.md).
42
+
43
+ - [Mathematical contract](docs/mathematical_contract.md).
44
+ - [Algebraic reduction algorithms](docs/algebraic_reduction.md).
45
+ - [DAEs: initial implementation limits and proof requirements](docs/dae.md).
46
+ - [Python library architecture](docs/architecture.md).
47
+ - [Target API](docs/api.md) and [examples](docs/examples.md).
48
+ - [Lean verification](docs/lean.md).
49
+ - [Certificate and audit artifact format](docs/artifacts.md).
50
+ - [Testing and quality criteria](docs/testing.md).
51
+ - [Development, packaging, and releases](docs/development.md).
52
+ - [Terminology and notation](docs/glossary.md).
53
+ - [Architecture decision records](docs/decisions.md).
54
+
55
+ ## Building the documentation
56
+
57
+ Clone the standalone repository and install the local package for the API
58
+ reference; Lean and Mathlib are not required to build the documentation:
59
+
60
+ ```bash
61
+ git clone https://github.com/konst1970/EquiReduce.git
62
+ cd EquiReduce
63
+ python3 -m venv .venv
64
+ .venv/bin/python -m pip install -e '.[dev,docs]'
65
+ .venv/bin/python -m sphinx -n -W --keep-going -b html docs docs/_build/html
66
+ ```
67
+
68
+ Open `docs/_build/html/index.html`. You can also read the Markdown files
69
+ directly on GitHub or in an editor without building them.
70
+
71
+ The availability of the distribution name `equireduce` must be checked before
72
+ publication.
73
+
74
+ ## License
75
+
76
+ EquiReduce is distributed under the [MIT License](LICENSE).
77
+ Copyright (c) 2026 konst1970.
78
+ See [code provenance](PROVENANCE.md) for the origin of extracted code.
79
+ Third-party dependencies retain their own licenses.
@@ -0,0 +1,105 @@
1
+ # Algebraic reduction algorithms
2
+
3
+ ## Processing sequence
4
+
5
+ 1. Validate types, unknown order, parameters, domains, and numeric exactness.
6
+ 2. Keep an immutable snapshot of the input and conditions before transformation.
7
+ 3. Identify variables and blocks in which the residuals are affine.
8
+ 4. Construct an elimination candidate and every required condition.
9
+ 5. Substitute reconstruction formulas, updating remaining equations and the step trace.
10
+ 6. Independently verify the candidate certificate.
11
+ 7. Compare admissible results using the chosen objective.
12
+ 8. Generate or compile a Lean proof when requested.
13
+
14
+ Normalization must be conservative: avoid expanding arbitrarily large products
15
+ or applying transformations that require unrecorded assumptions. Search time
16
+ and expression sizes are bounded by budgets.
17
+
18
+ ## Scalar affine step
19
+
20
+ A row has the form
21
+
22
+ $$a(Z,p)y+b(Z,p)=0.$$
23
+
24
+ When $a\ne0$, $y=-b/a$. The coefficients must be independent of $y$;
25
+ this must be checked rather than inferred from the expression's appearance.
26
+ Substitute the formula into every remaining equation.
27
+ Every previously eliminated variable must eventually have a reconstruction
28
+ using only final coordinates and parameters, without cyclic dependencies.
29
+ Conditions from earlier steps are also transported through all subsequent
30
+ substitutions. If reconstruction makes a condition false, the candidate
31
+ cannot be treated as an admissible nonempty branch. If its truth is unknown,
32
+ the obligation remains explicit.
33
+
34
+ ## Block elimination
35
+
36
+ For selected rows and variables:
37
+
38
+ $$A(Z,p)Y+b(Z,p)=0,\qquad \det A(Z,p)\ne0.$$
39
+
40
+ Return the exact block solution $Y=\varphi(Z,p)$. The implementation may use
41
+ exact linear solving without explicitly computing an inverse matrix.
42
+ Nonzero assumptions for denominators introduced by the algorithm are checked
43
+ separately; a symbolic rank estimate does not remove the need for conditions.
44
+
45
+ A singular, rectangular, or undetermined block must not be treated as an
46
+ ordinary invertible square block. The first release skips such a candidate
47
+ or selects a certified square subblock. Remaining equations are not removed
48
+ without proof of redundancy.
49
+
50
+ ## Nonlinear functions
51
+
52
+ Exponentials, logarithms, and other nonlinear dependencies can remain in the
53
+ residual core. If an affine step is valid for any function $f(Z)$, its physical
54
+ formula need not be proved.
55
+
56
+ However, replacing $f(y)$ with a new independent symbol must not allow $y$
57
+ to be eliminated while losing the function's dependence on $y$. Every function
58
+ occurrence must receive the exact argument substitution after reconstruction.
59
+
60
+ ## Coordinate changes
61
+
62
+ The initial supported class is $X=M U+c$ with an exact inverse matrix and
63
+ conditions $\det M\ne0$. The matrix and offset may depend on parameters
64
+ but not unknowns. Both maps are checked by a separate certificate; this
65
+ does not permit arbitrary nonlinear coordinate changes.
66
+
67
+ Automatic search starts with the identity, permutations, simple integer linear
68
+ combinations, and sum/difference bases. The coefficient bound and candidate
69
+ count are parameters rather than hidden heuristics.
70
+
71
+ ## Certificate and independent verification
72
+
73
+ For each step, record source rows, pivot coefficients, conditions, the
74
+ elimination formula, substitutions, and the link to the next system.
75
+ For linear row combinations, matrices $Q,T$ may additionally be constructed
76
+ with identities $F=QG$, $G=TF$. Requiring both matrices is not universal for
77
+ arbitrary nonlinear substitutions; the general contract is defined by a
78
+ bidirectional statement and reconstruction.
79
+
80
+ The verifier does not repeat the search for the best candidate: it takes a
81
+ completed certificate and checks every claimed step against the immutable
82
+ input. An unconfirmed identity yields `unknown` or `failed`, not success.
83
+
84
+ ## Optimization criteria
85
+
86
+ The initial deterministic ranking is lexicographic:
87
+
88
+ 1. Fewer unknowns.
89
+ 2. Lower estimated complexity of the reduced Jacobian.
90
+ 3. Smaller expression trees and DAGs.
91
+ 4. Fewer new conditions and lower coordinate transformation cost.
92
+ 5. Estimated formal proof complexity and stable candidate order.
93
+
94
+ An estimated Lean operation count is not measured compilation time.
95
+ Timing comparisons require a fixed environment with the same cache warm-up
96
+ and repetition rules. Extended objectives must be explicitly available
97
+ without changing the mathematical contract.
98
+
99
+ ## Termination
100
+
101
+ The result records the termination reason: no supported steps, budget reached,
102
+ a contradiction found, or completion of the declared candidate family.
103
+ No reduction is a valid result with identity reconstruction.
104
+ `search_complete` applies only to the declared finite family, not to all
105
+ possible mathematical transformations.
@@ -0,0 +1,180 @@
1
+ # Python API: implementation and future extensions
2
+
3
+ Algebraic `System`, `reduce_system`, certificate verification, Lean modes,
4
+ and artifact operations are implemented in `0.1.0.dev0`.
5
+ Exact signatures appear in the [generated reference](reference.md).
6
+ Coordinates and search are described [separately](coordinates.md), and the
7
+ experimental DAE API in the [DAE contract](dae.md).
8
+
9
+ ## Creating an algebraic system
10
+
11
+ ```python
12
+ import sympy as sp
13
+ from equireduce import System
14
+
15
+ x, y, a = sp.symbols("x y a", real=True)
16
+
17
+ system = System.algebraic(
18
+ residuals=(a*y - x, y + x - 1),
19
+ unknowns=(x, y),
20
+ parameters=(a,),
21
+ conditions=(sp.Ne(a, 0),),
22
+ )
23
+ ```
24
+
25
+ `residuals` are `Expr` objects, each set equal to zero. The initial API does
26
+ not accept strings or `Eq`: this avoids ambiguity between a residual, an
27
+ equality, and an already evaluated Boolean. A `Matrix` can be normalized
28
+ into an ordered tuple of scalar residuals.
29
+
30
+ `unknowns` contains distinct real `Symbol` objects, preserving order.
31
+ `parameters` explicitly declares other free symbols and is disjoint from the
32
+ unknowns. Examples should use `real=True`; unknown or incompatible assumptions
33
+ are not silently reinterpreted. `conditions` contains SymPy predicates.
34
+ Empty tuples are allowed. Sign assumptions on symbols and undefined functions
35
+ are included in the domain. Discrete assumptions such as `integer=True` are
36
+ unsupported. For explicit conversion of decimal coefficients, the factory has
37
+ `float_policy="exact_decimal"`; numbers in the resulting system are exact.
38
+
39
+ Hidden free symbols, `Derivative` in the algebraic domain, invalid numbers,
40
+ and repeated unknowns cause validation errors. An empty system is valid and
41
+ means no constraints within the specified domain.
42
+
43
+ ## Main operation
44
+
45
+ ```python
46
+ def reduce_system(
47
+ system: System,
48
+ *,
49
+ candidates=None,
50
+ options=None,
51
+ proof="none",
52
+ lean=None,
53
+ ) -> ReductionResult:
54
+ ...
55
+ ```
56
+
57
+ - `candidates`: unknowns explicitly eligible for elimination; `None` permits
58
+ considering all of them. Order is a search preference, not permission for
59
+ an invalid step.
60
+ - `options`: immutable `ReductionOptions` with budgets and a selection criterion.
61
+ - `proof`: `"none"`, `"generate"`, or `"require"`.
62
+ - `lean`: `LeanConfig` with the pinned Lake project's working directory,
63
+ a command tuple, and a timeout.
64
+
65
+ `coordinate_search=True` searches a finite family of charts.
66
+ `max_candidates` bounds evaluated charts; `coefficient_bound` bounds integer
67
+ coordinate shear coefficients. `allow_blocks=False` restricts elimination to
68
+ scalar steps. The decimal policy applies when creating `System`, not after
69
+ input precision has already been lost.
70
+
71
+ ```python
72
+ from equireduce import LeanConfig, ReductionOptions, reduce_system
73
+
74
+ options = ReductionOptions(
75
+ max_candidates=32,
76
+ coordinate_search=False,
77
+ float_policy="reject",
78
+ )
79
+ lean = LeanConfig(
80
+ project_dir="./lean",
81
+ command=("lake", "env", "lean"),
82
+ timeout_seconds=120,
83
+ )
84
+
85
+ result = reduce_system(
86
+ system,
87
+ candidates=(y,),
88
+ options=options,
89
+ proof="require",
90
+ lean=lean,
91
+ )
92
+ ```
93
+
94
+ `project_dir` is explicit rather than inferred from the current process.
95
+ The command is not passed to a shell. Parameters must have checkable bounds,
96
+ such as positive integer budgets and a positive timeout.
97
+
98
+ ## Result
99
+
100
+ | `ReductionResult` field | Meaning |
101
+ |---|---|
102
+ | `source` | Immutable source `System` |
103
+ | `reduced_system` | Reduced residuals and their domain as SymPy objects |
104
+ | `remaining_unknowns` | Ordered final coordinates |
105
+ | `reconstruction` | SymPy mapping for all eliminated variables |
106
+ | `coordinate_map` | Forward and inverse charts when coordinates change |
107
+ | `conditions` | All result conditions with provenance |
108
+ | `additional_conditions` | New restrictions relative to the input domain |
109
+ | `coverage` | `complete` relative to the input domain, or `conditional` |
110
+ | `assumption_consistency` | `consistent`, `inconsistent`, or `unknown` |
111
+ | `certificate` | Versioned trace of checkable steps |
112
+ | `symbolic_check` | Separate SymPy verification status |
113
+ | `formal_check` | Lean status, theorem, source, versions, and log |
114
+ | `metrics` | Complexity comparison before and after reduction |
115
+ | `search` | Budget, candidate count, family completeness, and termination reason |
116
+
117
+ For plain reduction, `coordinate_map` and `metrics` are `None`, while `search`
118
+ records the deterministic algorithm's termination reason. The formal result
119
+ also has `origin`, `command`, `seconds`, `checked_at_utc`, and a source hash.
120
+ After artifact loading, `origin="recorded"` identifies a historical result,
121
+ not fresh compilation.
122
+
123
+ `reduced_system.residuals` and `reconstruction` must remain SymPy objects.
124
+ Text representations are intended for documentation and export, not mandatory
125
+ reparsing within the Python API.
126
+
127
+ `coverage="complete"` is valid only if the certificate does not restrict the
128
+ input solution set, or if the new conditions are proved to follow from it.
129
+ It makes no claim about search completeness or existence of solutions.
130
+
131
+ ## Proof modes
132
+
133
+ | `proof` | Expected behavior |
134
+ |---|---|
135
+ | `none` | Symbolic verification; Lean is not run, status `not_requested` |
136
+ | `generate` | Source is generated; status `generated` if export is supported |
137
+ | `require` | A certified result is returned only after actual Lean verification |
138
+
139
+ With `require`, missing Lean, a timeout, unsupported export, or a rejected
140
+ proof raises `ProofVerificationError` with diagnostics and access to the
141
+ unconfirmed candidate. There is no silent fallback to `none`.
142
+ Generated text never has `verified` status.
143
+
144
+ In other modes, unsupported export is reported in `formal_check`; a valid
145
+ symbolic result can be inspected without claiming formal verification.
146
+ An unverified symbolic candidate is not presented as a confirmed reduction:
147
+ the source system is returned with diagnostics, or an explicit error is raised.
148
+
149
+ ## Separate operations
150
+
151
+ Public functions:
152
+
153
+ ```python
154
+ def verify_certificate(system, certificate): ...
155
+ def generate_lean(system, certificate, *, config): ...
156
+ def verify_with_lean(system, certificate, *, config): ...
157
+ def export_artifact(result, path): ...
158
+ def load_artifact(path): ...
159
+ ```
160
+
161
+ File export is an explicit user operation. Artifact loading checks the schema
162
+ and integrity; it does not run Lean or automatically repeat the formal proof.
163
+
164
+ ## Exceptions
165
+
166
+ The base exception is `EquiReduceError`, with subclasses `InvalidSystemError`,
167
+ `UnsupportedDomainError`, `UnsupportedExpressionError`, `CertificateError`,
168
+ `ProofVerificationError`, and `ArtifactError`.
169
+ Messages identify the equation index, variable, or expression node path where
170
+ the problem occurred. Failure to find a reduction is not itself an exception.
171
+ A contradictory system is also a mathematical result if the contradiction
172
+ has actually been justified.
173
+
174
+ ## Experimental DAE API
175
+
176
+ `DAESystem.semi_explicit(...)` and `reduce_dae(...)` accept time functions,
177
+ a square affine algebraic block, and an open interval. They return
178
+ `DAEReductionResult` with reconstruction, first derivatives, interval-wide
179
+ conditions, and initial data checks. `verify_dae_certificate` checks a separate
180
+ DAE certificate. Algebraic `System.algebraic` continues to reject derivatives.
@@ -0,0 +1,114 @@
1
+ # Python library architecture
2
+
3
+ ## Dependencies and boundaries
4
+
5
+ Equation producer → `System` → reducer → certificate → independent verifier
6
+ → optional Lean backend → `ReductionResult`.
7
+
8
+ The core depends on the Python standard library and SymPy. Lean and Mathlib
9
+ form an external tool environment, not a core `pip` dependency. Ordinary
10
+ library import requires neither Git, Lake, network access, nor an application
11
+ package such as Dnipro.
12
+
13
+ Circuit construction, the SPICE parser, BJT models, and numerical solvers
14
+ remain outside EquiReduce. Reduction does not automatically download Lean
15
+ or Mathlib.
16
+
17
+ ## Planned structure
18
+
19
+ `0.1.0.dev0` already includes `system.py`, `result.py`, `conditions.py`,
20
+ `api.py`, `artifacts.py`, `lean.py`, `coordinates.py`, `search.py`,
21
+ `metrics.py`, `dae.py`, and private modules `_core.py`, `_lean_export.py`,
22
+ `_coordinate_lean.py`, and `_dae_lean.py`. Extracted primitives remain in
23
+ private modules with their origins recorded in `PROVENANCE.md`.
24
+ The following layout is a target for further separation, not the current tree.
25
+
26
+ This tree describes the initial implementation target rather than files
27
+ that have all already been created.
28
+
29
+ ```text
30
+ EquiReduce/
31
+ pyproject.toml
32
+ src/equireduce/
33
+ __init__.py
34
+ system.py # immutable general system description
35
+ result.py # result and statuses
36
+ conditions.py # domains, assumptions, obligations
37
+ errors.py
38
+ algebraic/
39
+ affinity.py
40
+ elimination.py
41
+ coordinates.py
42
+ search.py
43
+ metrics.py
44
+ certificates/
45
+ model.py
46
+ verify.py
47
+ serialization.py
48
+ backends/lean/
49
+ expressions.py # explicitly supported SymPy subset
50
+ algebraic.py
51
+ runner.py
52
+ manifest.py
53
+ lean/ # pinned toolchain and Mathlib
54
+ examples/
55
+ tests/{unit,integration,properties,regression}/
56
+ docs/
57
+ ```
58
+
59
+ The `dae/` package and Lean trajectory theorems are added at the corresponding
60
+ stage. An absent feature must not be hidden behind an empty "successful"
61
+ backend or proof stub.
62
+
63
+ ## Component responsibilities
64
+
65
+ | Component | Responsibility |
66
+ |---|---|
67
+ | `System` | Validated immutable input, coordinate order, and domains |
68
+ | Conditions | Assumption provenance, new restrictions, and consistency status |
69
+ | Reducer | Construction of exact steps and reconstruction |
70
+ | Search | Enumeration and ranking; does not determine certificate validity |
71
+ | Certificate | Data sufficient for independent step verification |
72
+ | SymPy verifier | Exact identities and structural invariants |
73
+ | Lean exporter | Translation of supported expressions and theorem generation |
74
+ | Lean runner | Specific compiler invocation, log, timeout, and status |
75
+ | Serializer | Versioned safe data format and hashing |
76
+
77
+ The verifier and reducer may share arithmetic primitives, but verification
78
+ must not simply trust a flag set by the generator. Formal compilation is a
79
+ separate verification layer.
80
+
81
+ ## Data invariants
82
+
83
+ - Input is unchanged; result matrices are immutable and collections are ordered.
84
+ - Every source unknown is either retained or reconstructed.
85
+ - Reconstruction is acyclic and expressed through final coordinates.
86
+ - Conditions have provenance: input, denominator, pivot block, branch,
87
+ coordinate transformation, or DAE reconstruction differentiation.
88
+ - All free symbols are declared; unknowns, parameters, and the independent
89
+ variable must not be substituted for one another.
90
+ - Search, symbolic verification, and Lean compilation have independent statuses.
91
+
92
+ ## Extraction from Dnipro
93
+
94
+ 1. Fix regression examples for the prototype.
95
+ 2. Extract mathematical types without `dnipro` imports or `domain="dc"`.
96
+ 3. Replace application fields `node_order` and `branch_current_order` with
97
+ optional external metadata that does not affect the proof.
98
+ 4. Extract algorithms and verifiers while auditing assumptions and domains.
99
+ 5. Extract the Lean exporter, checking expression classes with actual Lean.
100
+ 6. Create a Dnipro adapter that explicitly obtains static equations and passes
101
+ them to EquiReduce. Do not simply relabel the time domain as DC.
102
+ 7. Compare results before and after extraction on the same systems.
103
+
104
+ The recommended adapter location is Dnipro, avoiding a reverse dependency
105
+ from EquiReduce. After migration, maintain one mathematical implementation
106
+ rather than two copies that change independently.
107
+
108
+ ## Determinism and resources
109
+
110
+ Unknown, candidate, condition, and Lean name order is fixed. Search and
111
+ expression-size budgets are explicit. Temporary directories are unique per
112
+ run; parallel checks do not overwrite a shared proof file. Caches are keyed
113
+ by input, assumptions, versions, and proof content. A cached result is
114
+ identified as reuse of an earlier verification rather than fresh compilation.