我如何在Idris中描述这个可分性属性?
我想证明,如果b(整数)除以a(整数),那么b也除以a*c(其中c是整数)。首先,我需要将这个问题重新表述为计算机可以理解的问题,下面是一个尝试:我如何在Idris中描述这个可分性属性?,idris,Idris,我想证明,如果b(整数)除以a(整数),那么b也除以a*c(其中c是整数)。首先,我需要将这个问题重新表述为计算机可以理解的问题,下面是一个尝试: -- 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
-- 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)
但是,我遇到了类型统一失败
。我真的不确定出了什么问题
|
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中,命题由类型表示,而命题的证明则由这些类型的元素表示。这里的基本问题是,您已经将
可除性by
定义为一个返回元素(即证明)而不是类型(命题)的函数。因此,正如您在这里定义的,divisibleby
实际上是证明所有整数都可以被所有其他整数整除,这显然不是真的!我想你实际上是在找这样的东西
DivisibleBy : Integer -> Integer -> Type
DivisibleBy a b = (n : Integer ** a = b * n)
alsoDividesMultiples : (a, b, c : Integer) ->
DivisibleBy a b ->
DivisibleBy (a * c) b
您是否可以包括完整的程序,或者至少包括这里描述的变量的实现?很难从中知道发生了什么。@Kwarrtz只有一行额外的
模块Numbris.Divisibility
(用于以后的软件包)。但是,可以将其删除,并给出相同的确切错误消息。换句话说,这是完整的程序。