我如何描述 Idris 中的这种 属性 可分性?
How can I describe this property of divisibility in Idris?
我想证明如果b(Integer)整除a(Integer),那么b也整除a * c(其中c是一个Integer)。首先,我需要将问题重新表述为计算机可以理解的问题,这是一次尝试:
-- If a is divisible by b, then there exists an integer such that a = b * n
divisibleBy : (a, b : Integer) ->
(n : Integer **
(a = b * n))
-- If b | a then b | ac.
alsoDividesMultiples : (a, b, c : Integer) ->
(divisibleBy a b) ->
(divisibleBy (a * c) b)
但是,我得到 TypeUnification failure
。我不太确定哪里出了问题。
|
7 | alsoDividesMultiples : (a, b, c : Integer) ->
| ^
When checking type of Numbris.Divisibility.alsoDividesMultiples:
Type mismatch between
(n : Integer ** a = b * n) (Type of divisibleBy a b)
and
Type (Expected type)
Specifically:
Type mismatch between
(n : Integer ** a = prim__mulBigInt b n)
and
TypeUnification failure
In context:
a : Integer
b : Integer
c : Integer
{a_509} : Integer
{b_510} : Integer
在 Idris 中,命题由类型表示,而命题的证明由这些类型的元素表示。这里的基本问题是您已将 divisibleBy
定义为一个函数,其中 returns 是一个元素(即证明)而不是类型(命题)。因此,正如您在此处定义的那样,divisbleBy
实际上声称证明所有整数都可以被所有其他整数整除,这显然不是真的!我想你真正要找的是这样的东西。
DivisibleBy : Integer -> Integer -> Type
DivisibleBy a b = (n : Integer ** a = b * n)
alsoDividesMultiples : (a, b, c : Integer) ->
DivisibleBy a b ->
DivisibleBy (a * c) b
我想证明如果b(Integer)整除a(Integer),那么b也整除a * c(其中c是一个Integer)。首先,我需要将问题重新表述为计算机可以理解的问题,这是一次尝试:
-- If a is divisible by b, then there exists an integer such that a = b * n
divisibleBy : (a, b : Integer) ->
(n : Integer **
(a = b * n))
-- If b | a then b | ac.
alsoDividesMultiples : (a, b, c : Integer) ->
(divisibleBy a b) ->
(divisibleBy (a * c) b)
但是,我得到 TypeUnification failure
。我不太确定哪里出了问题。
|
7 | alsoDividesMultiples : (a, b, c : Integer) ->
| ^
When checking type of Numbris.Divisibility.alsoDividesMultiples:
Type mismatch between
(n : Integer ** a = b * n) (Type of divisibleBy a b)
and
Type (Expected type)
Specifically:
Type mismatch between
(n : Integer ** a = prim__mulBigInt b n)
and
TypeUnification failure
In context:
a : Integer
b : Integer
c : Integer
{a_509} : Integer
{b_510} : Integer
在 Idris 中,命题由类型表示,而命题的证明由这些类型的元素表示。这里的基本问题是您已将 divisibleBy
定义为一个函数,其中 returns 是一个元素(即证明)而不是类型(命题)。因此,正如您在此处定义的那样,divisbleBy
实际上声称证明所有整数都可以被所有其他整数整除,这显然不是真的!我想你真正要找的是这样的东西。
DivisibleBy : Integer -> Integer -> Type
DivisibleBy a b = (n : Integer ** a = b * n)
alsoDividesMultiples : (a, b, c : Integer) ->
DivisibleBy a b ->
DivisibleBy (a * c) b