Proving if then else in Coq -


i'm new @ coq , i'm trying prove pretty basic

lemma eq_if_eq : forall a1 a2, (if beq_nat a1 a2 a2 else a1) = a1.

i struggled through solution posted below, think there must better way. ideally, i'd cleanly case on beq_nat a1 a2 while putting case values in list of hypothesis. there tactic t such using t (beq_nat a1 a2) yields 2 subcases, 1 beq_nat a1 a2 = true , beq_nat a1 a2 = false? obviously, induction close loses history.

here's proof struggled through:

proof. hint resolve beq_nat_refl. hint resolve beq_nat_eq. hint resolve beq_nat_true. hint resolve beq_nat_false. intros. compare (beq_nat a1 a2) true. intros. assert (a1 = a2). auto.  replace (beq_nat a1 a2) true. auto. intros. assert (a1 <> a2). apply beq_nat_false. apply not_true_is_false. auto. assert (beq_nat a1 a2 = false). apply not_true_is_false. auto. replace (beq_nat a1 a2) false. auto. qed. 

generally kind of things, use eqn variant of destruct. this:

destruct (beq_nat a1 a2) []_eqn. (* coq <= 8.3 *)  destruct (beq_nat a1 a2) []eqn:? (* coq >= 8.4 *) 

it add equality hypothesis. in 8.4 variant, can replace question mark name give hypothesis.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -