Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

coq tactic - Decomposing equality of constructors coq

Often in Coq I find myself doing the following: I have the proof goal, for example:

some_constructor a c d = some_constructor b c d

And I really only need to prove a = b because everything else is identical anyway, so I do:

assert (a = b).

Then prove that subgoal, then

rewrite H.
reflexivity.

finishes the proof.

But it seems to just be unnecessary clutter to have those hanging around at the bottom of my proof.

Is there a general strategy in Coq for taking an equality of constructors and splitting it up into an equality of constructor parameters, kinda like a split but for equalities rather than conjunctions.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use Coq's searching capabilities:

  Search (?X _ = ?X _).
  Search (_ _ = _ _).

Among some noise it reveals a lemma

f_equal: forall (A B : Type) (f : A -> B) (x y : A), x = y -> f x = f y

And its siblings for multi-argument equalities: f_equal2 ... f_equal5 (as of Coq version 8.4).

Here is an example:

Inductive silly : Set :=
  | some_constructor : nat -> nat -> nat -> silly
  | another_constructor : nat -> nat -> silly.

Goal forall x y,
    x = 42 ->
    y = 6 * 7 ->
    some_constructor x 0 1 = some_constructor y 0 1.
  intros x y Hx Hy.
  apply f_equal3; try reflexivity.

At this point all you need to prove is x = y.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...