added Isar/net_rules.ML;
authorwenzelm
Sun Feb 27 15:07:53 2000 +0100 (2000-02-27)
changeset 82989b089bc07f69
parent 8297 f5fdb69ad4d2
child 8299 52d9f64841d6
added Isar/net_rules.ML;
src/Pure/IsaMakefile
src/Pure/Isar/ROOT.ML
src/Pure/Isar/net_rules.ML
     1.1 --- a/src/Pure/IsaMakefile	Thu Feb 24 21:33:32 2000 +0100
     1.2 +++ b/src/Pure/IsaMakefile	Sun Feb 27 15:07:53 2000 +0100
     1.3 @@ -23,30 +23,31 @@
     1.4  
     1.5  Pure: $(OUT)/Pure
     1.6  
     1.7 -$(OUT)/Pure: General/ROOT.ML General/buffer.ML General/file.ML \
     1.8 -  General/graph.ML General/history.ML General/name_space.ML \
     1.9 -  General/object.ML General/path.ML General/position.ML \
    1.10 -  General/pretty.ML General/scan.ML General/seq.ML General/source.ML \
    1.11 -  General/symbol.ML General/table.ML General/url.ML Interface/ROOT.ML \
    1.12 -  Interface/isamode.ML Interface/proof_general.ML Isar/ROOT.ML \
    1.13 -  Isar/args.ML Isar/attrib.ML Isar/auto_bind.ML Isar/calculation.ML \
    1.14 -  Isar/comment.ML Isar/isar.ML Isar/isar_cmd.ML Isar/isar_syn.ML \
    1.15 -  Isar/isar_thy.ML Isar/local_defs.ML Isar/method.ML Isar/obtain.ML \
    1.16 -  Isar/outer_lex.ML Isar/outer_parse.ML Isar/outer_syntax.ML \
    1.17 -  Isar/proof.ML Isar/proof_context.ML Isar/proof_data.ML \
    1.18 -  Isar/proof_history.ML Isar/session.ML Isar/skip_proof.ML \
    1.19 -  Isar/toplevel.ML ML-Systems/mlworks.ML ML-Systems/polyml.ML \
    1.20 -  ML-Systems/smlnj-0.93.ML ML-Systems/smlnj.ML ROOT.ML Syntax/ROOT.ML \
    1.21 -  Syntax/ast.ML Syntax/lexicon.ML Syntax/mixfix.ML Syntax/parser.ML \
    1.22 -  Syntax/printer.ML Syntax/syn_ext.ML Syntax/syn_trans.ML \
    1.23 -  Syntax/syntax.ML Syntax/token_trans.ML Syntax/type_ext.ML \
    1.24 -  Thy/ROOT.ML Thy/html.ML Thy/latex.ML Thy/present.ML Thy/thm_deps.ML \
    1.25 -  Thy/thm_database.ML Thy/thy_info.ML Thy/thy_load.ML Thy/thy_parse.ML \
    1.26 -  Thy/thy_scan.ML Thy/thy_syn.ML axclass.ML basis.ML context.ML \
    1.27 -  deriv.ML display.ML drule.ML envir.ML goals.ML install_pp.ML \
    1.28 -  library.ML locale.ML logic.ML net.ML pattern.ML pure.ML pure_thy.ML \
    1.29 -  search.ML sign.ML sorts.ML tactic.ML tctical.ML term.ML theory.ML \
    1.30 -  theory_data.ML thm.ML type.ML type_infer.ML unify.ML
    1.31 +$(OUT)/Pure: General/ROOT.ML General/buffer.ML General/file.ML		\
    1.32 +  General/graph.ML General/history.ML General/name_space.ML		\
    1.33 +  General/object.ML General/path.ML General/position.ML			\
    1.34 +  General/pretty.ML General/scan.ML General/seq.ML General/source.ML	\
    1.35 +  General/symbol.ML General/table.ML General/url.ML Interface/ROOT.ML	\
    1.36 +  Interface/isamode.ML Interface/proof_general.ML Isar/ROOT.ML		\
    1.37 +  Isar/args.ML Isar/attrib.ML Isar/auto_bind.ML Isar/calculation.ML	\
    1.38 +  Isar/comment.ML Isar/isar.ML Isar/isar_cmd.ML Isar/isar_syn.ML	\
    1.39 +  Isar/isar_thy.ML Isar/local_defs.ML Isar/method.ML Isar/net_rules.ML	\
    1.40 +  Isar/obtain.ML Isar/outer_lex.ML Isar/outer_parse.ML			\
    1.41 +  Isar/outer_syntax.ML Isar/proof.ML Isar/proof_context.ML		\
    1.42 +  Isar/proof_data.ML Isar/proof_history.ML Isar/session.ML		\
    1.43 +  Isar/skip_proof.ML Isar/toplevel.ML ML-Systems/mlworks.ML		\
    1.44 +  ML-Systems/polyml.ML ML-Systems/smlnj-0.93.ML ML-Systems/smlnj.ML	\
    1.45 +  ROOT.ML Syntax/ROOT.ML Syntax/ast.ML Syntax/lexicon.ML		\
    1.46 +  Syntax/mixfix.ML Syntax/parser.ML Syntax/printer.ML			\
    1.47 +  Syntax/syn_ext.ML Syntax/syn_trans.ML Syntax/syntax.ML		\
    1.48 +  Syntax/token_trans.ML Syntax/type_ext.ML Thy/ROOT.ML Thy/html.ML	\
    1.49 +  Thy/latex.ML Thy/present.ML Thy/thm_deps.ML Thy/thm_database.ML	\
    1.50 +  Thy/thy_info.ML Thy/thy_load.ML Thy/thy_parse.ML Thy/thy_scan.ML	\
    1.51 +  Thy/thy_syn.ML axclass.ML basis.ML context.ML deriv.ML display.ML	\
    1.52 +  drule.ML envir.ML goals.ML install_pp.ML library.ML locale.ML		\
    1.53 +  logic.ML net.ML pattern.ML pure.ML pure_thy.ML search.ML sign.ML	\
    1.54 +  sorts.ML tactic.ML tctical.ML term.ML theory.ML theory_data.ML	\
    1.55 +  thm.ML type.ML type_infer.ML unify.ML
    1.56  	@./mk
    1.57  
    1.58  
     2.1 --- a/src/Pure/Isar/ROOT.ML	Thu Feb 24 21:33:32 2000 +0100
     2.2 +++ b/src/Pure/Isar/ROOT.ML	Sun Feb 27 15:07:53 2000 +0100
     2.3 @@ -13,6 +13,7 @@
     2.4  use "proof_history.ML";
     2.5  use "args.ML";
     2.6  use "attrib.ML";
     2.7 +use "net_rules.ML";
     2.8  use "method.ML";
     2.9  
    2.10  (*derived proof elements*)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/Pure/Isar/net_rules.ML	Sun Feb 27 15:07:53 2000 +0100
     3.3 @@ -0,0 +1,74 @@
     3.4 +(*  Title:      Pure/Isar/net_rules.ML
     3.5 +    ID:         $Id$
     3.6 +    Author:     Markus Wenzel, TU Muenchen
     3.7 +
     3.8 +Efficient storage of rules: preserves order, prefers later entries.
     3.9 +*)
    3.10 +
    3.11 +signature NET_RULES =
    3.12 +sig
    3.13 +  type 'a T
    3.14 +  val rules: 'a T -> 'a list
    3.15 +  val may_unify: 'a T -> term -> 'a list
    3.16 +  val init: ('a * 'a -> bool) -> ('a -> term) -> 'a T
    3.17 +  val merge: 'a T * 'a T -> 'a T
    3.18 +  val delete: 'a -> 'a T -> 'a T
    3.19 +  val insert: 'a -> 'a T -> 'a T
    3.20 +  val deletes: 'a list -> 'a T -> 'a T
    3.21 +  val inserts: 'a list -> 'a T -> 'a T
    3.22 +  val init_intro: thm T
    3.23 +  val init_elim: thm T
    3.24 +end;
    3.25 +
    3.26 +structure NetRules: NET_RULES =
    3.27 +struct
    3.28 +
    3.29 +(* datatype rules *)
    3.30 +
    3.31 +datatype 'a T =
    3.32 +  Rules of {
    3.33 +    eq: 'a * 'a -> bool,
    3.34 +    index: 'a -> term,
    3.35 +    rules: 'a list,
    3.36 +    next: int,
    3.37 +    net: (int * 'a) Net.net};
    3.38 +
    3.39 +fun mk_rules eq index rules next net =
    3.40 +  Rules {eq = eq, index = index, rules = rules, next = next, net = net};
    3.41 +
    3.42 +fun rules (Rules {rules = rs, ...}) = rs;
    3.43 +fun may_unify (Rules {net, ...}) tm = Tactic.orderlist (Net.unify_term net tm);
    3.44 +
    3.45 +
    3.46 +(* build rules *)
    3.47 +
    3.48 +fun init eq index = mk_rules eq index [] ~1 Net.empty;
    3.49 +
    3.50 +fun add rule (Rules {eq, index, rules, next, net}) =
    3.51 +  mk_rules eq index (rule :: rules) (next - 1)
    3.52 +    (Net.insert_term ((index rule, (next, rule)), net, K false));
    3.53 +
    3.54 +fun make eq index rules = foldr (uncurry add) (rules, init eq index);
    3.55 +
    3.56 +
    3.57 +fun merge (Rules {eq, index, rules = rules1, ...}, Rules {rules = rules2, ...}) =
    3.58 +  make eq index (Library.generic_merge eq I I rules1 rules2);
    3.59 +
    3.60 +fun delete rule (rs as Rules {eq, index, rules, next, net}) =
    3.61 +  if not (Library.gen_mem eq (rule, rules)) then rs
    3.62 +  else mk_rules eq index (Library.gen_rem eq (rules, rule)) next
    3.63 +    (Net.delete_term ((index rule, (0, rule)), net, eq o pairself #2));
    3.64 +
    3.65 +fun insert rule rs = add rule (delete rule rs);    (*ensure new rule gets precedence*)
    3.66 +
    3.67 +fun deletes rules rs = foldr (uncurry delete) (rules, rs);
    3.68 +fun inserts rules rs = foldr (uncurry insert) (rules, rs);
    3.69 +
    3.70 +
    3.71 +(* intro/elim rules *)
    3.72 +
    3.73 +val init_intro = init Thm.eq_thm Thm.concl_of;
    3.74 +val init_elim = init Thm.eq_thm Thm.major_prem_of;
    3.75 +
    3.76 +
    3.77 +end;