How can I describe this property of divisibility in Idris?

家住魔仙堡 提交于 2019-12-13 18:01:10

问题


I want to prove that if b (Integer) divides a (Integer), then b also divides a * c (where c is an Integer). First, I need to reformulate the problem into a computer understandable problem, here was an attempt:

-- 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)

However, I am getting TypeUnification failure. I am not really sure what is wrong.

  |
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

回答1:


In Idris, propositions are represented by types, while proofs of propositions are represented by elements of those types. The basic issue here is that you have defined divisibleBy as a function which returns an element (i.e. a proof) rather than a type (proposition). Thus, as you've defined it here, divisbleBy actually purports to be a proof that all integers are divisible by all other integers, which is clearly not true! I think what you're actually looking for is something like this.

DivisibleBy : Integer -> Integer -> Type
DivisibleBy a b = (n : Integer ** a = b * n)

alsoDividesMultiples : (a, b, c : Integer) ->
                       DivisibleBy a b ->
                       DivisibleBy (a * c) b


来源:https://stackoverflow.com/questions/52799362/how-can-i-describe-this-property-of-divisibility-in-idris

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!