Download ArrayLang/Array.lean from Snapkitty/sovereign-array: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/Snapkitty/sovereign-array/resolve/main/ArrayLang/Array.lean
- Command line
-
hf download hf://Snapkitty/sovereign-array/ArrayLang/Array.lean
-
curl -L -o Array.lean https://huggingface.co/Snapkitty/sovereign-array/resolve/main/ArrayLang/Array.lean
2.39 kB
Lean 4 · 5
declarations statementsfull
25An array indexed by shape
Iwith elements of typeα. This is exactly the dependent-function model used in Cubical Agda / Lean.
def Array (I : Type u) (α : Type v) : Type (max u v) := I → α
33Pointwise lifting of a binary operation. Categorical semantics of a vectorized op: a
Π-map over the index spaceI.
def pmap₂ (op : α → α → α) (a b : Array I α) : Array I α :=
body · 1 line
fun i => op (a i) (b i)
38
O(1)proof equality is function extensionality. Computational equality isO(|I|); we never conflate the two.
theorem pmap₂_congr {op : α → α → α} {a a' b b' : Array I α}
(ha : ∀ i, a i = a' i) (hb : ∀ i, b i = b' i) :
pmap₂ op a b = pmap₂ op a' b' := by
proof · 2 lines
funext i simp [pmap₂, ha i, hb i]
46
pmap₂fusion: applying a post-map to apmap₂is itself apmap₂. Fusion =Π-map fusion; no loop exists in the denotation.
theorem pmap₂_fusion {op : α → α → α} {a b : Array I α} (f : α → α) :
(fun i => f (pmap₂ op a b i)) = pmap₂ (fun x _ => f (op x x)) a b := by
proof · 2 lines
funext i simp [pmap₂]
52
pmap₂is associative in the operation when the operation is.
theorem pmap₂_assoc {op : α → α → α} {a b c : Array I α}
(h : ∀ x y z, op (op x y) z = op x (op y z)) :
pmap₂ op (pmap₂ op a b) c = pmap₂ op a (pmap₂ op b c) := by
proof · 2 lines
funext i simp [pmap₂, h]
Outline