173 fun merge _ = Graph.merge eq_pred_data; |
173 fun merge _ = Graph.merge eq_pred_data; |
174 ); |
174 ); |
175 |
175 |
176 (* queries *) |
176 (* queries *) |
177 |
177 |
178 val lookup_pred_data = try rep_pred_data oo Graph.get_node o PredData.get; |
178 fun lookup_pred_data thy name = |
|
179 case try (Graph.get_node (PredData.get thy)) name of |
|
180 SOME pred_data => SOME (rep_pred_data pred_data) |
|
181 | NONE => NONE |
179 |
182 |
180 fun the_pred_data thy name = case lookup_pred_data thy name |
183 fun the_pred_data thy name = case lookup_pred_data thy name |
181 of NONE => error ("No such predicate " ^ quote name) |
184 of NONE => error ("No such predicate " ^ quote name) |
182 | SOME data => data; |
185 | SOME data => data; |
183 |
186 |
851 | _ => false) end)) |
854 | _ => false) end)) |
852 else false |
855 else false |
853 |
856 |
854 (* MAJOR FIXME: prove_params should be simple |
857 (* MAJOR FIXME: prove_params should be simple |
855 - different form of introrule for parameters ? *) |
858 - different form of introrule for parameters ? *) |
856 fun prove_param thy modes (NONE, t) = all_tac |
859 fun prove_param thy modes (NONE, t) = |
857 | prove_param thy modes (m as SOME (Mode (mode, is, ms)), t) = let |
860 all_tac |
|
861 | prove_param thy modes (m as SOME (Mode (mode, is, ms)), t) = |
|
862 let |
858 val (f, args) = strip_comb t |
863 val (f, args) = strip_comb t |
859 val (params, _) = chop (length ms) args |
864 val (params, _) = chop (length ms) args |
860 val f_tac = case f of |
865 val f_tac = case f of |
861 Const (name, T) => simp_tac (HOL_basic_ss addsimps |
866 Const (name, T) => simp_tac (HOL_basic_ss addsimps |
862 (@{thm eval_pred}::(predfun_definition_of thy name mode):: |
867 (@{thm eval_pred}::(predfun_definition_of thy name mode):: |
1307 *) |
1312 *) |
1308 val (preds, nparams, all_vs, param_vs, extra_modes, clauses, arities) = |
1313 val (preds, nparams, all_vs, param_vs, extra_modes, clauses, arities) = |
1309 prepare_intrs thy prednames |
1314 prepare_intrs thy prednames |
1310 val _ = tracing "Infering modes..." |
1315 val _ = tracing "Infering modes..." |
1311 val modes = infer_modes thy extra_modes arities param_vs clauses |
1316 val modes = infer_modes thy extra_modes arities param_vs clauses |
|
1317 val _ = print_modes modes |
1312 val _ = tracing "Defining executable functions..." |
1318 val _ = tracing "Defining executable functions..." |
1313 val thy' = fold (create_definitions preds nparams) modes thy |
1319 val thy' = fold (create_definitions preds nparams) modes thy |
1314 val clauses' = map (fn (s, cls) => (s, (the (AList.lookup (op =) preds s), cls))) clauses |
1320 val clauses' = map (fn (s, cls) => (s, (the (AList.lookup (op =) preds s), cls))) clauses |
1315 val _ = tracing "Compiling equations..." |
1321 val _ = tracing "Compiling equations..." |
1316 val ts = compile_preds thy' all_vs param_vs (extra_modes @ modes) clauses' |
1322 val ts = compile_preds thy' all_vs param_vs (extra_modes @ modes) clauses' |
|
1323 val _ = map (Output.tracing o (Syntax.string_of_term_global thy')) (flat ts) |
1317 val pred_mode = |
1324 val pred_mode = |
1318 maps (fn (s, (T, _)) => map (pair (s, T)) ((the o AList.lookup (op =) modes) s)) clauses' |
1325 maps (fn (s, (T, _)) => map (pair (s, T)) ((the o AList.lookup (op =) modes) s)) clauses' |
1319 val _ = tracing "Proving equations..." |
1326 val _ = tracing "Proving equations..." |
1320 val result_thms = |
1327 val result_thms = |
1321 prove_preds thy' all_vs param_vs (extra_modes @ modes) clauses (pred_mode ~~ (flat ts)) |
1328 prove_preds thy' all_vs param_vs (extra_modes @ modes) clauses (pred_mode ~~ (flat ts)) |
1362 let |
1369 let |
1363 fun is_intro_of intro = |
1370 fun is_intro_of intro = |
1364 let |
1371 let |
1365 val (const, _) = strip_comb (HOLogic.dest_Trueprop (concl_of intro)) |
1372 val (const, _) = strip_comb (HOLogic.dest_Trueprop (concl_of intro)) |
1366 in (fst (dest_Const const) = name) end; |
1373 in (fst (dest_Const const) = name) end; |
1367 val intros = filter is_intro_of (#intrs result) |
1374 val intros = map (preprocess_intro thy) (filter is_intro_of (#intrs result)) |
1368 val elim = nth (#elims result) (find_index (fn s => s = name) (#names (fst info))) |
1375 val elim = nth (#elims result) (find_index (fn s => s = name) (#names (fst info))) |
1369 val nparams = length (InductivePackage.params_of (#raw_induct result)) |
1376 val nparams = length (InductivePackage.params_of (#raw_induct result)) |
1370 in mk_pred_data ((intros, SOME elim, nparams), []) end |
1377 in mk_pred_data ((intros, SOME elim, nparams), []) end |
1371 | NONE => error ("No such predicate: " ^ quote name) |
1378 | NONE => error ("No such predicate: " ^ quote name) |
1372 |
1379 |