-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path++-injective.agda
53 lines (46 loc) · 1.58 KB
/
++-injective.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
open import Data.Nat
open import Data.Nat.Properties
open import Relation.Binary.PropositionalEquality
open import Data.Empty
open import Data.List
open import Data.List.Properties
open import Function
lemma : ∀ a b → a ≡ suc b + a → ⊥
lemma (suc a) b p =
lemma a b a=sucb+a
where
open ≡-Reasoning
a=sucb+a : a ≡ suc b + a
a=sucb+a = suc-injective $ begin
suc a ≡⟨ p ⟩
suc (b + suc a) ≡⟨ cong suc (+-suc b a) ⟩
suc (suc b) + a ∎
++-injectiveˡ : ∀ {ℓ} {A : Set ℓ} (a b c : List A) → a ++ c ≡ b ++ c → a ≡ b
++-injectiveˡ [] [] c p = refl
++-injectiveˡ [] (x ∷ b) c p =
⊥-elim $ lemma _ _ eq
where
open ≡-Reasoning
eq : length c ≡ suc (length b) + length c
eq = begin
length c ≡⟨ cong length p ⟩
length (x ∷ b ++ c) ≡⟨ length-++ (x ∷ b) ⟩
suc (length b) + length c ∎
++-injectiveˡ (x ∷ a) [] c p =
⊥-elim $ lemma _ _ eq
where
open ≡-Reasoning
eq : length c ≡ suc (length a) + length c
eq = begin
length c ≡⟨ sym (cong length p) ⟩
length (x ∷ a ++ c) ≡⟨ length-++ (x ∷ a) ⟩
suc (length a) + length c ∎
++-injectiveˡ (x ∷ a) (y ∷ b) c p
with ∷-injectiveˡ p | ++-injectiveˡ a b c $ ∷-injectiveʳ p
... | refl | refl
= refl
++-injectiveʳ : ∀ {ℓ} {A : Set ℓ} (a b c : List A) → a ++ b ≡ a ++ c → b ≡ c
++-injectiveʳ [] b c p = p
++-injectiveʳ (x ∷ a) b c p
rewrite ++-injectiveʳ a b c $ ∷-injectiveʳ p =
refl