HOL.thy:
authornipkow
Sat Apr 22 13:25:31 1995 +0200 (1995-04-22)
changeset 1068e0f2dffab506
parent 1067 00ed040f66e1
child 1069 66efd8f90fbd
HOL.thy:

"@" is no longer introduced as a "binder" but has its own explicit
translation rule "@x.b" == "Eps(%x.b)". If x is a proper pattern, further
translation rules for abstractions with patterns take care of the rest. This
is very modular and avoids problems with "binders" such as "!" mentioned
below.

let now allows pttrn (let (x,y) = t in u) instead of just idt (let x = t in u)


Set.thy:

UN, INT, ALL, EX, etc all use "pttrn" instead of idt. Same change as for "@"
above, except that "@" was a "binder" originally.


Prod.thy:

Added new syntax for pttrn which allows arbitrarily nested tuples. Two
translation rules take care of %pttrn. Unfortunately they cannot be
reversed. Hence a little ML-code is used as well.

Note that now "! (x,y). ..." is syntactically valid but leads to a
translation error. This is because "!" is introduced as a "binder" which
means that its translation into lambda-terms is not done by a rewrite rule
(aka macro) but by some fixed ML-code which comes after the rewriting stage
and does not know how to handle patterns. This looks like a minor blemish
since patterns in unbounded quantifiers are not that useful (well, except
maybe in unique existence ...). Ideally, there should be two syntactic
categories:

idts, as we know and love it, which does not admit patterns.
patterns, which is what idts has become now.

There is one more point where patterns are now allowed but don't make sense:

{e | idts . P}

where idts is the list of local variables.


