English 中文(简体)
How do I reason about conditionals in Coq?
原标题:

I m working through the ListSet module from the Coq standard library. I m unsure how to reason about conditionals in a proof. For instance, I am having trouble with the following proof. Definitions are provided for context.

Fixpoint set_mem (x : A) (xs : set) : bool :=
match xs with
  | nil       => false
  | cons y ys =>
      match Aeq_dec x y with
        | left  _ => true
        | right _ => set_mem x ys
      end
end.

Definition set_In : A -> set -> Prop := In (A := A).

Lemma set_mem_correct1 : forall (x : A) (xs : set),
  set_mem x xs = true -> set_In x xs.
Proof. intros. induction xs.
  discriminate.
  simpl; destruct Aeq_dec with a x.
    intuition.
    simpl in H.

The current proof state includes the inr of Aeq_dec as a hypothesis. I have discarded the base case of induction and the inductive case where the inl of Aeq_dec is true.

  A : Type
  Aeq_dec : forall x y : A, {x = y} + {x <> y}
  x : A
  a : A
  xs : list A
  H : (if Aeq_dec x a then true else set_mem x xs) = true
  IHxs : set_mem x xs = true -> set_In x xs
  n : a <> x
  ============================
   a = x / set_In x xs

The only way for H to be true if a <> x is if set_mem xs is true. I should be able to apply the conditional in H to a <> x in order to obtain set_mem xs. However, I don t understand how to do this. How do I deal with, or decompose, or apply conditionals?

最佳回答

Have you tried this? (syntax may be buggy, no coqtop here atm)

destruct (Aeq_dec x a);
[ subst; elim (n eq_refl)
| right; apply (IHxs H)
].

(if <foo> is more or less the same as match <foo> with. You ll have to reduce (destruct, case, ...) such that the match can be decided (or for the if, things must reduce to either the first or the second constructor of whatever type you re using it with.) Most of the time, you ll need the value that gets case-analyzed (though not here). If you need it, do a remember (<value>) as foo; destruct foo instead of destructing directly.)

问题回答

暂无回答




相关问题
How do I reason about conditionals in Coq?

I m working through the ListSet module from the Coq standard library. I m unsure how to reason about conditionals in a proof. For instance, I am having trouble with the following proof. Definitions ...

Z3: Extracting existential model-values

I m playing around with Z3 s QBVF solver, and wondering if it s possible to extract values from an existential assertion. To wit, let s say I have the following: (assert (exists ((x (_ BitVec 16))) (...

Tautology Checker for GNU Prolog [closed]

I am looking for open-source implementations of tautology checkers written in GNU Prolog (implementation for SWI-Prolog is acceptable as well, but GNU Prolog is preferred). I d like to feed program ...

Has anyone tried proving Z3 with Z3 itself?

Has anyone tried proving Z3 with Z3 itself? Is it even possible, to prove that Z3 is correct, using Z3? More theoretical, is it possible to prove that tool X is correct, using X itself?

How to proceed with this Coq Proof?

I m having a problem with my Coq proof and was hoping for some help and guidance. I have part of my definition below: Inductive Architecture : Set := | Create_Architecture (Arch_Name: string)(...

Searching through a list recursively in Coq

Im trying to search for an object in a list, and then perhaps return true if it is found; false otherwise. However, what I have tried to come up with is incorrect. I would really appreciate some ...

Pattern matching not specialising types

I m playing around in Coq, trying to create a sorted list. I just wanted a function that takes a list [1,2,3,2,4] and would return something like Sorted [1,2,3,4] - i.e. taking out the bad parts, but ...

Showing (head . init ) = head in Agda

I m trying to prove a simple lemma in Agda, which I think is true. If a vector has more than two elements, taking its head following taking the init is the same as taking its head immediately. I ...

热门标签