src/ZF/ex/TermFn.ML
author lcp
Tue Aug 16 18:58:42 1994 +0200 (1994-08-16)
changeset 532 851df239ac8b
parent 29 4ec9b266ccd1
permissions -rw-r--r--
ZF/Makefile,ROOT.ML, ZF/ex/Integ.thy: updated for EquivClass
clasohm@0
     1
(*  Title: 	ZF/ex/term
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1992  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Terms over a given alphabet -- function applications; illustrates list functor
clasohm@0
     7
  (essentially the same type as in Trees & Forests)
clasohm@0
     8
*)
clasohm@0
     9
clasohm@0
    10
writeln"File ZF/ex/term-fn.";
clasohm@0
    11
clasohm@0
    12
open TermFn;
clasohm@0
    13
clasohm@0
    14
(*** term_rec -- by Vset recursion ***)
clasohm@0
    15
clasohm@0
    16
(*Lemma: map works correctly on the underlying list of terms*)
clasohm@0
    17
val [major,ordi] = goal ListFn.thy
clasohm@0
    18
    "[| l: list(A);  Ord(i) |] ==>  \
lcp@29
    19
\    rank(l)<i --> map(%z. (lam x:Vset(i).h(x)) ` z, l) = map(h,l)";
clasohm@0
    20
by (rtac (major RS List.induct) 1);
lcp@7
    21
by (simp_tac list_ss 1);
clasohm@0
    22
by (rtac impI 1);
lcp@29
    23
by (forward_tac [rank_Cons1 RS lt_trans] 1);
lcp@29
    24
by (dtac (rank_Cons2 RS lt_trans) 1);
lcp@29
    25
by (asm_simp_tac (list_ss addsimps [ordi, VsetI]) 1);
clasohm@0
    26
val map_lemma = result();
clasohm@0
    27
clasohm@0
    28
(*Typing premise is necessary to invoke map_lemma*)
clasohm@0
    29
val [prem] = goal TermFn.thy
clasohm@0
    30
    "ts: list(A) ==> \
clasohm@0
    31
\    term_rec(Apply(a,ts), d) = d(a, ts, map (%z. term_rec(z,d), ts))";
clasohm@0
    32
by (rtac (term_rec_def RS def_Vrec RS trans) 1);
clasohm@0
    33
by (rewrite_goals_tac Term.con_defs);
lcp@7
    34
val term_rec_ss = ZF_ss addsimps [Ord_rank, rank_pair2, prem RS map_lemma];
lcp@7
    35
by (simp_tac term_rec_ss 1);
clasohm@0
    36
val term_rec = result();
clasohm@0
    37
clasohm@0
    38
(*Slightly odd typing condition on r in the second premise!*)
clasohm@0
    39
val major::prems = goal TermFn.thy
clasohm@0
    40
    "[| t: term(A);					\
clasohm@0
    41
\       !!x zs r. [| x: A;  zs: list(term(A)); 		\
clasohm@0
    42
\                    r: list(UN t:term(A). C(t)) |]	\
clasohm@0
    43
\                 ==> d(x, zs, r): C(Apply(x,zs))  	\
clasohm@0
    44
\    |] ==> term_rec(t,d) : C(t)";
clasohm@0
    45
by (rtac (major RS Term.induct) 1);
clasohm@0
    46
by (forward_tac [list_CollectD] 1);
clasohm@0
    47
by (rtac (term_rec RS ssubst) 1);
clasohm@0
    48
by (REPEAT (ares_tac prems 1));
clasohm@0
    49
by (etac List.induct 1);
lcp@7
    50
by (ALLGOALS (asm_simp_tac (list_ss addsimps [term_rec])));
clasohm@0
    51
by (etac CollectE 1);
clasohm@0
    52
by (REPEAT (ares_tac [ConsI, UN_I] 1));
clasohm@0
    53
val term_rec_type = result();
clasohm@0
    54
clasohm@0
    55
val [rew,tslist] = goal TermFn.thy
clasohm@0
    56
    "[| !!t. j(t)==term_rec(t,d);  ts: list(A) |] ==> \
clasohm@0
    57
\    j(Apply(a,ts)) = d(a, ts, map(%Z.j(Z), ts))";
clasohm@0
    58
by (rewtac rew);
clasohm@0
    59
by (rtac (tslist RS term_rec) 1);
clasohm@0
    60
val def_term_rec = result();
clasohm@0
    61
clasohm@0
    62
val prems = goal TermFn.thy
clasohm@0
    63
    "[| t: term(A);					     \
clasohm@0
    64
\       !!x zs r. [| x: A;  zs: list(term(A));  r: list(C) |]  \
clasohm@0
    65
\                 ==> d(x, zs, r): C  		     \
clasohm@0
    66
\    |] ==> term_rec(t,d) : C";
clasohm@0
    67
by (REPEAT (ares_tac (term_rec_type::prems) 1));
clasohm@0
    68
by (etac (subset_refl RS UN_least RS list_mono RS subsetD) 1);
clasohm@0
    69
val term_rec_simple_type = result();
clasohm@0
    70
clasohm@0
    71
clasohm@0
    72
(** term_map **)
clasohm@0
    73
clasohm@0
    74
val term_map = standard (term_map_def RS def_term_rec);
clasohm@0
    75
clasohm@0
    76
val prems = goalw TermFn.thy [term_map_def]
clasohm@0
    77
    "[| t: term(A);  !!x. x: A ==> f(x): B |] ==> term_map(f,t) : term(B)";
clasohm@0
    78
by (REPEAT (ares_tac ([term_rec_simple_type, ApplyI] @ prems) 1));
clasohm@0
    79
val term_map_type = result();
clasohm@0
    80
clasohm@0
    81
val [major] = goal TermFn.thy
clasohm@0
    82
    "t: term(A) ==> term_map(f,t) : term({f(u). u:A})";
clasohm@0
    83
by (rtac (major RS term_map_type) 1);
clasohm@0
    84
by (etac RepFunI 1);
clasohm@0
    85
val term_map_type2 = result();
clasohm@0
    86
clasohm@0
    87
clasohm@0
    88
(** term_size **)
clasohm@0
    89
clasohm@0
    90
val term_size = standard (term_size_def RS def_term_rec);
clasohm@0
    91
clasohm@0
    92
goalw TermFn.thy [term_size_def] "!!t A. t: term(A) ==> term_size(t) : nat";
clasohm@0
    93
by (REPEAT (ares_tac [term_rec_simple_type, list_add_type, nat_succI] 1));
clasohm@0
    94
val term_size_type = result();
clasohm@0
    95
clasohm@0
    96
clasohm@0
    97
(** reflect **)
clasohm@0
    98
clasohm@0
    99
val reflect = standard (reflect_def RS def_term_rec);
clasohm@0
   100
clasohm@0
   101
goalw TermFn.thy [reflect_def] "!!t A. t: term(A) ==> reflect(t) : term(A)";
clasohm@0
   102
by (REPEAT (ares_tac [term_rec_simple_type, rev_type, ApplyI] 1));
clasohm@0
   103
val reflect_type = result();
clasohm@0
   104
clasohm@0
   105
(** preorder **)
clasohm@0
   106
clasohm@0
   107
val preorder = standard (preorder_def RS def_term_rec);
clasohm@0
   108
clasohm@0
   109
goalw TermFn.thy [preorder_def]
clasohm@0
   110
    "!!t A. t: term(A) ==> preorder(t) : list(A)";
clasohm@0
   111
by (REPEAT (ares_tac [term_rec_simple_type, ConsI, flat_type] 1));
clasohm@0
   112
val preorder_type = result();
clasohm@0
   113
clasohm@0
   114
clasohm@0
   115
(** Term simplification **)
clasohm@0
   116
clasohm@0
   117
val term_typechecks =
clasohm@0
   118
    [ApplyI, term_map_type, term_map_type2, term_size_type, reflect_type, 
clasohm@0
   119
     preorder_type];
clasohm@0
   120
clasohm@0
   121
(*map_type2 and term_map_type2 instantiate variables*)
clasohm@0
   122
val term_ss = list_ss 
lcp@7
   123
      addsimps [term_rec, term_map, term_size, reflect, preorder]
lcp@7
   124
      setsolver type_auto_tac (list_typechecks@term_typechecks);
clasohm@0
   125
clasohm@0
   126
clasohm@0
   127
(** theorems about term_map **)
clasohm@0
   128
clasohm@0
   129
goal TermFn.thy "!!t A. t: term(A) ==> term_map(%u.u, t) = t";
clasohm@0
   130
by (etac term_induct_eqn 1);
lcp@7
   131
by (asm_simp_tac (term_ss addsimps [map_ident]) 1);
clasohm@0
   132
val term_map_ident = result();
clasohm@0
   133
clasohm@0
   134
goal TermFn.thy
clasohm@0
   135
  "!!t A. t: term(A) ==> term_map(f, term_map(g,t)) = term_map(%u.f(g(u)), t)";
clasohm@0
   136
by (etac term_induct_eqn 1);
lcp@7
   137
by (asm_simp_tac (term_ss addsimps [map_compose]) 1);
clasohm@0
   138
val term_map_compose = result();
clasohm@0
   139
clasohm@0
   140
goal TermFn.thy
clasohm@0
   141
    "!!t A. t: term(A) ==> term_map(f, reflect(t)) = reflect(term_map(f,t))";
clasohm@0
   142
by (etac term_induct_eqn 1);
lcp@7
   143
by (asm_simp_tac (term_ss addsimps [rev_map_distrib RS sym, map_compose]) 1);
clasohm@0
   144
val term_map_reflect = result();
clasohm@0
   145
clasohm@0
   146
clasohm@0
   147
(** theorems about term_size **)
clasohm@0
   148
clasohm@0
   149
goal TermFn.thy
clasohm@0
   150
    "!!t A. t: term(A) ==> term_size(term_map(f,t)) = term_size(t)";
clasohm@0
   151
by (etac term_induct_eqn 1);
lcp@7
   152
by (asm_simp_tac (term_ss addsimps [map_compose]) 1);
clasohm@0
   153
val term_size_term_map = result();
clasohm@0
   154
clasohm@0
   155
goal TermFn.thy "!!t A. t: term(A) ==> term_size(reflect(t)) = term_size(t)";
clasohm@0
   156
by (etac term_induct_eqn 1);
lcp@7
   157
by (asm_simp_tac (term_ss addsimps [rev_map_distrib RS sym, map_compose,
lcp@7
   158
				    list_add_rev]) 1);
clasohm@0
   159
val term_size_reflect = result();
clasohm@0
   160
clasohm@0
   161
goal TermFn.thy "!!t A. t: term(A) ==> term_size(t) = length(preorder(t))";
clasohm@0
   162
by (etac term_induct_eqn 1);
lcp@7
   163
by (asm_simp_tac (term_ss addsimps [length_flat, map_compose]) 1);
clasohm@0
   164
val term_size_length = result();
clasohm@0
   165
clasohm@0
   166
clasohm@0
   167
(** theorems about reflect **)
clasohm@0
   168
clasohm@0
   169
goal TermFn.thy "!!t A. t: term(A) ==> reflect(reflect(t)) = t";
clasohm@0
   170
by (etac term_induct_eqn 1);
lcp@7
   171
by (asm_simp_tac (term_ss addsimps [rev_map_distrib, map_compose,
lcp@7
   172
				    map_ident, rev_rev_ident]) 1);
clasohm@0
   173
val reflect_reflect_ident = result();
clasohm@0
   174
clasohm@0
   175
clasohm@0
   176
(** theorems about preorder **)
clasohm@0
   177
clasohm@0
   178
goal TermFn.thy
clasohm@0
   179
    "!!t A. t: term(A) ==> preorder(term_map(f,t)) = map(f, preorder(t))";
clasohm@0
   180
by (etac term_induct_eqn 1);
lcp@7
   181
by (asm_simp_tac (term_ss addsimps [map_compose, map_flat]) 1);
clasohm@0
   182
val preorder_term_map = result();
clasohm@0
   183
clasohm@0
   184
(** preorder(reflect(t)) = rev(postorder(t)) **)
clasohm@0
   185
clasohm@0
   186
writeln"Reached end of file.";