我想使用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 (*>*)
答案 0 :(得分:0)
这里有很多问题。
应该是value "coprime (Suc(Suc 0)) (Suc(Suc(Suc (Suc 0))))"
。函数应用程序绑定最强并关联到左侧,因此您编写的内容将被解释为coprime
应用于Suc
,Suc 0
以及其他一些参数,这是一个类型错误。
coprime 0 0
在我的Isabelle版本中效果很好;它输出有点令人困惑的"equal_class.equal (gcd 0 0) 1" :: "bool"
。这样做的原因是该术语中没有任何内容表明0
是一个自然数,并且多态常数的评估往往是有问题的。即使像2 ≠ 4
这样的内容也不会评估为True
,因为这取决于2
和4
的类型。如果你写coprime 0 (0::nat)
,一切都按预期工作。
此外,编写value "coprime 2 (4 :: nat)
而不是使用后继符号会更方便。