0

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?

DoubleX
  • 351
  • 3
  • 18
  • What would the tactic do when you have `n : nat` and `m : nat`? Would it clear one of them too? – Théo Winterhalter Jul 08 '21 at 06:38
  • Ah, I haven't thought about it yet. My original intention is to remove some duplicated hypo for better reading because Coq doesn't group them into `H1, H2: P1`. In contrast, Coq groups `n : nat` and `m : nat` into `n, m : nat`, thus I think there could exist some differences between "types" like `nat` and "Proposition". @ThéoWinterhalter – DoubleX Jul 08 '21 at 08:47
  • No, the reason it doesn't write them with a comma is because they are interleaved. If you have `n : nat`, `b : bool` and then `m : nat` it will write them in that order, showing `nat` twice. – Théo Winterhalter Jul 08 '21 at 08:50
  • I see, possibly what I want is to some facility of rearranging the hypo. I will update the question since removing duplicates is unwise and error-prone. – DoubleX Jul 08 '21 at 09:03

2 Answers2

1

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.

Théo Winterhalter
  • 4,908
  • 2
  • 18
  • 34
0

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.