如何避免(不必要?)在 Agda 中重复使用公理?

How to avoid (unnecessary?) repetitive use of axioms in Agda?

有没有一种方法可以在 Agda 中以编程方式构建(子)证明? 因为有些证明非常相似,最好简化它们……但我不知道该怎么做。例如考虑以下代码

{-
At first we reaname  Set to  (as in Universe)
-}
 = Set

{-
  We define also a polymorphic idenity
-}
data _==_ {A : } (a : A) : A →  where
  definition-of-idenity : a == a
infix 30 _==_

{-
  The finite set Ω 
-}
data Ω :  where
  A B : Ω

Operation = Ω → Ω → Ω

{-
 symmetry is a function that takes an Operation
 op and returns a proposition about this operation
-}

symmetry : Operation → 
symmetry op = ∀ x y → op x y == op y x

ope : Operation
ope A A = A
ope A B = B
ope B A = B
ope B B = B

proof-of-symmetry-of-operator-ope : symmetry ope
proof-of-symmetry-of-operator-ope A A = definition-of-idenity
proof-of-symmetry-of-operator-ope B B = definition-of-idenity
proof-of-symmetry-of-operator-ope A B = definition-of-idenity
proof-of-symmetry-of-operator-ope B A = definition-of-idenity

为什么我不能只使用以下简化的单行证明?

proof-of-symmetry-of-operator-ope _ _ = definition-of-idenity

模式匹配似乎是这种行为的原因。但是我不明白为什么。

通过查看 ope 参数的所有可能情况来证明对称性。在 Agda 中,您可以通过模式匹配按案例进行推理。

您可以使用 Agda 的 反射 功能以编程方式生成证明。

这是您使用可重用策略解决问题的示例。对于这个问题,我把它放在一起,所以我不保证这是最可靠的策略。但是,它应该让您了解如何在 Agda 中解决此类问题!

妙语是你可以像这样编写实现:

proof-of-symmetry-of-operator-ope : symmetry ope
proof-of-symmetry-of-operator-ope = tactic exhaustive-tactic

http://www.galois.com/~emertens/exhaustive-tactic-example/Tactic.html

在 Agda 中,您可以使用 quoteGoal g in e 将当前目标类型和环境具体化为一个值。 g 将绑定到具体化的目标,并将在 e 的范围内。这两个都应该有类型 Term

您可以使用 unquote.

Term 值转换回 Agda 语法

所有这些都可以使用 tactic 关键字捆绑在一起。您可以在变更日志中阅读一些关于 tactic 的稍微过时的信息,并且可能在 wiki 上的某个地方阅读更多信息。 https://github.com/agda/agda/blob/master/CHANGELOG