Theory Arities

sectionArities of internalized formulas
theory Arities
  imports
    Internalizations
    Discipline_Base
begin

lemmas FOL_arities [simp del, arity] = arity_And arity_Or arity_Implies arity_Iff arity_Exists

declare pred_Un_distrib[arity_aux]

context
  notes FOL_arities[simp]
begin

lemma arity_upair_fm [arity] : "  t1nat ; t2nat ; upnat   
  arity(upair_fm(t1,t2,up)) =  {succ(t1),succ(t2),succ(up)}"
  unfolding  upair_fm_def
  using union_abs1 union_abs2 pred_Un
  by auto


lemma arity_pair_fm [arity] : "  t1nat ; t2nat ; pnat   
  arity(pair_fm(t1,t2,p)) =  {succ(t1),succ(t2),succ(p)}"
  unfolding pair_fm_def
  using arity_upair_fm union_abs1 union_abs2 pred_Un
  by auto

lemma arity_composition_fm [arity] :
  " rnat ; snat ; tnat   arity(composition_fm(r,s,t)) =  {succ(r), succ(s), succ(t)}"
  unfolding composition_fm_def
  using arity_pair_fm union_abs1 union_abs2 pred_Un_distrib
  by auto

lemma arity_domain_fm [arity] :
    " rnat ; znat   arity(domain_fm(r,z)) = succ(r)  succ(z)"
  unfolding domain_fm_def
  using arity_pair_fm union_abs1 union_abs2 pred_Un_distrib
  by auto

lemma arity_range_fm [arity] :
    " rnat ; znat   arity(range_fm(r,z)) = succ(r)  succ(z)"
  unfolding range_fm_def
  using arity_pair_fm union_abs1 union_abs2 pred_Un_distrib
  by auto

lemma arity_union_fm [arity] :
  " xnat ; ynat ; znat   arity(union_fm(x,y,z)) =  {succ(x), succ(y), succ(z)}"
  unfolding union_fm_def
  using  union_abs1 union_abs2 pred_Un_distrib
  by auto

lemma arity_image_fm [arity] :
  " xnat ; ynat ; znat   arity(image_fm(x,y,z)) =  {succ(x), succ(y), succ(z)}"
  unfolding image_fm_def
  using arity_pair_fm  union_abs1 union_abs2 pred_Un_distrib
  by auto

lemma arity_pre_image_fm [arity] :
  " xnat ; ynat ; znat   arity(pre_image_fm(x,y,z)) =  {succ(x), succ(y), succ(z)}"
  unfolding pre_image_fm_def
  using arity_pair_fm  union_abs1 union_abs2 pred_Un_distrib
  by auto


lemma arity_big_union_fm [arity] :
  " xnat ; ynat   arity(big_union_fm(x,y)) = succ(x)  succ(y)"
  unfolding big_union_fm_def
  using union_abs1 union_abs2 pred_Un_distrib
  by auto

lemma arity_fun_apply_fm [arity] :
  " xnat ; ynat ; fnat  
    arity(fun_apply_fm(f,x,y)) =  succ(f)  succ(x)  succ(y)"
  unfolding fun_apply_fm_def
  using arity_upair_fm arity_image_fm arity_big_union_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_field_fm [arity] :
    " rnat ; znat   arity(field_fm(r,z)) = succ(r)  succ(z)"
  unfolding field_fm_def
  using arity_pair_fm arity_domain_fm arity_range_fm arity_union_fm
    union_abs1 union_abs2 pred_Un_distrib
  by auto

lemma arity_empty_fm [arity]:
    " rnat   arity(empty_fm(r)) = succ(r)"
  unfolding empty_fm_def
  using union_abs1 union_abs2 pred_Un_distrib
  by simp

lemma arity_cons_fm [arity] :
  "xnat;ynat;znat  arity(cons_fm(x,y,z)) = succ(x)  succ(y)  succ(z)"
  unfolding cons_fm_def
  using arity_upair_fm arity_union_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_succ_fm [arity] :
  "xnat;ynat  arity(succ_fm(x,y)) = succ(x)  succ(y)"
  unfolding succ_fm_def
  using arity_cons_fm
  by auto

lemma arity_number1_fm [arity] :
    " rnat   arity(number1_fm(r)) = succ(r)"
  unfolding number1_fm_def
  using arity_empty_fm arity_succ_fm union_abs1 union_abs2 pred_Un_distrib
  by simp

lemma arity_function_fm [arity] :
    " rnat   arity(function_fm(r)) = succ(r)"
  unfolding function_fm_def
  using arity_pair_fm union_abs1 union_abs2 pred_Un_distrib
  by simp

lemma arity_relation_fm [arity] :
    " rnat   arity(relation_fm(r)) = succ(r)"
  unfolding relation_fm_def
  using arity_pair_fm union_abs1 union_abs2 pred_Un_distrib
  by simp

lemma arity_restriction_fm [arity] :
    " rnat ; znat ; Anat   arity(restriction_fm(A,z,r)) = succ(A)  succ(r)  succ(z)"
  unfolding restriction_fm_def
  using arity_pair_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_typed_function_fm [arity] :
  " xnat ; ynat ; fnat  
    arity(typed_function_fm(f,x,y)) =  {succ(f), succ(x), succ(y)}"
  unfolding typed_function_fm_def
  using arity_pair_fm arity_relation_fm arity_function_fm arity_domain_fm
    union_abs2 pred_Un_distrib
  by auto


lemma arity_subset_fm [arity] :
  "xnat ; ynat  arity(subset_fm(x,y)) = succ(x)  succ(y)"
  unfolding subset_fm_def
  using union_abs2 pred_Un_distrib
  by auto

lemma arity_transset_fm [arity] :
  "xnat  arity(transset_fm(x)) = succ(x)"
  unfolding transset_fm_def
  using arity_subset_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_ordinal_fm [arity] :
  "xnat  arity(ordinal_fm(x)) = succ(x)"
  unfolding ordinal_fm_def
  using arity_transset_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_limit_ordinal_fm [arity] :
  "xnat  arity(limit_ordinal_fm(x)) = succ(x)"
  unfolding limit_ordinal_fm_def
  using arity_ordinal_fm arity_succ_fm arity_empty_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_finite_ordinal_fm [arity] :
  "xnat  arity(finite_ordinal_fm(x)) = succ(x)"
  unfolding finite_ordinal_fm_def
  using arity_ordinal_fm arity_limit_ordinal_fm arity_succ_fm arity_empty_fm
    union_abs2 pred_Un_distrib
  by auto

lemma arity_omega_fm [arity] :
  "xnat  arity(omega_fm(x)) = succ(x)"
  unfolding omega_fm_def
  using arity_limit_ordinal_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_cartprod_fm [arity] :
  " Anat ; Bnat ; znat   arity(cartprod_fm(A,B,z)) = succ(A)  succ(B)  succ(z)"
  unfolding cartprod_fm_def
  using arity_pair_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_singleton_fm [arity] :
  "xnat ; tnat  arity(singleton_fm(x,t)) = succ(x)  succ(t)"
  unfolding singleton_fm_def cons_fm_def
  using arity_union_fm arity_upair_fm arity_empty_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_Memrel_fm [arity] :
  "xnat ; tnat  arity(Memrel_fm(x,t)) = succ(x)  succ(t)"
  unfolding Memrel_fm_def
  using  arity_pair_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_quasinat_fm [arity] :
  "xnat  arity(quasinat_fm(x)) = succ(x)"
  unfolding quasinat_fm_def cons_fm_def
  using arity_succ_fm arity_empty_fm
    union_abs2 pred_Un_distrib
  by auto

lemma arity_is_recfun_fm [arity] :
  "pformula ; vnat ; nnat; Znat;inat   arity(p) = i 
  arity(is_recfun_fm(p,v,n,Z)) = succ(v)  succ(n)  succ(Z)  pred(pred(pred(pred(i))))"
  unfolding is_recfun_fm_def
  using arity_upair_fm arity_pair_fm arity_pre_image_fm arity_restriction_fm
    union_abs2 pred_Un_distrib
  by auto

lemma arity_is_wfrec_fm [arity] :
  "pformula ; vnat ; nnat; Znat ; inat  arity(p) = i 
    arity(is_wfrec_fm(p,v,n,Z)) = succ(v)  succ(n)  succ(Z)  pred(pred(pred(pred(pred(i)))))"
  unfolding is_wfrec_fm_def
  using arity_succ_fm  arity_is_recfun_fm
     union_abs2 pred_Un_distrib
  by auto

lemma arity_is_nat_case_fm [arity] :
  "pformula ; vnat ; nnat; Znat; inat  arity(p) = i 
    arity(is_nat_case_fm(v,p,n,Z)) = succ(v)  succ(n)  succ(Z)  pred(pred(i))"
  unfolding is_nat_case_fm_def
  using arity_succ_fm arity_empty_fm arity_quasinat_fm
    union_abs2 pred_Un_distrib
  by auto

lemma arity_iterates_MH_fm [arity] :
  assumes "isFformula" "vnat" "nnat" "gnat" "znat" "inat"
      "arity(isF) = i"
    shows "arity(iterates_MH_fm(isF,v,n,g,z)) =
           succ(v)  succ(n)  succ(g)  succ(z)  pred(pred(pred(pred(i))))"
proof -
  let  = "Exists(And(fun_apply_fm(succ(succ(succ(g))), 2, 0), Forall(Implies(Equal(0, 2), isF))))"
  let ?ar = "succ(succ(succ(g)))  pred(pred(i))"
  from assms
  have "arity() =?ar" "formula"
    using arity_fun_apply_fm
    union_abs1 union_abs2 pred_Un_distrib succ_Un_distrib Un_assoc[symmetric]
    by simp_all
  then
  show ?thesis
    unfolding iterates_MH_fm_def
    using arity_is_nat_case_fm[OF _ _ _ _ _ arity() = ?ar] assms pred_succ_eq pred_Un_distrib
    by auto
qed

lemma arity_is_iterates_fm [arity] :
  assumes "pformula" "vnat" "nnat" "Znat" "inat"
    "arity(p) = i"
  shows "arity(is_iterates_fm(p,v,n,Z)) = succ(v)  succ(n)  succ(Z) 
          pred(pred(pred(pred(pred(pred(pred(pred(pred(pred(pred(i)))))))))))"
proof -
  let  = "iterates_MH_fm(p, 7#+v, 2, 1, 0)"
  let  = "is_wfrec_fm(, 0, succ(succ(n)),succ(succ(Z)))"
  from v_
  have "arity() = (8#+v)  pred(pred(pred(pred(i))))" "formula"
    using assms arity_iterates_MH_fm union_abs2
    by simp_all
  then
  have "arity() = succ(succ(succ(n)))  succ(succ(succ(Z)))  (3#+v) 
      pred(pred(pred(pred(pred(pred(pred(pred(pred(i)))))))))"
    using assms arity_is_wfrec_fm[OF _ _ _ _ _ arity() = _] union_abs1 pred_Un_distrib
    by auto
  then
  show ?thesis
    unfolding is_iterates_fm_def
    using arity_Memrel_fm arity_succ_fm assms union_abs1 pred_Un_distrib
    by auto
qed

lemma arity_eclose_n_fm [arity] :
  assumes "Anat" "xnat" "tnat"
  shows "arity(eclose_n_fm(A,x,t)) = succ(A)  succ(x)  succ(t)"
proof -
  let  = "big_union_fm(1,0)"
  have "arity() = 2" "formula"
    using arity_big_union_fm union_abs2
    by simp_all
  with assms
  show ?thesis
    unfolding eclose_n_fm_def
    using arity_is_iterates_fm[OF _ _ _ _,of _ _ _ 2]
    by auto
qed

lemma arity_mem_eclose_fm [arity] :
  assumes "xnat" "tnat"
  shows "arity(mem_eclose_fm(x,t)) = succ(x)  succ(t)"
proof -
  let ="eclose_n_fm(x #+ 2, 1, 0)"
  from xnat
  have "arity() = x#+3"
    using arity_eclose_n_fm union_abs2
    by simp
  with assms
  show ?thesis
    unfolding mem_eclose_fm_def
    using arity_finite_ordinal_fm union_abs2 pred_Un_distrib
    by simp
qed

lemma arity_is_eclose_fm [arity] :
  "xnat ; tnat  arity(is_eclose_fm(x,t)) = succ(x)  succ(t)"
  unfolding is_eclose_fm_def
  using arity_mem_eclose_fm union_abs2 pred_Un_distrib
  by auto

lemma arity_Collect_fm [arity] :
  assumes "x  nat" "y  nat" "pformula"
  shows "arity(Collect_fm(x,p,y)) = succ(x)  succ(y)  pred(arity(p))"
  unfolding Collect_fm_def
  using assms pred_Un_distrib
  by auto

schematic_goal arity_least_fm':
  assumes
    "i  nat" "q  formula"
  shows
    "arity(least_fm(q,i))  ?ar"
  unfolding least_fm_def
  using assms pred_Un_distrib arity_And arity_Or arity_Neg arity_Implies arity_ordinal_fm
        arity_empty_fm Un_assoc[symmetric] Un_commute
  by auto

lemma arity_least_fm [arity] :
  assumes
    "i  nat" "q  formula"
  shows
    "arity(least_fm(q,i)) = succ(i)  pred(arity(q))"
  using assms arity_least_fm'
  by auto

lemma arity_Replace_fm [arity] :
  "pformula ; vnat ; nnat; inat  arity(p) = i 
    arity(Replace_fm(v,p,n)) = succ(n)  (succ(v)  Arith.pred(Arith.pred(i)))"
  unfolding Replace_fm_def
  using union_abs2 pred_Un_distrib
  by simp

lemma arity_lambda_fm [arity] :
  "pformula; vnat ; nnat; inat   arity(p) = i 
    arity(lambda_fm(p,v,n)) = succ(n)  (succ(v)  Arith.pred(Arith.pred(Arith.pred(i))))"
  unfolding lambda_fm_def
  using arity_pair_fm pred_Un_distrib union_abs1 union_abs2
  by simp

lemma arity_transrec_fm [arity] :
  "pformula ; vnat ; nnat; inat  arity(p) = i 
     arity(is_transrec_fm(p,v,n)) = succ(v)  succ(n)  (pred^8(i))"
  unfolding is_transrec_fm_def
  using arity Un_assoc[symmetric] pred_Un_distrib
  by simp

end ― ‹@{thm [source] FOL_arities}

declare arity_subset_fm [simp del] arity_ordinal_fm[simp del, arity] arity_transset_fm[simp del]

end