List.thy
changeset 48 21291189b51e
parent 42 87f6e8b93221
child 49 9f35f2744fa8
equal deleted inserted replaced
47:69d815b0e1eb 48:21291189b51e
    26   Rep_List      :: "'a list => 'a node set"
    26   Rep_List      :: "'a list => 'a node set"
    27   Abs_List      :: "'a node set => 'a list"
    27   Abs_List      :: "'a node set => 'a list"
    28   NIL           :: "'a node set"
    28   NIL           :: "'a node set"
    29   CONS          :: "['a node set, 'a node set] => 'a node set"
    29   CONS          :: "['a node set, 'a node set] => 'a node set"
    30   Nil           :: "'a list"
    30   Nil           :: "'a list"
    31   Cons          :: "['a, 'a list] => 'a list"
    31   "#"           :: "['a, 'a list] => 'a list"                   (infixr 65)
    32   List_case     :: "['a node set, 'b, ['a node set, 'a node set]=>'b] => 'b"
    32   List_case     :: "['a node set, 'b, ['a node set, 'a node set]=>'b] => 'b"
    33   List_rec      :: "['a node set, 'b, ['a node set, 'a node set, 'b]=>'b] => 'b"
    33   List_rec      :: "['a node set, 'b, ['a node set, 'a node set, 'b]=>'b] => 'b"
    34   list_rec      :: "['a list, 'b, ['a, 'a list, 'b]=>'b] => 'b"
    34   list_rec      :: "['a list, 'b, ['a, 'a list, 'b]=>'b] => 'b"
    35   Rep_map       :: "('b => 'a node set) => ('b list => 'a node set)"
    35   Rep_map       :: "('b => 'a node set) => ('b list => 'a node set)"
    36   Abs_map       :: "('a node set => 'b) => 'a node set => 'b list"
    36   Abs_map       :: "('a node set => 'b) => 'a node set => 'b list"
    38   hd            :: "'a list => 'a"
    38   hd            :: "'a list => 'a"
    39   tl,ttl        :: "'a list => 'a list"
    39   tl,ttl        :: "'a list => 'a list"
    40   mem		:: "['a, 'a list] => bool"			(infixl 55)
    40   mem		:: "['a, 'a list] => bool"			(infixl 55)
    41   list_all      :: "('a => bool) => ('a list => bool)"
    41   list_all      :: "('a => bool) => ('a list => bool)"
    42   map           :: "('a=>'b) => ('a list => 'b list)"
    42   map           :: "('a=>'b) => ('a list => 'b list)"
    43   "@"		:: "['a list, 'a list] => 'a list"		(infixr 65)
    43   "@"		:: "['a list, 'a list] => 'a list"		(infixl 65)
    44   list_case     :: "['a list, 'b, ['a, 'a list]=>'b] => 'b"
    44   list_case     :: "['a list, 'b, ['a, 'a list]=>'b] => 'b"
    45   filter	:: "['a => bool, 'a list] => 'a list"
    45   filter	:: "['a => bool, 'a list] => 'a list"
    46 
    46 
    47   (* List Enumeration *)
    47   (* List Enumeration *)
    48 
    48 
    52   (* Special syntax for list_all and filter *)
    52   (* Special syntax for list_all and filter *)
    53   "@Alls"	:: "[idt, 'a list, bool] => bool"	("(2Alls _:_./ _)" 10)
    53   "@Alls"	:: "[idt, 'a list, bool] => bool"	("(2Alls _:_./ _)" 10)
    54   "@filter"	:: "[idt, 'a list, bool] => 'a list"	("(1[_:_ ./ _])")
    54   "@filter"	:: "[idt, 'a list, bool] => 'a list"	("(1[_:_ ./ _])")
    55 
    55 
    56 translations
    56 translations
    57   "[x, xs]"     == "Cons(x, [xs])"
    57   "[x, xs]"     == "x#[xs]"
    58   "[x]"         == "Cons(x, [])"
    58   "[x]"         == "x#[]"
    59   "[]"          == "Nil"
    59   "[]"          == "Nil"
    60 
    60 
    61   "case xs of Nil => a | Cons(y,ys) => b" == "list_case(xs,a,%y ys.b)"
    61   "case xs of Nil => a | y#ys => b" == "list_case(xs,a,%y ys.b)"
    62 
    62 
    63   "[x:xs . P]"	== "filter(%x.P,xs)"
    63   "[x:xs . P]"	== "filter(%x.P,xs)"
    64   "Alls x:xs.P"	== "list_all(%x.P,xs)"
    64   "Alls x:xs.P"	== "list_all(%x.P,xs)"
    65 
    65 
    66 rules
    66 rules
    75   Abs_List_inverse  "M: List(range(Leaf)) ==> Rep_List(Abs_List(M)) = M"
    75   Abs_List_inverse  "M: List(range(Leaf)) ==> Rep_List(Abs_List(M)) = M"
    76 
    76 
    77   (* Defining the Concrete Constructors *)
    77   (* Defining the Concrete Constructors *)
    78 
    78 
    79   NIL_def       "NIL == In0(Numb(0))"
    79   NIL_def       "NIL == In0(Numb(0))"
    80   CONS_def      "CONS(M, N) == In1(M . N)"
    80   CONS_def      "CONS(M, N) == In1(M $ N)"
    81 
    81 
    82   (* Defining the Abstract Constructors *)
    82   (* Defining the Abstract Constructors *)
    83 
    83 
    84   Nil_def       "Nil == Abs_List(NIL)"
    84   Nil_def       "Nil == Abs_List(NIL)"
    85   Cons_def      "Cons(x, xs) == Abs_List(CONS(Leaf(x), Rep_List(xs)))"
    85   Cons_def      "x#xs == Abs_List(CONS(Leaf(x), Rep_List(xs)))"
    86 
    86 
    87   List_case_def "List_case(M, c, d) == Case(M, %x.c, %u. Split(u, %x y.d(x, y)))"
    87   List_case_def "List_case(M, c, d) == Case(M, %x.c, %u. Split(u, %x y.d(x, y)))"
    88 
    88 
    89   (* List Recursion -- the trancl is Essential; see list.ML *)
    89   (* List Recursion -- the trancl is Essential; see list.ML *)
    90 
    90 
    99   (* Generalized Map Functionals *)
    99   (* Generalized Map Functionals *)
   100 
   100 
   101   Rep_map_def
   101   Rep_map_def
   102    "Rep_map(f, xs) == list_rec(xs, NIL, %x l r. CONS(f(x), r))"
   102    "Rep_map(f, xs) == list_rec(xs, NIL, %x l r. CONS(f(x), r))"
   103   Abs_map_def
   103   Abs_map_def
   104    "Abs_map(g, M) == List_rec(M, Nil, %N L r. Cons(g(N), r))"
   104    "Abs_map(g, M) == List_rec(M, Nil, %N L r. g(N)#r)"
   105 
   105 
   106   null_def      "null(xs)            == list_rec(xs, True, %x xs r.False)"
   106   null_def      "null(xs)            == list_rec(xs, True, %x xs r.False)"
   107   hd_def        "hd(xs)              == list_rec(xs, @x.True, %x xs r.x)"
   107   hd_def        "hd(xs)              == list_rec(xs, @x.True, %x xs r.x)"
   108   tl_def        "tl(xs)              == list_rec(xs, @xs.True, %x xs r.xs)"
   108   tl_def        "tl(xs)              == list_rec(xs, @xs.True, %x xs r.xs)"
   109   (* a total version of tl: *)
   109   (* a total version of tl: *)
   110   ttl_def	"ttl(xs)             == list_rec(xs, [], %x xs r.xs)"
   110   ttl_def	"ttl(xs)             == list_rec(xs, [], %x xs r.xs)"
   111   mem_def	"x mem xs            == \
   111   mem_def	"x mem xs            == \
   112 \		   list_rec(xs, False, %y ys r. if(y=x, True, r))"
   112 \		   list_rec(xs, False, %y ys r. if(y=x, True, r))"
   113   list_all_def  "list_all(P, xs)     == list_rec(xs, True, %x l r. P(x) & r)"
   113   list_all_def  "list_all(P, xs)     == list_rec(xs, True, %x l r. P(x) & r)"
   114   map_def       "map(f, xs)          == list_rec(xs, [], %x l r. Cons(f(x),r))"
   114   map_def       "map(f, xs)          == list_rec(xs, [], %x l r. f(x)#r)"
   115   append_def	"xs@ys               == list_rec(xs, ys, %x l r. Cons(x,r))"
   115   append_def	"xs@ys               == list_rec(xs, ys, %x l r. x#r)"
   116   filter_def	"filter(P,xs)        == \
   116   filter_def	"filter(P,xs)        == \
   117 \                  list_rec(xs, [], %x xs r. if(P(x), Cons(x,r), r))"
   117 \                  list_rec(xs, [], %x xs r. if(P(x), x#r, r))"
   118   list_case_def "list_case(xs, a, f) == list_rec(xs, a, %x xs r.f(x, xs))"
   118   list_case_def "list_case(xs, a, f) == list_rec(xs, a, %x xs r.f(x, xs))"
   119 
   119 
   120 end
   120 end