在试图解决我提出的问题时
here
,我发现refl证明的可接受性(由Agda)以一种奇怪的方式取决于在方程一侧调用的函数的参数顺序。
在下面的代码中,看看除了下面4个定理中的一个之外,其他所有定理都是如何用refl证明的。需要注意的是
join
和
join'
仅在参数的顺序上不同。相应地,我认为
thm
调用它们的s应该被等价地证明,但显然不是这样。
为什么会出现这种差异?这是否代表Agda中的错误?我如何证明剩余定理(
thm1
)?
open import Data.Nat
open import Data.Product
-- Stolen (with little modification) from Data.AVL
data ââ : Set where
0# : ââ
1# : ââ
infixl 6 _â_
_â_ : ââ â â â â
0# â n = n
1# â n = suc n
infix 4 _â¼_â_
data _â¼_â_ : â â â â â â Set where
â¼+ : â {n} â n â¼ suc n â suc n
â¼0 : â {n} â n â¼ n â n
â¼- : â {n} â suc n â¼ n â suc n
maxâ¼ : â {i j m} â i â¼ j â m â m â¼ i â m
maxâ¼ â¼+ = â¼-
maxâ¼ â¼0 = â¼0
maxâ¼ â¼- = â¼0
â¼max : â {i j m} â i â¼ j â m â j â¼ m â m
â¼max â¼+ = â¼0
â¼max â¼0 = â¼0
â¼max â¼- = â¼+
-- for simplicity, this tree has no keys
data Tree : â â Set where
leaf : Tree 0
node : â {l u h}
(L : Tree l)
(U : Tree u)
(bal : l â¼ u â h) â
Tree (suc h)
-- similar to joinˡ⺠from Data.AVL
join : â {hË¡ hʳ h : â} â
(â λ i â Tree (i â hË¡)) â
Tree hʳ â
(bal : hË¡ â¼ hʳ â h) â
â λ i â Tree (i â (suc h))
join (1# , node tâ
(node tâ tâ
bal)
â¼+) tâ â¼- = (0# , node
(node tâ tâ (maxâ¼ bal))
(node tâ
tâ (â¼max bal))
â¼0)
join (1# , node tâ tâ â¼-) tâ
â¼- = (0# , node tâ (node tâ tâ
â¼0) â¼0)
join (1# , node tâ tâ â¼0) tâ
â¼- = (1# , node tâ (node tâ tâ
â¼-) â¼+)
join (1# , tâ) tâ â¼0 = (1# , node tâ tâ â¼-)
join (1# , tâ) tâ â¼+ = (0# , node tâ tâ â¼0)
join (0# , tâ) tâ bal = (0# , node tâ tâ bal)
-- just like join but with "bal" earlier in the argument list
join' : â {hË¡ hʳ h : â} â
(bal : hË¡ â¼ hʳ â h) â
(â λ i â Tree (i â hË¡)) â
Tree hʳ â
â λ i â Tree (i â (suc h))
join' â¼- (1# , node tâ
(node tâ tâ
bal)
â¼+) tâ = (0# , node
(node tâ tâ (maxâ¼ bal))
(node tâ
tâ (â¼max bal))
â¼0)
join' â¼- (1# , node tâ tâ â¼-) tâ
= (0# , node tâ (node tâ tâ
â¼0) â¼0)
join' â¼- (1# , node tâ tâ â¼0) tâ
= (1# , node tâ (node tâ tâ
â¼-) â¼+)
join' â¼0 (1# , tâ) tâ = (1# , node tâ tâ â¼-)
join' â¼+ (1# , tâ) tâ = (0# , node tâ tâ â¼0)
join' bal (0# , tâ) tâ = (0# , node tâ tâ bal)
open import Relation.Binary.PropositionalEquality
thm0 : â {h : â} (tl : Tree h ) (tr : Tree (suc h)) â join (0# , tl) tr â¼+ â¡ (0# , node tl tr â¼+)
thm0 tl tr = refl
thm1 : â {h : â} (tl : Tree (suc h)) (tr : Tree (suc h)) â join (1# , tl) tr â¼+ â¡ (0# , node tl tr â¼0)
thm1 tl tr = {!!} -- FIXME refl doesn't work here!
thm0' : â {h : â} (tl : Tree h ) (tr : Tree (suc h)) â join' â¼+ (0# , tl) tr â¡ (0# , node tl tr â¼+)
thm0' tl tr = refl
thm1' : â {h : â} (tl : Tree (suc h)) (tr : Tree (suc h)) â join' â¼+ (1# , tl) tr â¡ (0# , node tl tr â¼0)
thm1' tl tr = refl -- refl works fine here, and all I did was switch the order of arguments to join(')
如果我想证明
第1页
使用refl,我得到以下错误:
projâ (join (1# , tl) tr â¼+) != 0# of type ââ
when checking that the expression refl has type
join (1# , tl) tr â¼+ â¡ (0# , node tl tr â¼0)
注意:这是使用Agda 2.4.2.3和相同版本的stdlib(从github中提取
here
.