简体   繁体   中英

How to group duplicated hypothesis in Coq?

I have

1 subgoals, subgoal 1
n : nat
b : bool
m : nat
H1: P1
H2: P2
H3: P1
H4: P2
=========
some_goal

after I run the tactic auto_group_duplicates , it will become

1 subgoals, subgoal 1
n, m : nat
b : bool
H1, H3: P1
H2, H4: P2
=========
some_goal

Is there a tactic like this one?

I don't think that there is a tactic like this. But you can always come up with something using Ltac.

From Coq Require Import Utf8.

Definition mark {A : Type} (x : A) := x.

Ltac bar :=
  match goal with
  | x : ?A, y : ?A |- _ =>
    lazymatch A with
    | context [ mark ] => fail
    | _ =>
      move y after x ;
      change A with (mark A) in x
    end
  end.

Ltac remove_marks :=
  repeat match goal with
  | x : mark ?A |- _ =>
    change (mark A) with A in x
  end.

Ltac auto_group_duplicates :=
  repeat bar ; remove_marks.

Lemma foo :
  ∀ (n : nat) (b : bool) (m : nat) (c : bool),
    n = m →
    b = c →
    n = m →
    b = c →
    n = m →
    True.
Proof.
  intros n b m c e1 e2 e3 e4 e5.
  auto_group_duplicates.
  auto_group_duplicates.

Here I have to apply the tactic twice because Ltac unifies A with mark A annoyingly.

You can manually use the move tactic (see https://coq.inria.fr/refman/proof-engine/tactics.html?highlight=top#coq:tacn.move-%E2%80%A6-after-%E2%80%A6 ) to rearrange hypothesis.

I doubt that there is a general automatic tactic like the one you are looking for, but one could probably cook up a fancy match-goal -based one to automate rearranging hypothesis using this tactic as a basic block, although this is out of my league.

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