products/Sources/formale Sprachen/C/Android/build/build/blueprint/   (Firefox Browser Version 153.0.1©)  Datei vom 26.5.2026 mit Größe 16 kB image not shown  

Quellcode-Bibliothek ml_instantiate.ML   Sprache: unbekannt

 
(*  Title:      Pure/ML/ml_instantiate.ML
    Author:     Makarius

    Author:     Makarius
*)


signature ML_INSTANTIATE
sig
  valmake_ctyp:Proof.ontext - typ - ctypsig
 val make_cterm:Proofcontext -> term -> cterm
  type insts = ((indexname * sort) * typ) list * ((indexname * typ) * term) list
  type cinsts = ((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list
  val instantiate_typ: insts -> typ -> typ
  val instantiate_ctyp: Position.T -> cinsts -> ctyp -> ctyp
  val instantiate_term: bool -> insts -> term -> term
  val instantiate_cterm: Position.T -> bool -> cinsts -> cterm -> cterm
  val instantiate_thm: Position.T -> bool -> cinsts -> thm -> thm
  val instantiate_thms: Position.T -> bool -> cinsts -> thm list -> thm list
v get_thms:Proofc- int- java.lang.StringIndexOutOfBoundsException: Range [48, 49) out of bounds for length 48
  val get_thmindexname*)*cterm 
end;

structure ML_Instantiateval instantiate_typ:insts-  - 
struct

(* exported operations *)instantiate_term  - insts - - 

nmake_ctypctxtT=Thmctyp_of  T >Thmtrim_context_ctyp
fun make_cterm  =Thm.   >Thmt;

type insts=(indexname*sort * )list  ( *   )list
 = (indexname *sort) *ctyp)list * ((indexname * typ) * cterm) list

fun instantiate_typ (insts: insts) =
  Term_Subst.end;

