2
votes

Is there a method to programmatically construct (sub)proofs in 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.

2

2 Answers

4
votes

You can programmatically generate proofs using Agda's reflection capability.

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!

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

In Agda you can use quoteGoal g in e to reify the current goal type and environment as a value. g will be bound to the reified goal and will be in scope in e. Both of these should have type Term

You can convert a Term value back into Agda syntax with unquote.

All of this can be bundled up using the tactic keyword. You can read a bit of slightly outdated information about tactic in the changelog and presumably more somewhere on the wiki. https://github.com/agda/agda/blob/master/CHANGELOG

1
votes

The proof of symmetry goes by looking at all possible cases for the arguments of ope. In Agda, you do reasoning by cases via pattern matching.