Definition KSap i j a b (g : KleeneStore i j (a -> b)) (k : KleeneStore i j a) :
KleeneStore i j b :=
kleeneStore (fun v => append_view (P := fun _ => b) (fun v1 v2 => (peek (k:=g) v1) (peek (k:=k) v2)) v)
(Vector.append (pos g) (pos k)).

(* Specifications: *)
Lemma KSpure_KSap_KSmap i j a b (f : a -> b) (k : KleeneStore i j a) :
KSap (KSpure i j f) k = KSmap f k.
Lemma KSpure_id i j a (k : KleeneStore i j a) :
KSap (KSpure i j (fun x => x)) k = k.
Lemma equivalent_KS i j a (dim1 dim2 : nat) (peek1 : Vector.t j dim1 -> a) (peek2 : Vector.t j dim2 -> a)
(pos1 : Vector.t i dim1) (pos2 : Vector.t i dim2) (e : dim1 = dim2) :
(forall (v1 : Vector.t j dim1) (v2 : Vector.t j dim2), (eq_rect _ _ v1 _ e) = v2 -> peek1 v1 = peek2 v2) ->
eq_rect _ _ pos1 _ e = pos2 -> kleeneStore peek1 pos1 = kleeneStore peek2 pos2.
Lemma composition_KS i j a b c x y (z : KleeneStore i j a) :
KSap (KSap (KSap (KSpure i j (fun (f : b -> c) (g : a -> b) (x : a) => f (g x))) x) y) z =
KSap x (KSap y z).
Lemma KSpure_KSpure i j a b (f : a -> b) (x : a):
KSap (KSpure i j f) (KSpure i j x) = KSpure i j (f x).
Lemma interchange_KSpure i j a b (f : KleeneStore i j (a -> b)) (x : a):
KSap f (KSpure i j x) = KSap (KSpure i j (fun f => f x)) f.