{-# OPTIONS --allow-unsolved-metas #-} module fin where open import Data.Fin hiding (_<_ ; _≤_ ; _>_ ; _+_ ) open import Data.Fin.Properties hiding (≤-trans ; <-trans ; ≤-refl ) renaming ( <-cmp to <-fcmp ) open import Data.Nat open import Data.Nat.Properties open import logic open import nat open import Relation.Binary.PropositionalEquality -- toℕ 0 → Data.Nat.pred (toℕ f) < n pred ¬a ¬b c = fin-phase2 q qs fin-phase1 : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → Bool fin-phase1 q [] = false fin-phase1 q (x ∷ qs) with <-fcmp q x ... | tri< a ¬b ¬c = fin-phase1 q qs ... | tri≈ ¬a b ¬c = fin-phase2 q qs ... | tri> ¬a ¬b c = fin-phase1 q qs fin-dup-in-list : { n : ℕ} (q : Fin n) (qs : List (Fin n) ) → Bool fin-dup-in-list {n} q qs = fin-phase1 q qs record FDup-in-list (n : ℕ ) (qs : List (Fin n)) : Set where field dup : Fin n is-dup : fin-dup-in-list dup qs ≡ true list-less : {n : ℕ } → List (Fin (suc n)) → List (Fin n) list-less [] = [] list-less {n} (i ∷ ls) with NatP.<-cmp (toℕ i) n ... | tri< a ¬b ¬c = fromℕ< a ∷ list-less ls ... | tri≈ ¬a b ¬c = list-less ls ... | tri> ¬a ¬b c = ⊥-elim ( nat-≤> (fin≤n i) c ) record NList (n m : ℕ) (qs : List (Fin (suc n))) : Set where field ls : List (Fin n) lseq : list-less qs ≡ ls ls>n : m + length ls > n fin-dup-in-list>n : {n : ℕ } → (qs : List (Fin n)) → (len> : length qs > n ) → FDup-in-list n qs fin-dup-in-list>n {zero} [] () fin-dup-in-list>n {zero} (() ∷ qs) lt fin-dup-in-list>n {suc n} qs lt = fdup-phase0 where open import Level using ( Level ) mapleneq : {n : Level} {a b : Set n} { x : List a } {f : a → b} → length (map f x) ≡ length x mapleneq {_} {_} {_} {[]} {f} = refl mapleneq {_} {_} {_} {x ∷ x₁} {f} = cong suc (mapleneq {_} {_} {_} {x₁}) lt-conv : {l : Level} {a : Set l} {m n : ℕ } ( qs : List a ) → m + suc ( length qs ) > n → suc m + length qs > n lt-conv {_} {_} {m} {n} qs lt = begin suc n ≤⟨ lt ⟩ m + suc (length qs) ≡⟨ sym (+-assoc m 1 _) ⟩ (m + 1) + length qs ≡⟨ cong (λ k → k + length qs) (+-comm m _ ) ⟩ suc m + length qs ∎ where open ≤-Reasoning fdup+1 : (qs : List (Fin (suc n))) (i : Fin n) → fin-dup-in-list i (list-less qs) ≡ true → fin-dup-in-list (fin+1 i) qs ≡ true fdup+1 qs i p = f1-phase1 qs p where f1-phase2 : (qs : List (Fin (suc n)) ) → fin-phase2 i (list-less qs) ≡ true → fin-phase2 (fin+1 i) qs ≡ true f1-phase2 (x ∷ qs) p with <-fcmp (fin+1 i) x ... | tri< a ¬b ¬c = f1-phase2 qs {!!} -- fin-phase2 i (list-less (x ∷ qs)) ≡ true → fin-phase2 i (list-less qs) ≡ true ... | tri≈ ¬a b ¬c = refl ... | tri> ¬a ¬b c = f1-phase2 qs {!!} f1-phase1 : (qs : List (Fin (suc n)) ) → fin-phase1 i (list-less qs) ≡ true → fin-phase1 (fin+1 i) qs ≡ true f1-phase1 [] () f1-phase1 (x ∷ qs) p with <-fcmp (fin+1 i) x ... | tri< a ¬b ¬c = f1-phase1 qs {!!} ... | tri≈ ¬a b ¬c = f1-phase2 qs {!!} ... | tri> ¬a ¬b c = f1-phase1 qs {!!} fdup-phase2 : (qs : List (Fin (suc n)) ) → {m : ℕ} → m + length qs > n → ( fin-phase2 (fromℕ< an = lt } fdup-phase2 (x ∷ qs) {m} lt with <-fcmp (fromℕ< a a (subst (λ k → toℕ x < suc k) (sym fin ¬a ¬b c with fdup-phase2 qs {suc m} (lt-conv qs lt) ... | case1 p = case1 p ... | case2 nlist = case2 record { ls = xn = {!!} } fdup-phase1 : (qs : List (Fin (suc n)) ) → {m : ℕ} → m + length qs > n → (fin-phase1 (fromℕ< an = lt } fdup-phase1 (x ∷ qs) {m} lt with <-fcmp (fromℕ< a a (subst (λ k → toℕ x < suc k) (sym finn = NList.ls>n nlist } fdup-phase1 (x ∷ qs) {m} lt | tri> ¬a ¬b c with fdup-phase1 qs {m} {!!} ... | case1 p = case1 p ... | case2 nlist = case2 record { ls = xn = {!!} } fdup-phase0 : FDup-in-list (suc n) qs fdup-phase0 with fdup-phase1 qs {0} ( <-trans a n flt = subst ( λ k → length k > n ) (sym (NList.lseq nlist)) ( NList.ls>n nlist ) fdup : FDup-in-list n (list-less qs) fdup = fin-dup-in-list>n (list-less qs) flt