Isabelle 如何为唯一性量词生成代码
以下是一个示例理论:Isabelle 如何为唯一性量词生成代码,isabelle,Isabelle,以下是一个示例理论: datatype ty = A | B | C inductive test where "test A B" | "test B B" | "test B C" inductive test2 where "The (λy. test x y) = y ⟹ test2 x y" code_pred [show_modes] test2 . values "{x. test2 A x}" 生成的代码尝试枚举ty,但失败(如中所示)。我无法使该数据类型
datatype ty = A | B | C
inductive test where
"test A B"
| "test B B"
| "test B C"
inductive test2 where
"The (λy. test x y) = y ⟹
test2 x y"
code_pred [show_modes] test2 .
values "{x. test2 A x}"
生成的代码尝试枚举ty
,但失败(如中所示)。我无法使该数据类型成为enum
的实例
生成以下代码等式:
test2_i_o ?xa ≡
Predicate.bind (Predicate.single ?xa)
(λxa. Predicate.bind (eq_i_o (The (test xa))) Predicate.single
我猜这个错误是因为等式包含test
而不是test\u I\u o
你能建议如何定义这样一个谓词吗?我知道了。我不应该使用
操作符。谓词的定义如下。使用inductify
指令可以很好地生成代码。在这种情况下会生成一个辅助谓词
inductive test_uniq where
"test x y ⟹
(∀z. test x z ⟶ y = z) ⟹
test_uniq x y"
code_pred [inductify, show_modes] test_uniq .
或者,可以明确定义辅助谓词:
inductive test_not_uniq where
"test x z ⟹
y ≠ z ⟹
test_not_uniq x y"
inductive test_uniq where
"test x y ⟹
¬ test_not_uniq x y ⟹
test_uniq x y"
code_pred [show_modes] test_uniq .
旧的错误答案
也许它可以帮助某人为操作员生成代码:
inductive test_ex where
"The (λy. test x y) = y ⟹
test_ex x y"
code_pred [show_modes] test .
lemma test_ex_code [code_pred_intro]:
"Predicate.the (test_i_o x) = y ⟹
test_ex x y"
by (rule test_ex.intros) (simp add: Predicate.the_def test_i_o_def)
code_pred [show_modes] test_ex
by (metis test_ex.cases test_ex_code)
inductive test2 where
"test_ex x y ⟹
test2 x y"
code_pred [show_modes] test2 .
values "{x. test2 A x}"
代码方程式现在包含test\u i\u o
,而不是test
:
test_ex_i_o ?xa =
Predicate.bind (Predicate.single ?xa)
(λxa. Predicate.bind (eq_i_o (Predicate.the (test_i_o xa))) Predicate.single)
我知道了。我不应该使用操作符。谓词的定义如下。使用inductify
指令可以很好地生成代码。在这种情况下会生成一个辅助谓词
inductive test_uniq where
"test x y ⟹
(∀z. test x z ⟶ y = z) ⟹
test_uniq x y"
code_pred [inductify, show_modes] test_uniq .
或者,可以明确定义辅助谓词:
inductive test_not_uniq where
"test x z ⟹
y ≠ z ⟹
test_not_uniq x y"
inductive test_uniq where
"test x y ⟹
¬ test_not_uniq x y ⟹
test_uniq x y"
code_pred [show_modes] test_uniq .
旧的错误答案
也许它可以帮助某人为操作员生成代码:
inductive test_ex where
"The (λy. test x y) = y ⟹
test_ex x y"
code_pred [show_modes] test .
lemma test_ex_code [code_pred_intro]:
"Predicate.the (test_i_o x) = y ⟹
test_ex x y"
by (rule test_ex.intros) (simp add: Predicate.the_def test_i_o_def)
code_pred [show_modes] test_ex
by (metis test_ex.cases test_ex_code)
inductive test2 where
"test_ex x y ⟹
test2 x y"
code_pred [show_modes] test2 .
values "{x. test2 A x}"
代码方程式现在包含test\u i\u o
,而不是test
:
test_ex_i_o ?xa =
Predicate.bind (Predicate.single ?xa)
(λxa. Predicate.bind (eq_i_o (Predicate.the (test_i_o xa))) Predicate.single)
在归纳定义中,运算符的作用是什么?由于在示例中使用了它,因此如何使用它没有多大意义,因为前提实际上没有编码这样一个事实,即test
对于x
,只有一个y
。因此,从逻辑上讲,test2c…
适用于某些…
,但逻辑不会告诉您哪个值。。。实际上是。我的实际用例如下。我为面向对象编程语言定义了类型规则。对象模型可以定义不明确的操作和关联。在这种情况下,程序员应该更精确地指定操作参数类型,或者应该指定关联的opposite端。在任何情况下,类型关系都应该返回唯一类型,或者根本不应该返回类型。你是对的,我的定义是错误的。只有test2ab
应保持不变。你能建议如何修正这个定义吗?非常感谢!我知道了,并更新了我的答案。解决方案基于中给出的技术,归纳定义中的运算符的目的是什么?由于在示例中使用了它,因此如何使用它没有多大意义,因为前提实际上没有编码这样一个事实,即test
对于x
,只有一个y
。因此,从逻辑上讲,test2c…
适用于某些…
,但逻辑不会告诉您哪个值。。。实际上是。我的实际用例如下。我为面向对象编程语言定义了类型规则。对象模型可以定义不明确的操作和关联。在这种情况下,程序员应该更精确地指定操作参数类型,或者应该指定关联的opposite端。在任何情况下,类型关系都应该返回唯一类型,或者根本不应该返回类型。你是对的,我的定义是错误的。只有test2ab
应保持不变。你能建议如何修正这个定义吗?非常感谢!我知道了,并更新了我的答案。该解决方案基于和中给出的技术