src/HOL/Nominal/nominal_atoms.ML
changeset 18431 a59c79a3544c
parent 18430 46c18c0b52c1
child 18432 0b596274ba4f
equal deleted inserted replaced
18430:46c18c0b52c1 18431:a59c79a3544c
   370      (* some abbreviations for theorems *)
   370      (* some abbreviations for theorems *)
   371       val pt1           = thm "pt1";
   371       val pt1           = thm "pt1";
   372       val pt2           = thm "pt2";
   372       val pt2           = thm "pt2";
   373       val pt3           = thm "pt3";
   373       val pt3           = thm "pt3";
   374       val at_pt_inst    = thm "at_pt_inst";
   374       val at_pt_inst    = thm "at_pt_inst";
   375       val pt_bool_inst  = thm "pt_bool_inst";
       
   376       val pt_set_inst   = thm "pt_set_inst"; 
   375       val pt_set_inst   = thm "pt_set_inst"; 
   377       val pt_unit_inst  = thm "pt_unit_inst";
   376       val pt_unit_inst  = thm "pt_unit_inst";
   378       val pt_prod_inst  = thm "pt_prod_inst"; 
   377       val pt_prod_inst  = thm "pt_prod_inst"; 
   379       val pt_list_inst  = thm "pt_list_inst";   
   378       val pt_list_inst  = thm "pt_list_inst";   
   380       val pt_optn_inst  = thm "pt_option_inst";   
   379       val pt_optn_inst  = thm "pt_option_inst";   
   381       val pt_noptn_inst = thm "pt_noption_inst";   
   380       val pt_noptn_inst = thm "pt_noption_inst";   
   382       val pt_fun_inst   = thm "pt_fun_inst";     
   381       val pt_fun_inst   = thm "pt_fun_inst";     
   383 
   382 
   384      (* for all atom-kind combination shows that         *)
   383      (* for all atom-kind combination show that         *)
   385      (* every <ak> is an instance of pt_<ai>             *)
   384      (* every <ak> is an instance of pt_<ai>            *)
   386      val (thy13,_) = foldl_map (fn (thy, (ak_name, T)) =>
   385      val thy13 = fold (fn ak_name => fn thy =>
   387 	 foldl_map (fn (thy', (ak_name', T')) =>
   386 	fold (fn ak_name' => fn thy' =>
   388           (if ak_name = ak_name'
   387          let
   389 	   then
   388            val qu_name =  Sign.full_name (sign_of thy') ak_name';
   390 	     let
   389            val cls_name = Sign.full_name (sign_of thy') ("pt_"^ak_name);
   391 	      val qu_name =  Sign.full_name (sign_of thy') ak_name;
   390            val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name'^"_inst")); 
   392               val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
   391 
   393               val at_inst  = PureThy.get_thm thy' (Name ("at_"^ak_name ^"_inst"));
   392            val proof1 = EVERY [AxClass.intro_classes_tac [],
   394               val proof = EVERY [AxClass.intro_classes_tac [],
       
   395                                  rtac ((at_inst RS at_pt_inst) RS pt1) 1,
   393                                  rtac ((at_inst RS at_pt_inst) RS pt1) 1,
   396                                  rtac ((at_inst RS at_pt_inst) RS pt2) 1,
   394                                  rtac ((at_inst RS at_pt_inst) RS pt2) 1,
   397                                  rtac ((at_inst RS at_pt_inst) RS pt3) 1,
   395                                  rtac ((at_inst RS at_pt_inst) RS pt3) 1,
   398                                  atac 1];
   396                                  atac 1];
   399              in 
   397            val simp_s = HOL_basic_ss addsimps 
   400 	      (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy',()) 
   398                         PureThy.get_thmss thy' [Name (ak_name^"_prm_"^ak_name'^"_def")];  
   401              end
   399            val proof2 = EVERY [AxClass.intro_classes_tac [], REPEAT (asm_simp_tac simp_s 1)];
   402            else 
   400 
   403              let
   401          in
   404 	      val qu_name' = Sign.full_name (sign_of thy') ak_name';
   402            thy'
   405               val qu_class = Sign.full_name (sign_of thy') ("pt_"^ak_name);
   403            |> AxClass.add_inst_arity_i (qu_name,[],[cls_name])
   406               val simp_s = HOL_basic_ss addsimps 
   404               (if ak_name = ak_name' then proof1 else proof2)
   407                            PureThy.get_thmss thy' [Name (ak_name^"_prm_"^ak_name'^"_def")];  
   405          end) ak_names thy) ak_names thy12c;
   408               val proof = EVERY [AxClass.intro_classes_tac [], auto_tac (claset(),simp_s)];
       
   409              in 
       
   410 	      (AxClass.add_inst_arity_i (qu_name',[],[qu_class]) proof thy',()) 
       
   411              end)) 
       
   412 	     (thy, ak_names_types)) (thy12c, ak_names_types);
       
   413 
   406 
   414      (* show that                       *)
   407      (* show that                       *)
   415      (*      fun(pt_<ak>,pt_<ak>)       *)
   408      (*      fun(pt_<ak>,pt_<ak>)       *)
   416      (*      nOption(pt_<ak>)           *)
   409      (*      nOption(pt_<ak>)           *)
   417      (*      option(pt_<ak>)            *)
   410      (*      option(pt_<ak>)            *)
   418      (*      list(pt_<ak>)              *)
   411      (*      list(pt_<ak>)              *)
   419      (*      *(pt_<ak>,pt_<ak>)         *)
   412      (*      *(pt_<ak>,pt_<ak>)         *)
   420      (*      unit                       *)
   413      (*      unit                       *)
   421      (*      set(pt_<ak>)               *)
   414      (*      set(pt_<ak>)               *)
   422      (* are instances of pt_<ak>        *)
   415      (* are instances of pt_<ak>        *)
   423      val thy19 = fold (fn ak_name => fn thy =>
   416      val thy18 = fold (fn ak_name => fn thy =>
   424        let
   417        let
   425           val cls_name = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   418           val cls_name = Sign.full_name (sign_of thy) ("pt_"^ak_name);
   426           val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
   419           val at_thm   = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
   427           val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
   420           val pt_inst  = PureThy.get_thm thy (Name ("pt_"^ak_name^"_inst"));
   428           
   421           
   446         |> AxClass.add_inst_arity_i ("*",[[cls_name],[cls_name]],[cls_name]) (pt_proof pt_thm_prod)
   439         |> AxClass.add_inst_arity_i ("*",[[cls_name],[cls_name]],[cls_name]) (pt_proof pt_thm_prod)
   447         |> AxClass.add_inst_arity_i ("Product_Type.unit",[],[cls_name]) (pt_proof pt_thm_unit)
   440         |> AxClass.add_inst_arity_i ("Product_Type.unit",[],[cls_name]) (pt_proof pt_thm_unit)
   448         |> AxClass.add_inst_arity_i ("set",[[cls_name]],[cls_name]) (pt_proof pt_thm_set)
   441         |> AxClass.add_inst_arity_i ("set",[[cls_name]],[cls_name]) (pt_proof pt_thm_set)
   449      end) ak_names thy13; 
   442      end) ak_names thy13; 
   450 
   443 
   451      (* show that discrete types are permutation types and finitely supported *)
   444      (* show that discrete types are permutation types, finitely supported and *)
   452      (* discrete types have a permutation operation defined as pi o x = x;    *)
   445      (* have the commutation property                                          *)
   453      (* which renders the proofs to be simple "simp_all"-proofs.              *)            
   446      (* discrete types have a permutation operation defined as pi o x = x;     *)
       
   447      (* which renders the proofs to be simple "simp_all"-proofs.               *)            
   454      val thy19 =
   448      val thy19 =
   455         let 
   449         let 
   456 	  fun discrete_pt_inst discrete_ty defn = 
   450 	  fun discrete_pt_inst discrete_ty defn = 
   457 	     fold (fn ak_name => fn thy =>
   451 	     fold (fn ak_name => fn thy =>
   458 	     let
   452 	     let
   484              in  
   478              in  
   485 	       AxClass.add_inst_arity_i (discrete_ty,[],[qu_class]) proof thy
   479 	       AxClass.add_inst_arity_i (discrete_ty,[],[qu_class]) proof thy
   486              end) ak_names)) ak_names;  
   480              end) ak_names)) ak_names;  
   487           
   481           
   488         in
   482         in
   489          thy19
   483          thy18
   490          |> discrete_pt_inst "nat"  (thm "perm_nat_def")
   484          |> discrete_pt_inst "nat"  (thm "perm_nat_def")
   491          |> discrete_fs_inst "nat"  (thm "perm_nat_def") 
   485          |> discrete_fs_inst "nat"  (thm "perm_nat_def") 
   492          |> discrete_cp_inst "nat"  (thm "perm_nat_def") 
   486          |> discrete_cp_inst "nat"  (thm "perm_nat_def") 
   493          |> discrete_pt_inst "bool" (thm "perm_bool")
   487          |> discrete_pt_inst "bool" (thm "perm_bool")
   494          |> discrete_fs_inst "bool" (thm "perm_bool")
   488          |> discrete_fs_inst "bool" (thm "perm_bool")
   503 
   497 
   504 
   498 
   505        (*<<<<<<<  fs_<ak> class instances  >>>>>>>*)
   499        (*<<<<<<<  fs_<ak> class instances  >>>>>>>*)
   506        (*=========================================*)
   500        (*=========================================*)
   507        (* abbreviations for some lemmas *)
   501        (* abbreviations for some lemmas *)
   508        val fs1          = thm "fs1";
   502        val fs1            = thm "fs1";
   509        val fs_at_inst   = thm "fs_at_inst";
   503        val fs_at_inst     = thm "fs_at_inst";
   510        val fs_unit_inst = thm "fs_unit_inst";
   504        val fs_unit_inst   = thm "fs_unit_inst";
   511        val fs_bool_inst = thm "fs_bool_inst";
   505        val fs_prod_inst   = thm "fs_prod_inst";
   512        val fs_prod_inst = thm "fs_prod_inst";
   506        val fs_list_inst   = thm "fs_list_inst";
   513        val fs_list_inst = thm "fs_list_inst";
   507        val fs_option_inst = thm "fs_option_inst";
   514 
   508 
   515        (* shows that <ak> is an instance of fs_<ak>     *)
   509        (* shows that <ak> is an instance of fs_<ak>     *)
   516        (* uses the theorem at_<ak>_inst                 *)
   510        (* uses the theorem at_<ak>_inst                 *)
   517        val (thy20,_) = foldl_map (fn (thy, (ak_name, T)) =>
   511        (* FIXME -- needs to be done for all ak-combinations *) 
       
   512        val thy20 = fold (fn ak_name => fn thy =>
   518        let
   513        let
   519           val qu_name =  Sign.full_name (sign_of thy) ak_name;
   514           val qu_name =  Sign.full_name (sign_of thy) ak_name;
   520           val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   515           val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   521           val at_thm = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
   516           val at_thm = PureThy.get_thm thy (Name ("at_"^ak_name^"_inst"));
   522           val proof = EVERY [AxClass.intro_classes_tac [],
   517           val proof = EVERY [AxClass.intro_classes_tac [],
   523                              rtac ((at_thm RS fs_at_inst) RS fs1) 1];      
   518                              rtac ((at_thm RS fs_at_inst) RS fs1) 1];      
   524        in 
   519        in 
   525 	 (AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy,()) 
   520 	 AxClass.add_inst_arity_i (qu_name,[],[qu_class]) proof thy 
   526        end) (thy19,ak_names_types);  
   521        end) ak_names thy19;
   527 
   522 
   528        (* shows that unit is an instance of fs_<ak>     *)
   523        (* shows that                  *)
   529        (* uses the theorem fs_unit_inst                 *)
   524        (*    unit                     *)
   530        val (thy21,_) = foldl_map (fn (thy, (ak_name, T)) =>
   525        (*    *(fs_<ak>,fs_<ak>)       *)
   531        let
   526        (*    list(fs_<ak>)            *)
   532           val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   527        (*    option(fs_<ak>)          *) 
   533           val proof = EVERY [AxClass.intro_classes_tac [],
   528        (* are instances of fs_<ak>    *)
   534                              rtac (fs_unit_inst RS fs1) 1];      
   529 
   535        in 
   530        val thy24 = fold (fn ak_name => fn thy => 
   536 	 (AxClass.add_inst_arity_i ("Product_Type.unit",[],[qu_class]) proof thy,()) 
   531         let
   537        end) (thy20,ak_names_types);  
   532           val cls_name = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   538 
       
   539        (* shows that bool is an instance of fs_<ak>     *)
       
   540        (* uses the theorem fs_bool_inst                 *)
       
   541        val (thy22,_) = foldl_map (fn (thy, (ak_name, T)) =>
       
   542        let
       
   543           val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
       
   544           val proof = EVERY [AxClass.intro_classes_tac [],
       
   545                              rtac (fs_bool_inst RS fs1) 1];      
       
   546        in 
       
   547 	 (AxClass.add_inst_arity_i ("bool",[],[qu_class]) proof thy,()) 
       
   548        end) (thy21,ak_names_types);  
       
   549 
       
   550        (* shows that *(fs_<ak>,fs_<ak>) is an instance of fs_<ak>     *)
       
   551        (* uses the theorem fs_prod_inst                               *)
       
   552        val (thy23,_) = foldl_map (fn (thy, (ak_name, T)) =>
       
   553        let
       
   554           val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
       
   555           val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
   533           val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
   556           val proof = EVERY [AxClass.intro_classes_tac [],
   534           fun fs_proof thm = EVERY [AxClass.intro_classes_tac [], rtac (thm RS fs1) 1];      
   557                              rtac ((fs_inst RS (fs_inst RS fs_prod_inst)) RS fs1) 1];      
   535 
   558        in 
   536           val fs_thm_unit = fs_unit_inst;
   559 	 (AxClass.add_inst_arity_i ("*",[[qu_class],[qu_class]],[qu_class]) proof thy,()) 
   537           val fs_thm_prod = fs_inst RS (fs_inst RS fs_prod_inst);
   560        end) (thy22,ak_names_types);  
   538           val fs_thm_list = fs_inst RS fs_list_inst;
   561 
   539           val fs_thm_optn = fs_inst RS fs_option_inst;
   562        (* shows that list(fs_<ak>) is an instance of fs_<ak>     *)
   540         in 
   563        (* uses the theorem fs_list_inst                          *)
   541          thy 
   564        val (thy24,_) = foldl_map (fn (thy, (ak_name, T)) =>
   542          |> AxClass.add_inst_arity_i ("Product_Type.unit",[],[cls_name]) (fs_proof fs_thm_unit) 
   565        let
   543          |> AxClass.add_inst_arity_i ("*",[[cls_name],[cls_name]],[cls_name]) (fs_proof fs_thm_prod)    
   566           val qu_class = Sign.full_name (sign_of thy) ("fs_"^ak_name);
   544          |> AxClass.add_inst_arity_i ("List.list",[[cls_name]],[cls_name]) (fs_proof fs_thm_list)
   567           val fs_inst  = PureThy.get_thm thy (Name ("fs_"^ak_name^"_inst"));
   545          |> AxClass.add_inst_arity_i ("Datatype.option",[[cls_name]],[cls_name]) (fs_proof fs_thm_optn)
   568           val proof = EVERY [AxClass.intro_classes_tac [],
   546         end) ak_names thy20; 
   569                               rtac ((fs_inst RS fs_list_inst) RS fs1) 1];      
   547 
   570        in 
       
   571 	 (AxClass.add_inst_arity_i ("List.list",[[qu_class]],[qu_class]) proof thy,()) 
       
   572        end) (thy23,ak_names_types);  
       
   573 	   
       
   574        (*<<<<<<<  cp_<ak>_<ai> class instances  >>>>>>>*)
   548        (*<<<<<<<  cp_<ak>_<ai> class instances  >>>>>>>*)
   575        (*==============================================*)
   549        (*==============================================*)
   576        (* abbreviations for some lemmas *)
   550        (* abbreviations for some lemmas *)
   577        val cp1             = thm "cp1";
   551        val cp1             = thm "cp1";
   578        val cp_unit_inst    = thm "cp_unit_inst";
   552        val cp_unit_inst    = thm "cp_unit_inst";