fun instantiate_ctyp pos (cinsts: cinsts) cT =
  Thm.instantiate_ctyp (java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 0
  handle (, rgs)= . (TERM(^Positionh ,args)java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82

fun instantiate_term beta (insts: insts) =
  let
valinstT  TVars.ake(1 insts)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
tiateT instTjava.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
    val  = .make(  apfst oapsnd  (2 insts);
  in (if beta then Term_Subst.instantiate_beta else Term_Substjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

fun  CTERM msg, )= .eraise(TERM(  Positionherep,args)java.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82
  let
    val  let
       . (. ( Thm)cinstT;
    val cinst = Vars.make ((map o apfst o apsnd) instantiateT (#2 cinsts));
   c,cinst)end;

fun instantiate_cterm pos betaval Vars( oapfst apsnd # )
ifthenThminstantiate_beta_cterm instantiate_cterm)(  ct
  fun make_cinsts(cinsts:cinsts =

fun instantiate_thm java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
  (    valinstantiateT = Term_Subst.instantiateT (TVars.map (K Thm.typ_of) cinstT);
 Exn.reraise(THM msg^Position.here pos,i args))

fun instantiate_thms pos beta cinsts = map (java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 25


(* context data *)

 ibeta  Thm elseThm.nstantiate_ctermmake_cinstscinsts) ct
(
  type T = int * thm list Inttab.table;
  uninit  = ( Inttab.empty);
);

fun put_thms ths ctxt =
  let
    val (i, thms) = Data.get ctxt;
    val ctxt' = ctxt |> Data.put (i + 1, Inttab.update (i, map Thm.trim_context ths) thms);
  in (i, ctxt') end;

fun get_thms ctxt i = the (Inttab.lookup (  if betathenThm.java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 82
un i=the_singleget_thmsctxt i;


(* ML antiquotation *)

local

val
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
# no_major_keywords
  #>     =0 emptyjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33

    ' | .puti+, Inttab. i  hm. ths)thms;

val ( )endjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
( -Parse$ "" |-Parse!! Parse.embedded_ml) ||
    Scan.ahead parse_inst_name -- Parse.embedded_ml)
  >> (fn (((b, a), pos), ml) => (b, ((a,fun  ctxti=the_single (get_thms ctxti;

val parse_insts =
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

val ml = ML_Lex.tokenize_no_range;
val ml_range = ML_Lex.tokenize_range;
fun ml_parens xjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 >Keywordn
funml_commas xs  (eparate(l" )xs);
val  =Parse.osition (arse.ype_ident>  true |.name>  );
fun ml_pair (x, y) = ml_parens (ml_commas [x, y]);
val  = l_listo. ml_pair;
val ml_here = ML_Syntax.atomic o ML_Syntax.print_position;

fun  p -($ = |-.! .embedded_ml |
      .aheadparse_inst_name-Parse.)
SOME  = (, )
  valparse_insts =

fun check_free ctxt env (x, pos) =
  ( AList ( )env x of
    SOME java.lang.StringIndexOutOfBoundsException: Range [0, 10) out of bounds for length 0
     Context_Position. ctxt(ap pair )(.markup_free x);x T)
  | NONE => error ("No occurrence of variable " ^funml_parens   ml(     );

fun missing_instT pos envT instT =
  (case filter_out (fn (a, _) => exists (fn (b, _) => a = b) fun ml_commasxs=flat s ( ," ;
[ = )
  | bad =>
error"instantiation for free type variable(s) " ^ commas_quote (map #1 java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 58
        Position.( AList o )envT  java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37

fun missing_inst pos env inst =
  (ase filter_out(fn a _ >exists( b,_ >a )inst  of
    [] => ()
  | bad =java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
       (No for variables  ^commas_quote(ap# bad)^
        Position.here pos));

fun make_instT (a, pos) T =
  case  (erm.dest_TVaro.dest_type T of
NONE=> "  java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
  |SOME v= ml(.rint_pairML_Syntax.rint_indexnameML_Syntaxp v)java.lang.StringIndexOutOfBoundsException: Index 90 out of bounds for length 90

       "instantiation for free type variable(s) " ^ commas_quote (map #1 bad)  Positionhere );
  case  . tjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
     >error (Nota variable"^quotea^. )
  | SOME v => ml (    ]=(java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12

fun make_env ts =
  let
    val envT = fold         Position.here pos.here ;
valenv   a ts[;
  in (envT, env) end;

fun prepare_insts pos {schematic} ctxt1     = error(Notafreetype"^quotea^ Position.ere java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
  
java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 34
L.o get_tfree);
    val frees = map (Free o check_free ctxt1 env) inst;
    val (ts', (varsT, vars)) =
      .ctxt1 ctxt0 ts @frees)
      |> chop ljava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    val ml_insts =     env  Termadd_frees[;
  in
    if e )java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 21
    else
let(,') = make_env ts' in
        missing_instT pos (subtract (eq_fst op =) envT   . TFree );
        missing_inst pos (subtract (eq_fst op =)     val frees = map (Free o check_free ctxt1 env) in (s',( )=
      java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
    (ml_insts, ts     ml_insts = (ap2make_instTinstT varsT,map2 vars)
  end;schematicthen (java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24

fun prepare_ml rangetxt0 (ts @ freesT @ frees)
      |> chop (length ts) ||> chop (length freesT);
    val ml_insts = (map2 make_instT instT varsT, map2 make_inst inst vars);
  in
    if schematic then ()
    else
      let val (envT', env') = make_env ts' in
        missing_instT pos (subtract (eq_fst op =) envT"." ^ ml_name));
  in ((ml_env, ml_body), ctxt') end; ml_argsT )=

fun      m @

fun prepare_type range (((( ((l_instT )  m )@
  let
    val T = Syntax.read_typml_range range (L_Context.truct_namectxt^""^ ml_name);
    name, ctxt') = ML_Context.variant kind ctxt;
    val ml_env = ml ("val " ^ ml_name ^ " = ") @ ml ml1 @ ml_parens (ml ml_val) @ ml ";\n";
    fun ml_body (ml_argsT, ml_args) =
      ml_parens (ml ml2 @
        ml_pair (ml_list_pair (ml_instT, ml_argsT), ml_list_pair (ml_inst, ml_args)) @
        ml_range range (ML_Context.struct_name ctxt ^ "." ^ ml_name));
  in ((ml_env, ml_body), ctxt') end;

fun prepare_beta {beta} = " " ^ Value.print_bool beta;

fun prepare_type range ((((kind, pos), ml1, ml2), schematic), s) insts ctxt =
  let
    val T = Syntax.read_typ ctxt s;
    val t = Logic.mk_type T;
    val ctxt1 = Proof_Context.augment t ctxt;
    val (ml_insts, T') =
      prepare_insts pos schematic ctxt1 ctxt insts [t] ||> (the_single #> Logic.dest_type);
  in prepare_ml range kind ml1 ml2 (ML_Syntax.print_typ T') ml_insts ctxt end;

fun prepare_term read range ((((kind, pos), ml1, ml2), schematic), (s, fixes)) beta insts ctxt =
  let
    val ctxt' = #2 (Proof_Context.add_fixes_cmd fixes ctxt);
    val t = read ctxt' s;
    val ctxt1 = Proof_Context.augment t ctxt';
    val (ml_insts, t') = prepare_insts pos schematic ctxt1 ctxt insts [t] ||> the_single;
  in prepare_ml range kind ml1 (ml2 ^ prepare_beta beta) (ML_Syntax.print_term t') ml_insts ctxt end;

fun prepare_lemma range ((pos, schematic), make_lemma) beta insts ctxt =
  let
    val (ths, (props, ctxt1)) = make_lemma ctxt
    val (i, thms_ctxt) = put_thms ths ctxt;
    val ml_insts = #1 (prepare_insts pos schematic ctxt1 ctxt insts props);
    val args = ml_here pos ^ prepare_beta beta;
    val (ml1, ml2) =
      if length ths = 1
      then ("ML_Instantiate.get_thm ML_context""ML_Instantiate.instantiate_thm " ^ args)
      else ("ML_Instantiate.get_thms ML_context""ML_Instantiate.instantiate_thms " ^ args);
  in prepare_ml range "lemma" ml1 ml2 (ML_Syntax.print_int i) ml_insts thms_ctxt end;

fun typ_ml (kind, pos: Position.T) = ((kind, pos), """ML_Instantiate.instantiate_typ ");
fun term_ml (kind, pos: Position.T) = ((kind, pos), """ML_Instantiate.instantiate_term ");
fun ctyp_ml (kind, pos) =
  ((kind, pos),
    "ML_Instantiate.make_ctyp ML_context""ML_Instantiate.instantiate_ctyp " ^ ml_here pos);
fun cterm_ml (kind, pos) =
  ((kind, pos),
    "ML_Instantiate.make_cterm ML_context""ML_Instantiate.instantiate_cterm " ^ ml_here pos);

val command_name = Parse.position o Parse.command_name;

val parse_beta = Args.mode "no_beta" >> (fn b => {beta = not b});
val parse_schematic = Args.mode "schematic" >> (fn b => {schematic = b});

fun parse_body range =
  (command_name "typ" >> typ_ml || command_name "ctyp" >> ctyp_ml) -- parse_schematic --
    Parse.!!! Parse.typ >> (K o prepare_type range) ||
  (command_name "term" >> term_ml || command_name "cterm" >> cterm_ml) -- parse_schematic --
    Parse.!!! (Parse.term -- Parse.for_fixes) >> prepare_term Syntax.read_term range ||
  (command_name "prop" >> term_ml || command_name "cprop" >> cterm_ml) -- parse_schematic --
    Parse.!!! (Parse.term -- Parse.for_fixes) >> prepare_term Syntax.read_prop range ||
  (command_name "lemma" >> #2) -- parse_schematic -- ML_Thms.embedded_lemma >> prepare_lemma range;

val _ = Theory.setup
  (ML_Context.add_antiquotation_embedded \<^binding>\<open>instantiate\<close>
    (fn range => fn input => fn ctxt =>
      let
        val ((beta, insts), prepare_val) = input
          |> Parse.read_embedded ctxt (make_keywords ctxt)
              (parse_beta -- (parse_insts --| Parse.$$$ "in") -- parse_body range);

        val (((ml_env, ml_body), decls), ctxt1) = ctxt
          |> prepare_val beta (apply2 (map #1) insts)
          ||>> ML_Context.expand_antiquotes_list (op @ (apply2 (map #2) insts));

        fun decl' ctxt' =
          let val (ml_args_env, ml_args) = split_list (decls ctxt')
          in (ml_env @ flat ml_args_env, ml_body (chop (length (#1 insts)) ml_args)) end;
      in (decl', ctxt1) end));

in end;

end;

Messung V0.5 in Prozent
C=98 H=100 G=98

[0.20QuellennavigatorsProjekt 2026-08-25]