1

I'm having a problem understanding why my Coq code doesn't do what I expect in the code below.

  • I tried to make the example as simplified as possible, but the problem didn't show up anymore when I made it even simpler.
  • It's using CompCert 1.8 files.
  • This happened to me under Coq 8.2-pl2.

Here is the code:

Require Import Axioms.
Require Import Coqlib.
Require Import Integers.
Require Import Values.
Require Import Asm.

Definition foo (ofs: int) (c: code) : Prop :=
  c <> nil /\ ofs <> Int.zero.

Inductive some_prop: nat -> Prop :=
| some_prop_ctor :
  forall n other_n ofs c lo hi ofs_ra ofs_link,
    some_prop n ->
    foo ofs c ->
    find_instr (Int.unsigned ofs) c <> Some (Pallocframe lo hi ofs_ra ofs_link) ->
    find_instr (Int.unsigned ofs) c <> Some (Pfreeframe lo hi ofs_ra ofs_link) ->
    some_prop other_n
.

Lemma simplified:
  forall n other_n ofs c,
  some_prop n ->
  foo ofs c ->
  find_instr (Int.unsigned ofs) c = Some Pret ->
  some_prop other_n.
Proof.
  intros.

This does not work:

  eapply some_prop_ctor
    with (lo:=0) (hi:=0) (ofs_ra:=Int.zero) (ofs_link:=Int.zero);
      eauto; rewrite H1; discriminate.

Fails on rewrite H1 with:

Error:
Found no subterm matching "find_instr (Int.unsigned ofs) c" in the current goal.

This works though:

  eapply some_prop_ctor
    with (lo:=0) (hi:=0) (ofs_ra:=Int.zero) (ofs_link:=Int.zero);
      eauto.
  rewrite H1; discriminate.
  rewrite H1; discriminate.
Qed.

Also, just after the eauto, my goal looks like this:

2 subgoals
n : nat
other_n : nat
ofs : int
c : code
H : some_prop n
H0 : foo ofs c
H1 : find_instr (Int.unsigned ofs) c = Some Pret
______________________________________(1/2)
find_instr (Int.unsigned ofs) c <> Some (Pallocframe 0 0 Int.zero Int.zero)


______________________________________(2/2)
find_instr (Int.unsigned ofs) c <> Some (Pfreeframe 0 0 Int.zero Int.zero)

So, rewrite H1; discriminate twice works, but "piping" it after eauto using a semicolon doesn't work.

I hope the problem makes sense at least. Thank you!


Full code:

Require Import Axioms.
Require Import Coqlib.
Require Import Integers.
Require Import Values.
Require Import Asm.

Definition foo (ofs: int) (c: code) : Prop :=
  c <> nil /\ ofs <> Int.zero.

Inductive some_prop: nat -> Prop :=
| some_prop_ctor :
  forall n other_n ofs c lo hi ofs_ra ofs_link,
    some_prop n ->
    foo ofs c ->
    find_instr (Int.unsigned ofs) c <> Some (Pallocframe lo hi ofs_ra ofs_link) ->
    find_instr (Int.unsigned ofs) c <> Some (Pfreeframe lo hi ofs_ra ofs_link) ->
    some_prop other_n
.

Lemma simplified:
  forall n other_n ofs c,
  some_prop n ->
  foo ofs c ->
  find_instr (Int.unsigned ofs) c = Some Pret ->
  some_prop other_n.
Proof.
  intros.
(*** This does not work:
  eapply some_prop_ctor
    with (lo:=0) (hi:=0) (ofs_ra:=Int.zero) (ofs_link:=Int.zero);
      eauto; rewrite H1; discriminate.
***)
  eapply some_prop_ctor
    with (lo:=0) (hi:=0) (ofs_ra:=Int.zero) (ofs_link:=Int.zero);
      eauto.    
  rewrite H1; discriminate.
  rewrite H1; discriminate.
Qed.
Ptival
  • 9,167
  • 36
  • 53

1 Answers1

3

So, this might be an answer to my own question (thanks to someone on #coq IRC channel):

It could be the case that the unification of existential variables doesn't happen until the . Therefore, by semicolon-ing, I might have prevented the ofs and c from being unified.

What I found out though is that writing ...; eauto; subst; rewrite H1; discriminate. will work. subst would in this case force the unification of the existential variables, hence unlocking the ability to rewrite.

Ptival
  • 9,167
  • 36
  • 53