Univ.thy: converted the defs for <++> and <**> into pattern form. It worked
perfectly.
src/HOL/HOL.thy
src/HOL/Prod.thy
src/HOL/Set.thy
src/HOL/Univ.thy
     1.1 --- a/src/HOL/HOL.thy	Sat Apr 22 12:21:41 1995 +0200
     1.2 +++ b/src/HOL/HOL.thy	Sat Apr 22 13:25:31 1995 +0200
     1.3 @@ -43,7 +43,7 @@
     1.4  
     1.5    (* Binders *)
     1.6  
     1.7 -  Eps           :: "('a => bool) => 'a"               (binder "@" 10)
     1.8 +  Eps           :: "('a => bool) => 'a"
     1.9    All           :: "('a => bool) => bool"             (binder "! " 10)
    1.10    Ex            :: "('a => bool) => bool"             (binder "? " 10)
    1.11    Ex1           :: "('a => bool) => bool"             (binder "?! " 10)
    1.12 @@ -53,7 +53,6 @@
    1.13  
    1.14    o             :: "['b => 'c, 'a => 'b, 'a] => 'c"   (infixr 50)
    1.15    "="           :: "['a, 'a] => bool"                 (infixl 50)
    1.16 -(*"~="          :: "['a, 'a] => bool"                 (infixl 50)*)
    1.17    "&"           :: "[bool, bool] => bool"             (infixr 35)
    1.18    "|"           :: "[bool, bool] => bool"             (infixr 30)
    1.19    "-->"         :: "[bool, bool] => bool"             (infixr 25)
    1.20 @@ -73,6 +72,8 @@
    1.21  
    1.22    "~="          :: "['a, 'a] => bool"                 (infixl 50)
    1.23  
    1.24 +  "@Eps"        :: "[pttrn,bool] => 'a"               ("(3@ _./ _)" 10)
    1.25 +
    1.26    (* Alternative Quantifiers *)
    1.27  
    1.28    "*All"        :: "[idts, bool] => bool"             ("(3ALL _./ _)" 10)
    1.29 @@ -81,7 +82,7 @@
    1.30  
    1.31    (* Let expressions *)
    1.32  
    1.33 -  "_bind"       :: "[idt, 'a] => letbind"             ("(2_ =/ _)" 10)
    1.34 +  "_bind"       :: "[pttrn, 'a] => letbind"           ("(2_ =/ _)" 10)
    1.35    ""            :: "letbind => letbinds"              ("_")
    1.36    "_binds"      :: "[letbind, letbinds] => letbinds"  ("_;/ _")
    1.37    "_Let"        :: "[letbinds, 'a] => 'a"             ("(let (_)/ in (_))" 10)
    1.38 @@ -95,6 +96,7 @@
    1.39  
    1.40  translations
    1.41    "x ~= y"      == "~ (x = y)"
    1.42 +  "@ x.b"       == "Eps(%x.b)"
    1.43    "ALL xs. P"   => "! xs. P"
    1.44    "EX xs. P"    => "? xs. P"
    1.45    "EX! xs. P"   => "?! xs. P"
     2.1 --- a/src/HOL/Prod.thy	Sat Apr 22 12:21:41 1995 +0200
     2.2 +++ b/src/HOL/Prod.thy	Sat Apr 22 13:25:31 1995 +0200
     2.3 @@ -34,13 +34,25 @@
     2.4    Pair          :: "['a, 'b] => 'a * 'b"
     2.5    Sigma         :: "['a set, 'a => 'b set] => ('a * 'b) set"
     2.6  
     2.7 +(** Patterns -- extends pre-defined type "pttrn" used in abstractions **)
     2.8 +types pttrns
     2.9 +
    2.10  syntax
    2.11    "@Tuple"      :: "['a, args] => 'a * 'b"            ("(1'(_,/ _'))")
    2.12  
    2.13 +  "@pttrn"  :: "pttrns => pttrn"            ("'(_')")
    2.14 +  ""        :: " pttrn           => pttrns" ("_")
    2.15 +  "@pttrns" :: "[pttrn,pttrns]   => pttrns" ("_,/_")
    2.16 +
    2.17  translations
    2.18    "(x, y, z)"   == "(x, (y, z))"
    2.19    "(x, y)"      == "Pair x y"
    2.20  
    2.21 +  "%(x,y,zs).b"   => "split(%x (y,zs).b)"
    2.22 +  "%(x,y).b"      => "split(%x y.b)"
    2.23 +(* The <= direction fails if split has more than one argument because
    2.24 +   ast-matching fails. Otherwise it would work fine *)
    2.25 +
    2.26  defs
    2.27    Pair_def      "Pair a b == Abs_Prod(Pair_Rep a b)"
    2.28    fst_def       "fst(p) == @a. ? b. p = (a, b)"
    2.29 @@ -63,3 +75,34 @@
    2.30    Unity_def     "() == Abs_Unit(True)"
    2.31  
    2.32  end
    2.33 +
    2.34 +ML
    2.35 +
    2.36 +local open Syntax
    2.37 +
    2.38 +fun pttrn s = const"@pttrn" $ s;
    2.39 +fun pttrns s t = const"@pttrns" $ s $ t;
    2.40 +
    2.41 +fun split2(Abs(x,T,t)) =
    2.42 +      let val (pats,u) = split1 t
    2.43 +      in (pttrns (Free(x,T)) pats, subst_bounds([free x],u)) end
    2.44 +  | split2(Const("split",_) $ r) =
    2.45 +      let val (pats,s) = split2(r)
    2.46 +          val (pats2,t) = split1(s)
    2.47 +      in (pttrns (pttrn pats) pats2, t) end
    2.48 +and split1(Abs(x,T,t)) =  (Free(x,T), subst_bounds([free x],t))
    2.49 +  | split1(Const("split",_)$t) = split2(t);
    2.50 +
    2.51 +fun split_tr'(t::args) =
    2.52 +  let val (pats,ft) = split2(t)
    2.53 +  in case args of
    2.54 +       [] => const"_abs" $ pttrn pats $ ft
    2.55 +     | arg::rest =>
    2.56 +         list_comb(const"_Let"$(const"_bind"$(pttrn pats)$arg)$ft, rest)
    2.57 +  end
    2.58 +
    2.59 +in
    2.60 +
    2.61 +val print_translation = [("split", split_tr')];
    2.62 +
    2.63 +end;
     3.1 --- a/src/HOL/Set.thy	Sat Apr 22 12:21:41 1995 +0200
     3.2 +++ b/src/HOL/Set.thy	Sat Apr 22 13:25:31 1995 +0200
     3.3 @@ -41,20 +41,20 @@
     3.4  
     3.5    "@Finset"     :: "args => 'a set"                   ("{(_)}")
     3.6  
     3.7 -  "@Coll"       :: "[idt, bool] => 'a set"            ("(1{_./ _})")
     3.8 +  "@Coll"       :: "[pttrn, bool] => 'a set"          ("(1{_./ _})")
     3.9    "@SetCompr"   :: "['a, idts, bool] => 'a set"       ("(1{_ |/_./ _})")
    3.10  
    3.11    (* Big Intersection / Union *)
    3.12  
    3.13 -  "@INTER"      :: "[idt, 'a set, 'b set] => 'b set"  ("(3INT _:_./ _)" 10)
    3.14 -  "@UNION"      :: "[idt, 'a set, 'b set] => 'b set"  ("(3UN _:_./ _)" 10)
    3.15 +  "@INTER"      :: "[pttrn, 'a set, 'b set] => 'b set"  ("(3INT _:_./ _)" 10)
    3.16 +  "@UNION"      :: "[pttrn, 'a set, 'b set] => 'b set"  ("(3UN _:_./ _)" 10)
    3.17  
    3.18    (* Bounded Quantifiers *)
    3.19  
    3.20 -  "@Ball"       :: "[idt, 'a set, bool] => bool"      ("(3! _:_./ _)" 10)
    3.21 -  "@Bex"        :: "[idt, 'a set, bool] => bool"      ("(3? _:_./ _)" 10)
    3.22 -  "*Ball"       :: "[idt, 'a set, bool] => bool"      ("(3ALL _:_./ _)" 10)
    3.23 -  "*Bex"        :: "[idt, 'a set, bool] => bool"      ("(3EX _:_./ _)" 10)
    3.24 +  "@Ball"       :: "[pttrn, 'a set, bool] => bool"      ("(3! _:_./ _)" 10)
    3.25 +  "@Bex"        :: "[pttrn, 'a set, bool] => bool"      ("(3? _:_./ _)" 10)
    3.26 +  "*Ball"       :: "[pttrn, 'a set, bool] => bool"      ("(3ALL _:_./ _)" 10)
    3.27 +  "*Bex"        :: "[pttrn, 'a set, bool] => bool"      ("(3EX _:_./ _)" 10)
    3.28  
    3.29  translations
    3.30    "x ~: y"      == "~ (x : y)"
     4.1 --- a/src/HOL/Univ.thy	Sat Apr 22 12:21:41 1995 +0200
     4.2 +++ b/src/HOL/Univ.thy	Sat Apr 22 13:25:31 1995 +0200
     4.3 @@ -76,7 +76,7 @@
     4.4    In1_def    "In1(M) == Numb(Suc(0)) $ M"
     4.5  
     4.6    (*the set of nodes with depth less than k*)
     4.7 -  ndepth_def "ndepth(n) == split (%f x. LEAST k. f(k)=0) (Rep_Node n)"
     4.8 +  ndepth_def "ndepth(n) == (%(f,x). LEAST k. f(k)=0) (Rep_Node n)"
     4.9    ntrunc_def "ntrunc k N == {n. n:N & ndepth(n)<k}"
    4.10  
    4.11    (*products and sums for the "universe"*)
    4.12 @@ -94,10 +94,9 @@
    4.13  
    4.14    diag_def   "diag(A) == UN x:A. {(x,x)}"
    4.15  
    4.16 -  dprod_def  "r<**>s == UN u:r. split (%x x'. \
    4.17 -\                       UN v:s. split (%y y'. {(x$y,x'$y')}) v) u"
    4.18 +  dprod_def  "r<**>s == UN (x,x'):r. UN (y,y'):s. {(x$y,x'$y')}"
    4.19  
    4.20 -  dsum_def   "r<++>s == (UN u:r. split (%x x'. {(In0(x),In0(x'))}) u) Un \
    4.21 -\                       (UN v:s. split (%y y'. {(In1(y),In1(y'))}) v)"
    4.22 +  dsum_def   "r<++>s == (UN (x,x'):r. {(In0(x),In0(x'))}) Un \
    4.23 +\                       (UN (y,y'):s. {(In1(y),In1(y'))})"
    4.24  
    4.25  end