简体   繁体   中英

What forms of goal in Coq are considered to be “true”?

When I prove some theorem, my goal evolves as I apply more and more tactics. Generally speaking the goal tends to split into sub goals, where the subgoals are more simple. At some final point Coq decides that the goal is proven. How this "proven" goal may look like? These goals seems to be fine:

a = a.                       (* Any object is identical to itself (?) *)
myFunc x y = myFunc x y.     (* Result of the same function with the same params
                                is always the same (?) *)

What else can be here or can it be that examples are fundamentally wrong?

In other words, when I finally apply reflexivity , Coq just says ** Got it ** without any explanation. Is there any way to get more details on what it actually did or why it decided that the goal is proven?

You're actually facing a very general notion that seems not so general because Coq has some user-friendly facility for reasoning with equality in particular.

In general, Coq accepts a goal as solved as soon as it receives a term whose type is the type of the goal: it has been convinced the proposition is true because it has been convinced the type that this proposition describes is inhabited, and what convinced it is the actual witness you helped build along your proof.


For the particular case of inductive datatypes, the two ways you are going to be able to proved the proposition P abc are:

  • by constructing a term of type P abc , using the constructors of the inductive type P , and providing all the necessary arguments.

  • or by reusing an existing proof or an axiom in the environment whose type you can get to match P abc .


For the even more particular case of equality proofs (equality is just an inductive datatype in Coq), the same two ways I list above degenerate to this:

  • the only constructor of equality is eq_refl , and to apply it you need to show that the two sides are judgementally equal. For most purposes, this corresponds to goals that look like T abc = T abc , but it is actually a slightly more broad notion of equality (see below). For these, all you have to do is apply the eq_refl constructor. In a nutshell, that is what reflexivity does!

  • the second case consists in proving that the equality holds because you have other equalities in your context, nothing special here.


Now one part of your question was: when does Coq accept that two sides of an equality are equal by reflexivity?

If I am not mistaken, the answer is when the two sides of the equality are αβδιζ-convertible. What this grossly means is that there is a way to make them syntactically equal by repeated applications of:

  • α : sane renaming of non-free variables
  • β : computing reducible expressions
  • δ : unfolding definitions
  • ι : simplifying matches
  • ζ : expanding let-bound expressions

[someone please correct me if more rules apply or if I got one wrong]

For instance some of the things that are not captured by these rules are:

  • equality of functions that do more or less the same thing in different ways:

     (fun x => 0 + x) = (fun x => x + 0) quicksort = mergesort 
  • equality of terms that are stuck reducing but would be equal:

     forall n, 0 + n = n + 0 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM