代码之家  ›  专栏  ›  技术社区  ›  Denis

如何生成存在量词的代码

  •  0
  • Denis  · 技术社区  · 7 年前

    这是一个样本理论:

    datatype ty = A | B | C
    
    inductive test where
      "test A B"
    | "test B C"
    
    inductive test2 where
      "¬(∃z. test x z) ⟹ test2 x"
    
    code_pred [show_modes] test .
    code_pred [show_modes] test2 .
    
    values "{x. test2 A}"
    

    ty . 所以失败了。

    test 谓语:

    definition "test_ex x ≡ ∃y. test x y"
    
    definition "test_ex_fun x ≡
      Predicate.singleton (λ_. False)
        (Predicate.map (λ_. True) (test_i_o x))"
    
    lemma test_ex_code [code_abbrev, simp]:
      "test_ex_fun = test_ex"
      apply (intro ext)
      unfolding test_ex_def test_ex_fun_def Predicate.singleton_def
      apply (simp split: if_split)
    

    0 回复  |  直到 7 年前
        1
  •  2
  •   Andreas Lochbihler    7 年前

    归纳谓词的参数上的存在量词可以通过引入另一个归纳谓词来执行。例如:

    inductive test2_aux where "test x z ==> test2_aux x"
    inductive test2 where "~ test2_aux x ==> test2 x"
    

    适当的 code_pred z test2_aux 有一个预处理器来执行此操作:

    code_pred [inductify] test2 .
    

        2
  •  2
  •   René Thiemann    7 年前

    好, values ty 不是那种 enum . 因此,在这种特殊情况下,执行这个实例化是最容易的。

    instantiation ty :: enum
    begin
    definition enum_ty :: "ty list" where
      "enum_ty = [A,B,C]"  
    definition "enum_all_ty f = list_all f [A,B,C]" 
    definition "enum_ex_ty f = list_ex f [A,B,C]" 
    instance
    proof (intro_classes)
      let ?U = "UNIV :: ty set" 
      show id: "?U = set enum_class.enum" 
        unfolding enum_ty_def
        using ty.exhaust by auto
      fix P
      show "enum_class.enum_all P = Ball ?U P" 
        "enum_class.enum_ex P = Bex ?U P" 
        unfolding id enum_all_ty_def enum_ex_ty_def enum_ty_def by auto
      show "distinct (enum_class.enum :: ty list)" unfolding enum_ty_def by auto
    qed
    

    之后,你的 -命令的计算没有问题。

        3
  •  0
  •   Denis    7 年前

    我认为引理是不可证明的,我应该找到另一种方法。但可以证明如下:

    lemma test_ex_code [code_abbrev, simp]:
      "Predicate.singleton (λ_. False)
        (Predicate.map (λ_. True) (test_i_o x)) = (∃y. test x y)"
      apply (intro ext iffI)
      unfolding Predicate.singleton_def
      apply (simp_all split: if_split)
      apply (metis SUP1_E mem_Collect_eq pred.sel test_i_o_def)
      apply (intro conjI impI)
      apply (smt SUP1_E the_equality)
      apply (metis (full_types) SUP1_E SUP1_I mem_Collect_eq pred.sel test_i_o_def)
      done
    

    推荐文章