src/Provers/classical.ML
changeset 26928 ca87aff1ad2d
parent 26497 1873915c64a9
child 26938 64e850c3da9e
equal deleted inserted replaced
26927:8684b5240f11 26928:ca87aff1ad2d
   336 
   336 
   337 (*Warn if the rule is already present ELSEWHERE in the claset.  The addition
   337 (*Warn if the rule is already present ELSEWHERE in the claset.  The addition
   338   is still allowed.*)
   338   is still allowed.*)
   339 fun warn_dup th (CS{safeIs, safeEs, hazIs, hazEs, ...}) =
   339 fun warn_dup th (CS{safeIs, safeEs, hazIs, hazEs, ...}) =
   340        if mem_thm safeIs th then
   340        if mem_thm safeIs th then
   341          warning ("Rule already declared as safe introduction (intro!)\n" ^ string_of_thm th)
   341          warning ("Rule already declared as safe introduction (intro!)\n" ^ Display.string_of_thm th)
   342   else if mem_thm safeEs th then
   342   else if mem_thm safeEs th then
   343          warning ("Rule already declared as safe elimination (elim!)\n" ^ string_of_thm th)
   343          warning ("Rule already declared as safe elimination (elim!)\n" ^ Display.string_of_thm th)
   344   else if mem_thm hazIs th then
   344   else if mem_thm hazIs th then
   345          warning ("Rule already declared as introduction (intro)\n" ^ string_of_thm th)
   345          warning ("Rule already declared as introduction (intro)\n" ^ Display.string_of_thm th)
   346   else if mem_thm hazEs th then
   346   else if mem_thm hazEs th then
   347          warning ("Rule already declared as elimination (elim)\n" ^ string_of_thm th)
   347          warning ("Rule already declared as elimination (elim)\n" ^ Display.string_of_thm th)
   348   else ();
   348   else ();
   349 
   349 
   350 
   350 
   351 (*** Safe rules ***)
   351 (*** Safe rules ***)
   352 
   352 
   353 fun addSI w th
   353 fun addSI w th
   354   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   354   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   355              safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   355              safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   356   if mem_thm safeIs th then
   356   if mem_thm safeIs th then
   357          (warning ("Ignoring duplicate safe introduction (intro!)\n" ^ string_of_thm th);
   357          (warning ("Ignoring duplicate safe introduction (intro!)\n" ^ Display.string_of_thm th);
   358           cs)
   358           cs)
   359   else
   359   else
   360   let val th' = flat_rule th
   360   let val th' = flat_rule th
   361       val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
   361       val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
   362           List.partition Thm.no_prems [th']
   362           List.partition Thm.no_prems [th']
   378 
   378 
   379 fun addSE w th
   379 fun addSE w th
   380   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   380   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   381              safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   381              safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   382   if mem_thm safeEs th then
   382   if mem_thm safeEs th then
   383          (warning ("Ignoring duplicate safe elimination (elim!)\n" ^ string_of_thm th);
   383          (warning ("Ignoring duplicate safe elimination (elim!)\n" ^ Display.string_of_thm th);
   384           cs)
   384           cs)
   385   else if has_fewer_prems 1 th then
   385   else if has_fewer_prems 1 th then
   386     	error("Ill-formed elimination rule\n" ^ string_of_thm th)
   386     	error("Ill-formed elimination rule\n" ^ Display.string_of_thm th)
   387   else
   387   else
   388   let
   388   let
   389       val th' = classical_rule (flat_rule th)
   389       val th' = classical_rule (flat_rule th)
   390       val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
   390       val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
   391           List.partition (fn rl => nprems_of rl=1) [th']
   391           List.partition (fn rl => nprems_of rl=1) [th']
   408 fun cs addSIs ths = fold_rev (addSI NONE) ths cs;
   408 fun cs addSIs ths = fold_rev (addSI NONE) ths cs;
   409 fun cs addSEs ths = fold_rev (addSE NONE) ths cs;
   409 fun cs addSEs ths = fold_rev (addSE NONE) ths cs;
   410 
   410 
   411 fun make_elim th =
   411 fun make_elim th =
   412     if has_fewer_prems 1 th then
   412     if has_fewer_prems 1 th then
   413     	error("Ill-formed destruction rule\n" ^ string_of_thm th)
   413     	error("Ill-formed destruction rule\n" ^ Display.string_of_thm th)
   414     else Tactic.make_elim th;
   414     else Tactic.make_elim th;
   415 
   415 
   416 fun cs addSDs ths = cs addSEs (map make_elim ths);
   416 fun cs addSDs ths = cs addSEs (map make_elim ths);
   417 
   417 
   418 
   418 
   420 
   420 
   421 fun addI w th
   421 fun addI w th
   422   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   422   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   423              safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   423              safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   424   if mem_thm hazIs th then
   424   if mem_thm hazIs th then
   425          (warning ("Ignoring duplicate introduction (intro)\n" ^ string_of_thm th);
   425          (warning ("Ignoring duplicate introduction (intro)\n" ^ Display.string_of_thm th);
   426           cs)
   426           cs)
   427   else
   427   else
   428   let val th' = flat_rule th
   428   let val th' = flat_rule th
   429       val nI = length hazIs + 1
   429       val nI = length hazIs + 1
   430       and nE = length hazEs
   430       and nE = length hazEs
   440         safe0_netpair = safe0_netpair,
   440         safe0_netpair = safe0_netpair,
   441         safep_netpair = safep_netpair,
   441         safep_netpair = safep_netpair,
   442         xtra_netpair = insert' (the_default 1 w) (nI,nE) ([th], []) xtra_netpair}
   442         xtra_netpair = insert' (the_default 1 w) (nI,nE) ([th], []) xtra_netpair}
   443   end
   443   end
   444   handle THM("RSN: no unifiers",_,_) => (*from dup_intr*)
   444   handle THM("RSN: no unifiers",_,_) => (*from dup_intr*)
   445          error ("Ill-formed introduction rule\n" ^ string_of_thm th);
   445          error ("Ill-formed introduction rule\n" ^ Display.string_of_thm th);
   446 
   446 
   447 fun addE w th
   447 fun addE w th
   448   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   448   (cs as CS {safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   449             safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   449             safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   450   if mem_thm hazEs th then
   450   if mem_thm hazEs th then
   451          (warning ("Ignoring duplicate elimination (elim)\n" ^ string_of_thm th);
   451          (warning ("Ignoring duplicate elimination (elim)\n" ^ Display.string_of_thm th);
   452           cs)
   452           cs)
   453   else if has_fewer_prems 1 th then
   453   else if has_fewer_prems 1 th then
   454     	error("Ill-formed elimination rule\n" ^ string_of_thm th)
   454     	error("Ill-formed elimination rule\n" ^ Display.string_of_thm th)
   455   else
   455   else
   456   let
   456   let
   457       val th' = classical_rule (flat_rule th)
   457       val th' = classical_rule (flat_rule th)
   458       val nI = length hazIs
   458       val nI = length hazIs
   459       and nE = length hazEs + 1
   459       and nE = length hazEs + 1
   541         safep_netpair = safep_netpair,
   541         safep_netpair = safep_netpair,
   542         xtra_netpair = delete' ([th], []) xtra_netpair}
   542         xtra_netpair = delete' ([th], []) xtra_netpair}
   543     end
   543     end
   544  else cs
   544  else cs
   545  handle THM("RSN: no unifiers",_,_) => (*from dup_intr*)
   545  handle THM("RSN: no unifiers",_,_) => (*from dup_intr*)
   546         error ("Ill-formed introduction rule\n" ^ string_of_thm th);
   546         error ("Ill-formed introduction rule\n" ^ Display.string_of_thm th);
   547 
   547 
   548 
   548 
   549 fun delE th
   549 fun delE th
   550          (cs as CS{safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   550          (cs as CS{safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   551                    safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   551                    safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   570   let val th' = Tactic.make_elim th in
   570   let val th' = Tactic.make_elim th in
   571     if mem_thm safeIs th orelse mem_thm safeEs th orelse
   571     if mem_thm safeIs th orelse mem_thm safeEs th orelse
   572       mem_thm hazIs th orelse mem_thm hazEs th orelse
   572       mem_thm hazIs th orelse mem_thm hazEs th orelse
   573       mem_thm safeEs th' orelse mem_thm hazEs th'
   573       mem_thm safeEs th' orelse mem_thm hazEs th'
   574     then delSI th (delSE th (delI th (delE th (delSE th' (delE th' cs)))))
   574     then delSI th (delSE th (delI th (delE th (delSE th' (delE th' cs)))))
   575     else (warning ("Undeclared classical rule\n" ^ string_of_thm th); cs)
   575     else (warning ("Undeclared classical rule\n" ^ Display.string_of_thm th); cs)
   576   end;
   576   end;
   577 
   577 
   578 fun cs delrules ths = fold delrule ths cs;
   578 fun cs delrules ths = fold delrule ths cs;
   579 
   579 
   580 
   580