[英]How to avoid (unnecessary?) repetitive use of axioms in Agda?
Is there a method to programmatically construct (sub)proofs in Agda? 有没有一种方法可以在Agda中以编程方式构造(子)证明? Because some proofs are very similar and it's better to simplify them... but i don't know how to do this. 因为一些证明非常相似,最好简化它们……但是我不知道该怎么做。 Consider for example the following code 例如考虑以下代码
{-
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
Why I cannot just use the following simplified one-line proof ? 为什么我不能只使用以下简化的单行证明?
proof-of-symmetry-of-operator-ope _ _ = definition-of-idenity
It seems that pattern matching is the cause of such behaviour. 模式匹配似乎是这种行为的原因。 But I don't understand why. 但是我不明白为什么。
You can programmatically generate proofs using Agda's reflection capability. 您可以使用Agda的反射功能以编程方式生成证明。
Here's an example of your problem solved with a reusable tactic. 这是您使用可重用策略解决问题的示例。 I threw this together for this question, so I'm not promising that it's the most robust tactic. 对于这个问题,我将其综合考虑,所以我不能保证这是最有效的策略。 It should give you a sense of how to tackle problems like this in Agda, however! 但是,它应该使您了解如何在Agda中解决此类问题!
The punchline is that you can write implementations like this: 最重要的是,您可以编写这样的实现:
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 http://www.galois.com/~emertens/exhaustive-tactic-example/Tactic.html
In Agda you can use quoteGoal g in e
to reify the current goal type and environment as a value. 在阿格达(Agda)中,您可以quoteGoal g in e
使用quoteGoal g in e
将当前目标类型和环境确认为一个值。 g
will be bound to the reified goal and will be in scope in e
. g
将绑定到确定的目标,并且将在e
范围内。 Both of these should have type Term
这两个都应具有Term
类型
You can convert a Term
value back into Agda syntax with unquote
. 您可以使用unquote
将Term
值转换回Agda语法。
All of this can be bundled up using the tactic
keyword. 所有这些都可以使用tactic
关键字捆绑在一起。 You can read a bit of slightly outdated information about tactic
in the changelog and presumably more somewhere on the wiki. 您可以在变更日志中阅读一些稍微过时的有关tactic
信息,大概在Wiki上的某个地方可以阅读更多。 https://github.com/agda/agda/blob/master/CHANGELOG https://github.com/agda/agda/blob/master/CHANGELOG
The proof of symmetry goes by looking at all possible cases for the arguments of ope
. 对称性的证明是通过考察ope
的论点的所有可能情况来进行的。 In Agda, you do reasoning by cases via pattern matching. 在Agda中,您可以通过模式匹配按案例进行推理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.