我试图证明二进制排序树插入。我在证明的中间,环境看起来像这样:
-- new rx : ℕ
Goal: SortedTree (node leaf x (node (insertTree new rl) rx rr))
Have: SortedTree (insertTree new (node rl rx rr) | new ≤? rx)
————————————————————————————————————————————————————————————
new≤rx : new ≤ rx
请注意AFAIK表示的| new ≤? rx
"我需要知道价值以进一步减少它"
如何申请new≤rx?
insertTree的定义如下:
insertTree : (a : ℕ) → (t : Tree ℕ) → Tree ℕ
insertTree a (node l x r) with a ≤? x
insertTree a (node l x r) | yes p = node (insertTree a l) x r
insertTree a (node l x r) | no ¬p = node l x (insertTree a r)
我知道新的价值≤? rx(它的yes new≤rx
),实际上我with
正在new ≤? x
编辑:
... | no ¬n≤x with new ≤? rx
... | yes new≤rx = {!proof⟦insertTree⟧ (node rl rx rr) (sorted-rhs st) new !}
... | no p = {!!}
那么我怎么能告诉agda new ≤? rx
的值是已知的并且它应该随之而来
insertTree a (node l x r) | yes p = node (insertTree a l) x r
?
我尝试使用重写
where prf : (new ≤? rx ≡ yes new≤rx) → SortedTree (node (insertTree new rl) rx rr)
prf p1 rewrite p1 = {!proof⟦insertTree⟧ (node rl rx rr) (sorted-rhs st) new !}
但即使我有p1 : new ≤? rx ≡ yes new≤rx
,agda也会忽略它,并说我有SortedTree (insertTree new (node rl rx rr) | new ≤? rx)
答案 0 :(得分:1)
我设法通过inspect + rewrite得到了它。
proof⟦insertTree⟧ (node leaf x (node rl rx rr)) st new with new ≤? x
... | yes p = st-node (empty new) (sorted-rhs st) p (st-cmp-rhs st)
... | no ¬n≤x with new ≤? rx | inspect (_≤?_ new) rx
... | yes p | PropEq.[ eq ] = {!!}
where prf : (new ≤? rx ≡ yes p) → SortedTree (insertTree new (node rl rx rr)) → SortedTree (node (insertTree new rl) rx rr)
prf p0 p rewrite p0 = p
请注意,prf
subproof接受p
类型的SortedTree (insertTree new (node rl rx rr))
并返回p
本身,但由于重写,返回的类型已更改。