src/Pure/variable.ML
changeset 60707 e96b7be56d44
parent 60695 757549b4bbe6
child 60805 4cc49ead6e75
equal deleted inserted replaced
60706:03a6b1792cd8 60707:e96b7be56d44
    76   val import_prf: bool -> Proofterm.proof -> Proof.context -> Proofterm.proof * Proof.context
    76   val import_prf: bool -> Proofterm.proof -> Proof.context -> Proofterm.proof * Proof.context
    77   val import: bool -> thm list -> Proof.context ->
    77   val import: bool -> thm list -> Proof.context ->
    78     ((((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list) * thm list) * Proof.context
    78     ((((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list) * thm list) * Proof.context
    79   val tradeT: (Proof.context -> thm list -> thm list) -> Proof.context -> thm list -> thm list
    79   val tradeT: (Proof.context -> thm list -> thm list) -> Proof.context -> thm list -> thm list
    80   val trade: (Proof.context -> thm list -> thm list) -> Proof.context -> thm list -> thm list
    80   val trade: (Proof.context -> thm list -> thm list) -> Proof.context -> thm list -> thm list
       
    81   val is_bound_focus: Proof.context -> bool
       
    82   val set_bound_focus: bool -> Proof.context -> Proof.context
       
    83   val restore_bound_focus: Proof.context -> Proof.context -> Proof.context
    81   val focus_params: binding list option -> term -> Proof.context ->
    84   val focus_params: binding list option -> term -> Proof.context ->
    82     (string list * (string * typ) list) * Proof.context
    85     (string list * (string * typ) list) * Proof.context
    83   val focus: binding list option -> term -> Proof.context ->
    86   val focus: binding list option -> term -> Proof.context ->
    84     ((string * (string * typ)) list * term) * Proof.context
    87     ((string * (string * typ)) list * term) * Proof.context
    85   val focus_cterm: binding list option -> cterm -> Proof.context ->
    88   val focus_cterm: binding list option -> cterm -> Proof.context ->
   445     val (xs', names') =
   448     val (xs', names') =
   446       if is_body ctxt then fold_map Name.variant xs names |>> map Name.skolem
   449       if is_body ctxt then fold_map Name.variant xs names |>> map Name.skolem
   447       else (xs, fold Name.declare xs names);
   450       else (xs, fold Name.declare xs names);
   448   in ctxt |> new_fixes names' xs xs' (map Binding.pos_of bs) end;
   451   in ctxt |> new_fixes names' xs xs' (map Binding.pos_of bs) end;
   449 
   452 
       
   453 fun bound_fixes xs ctxt =
       
   454   let
       
   455     val (xs', ctxt') = fold_map next_bound xs ctxt;
       
   456     val no_ps = replicate (length xs) Position.none;
       
   457   in ctxt' |> new_fixes (names_of ctxt') (map #1 xs) (map (#1 o dest_Free) xs') no_ps end;
       
   458 
   450 fun variant_fixes raw_xs ctxt =
   459 fun variant_fixes raw_xs ctxt =
   451   let
   460   let
   452     val names = names_of ctxt;
   461     val names = names_of ctxt;
   453     val xs = map (fn x => Name.clean x |> Name.is_internal x ? Name.internal) raw_xs;
   462     val xs = map (fn x => Name.clean x |> Name.is_internal x ? Name.internal) raw_xs;
   454     val (xs', names') = fold_map Name.variant xs names |>> (is_body ctxt ? map Name.skolem);
   463     val (xs', names') = fold_map Name.variant xs names |>> (is_body ctxt ? map Name.skolem);
   455   in ctxt |> new_fixes names' xs xs' (replicate (length xs) Position.none) end;
   464     val no_ps = replicate (length xs) Position.none;
       
   465   in ctxt |> new_fixes names' xs xs' no_ps end;
   456 
   466 
   457 end;
   467 end;
   458 
   468 
   459 val add_fixes = add_fixes_binding o map Binding.name;
   469 val add_fixes = add_fixes_binding o map Binding.name;
   460 
   470 
   618 val trade = gen_trade (import true) export;
   628 val trade = gen_trade (import true) export;
   619 
   629 
   620 
   630 
   621 (* focus on outermost parameters: !!x y z. B *)
   631 (* focus on outermost parameters: !!x y z. B *)
   622 
   632 
       
   633 val bound_focus =
       
   634   Config.bool (Config.declare ("bound_focus", @{here}) (K (Config.Bool false)));
       
   635 
       
   636 fun is_bound_focus ctxt = Config.get ctxt bound_focus;
       
   637 val set_bound_focus = Config.put bound_focus;
       
   638 fun restore_bound_focus ctxt = set_bound_focus (is_bound_focus ctxt);
       
   639 
   623 fun focus_params bindings t ctxt =
   640 fun focus_params bindings t ctxt =
   624   let
   641   let
   625     val (xs, Ts) =
   642     val ps = Term.variant_frees t (Term.strip_all_vars t);  (*as they are printed :-*)
   626       split_list (Term.variant_frees t (Term.strip_all_vars t));  (*as they are printed :-*)
   643     val (xs, Ts) = split_list ps;
   627     val (xs', ctxt') =
   644     val (xs', ctxt') =
   628       (case bindings of
   645       (case bindings of
   629         SOME bs => ctxt |> set_body true |> add_fixes_binding bs ||> restore_body ctxt
   646         SOME bs => ctxt |> set_body true |> add_fixes_binding bs ||> restore_body ctxt
   630       | NONE => ctxt |> variant_fixes xs);
   647       | NONE => if is_bound_focus ctxt then bound_fixes ps ctxt else variant_fixes xs ctxt);
   631     val ps = xs' ~~ Ts;
   648     val ps' = xs' ~~ Ts;
   632     val ctxt'' = ctxt' |> fold (declare_constraints o Free) ps;
   649     val ctxt'' = ctxt' |> fold (declare_constraints o Free) ps';
   633   in ((xs, ps), ctxt'') end;
   650   in ((xs, ps'), ctxt'') end;
   634 
   651 
   635 fun focus bindings t ctxt =
   652 fun focus bindings t ctxt =
   636   let
   653   let
   637     val ((xs, ps), ctxt') = focus_params bindings t ctxt;
   654     val ((xs, ps), ctxt') = focus_params bindings t ctxt;
   638     val t' = Term.subst_bounds (rev (map Free ps), Term.strip_all_body t);
   655     val t' = Term.subst_bounds (rev (map Free ps), Term.strip_all_body t);