@@ -52,6 +52,15 @@ private
52
52
m n o : ℕ
53
53
ws xs ys zs : Vec A n
54
54
55
+ ------------------------------------------------------------------------
56
+ -- Properties of toList
57
+
58
+ toList-injective : .(m≡n : m ≡ n) → (xs : Vec A m) (ys : Vec A n) →
59
+ toList xs ≡ toList ys → xs ≈[ m≡n ] ys
60
+ toList-injective m≡n [] [] xs=ys = refl
61
+ toList-injective m≡n (x ∷ xs) (y ∷ ys) xs=ys =
62
+ cong₂ _∷_ (List.∷-injectiveˡ xs=ys) (toList-injective (cong pred m≡n) xs ys (List.∷-injectiveʳ xs=ys))
63
+
55
64
------------------------------------------------------------------------
56
65
-- Properties of propositional equality over vectors
57
66
@@ -1016,26 +1025,41 @@ map-reverse : ∀ (f : A → B) (xs : Vec A n) →
1016
1025
map f (reverse xs) ≡ reverse (map f xs)
1017
1026
map-reverse f [] = refl
1018
1027
map-reverse f (x ∷ xs) = begin
1019
- map f (reverse (x ∷ xs)) ≡⟨ cong (map f) (reverse-∷ x xs) ⟩
1020
- map f (reverse xs ∷ʳ x) ≡⟨ map-∷ʳ f x (reverse xs) ⟩
1021
- map f (reverse xs) ∷ʳ f x ≡⟨ cong (_∷ʳ f x) (map-reverse f xs ) ⟩
1028
+ map f (reverse (x ∷ xs)) ≡⟨ cong (map f) (reverse-∷ x xs) ⟩
1029
+ map f (reverse xs ∷ʳ x) ≡⟨ map-∷ʳ f x (reverse xs) ⟩
1030
+ map f (reverse xs) ∷ʳ f x ≡⟨ cong (_∷ʳ f x) (map-reverse f xs ) ⟩
1022
1031
reverse (map f xs) ∷ʳ f x ≡⟨ reverse-∷ (f x) (map f xs) ⟨
1023
1032
reverse (f x ∷ map f xs) ≡⟨⟩
1024
1033
reverse (map f (x ∷ xs)) ∎
1025
1034
where open ≡-Reasoning
1026
1035
1027
1036
-- append and reverse
1037
+ toList-∷ʳ : ∀ x (xs : Vec A n) → toList (xs ∷ʳ x) ≡ toList xs List.++ List.[ x ]
1038
+ toList-∷ʳ x [] = refl
1039
+ toList-∷ʳ x (y ∷ xs) = cong (y List.∷_) (toList-∷ʳ x xs)
1040
+
1041
+ toList-reverse : ∀ (xs : Vec A n) → toList (reverse xs) ≡ List.reverse (toList xs)
1042
+ toList-reverse [] = refl
1043
+ toList-reverse (x ∷ xs) = begin
1044
+ toList (reverse (x ∷ xs)) ≡⟨ cong toList (reverse-∷ x xs) ⟩
1045
+ toList (reverse xs ∷ʳ x) ≡⟨ toList-∷ʳ x (reverse xs) ⟩
1046
+ toList (reverse xs) List.++ List.[ x ] ≡⟨ cong (List._++ List.[ x ]) (toList-reverse xs) ⟩
1047
+ List.reverse (toList xs) List.++ List.[ x ] ≡⟨ List.unfold-reverse x (toList xs) ⟨
1048
+ List.reverse (toList (x ∷ xs)) ∎
1049
+ where open ≡-Reasoning
1028
1050
1029
- reverse-++-eqFree : ∀ (xs : Vec A m) (ys : Vec A n) → let eq = +-comm m n in
1030
- cast eq (reverse (xs ++ ys)) ≡ reverse ys ++ reverse xs
1031
- reverse-++-eqFree {m = zero} {n = n} [] ys = ≈-sym (++-identityʳ-eqFree (reverse ys))
1032
- reverse-++-eqFree {m = suc m} {n = n} (x ∷ xs) ys = begin
1033
- reverse (x ∷ xs ++ ys) ≂⟨ reverse-∷ x (xs ++ ys) ⟩
1034
- reverse (xs ++ ys) ∷ʳ x ≈⟨ ≈-cong′ (_∷ʳ x) (reverse-++-eqFree xs ys) ⟩
1035
- (reverse ys ++ reverse xs) ∷ʳ x ≈⟨ ++-∷ʳ-eqFree x (reverse ys) (reverse xs) ⟩
1036
- reverse ys ++ (reverse xs ∷ʳ x) ≂⟨ cong (reverse ys ++_) (reverse-∷ x xs) ⟨
1037
- reverse ys ++ (reverse (x ∷ xs)) ∎
1038
- where open CastReasoning
1051
+ reverse-++-eqFree : ∀ (xs : Vec A m) (ys : Vec A n)
1052
+ → reverse (xs ++ ys) ≈[ +-comm m n ] reverse ys ++ reverse xs
1053
+ reverse-++-eqFree {m = m} {n = n} xs ys =
1054
+ toList-injective (+-comm m n) (reverse (xs ++ ys)) (reverse ys ++ reverse xs) $
1055
+ begin
1056
+ toList (reverse (xs ++ ys)) ≡⟨ toList-reverse ((xs ++ ys)) ⟩
1057
+ List.reverse (toList (xs ++ ys)) ≡⟨ cong List.reverse (toList-++ xs ys) ⟩
1058
+ List.reverse (toList xs List.++ toList ys) ≡⟨ List.reverse-++ (toList xs) (toList ys) ⟩
1059
+ List.reverse (toList ys) List.++ List.reverse (toList xs) ≡⟨ cong₂ List._++_ (toList-reverse ys) (toList-reverse xs) ⟨
1060
+ toList (reverse ys) List.++ toList (reverse xs) ≡⟨ toList-++ (reverse ys) (reverse xs) ⟨
1061
+ toList (reverse ys ++ reverse xs) ∎
1062
+ where open ≡-Reasoning
1039
1063
1040
1064
cast-reverse : ∀ .(eq : m ≡ n) → cast eq ∘ reverse {A = A} {n = m} ≗ reverse ∘ cast eq
1041
1065
cast-reverse _ _ = ≈-cong′ reverse refl
@@ -1061,53 +1085,57 @@ foldr-ʳ++ B f {e} xs = foldl-fusion (foldr B f e) refl (λ _ _ → refl) xs
1061
1085
map-ʳ++ : ∀ (f : A → B) (xs : Vec A m) →
1062
1086
map f (xs ʳ++ ys) ≡ map f xs ʳ++ map f ys
1063
1087
map-ʳ++ {ys = ys} f xs = begin
1064
- map f (xs ʳ++ ys) ≡⟨ cong (map f) (unfold-ʳ++ xs ys) ⟩
1065
- map f (reverse xs ++ ys) ≡⟨ map-++ f (reverse xs) ys ⟩
1066
- map f (reverse xs) ++ map f ys ≡⟨ cong (_++ map f ys) (map-reverse f xs) ⟩
1088
+ map f (xs ʳ++ ys) ≡⟨ cong (map f) (unfold-ʳ++ xs ys) ⟩
1089
+ map f (reverse xs ++ ys) ≡⟨ map-++ f (reverse xs) ys ⟩
1090
+ map f (reverse xs) ++ map f ys ≡⟨ cong (_++ map f ys) (map-reverse f xs) ⟩
1067
1091
reverse (map f xs) ++ map f ys ≡⟨ unfold-ʳ++ (map f xs) (map f ys) ⟨
1068
1092
map f xs ʳ++ map f ys ∎
1069
1093
where open ≡-Reasoning
1070
1094
1071
- ∷-ʳ++-eqFree : ∀ a (xs : Vec A m) {ys : Vec A n} → let eq = sym (+-suc m n) in
1072
- cast eq ((a ∷ xs) ʳ++ ys) ≡ xs ʳ++ (a ∷ ys)
1073
- ∷-ʳ++-eqFree a xs {ys} = begin
1074
- (a ∷ xs) ʳ++ ys ≂⟨ unfold-ʳ++ (a ∷ xs) ys ⟩
1075
- reverse (a ∷ xs) ++ ys ≂⟨ cong (_++ ys) (reverse-∷ a xs) ⟩
1076
- (reverse xs ∷ʳ a) ++ ys ≈⟨ ∷ʳ-++-eqFree a (reverse xs) ⟩
1077
- reverse xs ++ (a ∷ ys) ≂⟨ unfold-ʳ++ xs (a ∷ ys) ⟨
1078
- xs ʳ++ (a ∷ ys) ∎
1079
- where open CastReasoning
1095
+ toList-ʳ++ : ∀ (xs : Vec A m) {ys : Vec A n} →
1096
+ toList (xs ʳ++ ys) ≡ (toList xs) List.ʳ++ toList ys
1097
+ toList-ʳ++ xs {ys} = begin
1098
+ toList (xs ʳ++ ys) ≡⟨ cong toList (unfold-ʳ++ xs ys) ⟩
1099
+ toList (reverse xs ++ ys) ≡⟨ toList-++ ((reverse xs )) ys ⟩
1100
+ toList (reverse xs) List.++ toList ys ≡⟨ cong (List._++ toList ys) (toList-reverse xs) ⟩
1101
+ List.reverse (toList xs) List.++ toList ys ≡⟨ List.ʳ++-defn (toList xs) ⟨
1102
+ toList xs List.ʳ++ toList ys ∎
1103
+ where open ≡-Reasoning
1104
+
1080
1105
1081
1106
++-ʳ++-eqFree : ∀ (xs : Vec A m) {ys : Vec A n} {zs : Vec A o} → let eq = m+n+o≡n+[m+o] m n o in
1082
1107
cast eq ((xs ++ ys) ʳ++ zs) ≡ ys ʳ++ (xs ʳ++ zs)
1083
- ++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} = begin
1084
- ((xs ++ ys) ʳ++ zs) ≂⟨ unfold-ʳ++ (xs ++ ys) zs ⟩
1085
- reverse (xs ++ ys) ++ zs ≈⟨ ≈-cong′ (_++ zs) (reverse-++-eqFree xs ys) ⟩
1086
- (reverse ys ++ reverse xs) ++ zs ≈⟨ ++-assoc-eqFree (reverse ys) (reverse xs) zs ⟩
1087
- reverse ys ++ (reverse xs ++ zs) ≂⟨ cong (reverse ys ++_) (unfold-ʳ++ xs zs) ⟨
1088
- reverse ys ++ (xs ʳ++ zs) ≂⟨ unfold-ʳ++ ys (xs ʳ++ zs) ⟨
1089
- ys ʳ++ (xs ʳ++ zs) ∎
1090
- where open CastReasoning
1108
+ ++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} =
1109
+ toList-injective (m+n+o≡n+[m+o] m n o) ((xs ++ ys) ʳ++ zs) (ys ʳ++ (xs ʳ++ zs)) $
1110
+ begin
1111
+ toList ((xs ++ ys) ʳ++ zs) ≡⟨ toList-ʳ++ (xs ++ ys) ⟩
1112
+ toList (xs ++ ys) List.ʳ++ toList zs ≡⟨ cong (List._ʳ++ toList zs) (toList-++ xs ys) ⟩
1113
+ ((toList xs) List.++ toList ys ) List.ʳ++ toList zs ≡⟨ List.++-ʳ++ (toList xs) ⟩
1114
+ toList ys List.ʳ++ (toList xs List.ʳ++ toList zs) ≡⟨ cong (toList ys List.ʳ++_) (toList-ʳ++ xs) ⟨
1115
+ toList ys List.ʳ++ toList (xs ʳ++ zs) ≡⟨ toList-ʳ++ ys ⟨
1116
+ toList (ys ʳ++ (xs ʳ++ zs)) ∎
1117
+ where open ≡-Reasoning
1091
1118
1092
1119
ʳ++-ʳ++-eqFree : ∀ (xs : Vec A m) {ys : Vec A n} {zs : Vec A o} → let eq = m+n+o≡n+[m+o] m n o in
1093
1120
cast eq ((xs ʳ++ ys) ʳ++ zs) ≡ ys ʳ++ (xs ++ zs)
1094
- ʳ++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} = begin
1095
- (xs ʳ++ ys) ʳ++ zs ≂⟨ cong (_ʳ++ zs) (unfold-ʳ++ xs ys) ⟩
1096
- (reverse xs ++ ys) ʳ++ zs ≂⟨ unfold-ʳ++ (reverse xs ++ ys) zs ⟩
1097
- reverse (reverse xs ++ ys) ++ zs ≈⟨ ≈-cong′ (_++ zs) (reverse-++-eqFree (reverse xs) ys) ⟩
1098
- (reverse ys ++ reverse (reverse xs)) ++ zs ≂⟨ cong ((_++ zs) ∘ (reverse ys ++_)) (reverse-involutive xs) ⟩
1099
- (reverse ys ++ xs) ++ zs ≈⟨ ++-assoc-eqFree (reverse ys) xs zs ⟩
1100
- reverse ys ++ (xs ++ zs) ≂⟨ unfold-ʳ++ ys (xs ++ zs) ⟨
1101
- ys ʳ++ (xs ++ zs) ∎
1102
- where open CastReasoning
1121
+ ʳ++-ʳ++-eqFree {m = m} {n} {o} xs {ys} {zs} =
1122
+ toList-injective (m+n+o≡n+[m+o] m n o) ((xs ʳ++ ys) ʳ++ zs) (ys ʳ++ (xs ++ zs)) $
1123
+ begin
1124
+ toList ((xs ʳ++ ys) ʳ++ zs) ≡⟨ toList-ʳ++ (xs ʳ++ ys) ⟩
1125
+ toList (xs ʳ++ ys) List.ʳ++ toList zs ≡⟨ cong (List._ʳ++ toList zs) (toList-ʳ++ xs) ⟩
1126
+ (toList xs List.ʳ++ toList ys) List.ʳ++ toList zs ≡⟨ List.ʳ++-ʳ++ (toList xs) ⟩
1127
+ toList ys List.ʳ++ (toList xs List.++ toList zs) ≡⟨ cong (toList ys List.ʳ++_) (toList-++ xs zs) ⟨
1128
+ toList ys List.ʳ++ (toList (xs ++ zs)) ≡⟨ toList-ʳ++ ys ⟨
1129
+ toList (ys ʳ++ (xs ++ zs)) ∎
1130
+ where open ≡-Reasoning
1103
1131
1104
1132
------------------------------------------------------------------------
1105
- -- sum
1133
+ --sum
1106
1134
1107
1135
sum-++ : ∀ (xs : Vec ℕ m) → sum (xs ++ ys) ≡ sum xs + sum ys
1108
1136
sum-++ {_} [] = refl
1109
1137
sum-++ {ys = ys} (x ∷ xs) = begin
1110
- x + sum (xs ++ ys) ≡⟨ cong (x +_) (sum-++ xs) ⟩
1138
+ x + sum (xs ++ ys) ≡⟨ cong (x +_) (sum-++ xs) ⟩
1111
1139
x + (sum xs + sum ys) ≡⟨ +-assoc x (sum xs) (sum ys) ⟨
1112
1140
sum (x ∷ xs) + sum ys ∎
1113
1141
where open ≡-Reasoning
@@ -1293,6 +1321,10 @@ toList∘fromList : (xs : List A) → toList (fromList xs) ≡ xs
1293
1321
toList∘fromList List.[] = refl
1294
1322
toList∘fromList (x List.∷ xs) = cong (x List.∷_) (toList∘fromList xs)
1295
1323
1324
+ fromList∘toList : ∀ (xs : Vec A n) → fromList (toList xs) ≈[ length-toList xs ] xs
1325
+ fromList∘toList [] = refl
1326
+ fromList∘toList (x ∷ xs) = cong (x ∷_) (fromList∘toList xs)
1327
+
1296
1328
toList-cast : ∀ .(eq : m ≡ n) (xs : Vec A m) → toList (cast eq xs) ≡ toList xs
1297
1329
toList-cast {n = zero} eq [] = refl
1298
1330
toList-cast {n = suc _} eq (x ∷ xs) =
@@ -1318,33 +1350,42 @@ fromList-++ : ∀ (xs : List A) {ys : List A} →
1318
1350
fromList-++ List.[] {ys} = cast-is-id refl (fromList ys)
1319
1351
fromList-++ (x List.∷ xs) {ys} = cong (x ∷_) (fromList-++ xs)
1320
1352
1321
- fromList-reverse : (xs : List A) → cast (List.length-reverse xs) (fromList (List.reverse xs)) ≡ reverse (fromList xs)
1322
- fromList-reverse List.[] = refl
1323
- fromList-reverse (x List.∷ xs) = begin
1324
- fromList (List.reverse (x List.∷ xs)) ≈⟨ cast- fromList (List.ʳ++-defn xs) ⟩
1325
- fromList (List.reverse xs List.++ List.[ x ]) ≈⟨ fromList-++ (List.reverse xs) ⟩
1326
- fromList (List.reverse xs) ++ [ x ] ≈⟨ unfold-∷ʳ-eqFree x ( fromList (List.reverse xs)) ⟨
1327
- fromList ( List.reverse xs) ∷ʳ x ≈⟨ ≈- cong′ (_∷ʳ x ) (fromList-reverse xs) ⟩
1328
- reverse (fromList xs) ∷ʳ x ≂⟨ reverse-∷ x (fromList xs) ⟨
1329
- reverse (x ∷ fromList xs) ≈⟨⟩
1330
- reverse (fromList (x List.∷ xs)) ∎
1331
- where open CastReasoning
1353
+ fromList-reverse : (xs : List A) →
1354
+ ( fromList ( List.reverse xs)) ≈[ List.length-reverse xs ] reverse (fromList xs)
1355
+ fromList-reverse xs =
1356
+ toList-injective (List.length- reverse xs) (fromList ( List.reverse xs)) (reverse ( fromList xs)) $
1357
+ begin
1358
+ toList ( fromList (List.reverse xs)) ≡⟨ toList∘ fromList (List.reverse xs) ⟩
1359
+ List.reverse xs ≡⟨ cong ( λ x → List.reverse x ) (toList∘ fromList xs) ⟨
1360
+ List. reverse (toList ( fromList xs)) ≡⟨ toList-reverse (fromList xs) ⟨
1361
+ toList (reverse ( fromList xs)) ∎
1362
+ where open ≡-Reasoning
1363
+
1332
1364
1333
1365
------------------------------------------------------------------------
1334
- -- TRANSITION TO EQ-FREE LEMMA
1366
+ -- DEPRECATED NAMES
1335
1367
------------------------------------------------------------------------
1368
+ -- Please use the new names as continuing support for the old names is
1369
+ -- not guaranteed.
1370
+
1371
+ -- Version 2.3
1372
+
1373
+ ∷-ʳ++-eqFree : ∀ a (xs : Vec A m) {ys : Vec A n} → let eq = sym (+-suc m n) in
1374
+ cast eq ((a ∷ xs) ʳ++ ys) ≡ xs ʳ++ (a ∷ ys)
1375
+ ∷-ʳ++-eqFree a xs {ys} = ʳ++-ʳ++-eqFree (a ∷ []) {ys = xs} {zs = ys}
1376
+ {-# WARNING_ON_USAGE ∷-ʳ++-eqFree
1377
+ "Warning: ∷-ʳ++-eqFree was deprecated in v2.3.
1378
+ Please use ʳ++-ʳ++-eqFree instead, which does not take eq."
1379
+ #-}
1380
+
1381
+ -- Version 2.2
1382
+
1383
+ -- TRANSITION TO EQ-FREE LEMMA
1384
+ --
1336
1385
-- Please use the new proofs, which do not require an `eq` parameter.
1337
1386
-- In v3, `name` will be changed to be the same lemma as `name-eqFree`,
1338
1387
-- and `name-eqFree` will be deprecated.
1339
1388
1340
- ++-assoc : ∀ .(eq : (m + n) + o ≡ m + (n + o)) (xs : Vec A m) (ys : Vec A n) (zs : Vec A o) →
1341
- cast eq ((xs ++ ys) ++ zs) ≡ xs ++ (ys ++ zs)
1342
- ++-assoc _ = ++-assoc-eqFree
1343
- {-# WARNING_ON_USAGE ++-assoc
1344
- "Warning: ++-assoc was deprecated in v2.2.
1345
- Please use ++-assoc-eqFree instead, which does not take eq."
1346
- #-}
1347
-
1348
1389
++-identityʳ : ∀ .(eq : n + zero ≡ n) (xs : Vec A n) → cast eq (xs ++ []) ≡ xs
1349
1390
++-identityʳ _ = ++-identityʳ-eqFree
1350
1391
{-# WARNING_ON_USAGE ++-identityʳ
@@ -1385,7 +1426,8 @@ Please use reverse-++-eqFree instead, which does not take eq."
1385
1426
1386
1427
∷-ʳ++ : ∀ .(eq : (suc m) + n ≡ m + suc n) a (xs : Vec A m) {ys} →
1387
1428
cast eq ((a ∷ xs) ʳ++ ys) ≡ xs ʳ++ (a ∷ ys)
1388
- ∷-ʳ++ _ = ∷-ʳ++-eqFree
1429
+ ∷-ʳ++ _ a xs {ys} = ʳ++-ʳ++-eqFree (a ∷ []) {ys = xs} {zs = ys}
1430
+
1389
1431
{-# WARNING_ON_USAGE ∷-ʳ++
1390
1432
"Warning: ∷-ʳ++ was deprecated in v2.2.
1391
1433
Please use ∷-ʳ++-eqFree instead, which does not take eq."
@@ -1407,11 +1449,13 @@ Please use ++-ʳ++-eqFree instead, which does not take eq."
1407
1449
Please use ʳ++-ʳ++-eqFree instead, which does not take eq."
1408
1450
#-}
1409
1451
1410
- ------------------------------------------------------------------------
1411
- -- DEPRECATED NAMES
1412
- ------------------------------------------------------------------------
1413
- -- Please use the new names as continuing support for the old names is
1414
- -- not guaranteed.
1452
+ ++-assoc : ∀ .(eq : (m + n) + o ≡ m + (n + o)) (xs : Vec A m) (ys : Vec A n) (zs : Vec A o) →
1453
+ cast eq ((xs ++ ys) ++ zs) ≡ xs ++ (ys ++ zs)
1454
+ ++-assoc _ = ++-assoc-eqFree
1455
+ {-# WARNING_ON_USAGE ++-assoc
1456
+ "Warning: ++-assoc was deprecated in v2.2.
1457
+ Please use ++-assoc-eqFree instead, which does not take eq."
1458
+ #-}
1415
1459
1416
1460
-- Version 2.0
1417
1461
0 commit comments