如何自动将对称性引入 Coq 假设?

How to automatically introduce symmetries into Coq hypotheses?

我在假设中有一些等式(=)和不等式(<>),例如:

e : x2 = x1
n : x3 <> x1

我想使用像 assumption 这样的策略,但有时目标中预期的(不)平等是在另一个方向,如:

x1 = x2
x1 <> x3

我的问题是:

是否可以将上面的(不)等式的对称形式自动引入到假设中?

如果没有,是否可以使用 Notation 编写战术来执行此操作。

到目前为止,我可以像这样手动执行此操作:

assert (x1 = x2) by (symmetry in e; assumption).

assert (x1 <> x3) by (unfold not; intro Hnot; 
  symmetry in Hnot; unfold not in n; apply n in Hnot; inversion Hnot). 

但是真的很乏味和嘈杂。我不太了解如何自动执行此操作,或者是否有更好的方法。

也许这个策略可以帮助:

Ltac maybe_intro_sym A B :=
  match goal with
    |[H:B=A|-_] => fail 1
    |[H:A=B|-_] => assert (B=A) by auto
  end.

Ltac maybe_intro_sym_neg A B :=
  match goal with
    |[H:B<>A|-_] => fail 1
    |[H:A<>B|-_] => assert (B<>A) by auto
  end.

Ltac intro_sym :=
  repeat match goal with
    |[H:?A=?B|-_] => maybe_intro_sym A B
    |[H:?A<>?B|-_] => maybe_intro_sym_neg A B
  end.

这是一个例子:

Parameters a b c d:nat.
Goal a=b -> c=d -> c<>d -> True.
intros.
intro_sym.

现在上下文是

  H : a = b
  H0 : c = d
  H1 : c <> d
  H2 : d = c
  H3 : b = a
  H4 : d <> c
  ============================
   True