src/HOL/Induct/Term.thy
author paulson
Wed May 07 12:50:26 1997 +0200 (1997-05-07)
changeset 3120 c58423c20740
child 5191 8ceaa19f7717
permissions -rw-r--r--
New directory to contain examples of (co)inductive definitions
paulson@3120
     1
(*  Title:      HOL/ex/Term
paulson@3120
     2
    ID:         $Id$
paulson@3120
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@3120
     4
    Copyright   1992  University of Cambridge
paulson@3120
     5
paulson@3120
     6
Terms over a given alphabet -- function applications; illustrates list functor
paulson@3120
     7
  (essentially the same type as in Trees & Forests)
paulson@3120
     8
paulson@3120
     9
There is no constructor APP because it is simply cons ($) 
paulson@3120
    10
*)
paulson@3120
    11
paulson@3120
    12
Term = SList +
paulson@3120
    13
paulson@3120
    14
types   'a term
paulson@3120
    15
paulson@3120
    16
arities term :: (term)term
paulson@3120
    17
paulson@3120
    18
consts
paulson@3120
    19
  term          :: 'a item set => 'a item set
paulson@3120
    20
  Rep_term      :: 'a term => 'a item
paulson@3120
    21
  Abs_term      :: 'a item => 'a term
paulson@3120
    22
  Rep_Tlist     :: 'a term list => 'a item
paulson@3120
    23
  Abs_Tlist     :: 'a item => 'a term list
paulson@3120
    24
  App           :: ['a, ('a term)list] => 'a term
paulson@3120
    25
  Term_rec      :: ['a item, ['a item , 'a item, 'b list]=>'b] => 'b
paulson@3120
    26
  term_rec      :: ['a term, ['a ,'a term list, 'b list]=>'b] => 'b
paulson@3120
    27
paulson@3120
    28
inductive "term(A)"
paulson@3120
    29
  intrs
paulson@3120
    30
    APP_I "[| M: A;  N : list(term(A)) |] ==> M$N : term(A)"
paulson@3120
    31
  monos   "[list_mono]"
paulson@3120
    32
paulson@3120
    33
defs
paulson@3120
    34
  (*defining abstraction/representation functions for term list...*)
paulson@3120
    35
  Rep_Tlist_def "Rep_Tlist == Rep_map(Rep_term)"
paulson@3120
    36
  Abs_Tlist_def "Abs_Tlist == Abs_map(Abs_term)"
paulson@3120
    37
paulson@3120
    38
  (*defining the abstract constants*)
paulson@3120
    39
  App_def       "App a ts == Abs_term(Leaf(a) $ Rep_Tlist(ts))"
paulson@3120
    40
paulson@3120
    41
  (*list recursion*)
paulson@3120
    42
  Term_rec_def  
paulson@3120
    43
   "Term_rec M d == wfrec (trancl pred_sexp)
paulson@3120
    44
           (%g. Split(%x y. d x y (Abs_map g y))) M"
paulson@3120
    45
paulson@3120
    46
  term_rec_def
paulson@3120
    47
   "term_rec t d == 
paulson@3120
    48
   Term_rec (Rep_term t) (%x y r. d (inv Leaf x) (Abs_Tlist(y)) r)"
paulson@3120
    49
paulson@3120
    50
rules
paulson@3120
    51
    (*faking a type definition for term...*)
paulson@3120
    52
  Rep_term              "Rep_term(n): term(range(Leaf))"
paulson@3120
    53
  Rep_term_inverse      "Abs_term(Rep_term(t)) = t"
paulson@3120
    54
  Abs_term_inverse      "M: term(range(Leaf)) ==> Rep_term(Abs_term(M)) = M"
paulson@3120
    55
end