Isabelle中list类型order实例化证明报错:无法细化待处理目标
Isabelle实例化
order类时的子目标匹配错误原因分析 问题场景代码
datatype 'a list = Cons 'a "'a list" | Nil instantiation list :: (order) order begin fun less_eq_list :: "'a list ⇒ 'a list ⇒ bool" where "less_eq_list Nil Nil = True" | "less_eq_list (Cons _ _) Nil = True" | "less_eq_list Nil (Cons _ _) = False" | "less_eq_list (Cons _ a) (Cons _ b) = less_eq_list a b" instance proof fix x y:: "'a list" show "x ≤ x" apply(induct_tac x) apply(auto) done (* at this point the state is show x ≤ x Successful attempt to solve goal by exported rule: ?x2 ≤ ?x2 proof (state) this: x ≤ x goal (3 subgoals): 1. ⋀x y. (x < y) = (x ≤ y ∧ ¬ y ≤ x) 2. ⋀x y z. x ≤ y ⟹ y ≤ z ⟹ x ≤ z 3. ⋀x y. x ≤ y ⟹ y ≤ x ⟹ x = y *) show "(x < y) = (x ≤ y ∧ ¬ y ≤ x)" (* I get an error here Failed to refine any pending goal Local statement fails to refine any pending goal Failed attempt to solve goal by exported rule: (?x2 < ?y2) = (?x2 ≤ ?y2 ∧ ¬ ?y2 ≤ ?x2) *) qed end
错误原因
核心问题是子目标的变量绑定与你show语句中的变量不匹配:
- 证明状态里的第一个待解决子目标是
⋀x y. (x < y) = (x ≤ y ∧ ¬ y ≤ x),这里的⋀x y表示这是一个全称量化的目标,子目标内的x和y是全新的绑定变量。 - 你之前手动
fix x y:: "'a list"的变量,和子目标里被⋀绑定的变量不属于同一作用域,导致show "(x < y) = ..."无法匹配到带全称量词的子目标。
额外注意点
你定义的less_eq_list逻辑存在缺陷:当前实现忽略列表元素,仅通过递归尾部比较长度,这种“小于等于”关系不满足order类要求的反对称性——第三个子目标x ≤ y ⟹ y ≤ x ⟹ x = y会证明失败,因为两个长度相同但元素不同的列表会互相满足≤,但它们并不相等。
解决方向
- 移除手动
fix x y,让Isabelle自动处理变量绑定,直接用策略(如apply(auto))解决子目标; - 如果要手动匹配子目标,需要明确带上全称量词,写成
show "(⋀x y. (x < y) = (x ≤ y ∧ ¬ y ≤ x))"; - 修正
less_eq_list的定义,使其符合order类的公理要求(比如按字典序比较,同时考虑元素和长度)。
内容的提问来源于stack exchange,提问作者alagris
相关产品推荐
相关产品推荐

