(* Title: Pure/more_pattern.ML Author: Tobias Nipkow, TU Muenchen Author: Stefan Berghofer, TU Muenchen
Add-ons to Higher-Order Patterns, outside the inference kernel.
*)
signature PATTERN = sig
include PATTERN val matches: theory -> term * term -> bool val matchess: theory -> term list * term list -> bool val equiv: theory -> term * term -> bool val first_order: term -> bool val match_rew: theory -> term -> term * term -> (term * term) option val rewrite_term: theory -> (term * term) list -> (term -> term option) list -> term -> term val rewrite_term_topdown: theory -> (term * term) list -> (term -> term option) list -> term -> term val rewrite_term_yoyo: theory -> (term * term) list -> (term -> term option) list -> term -> term end;
structure Pattern: PATTERN = struct
fun matches thy po =
(Pattern.match thy po (Vartab.empty, Vartab.empty); true) handle Pattern.MATCH => false;
fun rew_sub rw bounds _ (Abs (_, _, body) $ t) = letval t' = subst_bound (t, body) in SOME (perhaps (rew_sub rw bounds skel0) t') end
| rew_sub rw bounds skel (t $ u) =
(case (rw bounds (skel_fun skel) t, rw bounds (skel_arg skel) u) of
(SOME t', SOME u') => SOME (t' $ u')
| (SOME t', NONE) => SOME (t' $ u)
| (NONE, SOME u') => SOME (t $ u')
| (NONE, NONE) => NONE)
| rew_sub rw bounds skel (t as Abs (x, _, _)) = letval (abs, t') = variant_absfree bounds x t inOption.map abs (rw (bounds + 1) (skel_body skel) t') end
| rew_sub _ _ _ _ = NONE;
(* bottom-up with skeleton *)
fun rew_bottom _ (Var _) _ = NONE
| rew_bottom bounds skel t =
(case rew_sub rew_bottom bounds skel t of
SOME t1 =>
(case rew t1 of
SOME (t2, skel') => SOME (perhaps (rew_bottom bounds skel') t2)
| NONE => SOME t1)
| NONE =>
(case rew t of
SOME (t1, skel') => SOME (perhaps (rew_bottom bounds skel') t1)
| NONE => NONE));
(* top-down *)
fun rew_top bounds _ t =
(case rew t of
SOME (t1, _) =>
(case rew_sub rew_top bounds skel0 t1 of
SOME t2 => SOME (perhaps (rew_top bounds skel0) t2)
| NONE => SOME t1)
| NONE =>
(case rew_sub rew_top bounds skel0 t of
SOME t1 => SOME (perhaps (rew_top bounds skel0) t1)
| NONE => NONE));
(* yoyo: see also Ast.normalize *)
val rew_yoyo1 = perhaps_loop (rew #> Option.map #1);
fun rew_yoyo2 bounds _ t =
(case rew_yoyo1 t of
SOME t1 =>
(case rew_sub rew_yoyo2 bounds skel0 t1 of
SOME t2 => SOME (perhaps rew_yoyo1 t2)
| NONE => SOME t1)
| NONE =>
(case rew_sub rew_yoyo2 bounds skel0 t of
SOME t1 => SOME (perhaps rew_yoyo1 t1)
| NONE => NONE));
fun rew_yoyo bounds skel = perhaps_loop (rew_yoyo2 bounds skel); in
perhaps ((case mode of Bottom => rew_bottom | Top => rew_top | Yoyo => rew_yoyo) 0 skel0) end;
in
val rewrite_term = rewrite_term_mode Bottom; val rewrite_term_topdown = rewrite_term_mode Top; val rewrite_term_yoyo = rewrite_term_mode Yoyo;
end;
open Pattern;
end;
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.