Proofs of functions depending on the ordering of their alternatives

With enough experience at Haskell, I recently started using Idris to prove the theorem. This is a minimal example illustrating the problem that I encountered when trying to prove fairly simple statements.

Consider that we have a complete function test:

total test : Integer -> Integer
test 1 = 1
test n = n

Of course, we see that the function can be simplified to test n = n, but let it prove. I just look through all the cases:

total lemma_test : (n : Integer) -> test n = n
lemma_test 1 = Refl
lemma_test n = Refl

But this does not check the type:

Type mismatch between
        n = n (Type of Refl) and
        test n = n (Expected type)

Specifically:
        Type mismatch between
                n
        and
                test n

So the problem is that Idris cannot conclude the second case lemma_test, which is nnot the same 1and that the second case should also apply test.

, , , , Integer s:

total lemma_test : (n : Integer) -> test n = n
lemma_test 1 = Refl
lemma_test 2 = Refl
lemma_test 3 = Refl
...

, , , , test ?

, , , , .

+4
3

, Integer , Idris, . , , ( Agda !) , , . test n = 1 , n 1.

, (Boolean ) :

import Prelude

%default total

test : Integer -> Integer
test n with (decEq n 1)
  test n | Yes p = 1
  test n | No  p = n

lemma_test : (n : Integer) -> (test n) = n
lemma_test n with (decEq n 1)
 lemma_test _ | (Yes Refl)  = Refl
 lemma_test n | (No contra) = Refl

No .

+2

, Integer, .., ; , , Nat ? (, , Nat, naturals?)

test Nat s:

total test : Nat -> Nat
test (S Z) = 1
test n = n

lemma_test:

total lemma_test : (n : Nat) -> test n = n
lemma_test (S Z) = Refl
lemma_test Z = Refl
lemma_test (S (S k)) = Refl
+1

Integer Idris, GMP bigints. , , -, , . - Nat, , .

n, test n, , Idris test n. , - , , afaik. , Integer ?

repl, labmda. . \n => test n \n => test n : Integer -> Integer ( ), , test 1 = 1 , \n => n : Integer -> Integer - test n n. .

+1

All Articles