-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
306 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Std.Data.Fin.Basic | ||
import Std.Classes.Cast | ||
import Mathlib.Data.Fin.Basic | ||
import Mathlib.Tactic.Linarith.Frontend | ||
|
||
namespace Fin | ||
|
||
theorem castSucc_succ_eq_succ_castSucc : Fin.castSucc (Fin.succ i) = Fin.succ (Fin.castSucc i) := by | ||
rfl | ||
|
||
theorem last_succ_eq_succ_last : Fin.last (Nat.succ n) = Fin.succ (Fin.last n) := by | ||
rfl | ||
|
||
theorem last_def : Fin.mk (n := Nat.succ n) n (by simp) = Fin.last n := by | ||
rfl | ||
|
||
theorem castSucc_def {i : Fin n} : | ||
Fin.mk (n := Nat.succ n) (i.val) (by cases i; linarith) = i.castSucc := by | ||
rfl | ||
|
||
theorem cast_last {n : Nat} : ↑n = Fin.last n := by | ||
conv => lhs; whnf | ||
conv => rhs; whnf | ||
simp | ||
|
||
end Fin |
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import ProvenZk.Ext.Vector | ||
|
||
abbrev SubVector α n prop := Subtype (α := Vector α n) (Vector.allIxes prop) | ||
|
||
namespace SubVector | ||
|
||
def nil : SubVector α 0 prop := ⟨Vector.nil, by simp⟩ | ||
|
||
def snoc (vs: SubVector α n prop) (v : Subtype prop): SubVector α n.succ prop := | ||
⟨vs.val.snoc v.val, by | ||
intro i | ||
cases i using Fin.lastCases with | ||
| hlast => simp [GetElem.getElem, Fin.last_def, Subtype.property] | ||
| hcast i => | ||
have := vs.prop i | ||
simp at this | ||
simp [*] | ||
⟩ | ||
|
||
@[elab_as_elim] | ||
def revCases {C : ∀ {n:Nat}, SubVector α n prop → Sort _} (v : SubVector α n prop) | ||
(nil : C nil) | ||
(snoc : ∀ {n : Nat} (vs : SubVector α n prop) (v : Subtype prop), C (vs.snoc v)): C v := by | ||
rcases v with ⟨v, h⟩ | ||
cases v using Vector.revCasesOn with | ||
| nil => exact nil | ||
| snoc vs v => | ||
refine snoc ⟨vs, ?vsp⟩ ⟨v, ?vp⟩ | ||
case vsp => | ||
intro i | ||
have := h i.castSucc | ||
simp at this | ||
simp [this] | ||
case vp => | ||
have := h (Fin.last _) | ||
simp [GetElem.getElem, Fin.last_def] at this | ||
exact this | ||
|
||
instance : GetElem (SubVector α n prop) (Fin n) (Subtype prop) (fun _ _ => True) where | ||
getElem v i _ := ⟨v.val.get i, v.prop i⟩ | ||
|
||
def lower (v: SubVector α n prop): Vector {v : α // prop v} n := | ||
Vector.ofFn fun i => v[i] | ||
|
||
def lift {prop : α → Prop} (v : Vector (Subtype prop) n): SubVector α n prop := | ||
⟨v.map Subtype.val, by | ||
intro i | ||
simp [GetElem.getElem, Subtype.property]⟩ | ||
|
||
theorem snoc_lower {vs : SubVector α n prop} {v : Subtype prop}: | ||
(vs.snoc v).lower = vs.lower.snoc v := by | ||
unfold lower | ||
rw [Vector.ofFn_snoc'] | ||
congr | ||
. funext i | ||
cases n with | ||
| zero => cases i using finZeroElim | ||
| _ => simp [GetElem.getElem, snoc] | ||
. simp [GetElem.getElem, snoc, Fin.cast_last] | ||
|
||
end SubVector |