Simp不使用Isabelle中提供的引理
我正在做书中的练习2.6: 从“文本中定义的树”类型开始,定义函数内容::“树”⇒ '以任何顺序收集列表中树中所有值而不删除重复项的列表。然后定义一个函数sum_tree::nat tree⇒ 对自然数树中的所有值求和并证明sum_tree t=sum_list(contents t)(其中sum_list是预定义的)的nat 我已经开始证明这个定理,不是用auto,而是指导Isabelle使用必要的定理:Simp不使用Isabelle中提供的引理,isabelle,theorem-proving,simplification,Isabelle,Theorem Proving,Simplification,我正在做书中的练习2.6: 从“文本中定义的树”类型开始,定义函数内容::“树”⇒ '以任何顺序收集列表中树中所有值而不删除重复项的列表。然后定义一个函数sum_tree::nat tree⇒ 对自然数树中的所有值求和并证明sum_tree t=sum_list(contents t)(其中sum_list是预定义的)的nat 我已经开始证明这个定理,不是用auto,而是指导Isabelle使用必要的定理: theory Minimal imports Main begin datatyp
theory Minimal
imports Main
begin
datatype 'a tree = Tip | Node "'a tree" 'a "'a tree"
fun contents :: "'a tree ⇒ 'a list" where
"contents Tip = []"
| "contents (Node l a r) = a # (contents l) @ (contents r)"
fun sum_tree :: "nat tree ⇒ nat" where
"sum_tree Tip = 0"
| "sum_tree (Node l a r) = a + (sum_tree l) + (sum_tree r)"
lemma sum_list_contents:
"sum_list (contents t1) + sum_list (contents t2) = sum_list (contents t1 @ contents t2)"
apply auto
done
lemma sum_commutes: "sum_tree(t) = sum_list(contents(t))"
apply (induction t)
apply (simp only: sum_tree.simps contents.simps sum_list.Nil)
apply (simp only: sum_list.Cons contents.simps sum_tree.simps sum_list_contents)
在这里,它到达了一个证明状态
proof (prove)
goal (1 subgoal):
1. ⋀t1 x2 t2.
sum_tree t1 = sum_list (contents t1) ⟹
sum_tree t2 = sum_list (contents t2) ⟹
x2 + sum_list (contents t1) + sum_list (contents t2) = x2 + sum_list (contents t1 @ contents t2)
我想知道为什么simp
没有使用提供的sum\u list\u内容
引理。我知道simplesimp
可以解这个方程
一般的
simp
包含哪些simp only
在这种情况下不会使用的内容?正如注释中指出的,缺少的部分是自然数加法的关联性。将add.assoc
添加到simapplication规则中可以解决该方程
或者,可以更改定义树和时的操作数顺序:
fun sum_tree_1 :: "nat tree ⇒ nat" where
"sum_tree_1 Tip = 0"
| "sum_tree_1 (Node l a r) = a + ((sum_tree_1 l) + (sum_tree_1 r))"
则不需要关联性:
lemma sum_commutes_1: "sum_tree_1(t) = sum_list(contents(t))"
apply (induction t)
apply (simp only: sum_tree_1.simps contents.simps sum_list.Nil)
apply (simp only: sum_list.Cons contents.simps sum_tree_1.simps sum_list_contents)
done
这可能是因为
+
是左关联的,所以实际上你有(x2+sum\u list(contents t1))+sum\u list(contents t2)
,现在你的引理LHS不再匹配了。不过,我会等待专家告诉你解决这个问题的“正确”方法。