src/HOL/Tools/specification_package.ML
author skalberg
Mon, 21 Jul 2003 17:27:23 +0200
changeset 14122 433f9a414537
parent 14121 d2a0fd183f5f
child 14164 8c3fab596219
permissions -rw-r--r--
Added handling of meta implication and meta quantification.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     1
(*  Title:      HOL/Tools/specification_package.ML
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     2
    ID:         $Id$
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     3
    Author:     Sebastian Skalberg, TU Muenchen
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     5
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     6
Package for defining constants by specification.
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     7
*)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     8
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
     9
signature SPECIFICATION_PACKAGE =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    10
sig
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    11
    val quiet_mode: bool ref
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
    12
    val add_specification_i: (bstring * xstring * bool) list
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    13
			     -> theory * thm -> theory * thm
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    14
end
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    15
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    16
structure SpecificationPackage : SPECIFICATION_PACKAGE =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    17
struct
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    18
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    19
(* messages *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    20
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    21
val quiet_mode = ref false
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    22
fun message s = if ! quiet_mode then () else writeln s
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    23
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    24
local
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    25
    val _ = Goal "[| Ex P ; c == Eps P |] ==> P c"
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    26
    val _ = by (Asm_simp_tac 1)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    27
    val _ = by (rtac (thm "someI_ex") 1)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    28
    val _ = ba 1
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    29
in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    30
val helper = Goals.result()
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    31
end
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    32
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    33
(* Akin to HOLogic.exists_const *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    34
fun choice_const T = Const("Hilbert_Choice.Eps",(T-->HOLogic.boolT)-->T)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    35
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    36
(* Actual code *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    37
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    38
fun proc_exprop [] arg = arg
14116
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
    39
  | proc_exprop ((thname,cname,covld)::cos) (thy,thm) =
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    40
    case concl_of thm of
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    41
	Const("Trueprop",_) $ (Const("Ex",_) $ P) =>
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    42
	let
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    43
	    val ctype = domain_type (type_of P)
14117
d3512dedbaea *** empty log message ***
skalberg
parents: 14116
diff changeset
    44
	    val cname_full = Sign.intern_const (sign_of thy) cname
14116
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
    45
	    val cdefname = if thname = ""
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
    46
			   then Thm.def_name (Sign.base_name cname)
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
    47
			   else thname
14117
d3512dedbaea *** empty log message ***
skalberg
parents: 14116
diff changeset
    48
	    val def_eq = Logic.mk_equals (Const(cname_full,ctype),choice_const ctype $  P)
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    49
	    val (thy',thms) = PureThy.add_defs_i covld [((cdefname,def_eq),[])] thy
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    50
	    val thm' = [thm,hd thms] MRS helper
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    51
	in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    52
	    proc_exprop cos (thy',thm')
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    53
	end
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    54
      | _ => raise THM ("Internal error: Bad specification theorem",0,[thm])
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    55
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
    56
fun add_specification_i cos arg =
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
    57
    arg |> apsnd freezeT
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
    58
	|> proc_exprop cos
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
    59
	|> apsnd standard
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    60
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    61
(* Collect all intances of constants in term *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    62
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    63
fun collect_consts (        t $ u,tms) = collect_consts (u,collect_consts (t,tms))
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    64
  | collect_consts (   Abs(_,_,t),tms) = collect_consts (t,tms)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    65
  | collect_consts (tm as Const _,tms) = gen_ins (op aconv) (tm,tms)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    66
  | collect_consts (            _,tms) = tms
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    67
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    68
(* Complementing Type.varify... *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    69
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    70
fun unvarify t fmap =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    71
    let
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    72
	val fmap' = map Library.swap fmap
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    73
	fun unthaw (f as (a,S)) =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    74
	    (case assoc (fmap',a) of
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    75
		 None => TVar f
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    76
	       | Some b => TFree (b,S))
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    77
    in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    78
	map_term_types (map_type_tvar unthaw) t
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    79
    end
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    80
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    81
(* The syntactic meddling needed to setup add_specification for work *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    82
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    83
fun process_spec cos alt_name sprop int thy =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    84
    let
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    85
	val sg = sign_of thy
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    86
	fun typ_equiv t u =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    87
	    let
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    88
		val tsig = Sign.tsig_of sg
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    89
	    in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    90
		Type.typ_instance(tsig,t,u) andalso
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    91
		Type.typ_instance(tsig,u,t)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    92
	    end
14122
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
    93
	val cprop = Thm.read_cterm sg (sprop,Term.propT)
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
    94
	val prop = term_of cprop
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    95
	val (prop_thawed,vmap) = Type.varify (prop,[])
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    96
	val thawed_prop_consts = collect_consts (prop_thawed,[])
14116
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
    97
	val (altcos,overloaded) = Library.split_list cos
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
    98
	val (names,sconsts) = Library.split_list altcos
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
    99
	val consts = map (term_of o Thm.read_cterm sg o rpair TypeInfer.logicT) sconsts
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   100
	val _ = assert (not (Library.exists (not o Term.is_Const) consts))
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   101
		       "Non-constant found as parameter"
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   102
	fun proc_const c =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   103
	    let
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   104
		val c' = fst (Type.varify (c,[]))
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   105
		val (cname,ctyp) = dest_Const c'
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   106
	    in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   107
		case filter (fn t => let val (name,typ) = dest_Const t
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   108
				     in name = cname andalso typ_equiv typ ctyp
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   109
				     end) thawed_prop_consts of
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   110
		    [] => error ("Constant \"" ^ (Sign.string_of_term sg c) ^ "\" not found in specification")
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   111
		  | [cf] => unvarify cf vmap
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   112
		  | _ => error ("Several variations of \"" ^ (Sign.string_of_term sg c) ^ "\" found in specification")
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   113
	    end
14122
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   114
	val rew_imp = Simplifier.full_rewrite (empty_ss setmksimps single addsimps [thm "HOL.atomize_imp",thm "HOL.atomize_all"]) cprop
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   115
	val cprop' = snd (dest_equals (cprop_of rew_imp))
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   116
	val prop' = HOLogic.dest_Trueprop (term_of cprop')
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   117
	val frees = Term.term_frees prop'
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   118
	val tsig = Sign.tsig_of (sign_of thy)
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   119
	val _ = assert (forall (fn v => Type.of_sort tsig (type_of v,HOLogic.typeS)) frees)
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   120
		"Only free variables of sort 'type' allowed in specifications"
14122
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   121
	val prop_closed = foldr (fn ((vname,T),prop) => HOLogic.mk_all (vname,T,prop)) (map dest_Free frees,prop')
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   122
	val proc_consts = map proc_const consts
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   123
	fun mk_exist (c,prop) =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   124
	    let
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   125
		val T = type_of c
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   126
	    in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   127
		HOLogic.exists_const T $ Abs("x",T,Term.abstract_over (c,prop))
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   128
	    end
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   129
	val ex_prop = foldr mk_exist (proc_consts,prop_closed)
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   130
	val cnames = map (fst o dest_Const) proc_consts
14116
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
   131
	fun zip3 [] [] [] = []
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
   132
	  | zip3 (x::xs) (y::ys) (z::zs) = (x,y,z)::zip3 xs ys zs
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
   133
	  | zip3 _ _ _ = error "Internal error: Bad specification syntax"
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   134
	val (name,atts) = alt_name
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   135
	fun add_final (arg as (thy,thm)) =
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   136
	    if name = ""
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   137
	    then arg
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   138
	    else (writeln ("specification " ^ name ^ ": " ^ (string_of_thm thm));
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   139
		  PureThy.store_thm((name,thm),[]) thy)
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   140
	fun post_process (arg as (thy,thm)) =
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   141
	    let
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   142
		fun inst_all sg (thm,v) =
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   143
		    let
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   144
			val cv = cterm_of sg v
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   145
			val cT = ctyp_of_term cv
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   146
			val spec' = instantiate' [Some cT] [None,Some cv] spec
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   147
		    in
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   148
			thm RS spec'
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   149
		    end
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   150
		fun remove_alls frees thm = foldl (inst_all (sign_of_thm thm)) (thm,frees)
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   151
		fun apply_atts arg = Thm.apply_attributes (arg,map (Attrib.global_attribute thy) atts)
14122
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   152
		fun undo_imps thm =
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   153
		    equal_elim (symmetric rew_imp) thm
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   154
	    in
14122
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   155
		arg |> apsnd freezeT
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   156
		    |> apsnd (remove_alls frees)
433f9a414537 Added handling of meta implication and meta quantification.
skalberg
parents: 14121
diff changeset
   157
		    |> apsnd (undo_imps)
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   158
		    |> apsnd standard
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   159
		    |> apply_atts
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   160
		    |> add_final
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   161
	    end
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   162
    in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   163
	IsarThy.theorem_i Drule.internalK
14121
d2a0fd183f5f Added handling of free variables (provided they are of sort HOL.type).
skalberg
parents: 14118
diff changeset
   164
	    (("",[add_specification_i (zip3 (names:string list) (cnames:string list) (overloaded:bool list)),post_process]),
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   165
	     (HOLogic.mk_Trueprop ex_prop,([],[]))) int thy
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   166
    end
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   167
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   168
(* outer syntax *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   169
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   170
local structure P = OuterParse and K = OuterSyntax.Keyword in
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   171
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   172
(* taken from ~~/Pure/Isar/isar_syn.ML *)
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   173
val opt_overloaded =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   174
  Scan.optional (P.$$$ "(" |-- P.!!! ((P.$$$ "overloaded" >> K true) --| P.$$$ ")")) false
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   175
14116
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
   176
val opt_name = Scan.optional (P.name --| P.$$$ ":") ""
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
   177
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   178
val specification_decl =
14116
63337d8e6e0f Added optional theorem names for the constant definitions added during
skalberg
parents: 14115
diff changeset
   179
    P.$$$ "(" |-- Scan.repeat1 (opt_name -- P.term -- opt_overloaded) --| P.$$$ ")" --
14115
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   180
	  P.opt_thm_name ":" -- P.prop
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   181
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   182
val specificationP =
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   183
  OuterSyntax.command "specification" "define constants by specification" K.thy_goal
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   184
    (specification_decl >> (fn ((cos,alt_name), prop) =>
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   185
			       Toplevel.print o (Toplevel.theory_to_proof (process_spec cos alt_name prop))))
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   186
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   187
val _ = OuterSyntax.add_parsers [specificationP]
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   188
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   189
end
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   190
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   191
65ec3f73d00b Added package for definition by specification.
skalberg
parents:
diff changeset
   192
end