我能编写该函数。
然而,Idris拒绝评估powApplyI的应用程序,使得?powApplyIZero_rhs的类型为powApplyI (Pos 0) i x = x(是的,Z被更改为0)。我已经尝试以非pointsfree风格编写powApplyI,并使用%elim修饰符定义自己的ZZ(我不理解),但这两种方法都没有奏效。为什么证明不能通过检查powApplyI的第一个情况来处理?
Idris版本:0.9.15.1
这里有一些东西:
powApply : Nat -> (a -> a) -> a -> a
powApply Z f = id
powApply (S k) f = f . powApply k f
并且可以轻松证明:
powApplyZero : (f : _) -> (x : _) -> powApp Z f x = x
powApplyZero f x = Refl
目前为止,一切都很好。现在,我想将这个函数推广到负指数。当然,必须提供一个倒数:
import Data.ZZ
-- Two functions, f and g, with a proof that g is an inverse of f
data Invertible : Type -> Type -> Type where
MkInvertible : (f : a -> b) -> (g : b -> a) ->
((x : _) -> g (f x) = x) -> Invertible a b
powApplyI : ZZ -> Invertible a a -> a -> a
powApplyI (Pos Z) (MkInvertible f g x) = id
powApplyI (Pos (S k)) (MkInvertible f g x) =
f . powApplyI (Pos k) (MkInvertible f g x)
powApplyI (NegS Z) (MkInvertible f g x) = g
powApplyI (NegS (S k)) (MkInvertible f g x) =
g . powApplyI (NegS k) (MkInvertible f g x)
接下来我试图证明一个类似的陈述:
powApplyIZero : (i : _) -> (x : _) -> powApplyI (Pos Z) i x = x
powApplyIZero i x = ?powApplyIZero_rhs
然而,Idris拒绝评估powApplyI的应用程序,使得?powApplyIZero_rhs的类型为powApplyI (Pos 0) i x = x(是的,Z被更改为0)。我已经尝试以非pointsfree风格编写powApplyI,并使用%elim修饰符定义自己的ZZ(我不理解),但这两种方法都没有奏效。为什么证明不能通过检查powApplyI的第一个情况来处理?
Idris版本:0.9.15.1
这里有一些东西:
powApplyNI : Nat -> Invertible a a -> a -> a
powApplyNI Z (MkInvertible f g x) = id
powApplyNI (S k) (MkInvertible f g x) = f . powApplyNI k (MkInvertible f g x)
powApplyNIZero : (i : _) -> (x : _) -> powApplyNI 0 i x = x
powApplyNIZero (MkInvertible f g y) x = Refl
powApplyZF : ZZ -> (a -> a) -> a -> a
powApplyZF (Pos Z) f = id
powApplyZF (Pos (S k)) f = f . powApplyZF (Pos k) f
powApplyZF (NegS Z) f = f
powApplyZF (NegS (S k)) f = f . powApplyZF (NegS k) f
powApplyZFZero : (f : _) -> (x : _) -> powApplyZF 0 f x = x
powApplyZFZero f x = ?powApplyZFZero_rhs
第一次的证明进行得很好,但 ?powApplyZFZero_rhs
始终保持着类型 powApplyZF (Pos 0) f x = x
。很明显,ZZ
存在问题(或者是我使用它的问题)。
i
上进行了模式匹配,但它不是处于弱头标准形式。尝试用case表达式替换对i
的模式匹配。或者你可以将签名重写为powApplyIZero: (f : _) -> (g : _) -> (eq : _) -> (x : _) -> powApplyI (Pos Z) (MkInvertible f g eq) x = x
。 - effectfullycase
表达式?我认为模式匹配/with
是证明中的规范方式。(我在左侧尝试了case
表达式和模式匹配。) - mudri