Skip to content

Commit 01b6815

Browse files
committed
Proofs of preserving the last were added for all sums and products.
1 parent ddda0d5 commit 01b6815

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

libs/contrib/Data/Fin/Extra.idr

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ finToNat_mult_linearity (FS x) y {a=S i} = rewrite finToNat_plus_linearity y (x
191191
rewrite finToNat_mult_linearity x y in
192192
Refl
193193

194+
export
195+
plus_preserves_last : (a, b : Nat) -> Fin.last {n=a} + Fin.last {n=b} = Fin.last
196+
plus_preserves_last Z b = rewrite weakenNZero_preserves $ Fin.last {n=b} in Refl
197+
plus_preserves_last (S k) b = rewrite plus_preserves_last k b in Refl
198+
199+
export
200+
mult_preserves_last : (a, b : Nat) -> Fin.last {n=a} * Fin.last {n=b} = Fin.last
201+
mult_preserves_last Z b = Refl
202+
mult_preserves_last (S k) b = rewrite mult_preserves_last k b in plus_preserves_last _ _
203+
194204
export
195205
plusSuccRightSucc : {a, b : Nat} -> (left : Fin $ S a) -> (right : Fin $ S b) -> FS (left + right) = rewrite plusSuccRightSucc a b in left + FS right
196206
plusSuccRightSucc FZ right = rewrite plusCommutative a b in Refl
@@ -279,6 +289,24 @@ splitProd {a=S _} x = case splitSum x of
279289

280290
--- Properties ---
281291

292+
export
293+
indexSum_preserves_last : (a, b : Nat) -> indexSum {a} (Right $ Fin.last {n=b}) = rewrite sym $ plusSuccRightSucc a b in Fin.last {n=a+b}
294+
indexSum_preserves_last Z b = Refl
295+
indexSum_preserves_last (S k) b = rewrite indexSum_preserves_last k b in
296+
rewrite plusSuccRightSucc k b in
297+
Refl
298+
299+
export
300+
indexProd_preserves_last : (a, b : Nat) -> indexProd (Fin.last {n=a}) (Fin.last {n=b}) = Fin.last
301+
indexProd_preserves_last Z b = rewrite weakenNZero_preserves $ Fin.last {n=b} in
302+
rewrite plusZeroRightNeutral b in
303+
Refl
304+
indexProd_preserves_last (S k) b = rewrite indexProd_preserves_last k b in
305+
rewrite shiftAsPlus {b} $ last {n=pred $ S k * S b} in
306+
rewrite plus_preserves_last b $ pred $ S k * S b in
307+
rewrite sym $ plusSuccRightSucc b $ pred $ S k * S b in
308+
Refl
309+
282310
splitSum_of_weakenN : (l : Fin a) -> Left l = splitSum {b} (weakenN b l)
283311
splitSum_of_weakenN FZ = Refl
284312
splitSum_of_weakenN (FS x) = cong (mapFst FS) $ splitSum_of_weakenN {b} x

0 commit comments

Comments
 (0)