Compare commits

..

7 Commits

Author SHA1 Message Date
Kim Morrison
393c520afa rerevert 2024-09-24 21:59:52 +10:00
Kim Morrison
250c183bbd rfl proof 2024-09-24 21:58:47 +10:00
Kim Morrison
6722bc3f77 rerevert 2024-09-24 21:52:40 +10:00
Kim Morrison
6d0ab7e4de toArray_toList is rfl 2024-09-24 21:50:33 +10:00
Kim Morrison
540c343077 lemmas 2024-09-24 21:47:06 +10:00
Kim Morrison
3d25d0da03 . 2024-09-24 21:34:49 +10:00
Kim Morrison
627119f7b9 Revert "feat: theorems about List.toArray (#5403)"
This reverts commit e551a366a0.
2024-09-24 21:29:02 +10:00
8 changed files with 13 additions and 21 deletions

View File

@@ -837,9 +837,6 @@ instance : Trans Iff Iff Iff where
theorem Eq.comm {a b : α} : a = b b = a := Iff.intro Eq.symm Eq.symm
theorem eq_comm {a b : α} : a = b b = a := Eq.comm
theorem HEq.comm {a : α} {b : β} : HEq a b HEq b a := Iff.intro HEq.symm HEq.symm
theorem heq_comm {a : α} {b : β} : HEq a b HEq b a := HEq.comm
@[symm] theorem Iff.symm (h : a b) : b a := Iff.intro h.mpr h.mp
theorem Iff.comm: (a b) (b a) := Iff.intro Iff.symm Iff.symm
theorem iff_comm : (a b) (b a) := Iff.comm

View File

@@ -18,7 +18,7 @@ universe u v w
syntax "#[" withoutPosition(sepBy(term, ", ")) "]" : term
macro_rules
| `(#[ $elems,* ]) => `(Array.mk [ $elems,* ])
| `(#[ $elems,* ]) => `(List.toArray [ $elems,* ])
variable {α : Type u}

View File

@@ -57,7 +57,9 @@ open Array
/-! ### Lemmas about `List.toArray`. -/
@[simp] theorem size_toArrayAux {a : List α} {b : Array α} :
@[simp] theorem toArray_size (as : List α) : as.toArray.size = as.length := by simp [size]
@[simp] theorem toArrayAux_size {a : List α} {b : Array α} :
(a.toArrayAux b).size = b.size + a.length := by
simp [size]
@@ -65,7 +67,6 @@ open Array
@[deprecated toArray_toList (since := "2024-09-09")]
abbrev toArray_data := @toArray_toList
@[simp] theorem getElem_toArray {a : List α} {i : Nat} (h : i < a.toArray.size) :
a.toArray[i] = a[i]'(by simpa using h) := rfl

View File

@@ -154,10 +154,6 @@ end Lean
| _ => throw ()
| _ => throw ()
@[app_unexpander Array.mk] def unexpandArrayMk : Lean.PrettyPrinter.Unexpander
| `($(_) [$xs,*]) => `(#[$xs,*])
| _ => throw ()
@[app_unexpander List.toArray] def unexpandListToArray : Lean.PrettyPrinter.Unexpander
| `($(_) [$xs,*]) => `(#[$xs,*])
| _ => throw ()

View File

@@ -754,10 +754,10 @@ infer the proof of `Nonempty α`.
noncomputable def Classical.ofNonempty {α : Sort u} [Nonempty α] : α :=
Classical.choice inferInstance
instance {α : Sort u} {β : Sort v} [Nonempty β] : Nonempty (α β) :=
instance (α : Sort u) {β : Sort v} [Nonempty β] : Nonempty (α β) :=
Nonempty.intro fun _ => Classical.ofNonempty
instance Pi.instNonempty {α : Sort u} {β : α Sort v} [(a : α) Nonempty (β a)] :
instance Pi.instNonempty (α : Sort u) {β : α Sort v} [(a : α) Nonempty (β a)] :
Nonempty ((a : α) β a) :=
Nonempty.intro fun _ => Classical.ofNonempty
@@ -767,7 +767,7 @@ instance : Inhabited (Sort u) where
instance (α : Sort u) {β : Sort v} [Inhabited β] : Inhabited (α β) where
default := fun _ => default
instance Pi.instInhabited {α : Sort u} {β : α Sort v} [(a : α) Inhabited (β a)] :
instance Pi.instInhabited (α : Sort u) {β : α Sort v} [(a : α) Inhabited (β a)] :
Inhabited ((a : α) β a) where
default := fun _ => default
@@ -2570,9 +2570,7 @@ structure Array (α : Type u) where
/--
Converts a `List α` into an `Array α`.
You can also use the synonym `List.toArray` when dot notation is convenient.
At runtime, this constructor is implemented by `List.toArrayImpl` and is O(n) in the length of the
At runtime, this constructor is implemented by `List.toArray` and is O(n) in the length of the
list.
-/
mk ::

View File

@@ -502,7 +502,7 @@ def mkListLit (type : Expr) (xs : List Expr) : MetaM Expr := do
def mkArrayLit (type : Expr) (xs : List Expr) : MetaM Expr := do
let u getDecLevel type
let listLit mkListLit type xs
return mkApp (mkApp (mkConst ``Array.mk [u]) type) listLit
return mkApp (mkApp (mkConst ``List.toArray [u]) type) listLit
def mkNone (type : Expr) : MetaM Expr := do
let u getDecLevel type

View File

@@ -202,19 +202,19 @@ def getListLit? (e : Expr) : MetaM (Option (Array Expr)) := getListLitOf? e fun
/--
Check if an expression is an array literal
(i.e. `Array.mk` applied to a nested chain of `List.cons`, ending at a `List.nil`),
(i.e. `List.toArray` applied to a nested chain of `List.cons`, ending at a `List.nil`),
where each element is "recognised" by a given function `f : Expr → MetaM (Option α)`,
and return the array of recognised values.
-/
def getArrayLitOf? (e : Expr) (f : Expr MetaM (Option α)) : MetaM (Option (Array α)) := do
let e instantiateMVars e.consumeMData
match_expr e with
| Array.mk _ as => getListLitOf? as f
| List.toArray _ as => getListLitOf? as f
| _ => return none
/--
Check if an expression is an array literal
(i.e. `Array.mk` applied to a nested chain of `List.cons`, ending at a `List.nil`),
(i.e. `List.toArray` applied to a nested chain of `List.cons`, ending at a `List.nil`),
returning the array of `Expr` values.
-/
def getArrayLit? (e : Expr) : MetaM (Option (Array Expr)) := getArrayLitOf? e fun s => return some s

View File

@@ -97,7 +97,7 @@ partial def listLit? (e : Expr) : Option (Expr × List Expr) :=
loop e []
def arrayLit? (e : Expr) : Option (Expr × List Expr) :=
if e.isAppOfArity' ``Array.mk 2 then
if e.isAppOfArity' ``List.toArray 2 then
listLit? e.appArg!'
else
none