|
1 | 1 | import OpenGALib.Algebraic.BilinearForm.Basic |
| 2 | +import Mathlib.Algebra.BigOperators.Fin |
2 | 3 | import Mathlib.Data.Rat.Defs |
3 | 4 | import Mathlib.Data.Fintype.BigOperators |
4 | 5 | import Mathlib.Data.Fin.VecNotation |
5 | 6 | import Mathlib.LinearAlgebra.Matrix.DotProduct |
| 7 | +import Mathlib.Algebra.Order.Ring.Rat |
| 8 | +import Mathlib.Tactic.NormNum.Ineq |
6 | 9 |
|
7 | 10 | /-! |
8 | 11 | # Concrete instance: rational vectors |
9 | 12 |
|
10 | 13 | A fully `#eval`-able `BilinearForm` on `Fin n → ℚ`. `#eval inner` |
11 | | -produces a `Rat`; `native_decide` closes concrete equalities like |
12 | | -`inner ![1,2,3] ![4,5,6] = 32`. The same operations on the abstract |
| 14 | +produces a `Rat`; concrete equalities like |
| 15 | +`inner ![1,2,3] ![4,5,6] = 32` are closed by kernel-checked |
| 16 | +`simp`/`norm_num` proofs. The same operations on the abstract |
13 | 17 | `Form ℚ V` API give the same numerical results, demonstrating |
14 | 18 | algebraic-core ↔ concrete-instance consistency. |
15 | 19 |
|
@@ -78,24 +82,32 @@ open BilinearForm RatVector |
78 | 82 |
|
79 | 83 | #eval inner (stdForm 3) ![1, 0, 0] ![1, 0, 0] -- 1 |
80 | 84 |
|
81 | | -/-! ## `native_decide`-closed equalities — proof by execution |
| 85 | +/-! ## Kernel-checked equalities — proof by computation |
82 | 86 |
|
83 | | -The same equations that `#eval` produces are closed as theorems via |
84 | | -`native_decide`, which compiles the term to native code and uses the |
85 | | -result as a proof. -/ |
| 87 | +The same equations that `#eval` produces are closed as theorems by |
| 88 | +unfolding `inner` to the concrete sum (`stdForm_apply`, |
| 89 | +`Fin.sum_univ_two`/`Fin.sum_univ_three`) and discharging the rational |
| 90 | +arithmetic with `norm_num`. Each proof is checked by the kernel — no |
| 91 | +native code or compiler trust. -/ |
86 | 92 |
|
87 | | -example : inner (stdForm 3) ![1, 2, 3] ![4, 5, 6] = 32 := by native_decide |
| 93 | +example : inner (stdForm 3) ![1, 2, 3] ![4, 5, 6] = 32 := by |
| 94 | + simp [stdForm_apply, Fin.sum_univ_three]; norm_num |
88 | 95 |
|
89 | | -example : inner (stdForm 2) ![3, 4] ![3, 4] = 25 := by native_decide |
| 96 | +example : inner (stdForm 2) ![3, 4] ![3, 4] = 25 := by |
| 97 | + simp [stdForm_apply, Fin.sum_univ_two]; norm_num |
90 | 98 |
|
91 | | -example : inner (stdForm 3) ![1, 0, 0] ![0, 1, 0] = 0 := by native_decide |
| 99 | +example : inner (stdForm 3) ![1, 0, 0] ![0, 1, 0] = 0 := by |
| 100 | + simp [stdForm_apply, Fin.sum_univ_three] |
92 | 101 |
|
93 | | -example : inner (stdForm 3) ![1, 0, 0] ![1, 0, 0] = 1 := by native_decide |
| 102 | +example : inner (stdForm 3) ![1, 0, 0] ![1, 0, 0] = 1 := by |
| 103 | + simp [stdForm_apply, Fin.sum_univ_three] |
94 | 104 |
|
95 | | -/-- Cauchy–Schwarz on a concrete pair, verified by execution. -/ |
| 105 | +/-- Cauchy–Schwarz on a concrete pair, kernel-checked. -/ |
96 | 106 | example : |
97 | 107 | let v : Fin 3 → ℚ := ![1, 2, 3] |
98 | 108 | let w : Fin 3 → ℚ := ![4, 5, 6] |
99 | 109 | (inner (stdForm 3) v w) ^ 2 |
100 | 110 | ≤ inner (stdForm 3) v v * inner (stdForm 3) w w := by |
101 | | - native_decide |
| 111 | + norm_num [inner_def, stdForm_apply, Fin.sum_univ_three, |
| 112 | + Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, |
| 113 | + Matrix.cons_val_two, Matrix.tail_cons] |
0 commit comments