用简单的定理证明重写

时间:2017-07-05 14:28:05

标签: proof dependent-type idris theorem-proving formal-verification

我在伊德里斯写了group的定义:

data Group: Type -> Type where
    Unit: (x: t) -> Group t
    (*): Group t -> Group t -> Group t
    Inv: Group t -> Group t
postulate
    assoc: (a : Group t) -> (b : Group t) -> (c : Group t) -> ((a*b)*c = a*(b*c))
postulate
    neutralL: (x: t) -> (a : Group t) -> a * Unit x = a
postulate
    neutralR: (x: t) -> (a : Group t) -> Unit x * a = a
postulate
    invUnitL: (x: t) -> (a : Group t) -> a * (Inv a) = Unit x
postulate
    invUnitR: (x: t) -> (a : Group t) -> (Inv a) * a = Unit x

然后我证明了几个简单的命题:

cong : (a : Group t) -> (b : Group t) -> (c: Group t) -> a = b -> a*c = b*c
cong a b c post = rewrite post in Refl

neutralL1: (x: t) -> (a : Group t) -> a = a * Unit x
neutralL1 x a = rewrite neutralL x a in Refl

neutralR1: (x: t) -> (a : Group t) -> a = Unit x * a
neutralR1 x a = rewrite neutralR x a in Refl

但是,我有一个问题,证明只有一个单位元素:

singleUnit : (x: t) -> (y: t) -> (Unit x = Unit y)

我尝试使用一般概念的各种表达方式Unit x =(neutralL1 y (Unit x))= Unit x * Unit y =(neutralR x (Unit y)})= Unit y,但是没有成功:

singleUnit x y = rewrite neutralL1 y (Unit x) in neutralR x (Unit y)
singleUnit x y = rewrite neutralL1 y (Unit x) in rewrite neutralR x (Unit y) in Refl
singleUnit x y = rewrite neutralR x (Unit y) in neutralL1 y (Unit x)
singleUnit x y = rewrite neutralR x (Unit y) in rewrite neutralL1 y (Unit x) in Refl

我该如何证明这一点? 我有一种感觉,这里的问题与复杂表达式的替换有关,比如Unit x * Unit y

2 个答案:

答案 0 :(得分:3)

不幸的是,这个群体的定义不起作用。一般来说,你必须非常小心地引入新的公理(假设)。

E.g。很容易看出neutralL违反了(不同的)数据构造函数的不相交原则,即Constr1 <data> != Constr2 <data>

starAndUnitAreDisjoint : (*) a (Unit x) = a -> Void
starAndUnitAreDisjoint Refl impossible

现在我们可以证明是假的:

contradiction : Void
contradiction = starAndUnitAreDisjoint $ neutralL Z (Unit Z)

Finita la commedia!

您真正想要的是record或类型类,请参阅例如contrib/Control/Algebra.idrcontrib/Interfaces/Verified.idr。此外,Agda版本在语法上非常接近Idris(agda-stdlib/src/Algebra.agda,可能还有Abstract Algebra in Agda教程) - 您可能希望看一下它们。

答案 1 :(得分:2)

您的组定义的结构是有意义的,如果它是一个接口。我按如下方式重写了它,尽可能保留原始变量和函数名称:

%default total

interface Group t where
  Unit: t
  (*): t -> t -> t
  Inv: t -> t

  assoc: (a : t) -> (b : t) -> (c : t) -> ((a*b)*c = a*(b*c))
  neutralL: (x: t) -> (a : t) -> a * Unit = a
  neutralR: (x: t) -> (a : t) -> Unit * a = a
  invUnitL: (x: t) -> (a : t) -> a * (Inv a) = Unit
  invUnitR: (x: t) -> (a : t) -> (Inv a) * a = Unit

cong : Group t => (a : t) -> (b : t) -> (c: t) -> a = b -> a*c = b*c
cong a b c post = rewrite post in Refl

neutralL1: Group t => (x: t) -> (a : t) -> a = a * Unit
neutralL1 x a = rewrite neutralL x a in Refl

neutralR1: Group t => (x: t) -> (a : t) -> a = Unit * a
neutralR1 x a = rewrite neutralR x a in Refl

is_left_unit : Group t => (x : t) -> Type
is_left_unit x = (y : t) -> x * y = y

only_one_left_unit : Group t => (x : t) -> is_left_unit x -> x = Unit
only_one_left_unit x is_left_unit_x = 
  let x_times_unit_is_unit = is_left_unit_x Unit in
  let x_times_unit_is_x = neutralL Unit x in
    trans (sym x_times_unit_is_x) x_times_unit_is_unit

is_right_unit : Group t => (x : t) -> Type
is_right_unit x = (y : t) -> y * x = y

only_one_right_unit : Group t => (x : t) -> is_right_unit x -> x = Unit
only_one_right_unit x is_right_unit_x = 
  let unit_times_x_is_unit = is_right_unit_x Unit in
  let unit_times_x_is_x = neutralR Unit x in
    trans (sym unit_times_x_is_x) unit_times_x_is_unit

您会注意到类型t实际上是组类型,而Unit是一个值而不是具有一个参数的函数。我已经定义了单独的函数is_left_unitis_right_unit,分别代表左或右单位的概念。

为了确保所有这一切都有意义,我们希望定义一些实际的具体组,为Unit*Inv提供实现,并为{{1}提供实现},assocneutralLneutralRinvUnitL代表证明义务。