Skip to content

Commit a7aac85

Browse files
Factor antisymmetry proof for sublist (#2836)
* Simplify Sublist/Heterogeneous/antisym: collapse two cases * Simplify Sublist/Heterogeneous/antisym: factor out contradiction * Review comment: use contradiction * Apply suggestions from code review Co-authored-by: jamesmckinna <[email protected]> --------- Co-authored-by: jamesmckinna <[email protected]>
1 parent c233a37 commit a7aac85

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/Data/List/Relation/Binary/Sublist/Heterogeneous/Properties.agda

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ open import Function.Base
2929
open import Function.Bundles using (_⤖_; _⇔_ ; mk⤖; mk⇔)
3030
open import Function.Consequences.Propositional using (strictlySurjective⇒surjective)
3131
open import Relation.Nullary.Decidable as Dec using (Dec; does; _because_; yes; no; ¬?)
32-
open import Relation.Nullary.Negation using (¬_; contradiction)
32+
open import Relation.Nullary.Negation using (¬_; contradiction; contradiction′)
3333
open import Relation.Nullary.Reflects using (invert)
3434
open import Relation.Unary as U using (Pred)
3535
open import Relation.Binary.Core using (Rel; REL; _⇒_)
@@ -400,26 +400,21 @@ module Antisymmetry
400400

401401
open ℕ.≤-Reasoning
402402

403+
private
404+
antisym-lemma : Sublist R xs ys ¬ Sublist S (y ∷ ys) xs
405+
antisym-lemma {xs} {ys} {y} rs ss = ℕ.<-irrefl ≡.refl $ begin
406+
length (y ∷ ys) ≤⟨ length-mono-≤ ss ⟩
407+
length xs ≤⟨ length-mono-≤ rs ⟩
408+
length ys ∎
409+
403410
antisym : Antisym (Sublist R) (Sublist S) (Pointwise E)
404-
antisym [] [] = []
405-
antisym (r ∷ rs) (s ∷ ss) = rs⇒e r s ∷ antisym rs ss
406411
-- impossible cases
407-
antisym (_∷ʳ_ {xs} {ys₁} y rs) (_∷ʳ_ {ys₂} {zs} z ss) =
408-
contradiction (begin
409-
length (y ∷ ys₁) ≤⟨ length-mono-≤ ss ⟩
410-
length zs ≤⟨ ℕ.n≤1+n (length zs) ⟩
411-
length (z ∷ zs) ≤⟨ length-mono-≤ rs ⟩
412-
length ys₁ ∎) $ ℕ.<-irrefl ≡.refl
413-
antisym (_∷ʳ_ {xs} {ys₁} y rs) (_∷_ {y} {ys₂} {z} {zs} s ss) =
414-
contradiction (begin
415-
length (z ∷ zs) ≤⟨ length-mono-≤ rs ⟩
416-
length ys₁ ≤⟨ length-mono-≤ ss ⟩
417-
length zs ∎) $ ℕ.<-irrefl ≡.refl
412+
antisym (_ ∷ʳ rs) ss = contradiction′ (antisym-lemma rs) ss
418413
antisym (_∷_ {x} {xs} {y} {ys₁} r rs) (_∷ʳ_ {ys₂} {zs} z ss) =
419-
contradiction (begin
420-
length (y ∷ ys₁) ≤⟨ length-mono-≤ ss ⟩
421-
length xs ≤⟨ length-mono-≤ rs ⟩
422-
length ys₁ ∎) $ ℕ.<-irrefl ≡.refl
414+
contradiction′ (antisym-lemma rs) ss
415+
-- diagonal cases
416+
antisym [] [] = []
417+
antisym (r ∷ rs) (s ∷ ss) = rs⇒e r s ∷ antisym rs ss
423418

424419
open Antisymmetry public
425420

0 commit comments

Comments
 (0)