惯用地捕获“所有幂等半环都诱导出偏序”

时间:2019-03-26 11:41:02

标签: typeclass isabelle

我试图捕捉这样一个事实,即Isabelle / HOL中的任何幂等半环中都存在诱导的偏序,但是很难找到最佳/正确的方法。

我定义:

class idem_semiring_1 = semiring_1 +
  assumes idem [algebra_simps]: ‹a + a = a›
begin

definition less_eq :: ‹'a ⇒ 'a ⇒ bool›
  where ‹less_eq a b ⟷ a + b = b›

definition less :: ‹'a ⇒ 'a ⇒ bool›
  where ‹less a b ⟷ less_eq a b ∧ ¬ less_eq b a›

end

现在,很容易证明less_eqless满足order类型类的所有定律。但是,是否有一种方法可以说服Isabelle / HOL使用这些定义来使idem_semiring_1的任何实例也一定是order的实例,以便进行以下查询类型检查?

term ‹(y::'a::{idem_semiring_1}) ≤ x›

没有子类,子语言环境等的组合,魔咒似乎实现了我想要的。特别是以下内容:

sublocale idem_semiring_1 ⊆ order less_eq less
  by (standard; clarsimp simp add: algebra_simps less_eq_def less_def) (metis add.assoc)

似乎可以正常工作,因为在以下引理中,通过simp可以被证明是很简单的:

lemma
  fixes x::‹'a::{idem_semiring_1}›
  shows ‹less_eq x x›
    by simp

lemma
  assumes ‹less_eq x y›
      and ‹less_eq y z›
    shows ‹less_eq x z›
  using assms by simp

但以下内容不进行类型检查:

lemma
  fixes x :: ‹'a::{idem_semiring_1}›
  shows ‹x ≤ x›

我该如何说服Isabelle将语法与less_eq定义联系起来?

1 个答案:

答案 0 :(得分:1)

如果您这样定义idem_semiring_1怎么办?

class idem_semiring_1 = semiring_1 + order +
  assumes idem [algebra_simps]: ‹a + a = a› and
      less_eq_idem_semiring_1: ‹a ≤ b ⟷ a + b = b›