Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] How to avoid code-duplication in this proof?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] How to avoid code-duplication in this proof?


Chronological Thread 
  • From: Jasper Hugunin <jasper AT hugunin.net>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] How to avoid code-duplication in this proof?
  • Date: Sun, 13 Sep 2020 13:02:43 -0700
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jasper AT hugunin.net; spf=None smtp.mailfrom=jasper AT hugunin.net; spf=None smtp.helo=postmaster AT mail-pf1-f170.google.com
  • Ironport-phdr: 9a23:pt4CBRRt01UQKPmgQv4fXiMVstpsv+yvbD5Q0YIujvd0So/mwa6yZh2N2/xhgRfzUJnB7Loc0qyK6v6mADZcqsbY+Fk5M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aFRrwLxd6KfroEYDOkcu3y/qy+5rOaAlUmTaxe7x/IAi3oAnLq8Uan4RvJqkyxxfUv3BFZ/lYyWR0KFyJgh3y/N2w/Jlt8yRRv/Iu6ctNWrjkcqo7ULJVEi0oP3g668P3uxbDSxCP5mYHXWUNjhVIGQnF4wrkUZr3ryD3q/By2CiePc3xULA0RTGv5LplRRP0lCsKMSMy/WfKgcJyka1bugqsqBNxw4HWYI+bOvlwcL7Dc9wGXmdORNpdWjZbD4+gc4cCDewMNvtYoYnnoFsOqAOzCw22C+P00j9HmGX21rA43eQ8HgHGwQogH9MIsH/Jq9j1Nr0dUfutzKbW1zXOdPNW2Sry6IjVdBAhoPeMUah2ccXP1UkiDgXIhUifpoL5JT2azPgNs3SF4Op6U+Kik2AqpgF1rzWxx8oihYrEi58axF3Y9ih03Jg5KMClRENmbtOpFJ9duiCVOoZ0TM4sTG9mtDg4x7ACpZK2fzUHxZshyhXCZfKHdI2I7QjiVOaXOTp4hXRleKi+hxmo60SgxPf8W8+p21hJtipIisfAumwJ2hDJ6cWKSuFx8lm81TqTzQzf9+NJLVwymKHGMZAu2KQwmYAWsUnbHi/5hkH2jKiOe0Uh4Oeo6uDnbqz+pp+SKoN4kw/+Prksl8CjG+g4PQ8OX2+U+eS4yrLv51H2QLJPjvEuk6nZto7VJdgDq6KnHwNY1pwv5hW/Aju8ztgUgGULIEhYdB+Fk4TlI1TOL+r5Dfe7jVSsijBrx/XeM73jGJrNNWDDn6n7fbtm605c1QUzzc1Z55JVDLENOvTzVVHttNDAFB82LxS0w/r7CNV6zo4RRWWPAraAPKzOtV+I+/kgLvKXZI4VvTb9M+Iq6+TvjX8/g18dfLOm0YEZaHCiTbxaJBCSZmOpidMcG08LuBA/Rarkkg6sSzlWMlS7RLox/HkbFY27C4bFDtSviaeZ0T2THoBZe2ZHDBaKHGu+JNbMYOsFdC/HepwpqTcDT7X0E9Z9hyHrjxfzzv9cFsSR4jcR7Mmx1MV6+uvSk1c0+CAmV53AgVHIdHl9myYzfxFz3K17phYjmFKK0Kw9m/IBUNIKuKsPXQA9OprRied9DoKqA1OTTpKyUF+jB+6eL3Q0R9M1zcUJZh8mSdW/gQ3F3izsBbIJxeSG

Hi Ashish,

I'm not an expert on Ltac programming, so hopefully someone else will chime in here, but here is how I would solve your two issues.
(1) The first tactic lets you define `Ltac symmetric_apply H := first [ apply H | symmetry in H; apply H ].` which I believe has exactly the behavior you describe. You can also replace first with solve if you want to require that `symmetric_apply H''` finishes the proof.
(2) Consider using the form `assert (H'' : S1) by (apply L1; assumption);` This avoids the use of `{` which is causing you trouble when chaining with `;`.

Sincerely,
- Jasper Hugunin


On Sun, Sep 13, 2020 at 8:10 AM Kumar, Ashish <azk640 AT psu.edu> wrote:
Hi,

I am trying to prove a theorem (proof code given below). The issue is there is a lot of repeated code in the proof, which I would like to avoid. Is there a way to do so?


Proof has been summarized below to show only relevant details - In below proof,
(1) Let T1 and T2 denote a sequence of tactics of the form t1 ; t2 ; t3 ... ; tn.
(2) Let S1 be some lemma statement, which has type Prop.
(3) Let L1 be a lemma proved earlier.

Proof.
intros. split; intros H'; inversion_clear H'; T1.
+ assert (H" : S1). { apply L1; assumption}
    T2 ; apply H''.
assert (H" : S1). { apply L1; assumption. }
    T2;  symmetry in H''; apply H''.
Qed.

After the intros, we have a goal of the form (A -> B) /\ (B -> A).
The inversion_clear H' statement generates a total of 4 subgoals from the 2 subgoals generated by split, and T1 solves 2 of these 4 subgoals. 
As you can see the proof code for the remaining 2 subgoals is almost identical (excluding the symmetry tactic). Note that I cannot push the assert statement earlier in the proof, as inversion_clear H' generates a variable st'0 which is used in the assert statements.
I have 2 issues:
(1) Is there a way I can write a customized tactic 'symmetric_apply H' which applies either H or the reversed version of H, and fails if both fail.
(2) Once (1) is done, the proof statement of the remaining 2 subgoals becomes exactly identical (using 'symmetric_apply' instead of apply).
     Then is there a way, I could use the tactical ';' with the assert statement - Coq doesn't seem to be allowing me to do so?

Or if there is some other way of avoiding the code duplication, that would be great.

With regards,
Ashish




Archive powered by MHonArc 2.6.19+.

Top of Page