type nun_co_data_spec =
{ty: ty,
ctrs: nun_ctr_spec list}
type nun_const_spec =
{const: tm,
props: tm list}
type nun_consts_spec =
{consts: tm list,
props: tm list}
datatype nun_command =
NTVal of ty * (int option * int option)
| NCopy of nun_copy_spec
| NData of nun_co_data_spec list
| NCodata of nun_co_data_spec list
| NVal of tm * ty
| NPred ofbool * nun_const_spec list
| NCopred of nun_const_spec list
| NRec of nun_const_spec list
| NSpec of nun_consts_spec
| NAxiom of tm
| NGoal of tm
| NEval of tm
type nun_problem =
{commandss: nun_command listlist,
sound: bool,
complete: bool}
type name_pool =
{nice_of_ugly: string Symtab.table,
ugly_of_nice: string Symtab.table}
val nun_abstract: string val nun_and: string val nun_arrow: string val nun_asserting: string val nun_assign: string val nun_at: string val nun_axiom: string val nun_bar: string val nun_choice: string val nun_codata: string val nun_colon: string val nun_comma: string val nun_concrete: string val nun_conj: string val nun_copred: string val nun_copy: string val nun_data: string val nun_disj: string val nun_dollar: string val nun_dollar_anon_fun_prefix: string val nun_dot: string val nun_dummy: string val nun_else: string val nun_end: string val nun_equals: string val nun_eval: string val nun_exists: string val nun_false: string val nun_forall: string val nun_goal: string val nun_hash: string val nun_if: string val nun_implies: string val nun_irrelevant: string val nun_lambda: string val nun_lbrace: string val nun_lbracket: string val nun_lparen: string val nun_match: string val nun_mu: string val nun_not: string val nun_partial_quotient: string val nun_pred: string val nun_prop: string val nun_quotient: string val nun_rbrace: string val nun_rbracket: string val nun_rec: string val nun_rparen: string val nun_semicolon: string val nun_spec: string val nun_subset: string val nun_then: string val nun_true: string val nun_type: string val nun_unparsable: string val nun_unique: string val nun_unique_unsafe: string val nun_val: string val nun_wf: string val nun_with: string val nun__witness_of: string
val ident_of_str: string -> ident val str_of_ident: ident -> string val encode_args: stringlist -> string val nun_const_of_str: stringlist -> string -> ident val nun_tconst_of_str: stringlist -> string -> ident val nun_free_of_str: string -> ident val nun_tfree_of_str: string -> ident val nun_var_of_str: string -> ident val str_of_nun_const: ident -> stringlist * string val str_of_nun_tconst: ident -> stringlist * string val str_of_nun_free: ident -> string val str_of_nun_tfree: ident -> string val str_of_nun_var: ident -> string
val dummy_ty: ty val prop_ty: ty val mk_arrow_ty: ty * ty -> ty val mk_arrows_ty: ty list * ty -> ty val nabss: tm list * tm -> tm val napps: tm * tm list -> tm
val ty_of: tm -> ty val safe_ty_of: tm -> ty
val fold_map_ty_idents: (string -> 'a -> string * 'a) -> ty -> 'a -> ty * 'a val fold_map_tm_idents: (string -> 'a -> string * 'a) -> tm -> 'a -> tm * 'a val fold_map_nun_command_idents: (string -> 'a -> string * 'a) -> nun_command -> 'a ->
nun_command * 'a val fold_map_nun_problem_idents: (string -> 'a -> string * 'a) -> nun_problem -> 'a ->
nun_problem * 'a
type nun_co_data_spec =
{ty: ty,
ctrs: nun_ctr_spec list};
type nun_const_spec =
{const: tm,
props: tm list};
type nun_consts_spec =
{consts: tm list,
props: tm list};
datatype nun_command =
NTVal of ty * (int option * int option)
| NCopy of nun_copy_spec
| NData of nun_co_data_spec list
| NCodata of nun_co_data_spec list
| NVal of tm * ty
| NPred ofbool * nun_const_spec list
| NCopred of nun_const_spec list
| NRec of nun_const_spec list
| NSpec of nun_consts_spec
| NAxiom of tm
| NGoal of tm
| NEval of tm;
type nun_problem =
{commandss: nun_command listlist,
sound: bool,
complete: bool};
type name_pool =
{nice_of_ugly: string Symtab.table,
ugly_of_nice: string Symtab.table};
val nun_abstract = "abstract"; val nun_and = "and"; val nun_arrow = "->"; val nun_asserting = "asserting"; val nun_assign = ":="; val nun_at = "@"; val nun_axiom = "axiom"; val nun_bar = "|"; val nun_choice = "choice"; val nun_codata = "codata"; val nun_colon = ":"; val nun_comma = ","; val nun_concrete = "concrete"; val nun_conj = "&&"; val nun_copred = "copred"; val nun_copy = "copy"; val nun_data = "data"; val nun_disj = "||"; val nun_dollar = "$"; val nun_dollar_anon_fun_prefix = "$anon_fun_"; val nun_dot = "."; val nun_dummy = "_"; val nun_else = "else"; val nun_end = "end"; val nun_equals = "="; val nun_eval = "eval"; val nun_exists = "exists"; val nun_false = "false"; val nun_forall = "forall"; val nun_goal = "goal"; val nun_hash = "#"; val nun_if = "if"; val nun_implies = "=>"; val nun_irrelevant = "?__"; val nun_lambda = "fun"; val nun_lbrace = "{"; val nun_lbracket = "["; val nun_lparen = "("; val nun_match = "match"; val nun_mu = "mu"; val nun_not = "~"; val nun_partial_quotient = "partial_quotient"; val nun_pred = "pred"; val nun_prop = "prop"; val nun_quotient = "quotient"; val nun_rbrace = "}"; val nun_rbracket = "]"; val nun_rec = "rec"; val nun_rparen = ")"; val nun_semicolon = ";"; val nun_spec = "spec"; val nun_subset = "subset"; val nun_then = "then"; val nun_true = "true"; val nun_type = "type"; val nun_unique = "unique"; val nun_unique_unsafe = "unique_unsafe"; val nun_unparsable = "?__unparsable"; val nun_val = "val"; val nun_wf = "wf"; val nun_with = "with"; val nun__witness_of = "_witness_of";
val nun_parens = enclose nun_lparen nun_rparen;
fun nun_parens_if_space s = s |> String.isSubstring " " s ? nun_parens;
fun str_of_nun_arg_list str_of_arg = map (prefix " " o nun_parens_if_space o str_of_arg) #> space_implode "";
val arity_of_nun_builtin = AList.lookup (op =) nun_builtin_arity #> the_default 0;
val nun_const_prefix = "c."; val nun_free_prefix = "f."; val nun_var_prefix = "v."; val nun_tconst_prefix = "C."; val nun_tfree_prefix = "F."; val nun_custom_id_suffix = "_";
val ident_of_str = I : string -> ident; val str_of_ident = I : ident -> string;
val encode_args = enclose "("")" o commas;
fun decode_args s = let fun delta #"(" = 1
| delta #")" = ~1
| delta _ = 0;
fun dec 0 (#"(" :: #")" :: cs) _ = ([], String.implode cs)
| dec 0 (#"(" :: cs) [] = dec 1 cs [[]]
| dec 0 cs _ = ([], String.implode cs)
| dec _ [] _ = raise Fail ("ill-formed arguments in " ^ quote s)
| dec 1 (#")" :: cs) args = (rev (map (String.implode o rev) args), String.implode cs)
| dec 1 (#"," :: cs) args = dec 1 cs ([] :: args)
| dec n (c :: cs) (arg :: args) = dec (n + delta c) cs ((c :: arg) :: args); in
dec 0 (String.explode s) [] end;
val nun_free_of_str = suffix nun_custom_id_suffix #> prefix nun_free_prefix; val nun_tfree_of_str = suffix nun_custom_id_suffix #> prefix nun_tfree_prefix; val nun_var_of_str = suffix nun_custom_id_suffix #> prefix nun_var_prefix; val str_of_nun_const = decode_args ##> unprefix nun_const_prefix ##> unsuffix nun_custom_id_suffix; val str_of_nun_tconst = decode_args ##> unprefix nun_tconst_prefix ##> unsuffix nun_custom_id_suffix; val str_of_nun_free = unprefix nun_free_prefix #> unsuffix nun_custom_id_suffix; val str_of_nun_tfree = unprefix nun_tfree_prefix #> unsuffix nun_custom_id_suffix; val str_of_nun_var = unprefix nun_var_prefix #> unsuffix nun_custom_id_suffix;
fun index_name s 0 = s
| index_name s j = let val n = size s; val m = n - 1; in String.substring (s, 0, m) ^ string_of_int j ^ String.substring (s, m, n - m) end;
val dummy_ty = NType (nun_dummy, []); val prop_ty = NType (nun_prop, []);
fun mk_arrow_ty (dom, ran) = NType (nun_arrow, [dom, ran]); val mk_arrows_ty = Library.foldr mk_arrow_ty;
val nabss = Library.foldr NAbs; val napps = Library.foldl NApp;
fun domain_ty (NType (_, [ty, _])) = ty
| domain_ty ty = ty;
fun range_ty (NType (_, [_, ty])) = ty
| range_ty ty = ty;
fun domain_tys 0 _ = []
| domain_tys n ty = domain_ty ty :: domain_tys (n - 1) (range_ty ty);
val safe_ty_of = try ty_of #> the_default dummy_ty;
fun strip_nun_binders binder (app as NApp (NConst (id, _, _), NAbs (var, body))) = if id = binder then
strip_nun_binders binder body
|>> cons var else
([], app)
| strip_nun_binders _ tm = ([], tm);
fun fold_map_option _ NONE = pair NONE
| fold_map_option f (SOME x) = f x #>> SOME;
fun fold_map_ty_idents f (NType (id, tys)) =
f id
##>> fold_map (fold_map_ty_idents f) tys
#>> NType;
fun fold_map_match_branch_idents f (id, vars, body) =
f id
##>> fold_map (fold_map_tm_idents f) vars
##>> fold_map_tm_idents f body
#>> Scan.triple1 and fold_map_tm_idents f (NAtom (j, ty)) =
fold_map_ty_idents f ty
#>> curry NAtom j
| fold_map_tm_idents f (NConst (id, tys, ty)) =
f id
##>> fold_map (fold_map_ty_idents f) tys
##>> fold_map_ty_idents f ty
#>> (Scan.triple1 #> NConst)
| fold_map_tm_idents f (NAbs (var, body)) =
fold_map_tm_idents f var
##>> fold_map_tm_idents f body
#>> NAbs
| fold_map_tm_idents f (NMatch (obj, branches)) =
fold_map_tm_idents f obj
##>> fold_map (fold_map_match_branch_idents f) branches
#>> NMatch
| fold_map_tm_idents f (NApp (const, arg)) =
fold_map_tm_idents f const
##>> fold_map_tm_idents f arg
#>> NApp;
fun dest_rassoc_args oper arg0 rest =
(case rest of
NApp (NApp (oper', arg1), rest') => if oper' = oper then arg0 :: dest_rassoc_args oper arg1 rest'else [arg0, rest]
| _ => [arg0, rest]);
val rcomb_tms = fold (fn arg => fn func => NApp (func, arg)); val abs_tms = fold_rev (curry NAbs);
fun fresh_var_names_wrt_tm n tm = let fun max_var_br (_, vars, body) = fold max_var (body :: vars) and max_var (NAtom _) = I
| max_var (NConst (id, _, _)) =
(fn max => ifString.isPrefix nun_var_prefix id andalso size id > size max then id else max)
| max_var (NApp (func, arg)) = fold max_var [func, arg]
| max_var (NAbs (var, body)) = fold max_var [var, body]
| max_var (NMatch (obj, branches)) = max_var obj #> fold max_var_br branches;
val dummy_name = nun_var_of_str Name.uu; val max_name = max_var tm dummy_name; in map (index_name max_name) (1 upto n) end;
fun eta_expandN_tm 0 tm = tm
| eta_expandN_tm n tm = let val var_names = fresh_var_names_wrt_tm n tm; val arg_tys = domain_tys n (ty_of tm); val vars = map2 (fn id => fn ty => NConst (id, [], ty)) var_names arg_tys; in
abs_tms vars (rcomb_tms vars tm) end;
val str_of_ty = let fun str_of maybe_parens (NType (id, tys)) = if id = nun_arrow then
(case tys of
[ty, ty'] => maybe_parens (str_of nun_parens ty ^ " " ^ nun_arrow ^ " " ^ str_of I ty')) else
id ^ str_of_nun_arg_list (str_of I) tys in
str_of I end;
fun str_of_at_const id tys =
nun_at ^ str_of_ident id ^ str_of_nun_arg_list str_of_ty tys;
fun str_of_app ty_opt const arg = let val ty_opt' = try (Option.map (fn ty => mk_arrow_ty (ty_of arg, ty))) ty_opt
|> the_default NONE; in
(str_of ty_opt' const |> (case const of NAbs _ => nun_parens | _ => I)) ^
str_of_nun_arg_list (str_of NONE) [arg] end and str_of_br ty_opt (id, vars, body) = " " ^ nun_bar ^ " " ^ id ^ space_implode "" (map (prefix " " o str_of NONE) vars) ^ " " ^
nun_arrow ^ " " ^ str_of ty_opt body and str_of_tmty tm = letval ty = ty_of tm in
str_of (SOME ty) tm ^ " " ^ nun_colon ^ " " ^ str_of_ty ty end and str_of _ (NAtom (j, _)) = nun_dollar ^ string_of_int j
| str_of _ (NConst (id, [], _)) = str_of_ident id
| str_of (SOME ty0) (NConst (id, tys, ty)) = if ty = ty0 then str_of_ident id else str_of_at_const id tys
| str_of _ (NConst (id, tys, _)) = str_of_at_const id tys
| str_of ty_opt (NAbs (var, body)) =
nun_lambda ^ " " ^
(case ty_opt of
SOME ty => str_of (SOME (domain_ty ty))
| NONE => nun_parens o str_of_tmty) var ^
nun_dot ^ " " ^ str_of (Option.map range_ty ty_opt) body
| str_of ty_opt (NMatch (obj, branches)) =
nun_match ^ " " ^ str_of NONE obj ^ " " ^ nun_with ^
space_implode "" (map (str_of_br ty_opt) branches) ^ " " ^ nun_end
| str_of ty_opt (app as NApp (func, argN)) =
(case (func, argN) of
(NApp (oper as NConst (id, _, _), arg1), arg2) => if id = nun_asserting then
str_of ty_opt arg1 ^ " " ^ nun_asserting ^ " " ^ str_of (SOME prop_ty) arg2
|> nun_parens elseif id = nun_equals then
(str_of NONE arg1 |> not (is_triv_head arg1) ? nun_parens) ^ " " ^ id ^ " " ^
(str_of (try ty_of arg2) arg2 |> not (is_triv_head arg2) ? nun_parens) elseif is_nun_const_connective id then letval args = dest_rassoc_args oper arg1 arg2 in
space_implode (" " ^ id ^ " ")
(map (fn arg => str_of NONE arg |> not (is_triv_head arg) ? nun_parens) args) end else
str_of_app ty_opt func argN
| (NApp (NApp (NConst (id, _, _), arg1), arg2), arg3) => if id = nun_if then
nun_if ^ " " ^ str_of NONE arg1 ^ " " ^ nun_then ^ " " ^ str_of NONE arg2 ^ " " ^
nun_else ^ " " ^ str_of NONE arg3
|> nun_parens else
str_of_app ty_opt func argN
| (NConst (id, _, _), NAbs _) => if is_nun_const_quantifier id then letval (vars, body) = strip_nun_binders id appin
id ^ " " ^ implode_space (map (nun_parens o str_of_tmty) vars) ^ nun_dot ^ " " ^
str_of NONE body end else
str_of_app ty_opt func argN
| _ => str_of_app ty_opt func argN); in
(str_of_tmty, str_of NONE) end;
val empty_name_pool = {nice_of_ugly = Symtab.empty, ugly_of_nice = Symtab.empty};
val nice_of_ugly_suggestion =
unascii_of #> Long_Name.base_name #> ascii_of #> unsuffix nun_custom_id_suffix
#> (fn s => if s = "" orelse not (Char.isAlpha (String.sub (s, 0))) then"x" ^ s else s);
fun allocate_nice ({nice_of_ugly, ugly_of_nice} : name_pool) (ugly, nice_sugg0) = let fun alloc j = letval nice_sugg = index_name nice_sugg0 j in
(case Symtab.lookup ugly_of_nice nice_sugg of
NONE =>
(nice_sugg,
{nice_of_ugly = Symtab.update_new (ugly, nice_sugg) nice_of_ugly,
ugly_of_nice = Symtab.update_new (nice_sugg, ugly) ugly_of_nice})
| SOME _ => alloc (j + 1)) end; in
alloc 0 end;
fun nice_ident ugly (pool as {nice_of_ugly, ...}) = ifString.isSuffix nun_custom_id_suffix ugly then
(case Symtab.lookup nice_of_ugly ugly of
NONE => allocate_nice pool (ugly, nice_of_ugly_suggestion ugly)
| SOME nice => (nice, pool)) else
(ugly, pool);
fun nice_nun_problem problem =
fold_map_nun_problem_idents nice_ident problem empty_name_pool;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.