src/HOL/Import/proof_kernel.ML
changeset 14685 92f34880efe3
parent 14673 3d760a971fde
child 14818 ad83019a66a4
equal deleted inserted replaced
14684:d796124e435c 14685:92f34880efe3
   168 	PK (m,s) => (writeln ("PK (" ^ m ^ "): " ^ s); raise e)
   168 	PK (m,s) => (writeln ("PK (" ^ m ^ "): " ^ s); raise e)
   169       | _ => Goals.print_exn e
   169       | _ => Goals.print_exn e
   170 
   170 
   171 (* Compatibility. *)
   171 (* Compatibility. *)
   172 
   172 
   173 (* FIXME lookup inner syntax!? *)
   173 fun mk_syn thy c =
   174 fun mk_syn c = if Syntax.is_identifier c then NoSyn else Syntax.literal c
   174   if Syntax.is_identifier c andalso not (Syntax.is_keyword (Theory.syn_of thy) c) then NoSyn
   175 
   175   else Syntax.literal c
   176 (* FIXME lookup outer syntax!? *)
   176 
   177 val keywords = ["open"]
       
   178 fun quotename c =
   177 fun quotename c =
   179   if Syntax.is_identifier c andalso not (c mem_string keywords) then c else quote c
   178   if Syntax.is_identifier c andalso not (OuterSyntax.is_keyword c) then c else quote c
   180 
   179 
   181 fun smart_string_of_cterm ct =
   180 fun smart_string_of_cterm ct =
   182     let
   181     let
   183 	val {sign,t,T,...} = rep_cterm ct
   182 	val {sign,t,T,...} = rep_cterm ct
   184         (* Hack to avoid parse errors with Trueprop *)
   183         (* Hack to avoid parse errors with Trueprop *)
  1874 val spaces = String.concat o separate " "
  1873 val spaces = String.concat o separate " "
  1875 
  1874 
  1876 fun new_definition thyname constname rhs thy =
  1875 fun new_definition thyname constname rhs thy =
  1877     let
  1876     let
  1878 	val constname = rename_const thyname thy constname
  1877 	val constname = rename_const thyname thy constname
       
  1878         val sg = sign_of thy
       
  1879         val redeclared = is_some (Sign.const_type sg (Sign.intern_const sg constname));
  1879 	val _ = warning ("Introducing constant " ^ constname)
  1880 	val _ = warning ("Introducing constant " ^ constname)
  1880 	val (thmname,thy) = get_defname thyname constname thy
  1881 	val (thmname,thy) = get_defname thyname constname thy
  1881 	val (info,rhs') = disamb_term rhs
  1882 	val (info,rhs') = disamb_term rhs
  1882 	val ctype = type_of rhs'
  1883 	val ctype = type_of rhs'
  1883 	val csyn = mk_syn constname
  1884 	val csyn = mk_syn thy constname
  1884 	val thy1 = case HOL4DefThy.get thy of
  1885 	val thy1 = case HOL4DefThy.get thy of
  1885 		       Replaying _ => thy
  1886 		       Replaying _ => thy
  1886 		     | _ => Theory.add_consts_i [(constname,ctype,csyn)] thy
  1887 		     | _ => Theory.add_consts_i [(constname,ctype,csyn)] thy
  1887 	val eq = mk_defeq constname rhs' thy1
  1888 	val eq = mk_defeq constname rhs' thy1
  1888 	val (thy2,thms) = PureThy.add_defs_i false [((thmname,eq),[])] thy1
  1889 	val (thy2,thms) = PureThy.add_defs_i false [((thmname,eq),[])] thy1
  1893 	val thy'' = add_hol4_const_mapping thyname constname true fullcname thy'
  1894 	val thy'' = add_hol4_const_mapping thyname constname true fullcname thy'
  1894 	val (linfo,tm24) = disamb_term (mk_teq constname rhs' thy'')
  1895 	val (linfo,tm24) = disamb_term (mk_teq constname rhs' thy'')
  1895 	val sg = sign_of thy''
  1896 	val sg = sign_of thy''
  1896 	val rew = rewrite_hol4_term eq thy''
  1897 	val rew = rewrite_hol4_term eq thy''
  1897 	val crhs = cterm_of sg (#2 (Logic.dest_equals (prop_of rew)))
  1898 	val crhs = cterm_of sg (#2 (Logic.dest_equals (prop_of rew)))
  1898 	val thy22 = if (def_name constname) = thmname
  1899 	val thy22 = if (def_name constname) = thmname andalso not redeclared andalso csyn = NoSyn
  1899 		    then
  1900 		    then
  1900 			add_dump ("constdefs\n  " ^ (quotename constname) ^ " :: \"" ^ (string_of_ctyp (ctyp_of sg ctype)) ^ "\" " ^ (Syntax.string_of_mixfix csyn) ^ "\n  " ^ (smart_string_of_cterm crhs)) thy''
  1901 			add_dump ("constdefs\n  " ^ (quotename constname) ^ " :: \"" ^ (string_of_ctyp (ctyp_of sg ctype)) ^ "\" " ^ (Syntax.string_of_mixfix csyn) ^ "\n  " ^ (smart_string_of_cterm crhs)) thy''
  1901 		    else
  1902 		    else
  1902 			add_dump ("consts\n  " ^ (quotename constname) ^ " :: \"" ^ (string_of_ctyp (ctyp_of sg ctype)) ^
  1903 			add_dump ("consts\n  " ^ (quotename constname) ^ " :: \"" ^ (string_of_ctyp (ctyp_of sg ctype)) ^
  1903 				  "\" " ^ (Syntax.string_of_mixfix csyn) ^ "\n\ndefs\n  " ^ (quotename thmname) ^ ": " ^ (smart_string_of_cterm crhs))
  1904 				  "\" " ^ (Syntax.string_of_mixfix csyn) ^ "\n\ndefs\n  " ^ (quotename thmname) ^ ": " ^ (smart_string_of_cterm crhs))
  1957 					 
  1958 					 
  1958 			       val (consts,_) = foldl (fn ((cs,ex),cname) =>
  1959 			       val (consts,_) = foldl (fn ((cs,ex),cname) =>
  1959 							  let
  1960 							  let
  1960 							      val (_,cT,p) = dest_exists ex
  1961 							      val (_,cT,p) = dest_exists ex
  1961 							  in
  1962 							  in
  1962 							      ((cname,cT,mk_syn cname)::cs,p)
  1963 							      ((cname,cT,mk_syn thy cname)::cs,p)
  1963 							  end) (([],HOLogic.dest_Trueprop (concl_of th)),names)
  1964 							  end) (([],HOLogic.dest_Trueprop (concl_of th)),names)
  1964 			       val sg = sign_of thy
  1965 			       val sg = sign_of thy
  1965 			       val str = foldl (fn (acc,(c,T,csyn)) =>
  1966 			       val str = foldl (fn (acc,(c,T,csyn)) =>
  1966 						   acc ^ "\n  " ^ (quotename c) ^ " :: \"" ^ (string_of_ctyp (ctyp_of sg T)) ^ "\" " ^ (Syntax.string_of_mixfix csyn)) ("consts",consts)
  1967 						   acc ^ "\n  " ^ (quotename c) ^ " :: \"" ^ (string_of_ctyp (ctyp_of sg T)) ^ "\" " ^ (Syntax.string_of_mixfix csyn)) ("consts",consts)
  1967 			       val thy' = add_dump str thy
  1968 			       val thy' = add_dump str thy
  2036 	    val c = case concl_of th2 of
  2037 	    val c = case concl_of th2 of
  2037 			_ $ (Const("Ex",_) $ Abs(_,_,Const("op :",_) $ _ $ c)) => c
  2038 			_ $ (Const("Ex",_) $ Abs(_,_,Const("op :",_) $ _ $ c)) => c
  2038 		      | _ => raise ERR "new_type_definition" "Bad type definition theorem"
  2039 		      | _ => raise ERR "new_type_definition" "Bad type definition theorem"
  2039 	    val tfrees = term_tfrees c
  2040 	    val tfrees = term_tfrees c
  2040 	    val tnames = map fst tfrees
  2041 	    val tnames = map fst tfrees
  2041 	    val tsyn = mk_syn tycname
  2042 	    val tsyn = mk_syn thy tycname
  2042 	    val typ = (tycname,tnames,tsyn)
  2043 	    val typ = (tycname,tnames,tsyn)
  2043 	    val (thy',typedef_info) = TypedefPackage.add_typedef_i false (Some thmname) typ c None (rtac th2 1) thy
  2044 	    val (thy',typedef_info) = TypedefPackage.add_typedef_i false (Some thmname) typ c None (rtac th2 1) thy
  2044 				      
  2045 				      
  2045 	    val th3 = (#type_definition typedef_info) RS typedef_hol2hol4
  2046 	    val th3 = (#type_definition typedef_info) RS typedef_hol2hol4
  2046 
  2047 
  2099 	    val c = case concl_of th2 of
  2100 	    val c = case concl_of th2 of
  2100 			_ $ (Const("Ex",_) $ Abs(_,_,Const("op :",_) $ _ $ c)) => c
  2101 			_ $ (Const("Ex",_) $ Abs(_,_,Const("op :",_) $ _ $ c)) => c
  2101 		      | _ => raise ERR "type_introduction" "Bad type definition theorem"
  2102 		      | _ => raise ERR "type_introduction" "Bad type definition theorem"
  2102 	    val tfrees = term_tfrees c
  2103 	    val tfrees = term_tfrees c
  2103 	    val tnames = map fst tfrees
  2104 	    val tnames = map fst tfrees
  2104 	    val tsyn = mk_syn tycname
  2105 	    val tsyn = mk_syn thy tycname
  2105 	    val typ = (tycname,tnames,tsyn)
  2106 	    val typ = (tycname,tnames,tsyn)
  2106 	    val (thy',typedef_info) = TypedefPackage.add_typedef_i false (Some thmname) typ c (Some(rep_name,abs_name)) (rtac th2 1) thy
  2107 	    val (thy',typedef_info) = TypedefPackage.add_typedef_i false (Some thmname) typ c (Some(rep_name,abs_name)) (rtac th2 1) thy
  2107 				      
  2108 				      
  2108 	    val th3 = (#type_definition typedef_info) RS typedef_hol2hollight
  2109 	    val th3 = (#type_definition typedef_info) RS typedef_hol2hollight
  2109 
  2110