How to rewrite term in type signature for proof in Idris? -


basically, want prove either n - m or m - n equal 0 in recursive arithmetic. accomplish have been trying use rewrite ... in ... pattern without sucess.

the following base code:

data natural = c | s natural  resta : natural -> natural -> natural resta     c     = resta c     b     = c resta (s a) (s b) = resta b  data algunoescero : (n, m : natural) -> type   izquierdoescero : algunoescero c m   derechoescero :   algunoescero n c  alguna_resta_es_cero : (n, m: natural) -> algunoescero (resta n m) (resta m n) alguna_resta_es_cero c     m     = ?hoyo1 alguna_resta_es_cero n     c     = ?hoyo2 alguna_resta_es_cero (s n) (s m) = ?hoyo3 

however, when inspecting first 2 holes

- + main.hoyo1 [p]  `--           m : natural      -----------------------------------------       main.hoyo1 : algunoescero (resta c m) m  - + main.hoyo2 [p]  `--           n : natural      -----------------------------------------       main.hoyo2 : algunoescero n (resta c n) 

the way have been able move forward lemma in data algunoescero; way forward have read rewrite type using theorem like

cero_menos_algo_es_cero : (m: natural) -> resta c m = c cero_menos_algo_es_cero c     = refl cero_menos_algo_es_cero (s m) = refl 

so easy point out of 2 minus going 0 , build datatype rewrite cero_menos_algo_es_cero in izquierdoescero. spits out:

when checking right hand side of alguna_resta_es_cero expected type              algunoescero (resta c m) (resta m c)       _ not have equality type ((m1 : natural) -> resta c m1 = c) 

any resource pointers appreciated. (haven't been able find points in type driven development nor on documentation; maybe misunderstanding rewrite / proofs in general)

you need pattern-match 1 more time finish proof:

alguna_resta_es_cero : (n, m: natural) -> algunoescero (resta n m) (resta m n) alguna_resta_es_cero c c = izquierdoescero alguna_resta_es_cero c (s x) = izquierdoescero alguna_resta_es_cero (s x) c = derechoescero alguna_resta_es_cero (s x) (s y) = alguna_resta_es_cero x y 

also, if defined subtraction function as

resta : natural -> natural -> natural resta c     b     = c resta     c     = resta (s a) (s b) = resta b 

(notice pattern-match on first argument, opposed version starts pattern-matching on second one), proof of alguna_resta_es_cero mimic structure of function more closely:

alguna_resta_es_cero : (n, m: natural) -> algunoescero (resta n m) (resta m n) alguna_resta_es_cero c m = izquierdoescero alguna_resta_es_cero (s x) c = derechoescero alguna_resta_es_cero (s x) (s y) = alguna_resta_es_cero x y 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -