尝试评估`coprime`时出错

时间:2017-02-17 19:19:19

标签: isabelle

我想使用Isabelle coprime中定义的GCD函数,并对其进行一些处理。 为什么value "coprime Suc(Suc 0) Suc(Suc(Suc (Suc 0)))"会返回错误

Type unification failed: No type arity fun :: gcd

Type error in application: incompatible operand type

Operator:  coprime :: ??'a ⇒ ??'a ⇒ bool
Operand:   Suc :: nat ⇒ nat

Coercion Inference:

Local coercion insertion on the operand failed:
No type arity fun :: gcd

Now trying to infer coercions globally.

Coercion inference failed:
weak unification of subtype constraints fails
Clash of types "_ ⇒ _" and "nat"

而不是false

value "coprime 0 0"也是如此。)

最小的MWE w.r.t答案:

(*<*) theory T
  imports   
 Main
"~~/src/HOL/Number_Theory/Number_Theory"
begin (*>*)

value "coprime 2 (4 :: nat))"

(*<*) end (*>*)

1 个答案:

答案 0 :(得分:0)

这里有很多问题。

  1. 应该是value "coprime (Suc(Suc 0)) (Suc(Suc(Suc (Suc 0))))"。函数应用程序绑定最强并关联到左侧,因此您编写的内容将被解释为coprime应用于SucSuc 0以及其他一些参数,这是一个类型错误。

  2. coprime 0 0在我的Isabelle版本中效果很好;它输出有点令人困惑的"equal_class.equal (gcd 0 0) 1" :: "bool"。这样做的原因是该术语中没有任何内容表明0是一个自然数,并且多态常数的评估往往是有问题的。即使像2 ≠ 4这样的内容也不会评估为True,因为这取决于24的类型。如果你写coprime 0 (0::nat),一切都按预期工作。

  3. 此外,编写value "coprime 2 (4 :: nat)而不是使用后继符号会更方便。