pattern matching - Agda: Simulate Coq's rewrite tactic -


i have experience using coq , in process of learning agda. i'm working on correctness proof of insertion sort , have reached point perform similar coq's rewrite tactic. currently, have:

open import data.nat open import relation.binary.propositionalequality open import data.sum  data list : set   nil : list   cons : ℕ -> list -> list  data sorted (n : ℕ) : list -> set   nilsorted : sorted n nil   conssorted : ∀ hd tl -> hd ≥ n -> sorted hd tl -> sorted n (cons hd tl)  lemin : ∀ x y -> x ≤ y -> (x ⊓ y) ≡ x lemin 0 zero p = refl lemin 0 (suc y) p = refl lemin (suc x) 0 () lemin (suc x) (suc y) (s≤s p) = cong suc (lemin x y p)  insert : ℕ → list → list insert x l = {!!}  intdec : ∀ x y → x ≤ y ⊎ x > y intdec x y = {!!}  insertcorrect : ∀ {n} -> ∀ x l -> sorted n l -> sorted (n ⊓ x) (insert x l) insertcorrect {n} x nil p intdec n x insertcorrect {n} x nil p | inj₁ x₁ (lemin n x x₁)  ... | c = {c }0 

my proof context looks like:

goal: sorted (n ⊓ x) (cons x nil) ———————————————————————————————————————————————————————————— p  : sorted n nil c  : n ⊓ x ≡ n x₁ : n ≤ x x  : ℕ n  : ℕ 

i have tried breaking c in hopes of replacing occurrences of (n ⊓ x) n, however, following error:

i'm not sure if there should case constructor refl, because stuck when trying solve following unification problems (inferred index ≟ expected index): n₁ ⊓ x₂ ≟ n₁ when checking expression ? has type sorted (n ⊓ x) (cons x nil) 

basically, able perform rewrite can following point:

goal: sorted n (cons x nil) ———————————————————————————————————————————————————————————— p  : sorted n nil x₁ : n ≤ x x  : ℕ n  : ℕ 

any ideas on how proceed?

you can use agda keyword rewrite apply propositional equivalence on goal:

insertcorrect : ∀ {n} -> ∀ x l -> sorted n l -> sorted (n ⊓ x) (insert x l) insertcorrect {n} x nil p intdec n x insertcorrect {n} x nil p | inj₁ x₁ rewrite lemin n x x₁ = ? 

here, goal in ? is, hoped for:

goal: sorted n (cons x nil) ———————————————————————————————————————————————————————————— p  : sorted n nil x₁ : n ≤ x x  : ℕ n  : ℕ 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -