Idiomatic ways to select a subterm for dubbing

Suppose that we have the conclusion of the form: a + b + c + d + e.
We also have the lemma plus_assoc : forall n m p : nat, n + (m + p) = n + m + p.

What are the idiomatic ways to arbitrarily “insert a pair of parentheses” into a term? That is, how can we easily choose where to rewrite if there is more than one available space.

What I usually do is the following:

replace (a + b + c + d + e)
with (a + b + c + (d + e))
by now rewrite <- ?plus_assoc

Although this wording defines exactly what I want to do, it becomes extremely long for wordings that are more complex than "ab c ...".

+4
source share
3 answers

rewrite <- lemma , lemma , .. , something1 = something2. , , , , forall param1 … paramN, something1 = something2, Coq , . Coq , , , . Coq rewrite <- plus_assoc, , , .

, , , . , , (((a + b) + c) + d) + e ((a + b) + c) + (d + e), .. (a + b) + c, d e,

rewrite <- (plus_assoc ((a + b) + c) d e).

, , . , d . , _ .

rewrite <- (plus_assoc _ d).

, . rewrite. , replace , , , assert, . set, , , , , , subst, , .

, , , , assert replace … with ….. , congruence, omega, solve [firstorder] .., , . , . , , , , .

+1

IMO, - ssreflect, Coq 8.7, math-comp . : https://hal.inria.fr/inria-00258384

( Coq 8.7):

(* Replace with From mathcomp Require ... in Coq < 8.7 *)
From Coq Require Import ssreflect ssrfun ssrbool.

Lemma addnC n m : m + n = n + m. Admitted.
Lemma addnA m n o : m + (n + o) = m + n + o. Admitted.

Lemma example m n o p : n + o + p + m = m + n + o + p.
Proof. by rewrite -[_ + _ + o]addnA -[m + _ + p]addnA [m + _]addnC.
Qed.
+1

, Ltac . :

Require Import Coq.Arith.Arith.

Goal forall a b c d e,
    (a + 1 + 2) + b + c + d + e = (a + 1 + 2) + (b + c + d) + e -> True.
  intros a b c d e H.
  match type of H with ?a + ?b + ?c + ?d + ?e = _ =>
    replace (a + b + c + d + e)
       with (a + (b + c + d) + e)
    in H
    by now rewrite <- ?plus_assoc
  end.
Abort.

?a a + 1 + 2. , , , , , .

, , - :

match goal with
  | |- ?a + ?b + ?c + ?d + ?e = _ => <call your tactics here>
+1

Source: https://habr.com/ru/post/1679121/


All Articles