-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use RArray in simp_arith meta code (#6068 part 2)
This PR makes `simp_arith` use `RArray` for the context of the reflection proofs, which scales better when there are many variables.
- Loading branch information
Showing
3 changed files
with
35 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,60 @@ | ||
import Lean | ||
|
||
open Nat.Linear | ||
|
||
-- Convenient RArray literals | ||
elab tk:"#R[" ts:term,* "]" : term => do | ||
let ts : Array Lean.Syntax := ts | ||
let es ← ts.mapM fun stx => Lean.Elab.Term.elabTerm stx none | ||
if h : 0 < es.size then | ||
return (Lean.RArray.toExpr (← Lean.Meta.inferType es[0]!) id (Lean.RArray.ofArray es h)) | ||
else | ||
throwErrorAt tk "RArray cannot be empty" | ||
|
||
|
||
example (x₁ x₂ x₃ : Nat) : (x₁ + x₂) + (x₂ + x₃) = x₃ + 2*x₂ + x₁ := | ||
Expr.eq_of_toNormPoly [x₁, x₂, x₃] | ||
Expr.eq_of_toNormPoly #R[x₁, x₂, x₃] | ||
(Expr.add (Expr.add (Expr.var 0) (Expr.var 1)) (Expr.add (Expr.var 1) (Expr.var 2))) | ||
(Expr.add (Expr.add (Expr.var 2) (Expr.mulL 2 (Expr.var 1))) (Expr.var 0)) | ||
rfl | ||
|
||
example (x₁ x₂ x₃ : Nat) : ((x₁ + x₂) + (x₂ + x₃) = x₃ + x₂) = (x₁ + x₂ = 0) := | ||
Expr.of_cancel_eq [x₁, x₂, x₃] | ||
Expr.of_cancel_eq #R[x₁, x₂, x₃] | ||
(Expr.add (Expr.add (Expr.var 0) (Expr.var 1)) (Expr.add (Expr.var 1) (Expr.var 2))) | ||
(Expr.add (Expr.var 2) (Expr.var 1)) | ||
(Expr.add (Expr.var 0) (Expr.var 1)) | ||
(Expr.num 0) | ||
rfl | ||
|
||
example (x₁ x₂ x₃ : Nat) : ((x₁ + x₂) + (x₂ + x₃) ≤ x₃ + x₂) = (x₁ + x₂ ≤ 0) := | ||
Expr.of_cancel_le [x₁, x₂, x₃] | ||
Expr.of_cancel_le #R[x₁, x₂, x₃] | ||
(Expr.add (Expr.add (Expr.var 0) (Expr.var 1)) (Expr.add (Expr.var 1) (Expr.var 2))) | ||
(Expr.add (Expr.var 2) (Expr.var 1)) | ||
(Expr.add (Expr.var 0) (Expr.var 1)) | ||
(Expr.num 0) | ||
rfl | ||
|
||
example (x₁ x₂ x₃ : Nat) : ((x₁ + x₂) + (x₂ + x₃) < x₃ + x₂) = (x₁ + x₂ < 0) := | ||
Expr.of_cancel_lt [x₁, x₂, x₃] | ||
Expr.of_cancel_lt #R[x₁, x₂, x₃] | ||
(Expr.add (Expr.add (Expr.var 0) (Expr.var 1)) (Expr.add (Expr.var 1) (Expr.var 2))) | ||
(Expr.add (Expr.var 2) (Expr.var 1)) | ||
(Expr.add (Expr.var 0) (Expr.var 1)) | ||
(Expr.num 0) | ||
rfl | ||
|
||
example (x₁ x₂ : Nat) : x₁ + 2 ≤ 3*x₂ → 4*x₂ ≤ 3 + x₁ → 3 ≤ 2*x₂ → False := | ||
Certificate.of_combine_isUnsat [x₁, x₂] | ||
Certificate.of_combine_isUnsat #R[x₁, x₂] | ||
[ (1, { eq := false, lhs := Expr.add (Expr.var 0) (Expr.num 2), rhs := Expr.mulL 3 (Expr.var 1) }), | ||
(1, { eq := false, lhs := Expr.mulL 4 (Expr.var 1), rhs := Expr.add (Expr.num 3) (Expr.var 0) }), | ||
(0, { eq := false, lhs := Expr.num 3, rhs := Expr.mulL 2 (Expr.var 1) }) ] | ||
rfl | ||
|
||
example (x : Nat) (xs : List Nat) : (sizeOf x < 1 + (1 + sizeOf x + sizeOf xs)) = True := | ||
ExprCnstr.eq_true_of_isValid [sizeOf x, sizeOf xs] | ||
ExprCnstr.eq_true_of_isValid #R[sizeOf x, sizeOf xs] | ||
{ eq := false, lhs := Expr.inc (Expr.var 0), rhs := Expr.add (Expr.num 1) (Expr.add (Expr.add (Expr.num 1) (Expr.var 0)) (Expr.var 1)) } | ||
rfl | ||
|
||
example (x : Nat) (xs : List Nat) : (1 + (1 + sizeOf x + sizeOf xs) < sizeOf x) = False := | ||
ExprCnstr.eq_false_of_isUnsat [sizeOf x, sizeOf xs] | ||
ExprCnstr.eq_false_of_isUnsat #R[sizeOf x, sizeOf xs] | ||
{ eq := false, lhs := Expr.inc <| Expr.add (Expr.num 1) (Expr.add (Expr.add (Expr.num 1) (Expr.var 0)) (Expr.var 1)), rhs := Expr.var 0 } | ||
rfl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters