简体   繁体   中英

Why Left Identity over “Addition” is trivial proof but Right Identity is not?

I am just learning the Agda, but I do not understand that when I am trying to prove Identity over Addition then, I see that Left Identity is trivial proof.

left+identity : ∀ n -> (zero + n) ≡ n
left+identity n = refl

But It is not true for Right Identity.

right+identity : ∀ n -> (n + zero) ≡ n
right+identity zero = refl
right+identity (suc n) = cong suc (right+identity n)

I can not understand the reason. Please explain. Thanks.

The problem is how dependent typed theories deal with equality. Usually, the definition of addition is:

_+_ : Nat -> Nat -> Nat
zero + m = m              -- (1)
(suc n) + m = suc (n + m) -- (2)

Notice that equation one implies left identity. When you have:

 forall n -> 0 + n = n

Agda's type checker can use equation (1) of addition to verify that the equality holds. Remember, the propositional equality constructor ( refl ) has the type

 refl : x == x

So, when you use refl as an proof for the left identity, Agda will try to reduce both sides of equality (normalize them) and check if they are indeed equal. Using the definition of addition, left identity is immediate, by equation (1).

But for the right identity this does not hold by definition. Note that when we have

n + 0 == n

Agda's type checker cannot use addition equations in order to check that this equality indeed hold. The only way to prove this equality is using induction (or, if your prefer, recursion).

Hope that this can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM