Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coq: why do I need to manually unfold a value even though it has a `Hint Unfold` on it?

Tags:

coq

coq-tactic

I've come up with the following toy proof script:

Inductive myType : Type :=
| c : unit -> myType.

Inductive myProp : myType -> Type :=
| d : forall t, myProp (c t).
Hint Constructors myProp.

Definition myValue : myType := c tt.
Hint Unfold myValue.

Example test: myProp myValue.
Proof.
  auto 1000. (* does nothing *)
  unfold myValue.
  trivial.
Qed.

Why do I need to manually unfold myValue here? Shouldn't the hint suffice?

like image 483
Carl Patenaude Poulin Avatar asked Jun 26 '17 19:06

Carl Patenaude Poulin


People also ask

What does auto do in Coq?

auto generally either completely solves the goal or leaves it unchanged. Use solve [ auto ] if you want a failure when they don't solve the goal. auto will fail if fail or gfail are invoked directly or indirectly, in which case setting the Ltac Debug may help you debug the failure.

What are tactics in Coq?

This tactic applies to any goal. The argument term is a term well-formed in the local context. The tactic apply tries to match the current goal against the conclusion of the type of term . If it succeeds, then the tactic returns as many subgoals as the number of non-dependent premises of the type of term.

Which goals can you conclude with reflexivity?

reflexivity. Use reflexivity when your goal is to prove that something equals itself. In this example we will prove that any term x of type Set is equal to itself.


2 Answers

That's because (see refman)

This [Hint Unfold <qualid>] adds the tactic unfold qualid to the hint list that will only be used when the head constant of the goal is ident.

And the goal myProp myValue has myProp in the head position, not myValue.

There are several ways of dealing with this:

Hint Extern 4 => constructor.   (* change 4 with a cost of your choice *)

or

Hint Extern 4 => unfold myValue.

or even

Hint Extern 1 =>
  match goal with
  | [ |- context [myValue]] => unfold myValue
  end.
like image 150
Anton Trunov Avatar answered Sep 30 '22 21:09

Anton Trunov


@AntonTrunov is correct in his explanation on why Hint Unfold is not used here. There is the alternative Hint Transparent that makes the application work modulo delta for some specific constants. It seems not to be yet supported by trivial and auto but is supported by eauto as you can see in the following:

Inductive myType : Type :=
| c : unit -> myType.

Inductive myProp : myType -> Type :=
| d : forall t, myProp (c t).
Hint Constructors myProp.

Definition myValue : myType := c tt.
Hint Transparent myValue.

Example test: myProp myValue.
Proof.
  eauto.
Qed.
like image 30
Zimm i48 Avatar answered Sep 30 '22 21:09

Zimm i48