535 |> of_univ (bounds + 1) (apps t [BVar (bounds, [])]) |
535 |> of_univ (bounds + 1) (apps t [BVar (bounds, [])]) |
536 |-> (fn t' => pair (Term.Abs ("u", dummyT, t'))) |
536 |-> (fn t' => pair (Term.Abs ("u", dummyT, t'))) |
537 in of_univ 0 t 0 |> fst end; |
537 in of_univ 0 t 0 |> fst end; |
538 |
538 |
539 |
539 |
540 (* evaluation with type reconstruction *) |
540 (* normalize with type reconstruction *) |
541 |
541 |
542 fun eval_term (nbe_program, idx_tab) raw_ctxt t_original ((vs, ty) : typscheme, t) deps = |
542 fun normalize (nbe_program, idx_tab) raw_ctxt t_original ((vs, ty) : typscheme, t) deps = |
543 let |
543 let |
544 val ctxt = Syntax.init_pretty_global (Proof_Context.theory_of raw_ctxt); |
544 val ctxt = Syntax.init_pretty_global (Proof_Context.theory_of raw_ctxt); |
545 val string_of_term = Syntax.string_of_term (Config.put show_types true ctxt); |
545 val string_of_term = Syntax.string_of_term (Config.put show_types true ctxt); |
546 fun type_infer t' = |
546 fun type_infer t' = |
547 Syntax.check_term |
547 Syntax.check_term |
589 in Thm.mk_binop eq lhs rhs end; |
589 in Thm.mk_binop eq lhs rhs end; |
590 |
590 |
591 val (_, raw_oracle) = Context.>>> (Context.map_theory_result |
591 val (_, raw_oracle) = Context.>>> (Context.map_theory_result |
592 (Thm.add_oracle (@{binding normalization_by_evaluation}, |
592 (Thm.add_oracle (@{binding normalization_by_evaluation}, |
593 fn (nbe_program_idx_tab, ctxt, vs_ty_t, deps, ct) => |
593 fn (nbe_program_idx_tab, ctxt, vs_ty_t, deps, ct) => |
594 mk_equals ctxt ct (eval_term nbe_program_idx_tab ctxt (Thm.term_of ct) vs_ty_t deps)))); |
594 mk_equals ctxt ct (normalize nbe_program_idx_tab ctxt (Thm.term_of ct) vs_ty_t deps)))); |
595 |
595 |
596 fun oracle nbe_program_idx_tab ctxt vs_ty_t deps ct = |
596 fun oracle nbe_program_idx_tab ctxt vs_ty_t deps ct = |
597 raw_oracle (nbe_program_idx_tab, ctxt, vs_ty_t, deps, ct); |
597 raw_oracle (nbe_program_idx_tab, ctxt, vs_ty_t, deps, ct); |
598 |
598 |
599 fun dynamic_conv ctxt = lift_triv_classes_conv ctxt |
599 fun dynamic_conv ctxt = lift_triv_classes_conv ctxt |
600 (Code_Thingol.dynamic_conv ctxt (fn program => oracle (compile false ctxt program) ctxt)); |
600 (Code_Thingol.dynamic_conv ctxt (fn program => |
|
601 oracle (compile false ctxt program) ctxt)); |
601 |
602 |
602 fun dynamic_value ctxt = lift_triv_classes_rew ctxt |
603 fun dynamic_value ctxt = lift_triv_classes_rew ctxt |
603 (Code_Thingol.dynamic_value ctxt I (fn program => eval_term (compile false ctxt program) ctxt)); |
604 (Code_Thingol.dynamic_value ctxt I (fn program => |
|
605 normalize (compile false ctxt program) ctxt)); |
604 |
606 |
605 fun static_conv (ctxt_consts as { ctxt, ... }) = |
607 fun static_conv (ctxt_consts as { ctxt, ... }) = |
606 let |
608 let |
607 val evaluator = Code_Thingol.static_conv_thingol ctxt_consts |
609 val conv = Code_Thingol.static_conv_thingol ctxt_consts |
608 (fn { program, ... } => oracle (compile true ctxt program)); |
610 (fn { program, ... } => oracle (compile true ctxt program)); |
609 in fn ctxt' => lift_triv_classes_conv ctxt' (evaluator ctxt') end; |
611 in fn ctxt' => lift_triv_classes_conv ctxt' (conv ctxt') end; |
610 |
612 |
611 fun static_value { ctxt, consts } = |
613 fun static_value { ctxt, consts } = |
612 let |
614 let |
613 val evaluator = Code_Thingol.static_value { ctxt = ctxt, lift_postproc = I, consts = consts } |
615 val comp = Code_Thingol.static_value { ctxt = ctxt, lift_postproc = I, consts = consts } |
614 (fn { program, ... } => eval_term (compile false ctxt program)); |
616 (fn { program, ... } => normalize (compile false ctxt program)); |
615 in fn ctxt' => lift_triv_classes_rew ctxt' (evaluator ctxt') end; |
617 in fn ctxt' => lift_triv_classes_rew ctxt' (comp ctxt') end; |
616 |
618 |
617 end; |
619 end; |