|  | Who Cites col? | 
|  | 
| col | Def Collection(T) == T   Prop | 
 | |  | Thm*  T:Type{i'}. Collection{i}(T)  Type{i'} | 
|  | 
| trace_consistent | Def trace_consistent(rho;da;R;t)
==  g:Label.  term_mentions_guard(g;t)   subtype_rel(({a:(  [[da]] rho)|  (R(g,kind(a))) } List); (rho(lbl_pr( < Trace, g > )))) | 
 | |  | Thm*  rho:Decl, t:Term, da:Collection(dec()), R:(Label   Label    ).
trace_consistent(rho;da;R;t)  Prop | 
|  | 
| decls_mng | Def [[ds]] rho == [[d]] rho for d  {d:dec()| d  ds } | 
 | |  | Thm*  ds:Collection(dec()), rho:Decl. [[ds]] rho  Decl | 
|  | 
| sts_mng | Def [[sts]] rho ==  x:{x:SimpleType| x  sts }. [[x]] rho | 
 | |  | Thm*  sts:Collection(SimpleType), rho:Decl. [[sts]] rho  Type | 
|  | 
| term_types | Def term_types(ds;da;de;t)
== iterate(statevar x- > dec_lookup(ds;x)
 statevar x'- > dec_lookup(ds;x)
 funsymbol op- >  < de.fun(op) > 
 freevar x- > da
 trace(P)- >  < lbl_pr( < Trace, P > ) > 
 c1(c2)- > st_app(c1;c2)
 over t) | 
 | |  | Thm*  ds:Collection(dec()), da:Collection(SimpleType), de:sig(), t:Term.
term_types(ds;da;de;t)  Collection(SimpleType) | 
|  | 
| st_app | Def st_app(c1;c2) == (  s2  c2.(  s1  c1.st_app1(s1;s2))) | 
 | |  | Thm*  c1,c2:Collection(SimpleType). st_app(c1;c2)  Collection(SimpleType) | 
|  | 
| dec_lookup | Def dec_lookup(ds;x) ==  < d.typ | d  < d  ds |  d.lbl =  x >  > | 
 | |  | Thm*  ds:Collection(dec()), x:Label. dec_lookup(ds;x)  Collection(SimpleType) | 
|  | 
| col_accum | Def (  x  c.f(x))(y) ==  x:T. x  c  &  y  f(x) | 
 | |  | Thm*  T,T':Type, f:(T   Collection(T')), c:Collection(T). (  x  c.f(x))  Collection(T') | 
|  | 
| col_filter | Def  < x  c | P(x) > (x) == x  c  &  P(x) | 
 | |  | Thm*  T:Type, c:Collection(T), Q:(T   Prop).  < i  c | Q(i) >  Collection(T) | 
|  | 
| col_map | Def  < f(x) | x  c > (y) ==  x:T. x  c  &  y = f(x)  T' | 
 | |  | Thm*  T,T':Type, f:(T   T'), c:Collection(T).  < f(x) | x  c >  Collection(T') | 
|  | 
| col_member | Def x  c == c(x) | 
 | |  | Thm*  T:Type, x:T, c:Collection(T). x  c  Prop | 
|  | 
| dec | Def dec() == Label  SimpleType | 
 | |  | Thm* dec()  Type | 
|  | 
| decl | Def Decl == Label   Type | 
 | |  | Thm* Decl{i}  Type{i'} | 
|  | 
| sig_mng | Def [[s]] rho ==  <  op.[[s.fun(op)]] rho,  R.[[s.rel(R)]] rho > | 
 | |  | Thm*  s:sig(), rho:Decl{i}. sig_mng{i:l}(s; rho)  Decl{i}  Decl{i'} | 
|  | 
| term_mng | Def [[t]] e s a tr
== iterate(statevar x- > s.x
 statevar x'- > s.x
 funsymbol f- > e.f
 freevar x- > a
 trace(P)- > tr.P
 x(y)- > x(y)
 over t) | 
|  | 
| sig_fun | Def t.fun == 1of(t) | 
 | |  | Thm*  t:sig(). t.fun  Label   SimpleType | 
|  | 
| tproj | Def tre.P == tre.trace | tre.proj(P) | 
 | |  | Thm*  d:Decl, tre:trace_env(d), P:Label. tre.P  (  d) List | 
|  | 
| trace_projection | Def tr | P == filter(  x.P(kind(x));tr) | 
 | |  | Thm*  d:Decl, tr:(  d) List, P:(Label    ). tr | P  (  d) List | 
|  | 
| kind | Def kind(a) == 1of(a) | 
 | |  | Thm*  d:Decl, a:(  d). kind(a)  Label | 
 | |  | Thm*  M:sm{i:l}(), a:M.action. kind(a)  Label  &  kind(a)  Pattern | 
|  | 
| trace_env_trace | Def t.trace == 1of(t) | 
 | |  | Thm*  d:Decl, t:trace_env(d). t.trace  (  d) List | 
|  | 
| dec_lbl | Def t.lbl == 1of(t) | 
 | |  | Thm*  t:dec(). t.lbl  Label | 
|  | 
| pi1 | Def 1of(t) == t.1 | 
 | |  | Thm*  A:Type, B:(A   Type), p:(a:A  B(a)). 1of(p)  A | 
|  | 
| record | Def {d} == l:Label   decl_type(d;l) | 
 | |  | Thm*  d:Decl. {d}  Type | 
|  | 
| sig | Def sig() == (Label   SimpleType)  (Label   (SimpleType List)) | 
 | |  | Thm* sig()  Type | 
|  | 
| st_app1 | Def st_app1(s1;s2)
== Case(s1)
 Case a;b = > 
 if st_eq(a;s2)  < b >  else  <  >  fi
 Default = >   <  > | 
 | |  | Thm*  s1,s2:SimpleType. st_app1(s1;s2)  Collection(SimpleType) | 
|  | 
| st | Def SimpleType == Tree(Label+Unit) | 
 | |  | Thm* SimpleType  Type | 
|  | 
| dec_mng | Def [[d]] rho == Case(d) Case x : s = >   x:[[s]] rho | 
 | |  | Thm*  rho:Decl, d:dec(). [[d]] rho  Decl | 
|  | 
| st_list_mng | Def [[l]] rho == reduce(  s,m. [[s]] rho   m;Prop;l) | 
 | |  | Thm*  l:SimpleType List, rho:Decl{i}. [[l]] rho{i}  Type{i'} | 
|  | 
| st_mng | Def [[s]] rho == t_iterate(st_lift(rho);  x,y. x   y;s) | 
 | |  | Thm*  rho:Decl, s:SimpleType. [[s]] rho  Type | 
|  | 
| term | Def Term == Tree(ts()) | 
 | |  | Thm* Term  Type | 
|  | 
| trace_env | Def trace_env(d) == ((  d) List)  (Label   Label    ) | 
 | |  | Thm*  d:Decl. trace_env(d)  Type | 
|  | 
| trace_env_proj | Def t.proj == 2of(t) | 
 | |  | Thm*  d:Decl, t:trace_env(d). t.proj  Label   Label    | 
|  | 
| ts | Def ts() == Label+Label+Label+Label+Label | 
 | |  | Thm* ts()  Type | 
|  | 
| sigma | Def (  d) == l:Label  decl_type(d;l) | 
 | |  | Thm*  d:Decl. (  d)  Type | 
|  | 
| lbl | Def Label == {p:Pattern|  ground_ptn(p) } | 
 | |  | Thm* Label  Type | 
|  | 
| dall | Def D(i) for i  I(x) ==  i:I. D(i)(x) | 
 | |  | Thm*  I:Type, D:(I   Decl). D(i) for i  I  Decl | 
|  | 
| decl_type | Def decl_type(d;x) == d(x) | 
 | |  | Thm*  dec:Decl, x:Label. decl_type(dec;x)  Type | 
|  | 
| sig_rel | Def t.rel == 2of(t) | 
 | |  | Thm*  t:sig(). t.rel  Label   (SimpleType List) | 
|  | 
| tree | Def Tree(E) == rec(T.tree_con(E;T)) | 
 | |  | Thm*  E:Type. Tree(E)  Type | 
|  | 
| st_lift | Def st_lift(rho)(x) == InjCase(x; x'. rho(x'); a. Top) | 
 | |  | Thm*  rho:(Label   Type). st_lift(rho)  (Label+Unit)   Type | 
|  | 
| term_iter | Def iterate(statevar x- > v(x)
 statevar x''- > v'(x')
 funsymbol op- > opr(op)
 freevar f- > fvar(f)
 trace(tr)- > trace(tr)
 a(b)- > comb(a;b)
 over t)
== term_iterate(  x.v(x);  x'.v'(x');  op.opr(op);  f.fvar(f);  tr.trace(tr);  a,b. comb(a;b);
 t) | 
 | |  | Thm*  A:Type, v,v',opr,fvar,trace:(Label   A), comb:(A   A   A), t:Term.
iterate(statevar x- > v(x)
 statevar x''- > v'(x')
 funsymbol op- > opr(op)
 freevar f- > fvar(f)
 trace(tr)- > trace(tr)
 a(b)- > comb(a,b)
 over t)  A | 
|  | 
| term_mentions_guard | Def term_mentions_guard(g;t)
== term_iterate(  x.false  ;  x.false  ;  x.false  ;  x.false  ;  x.x =  g;  x,y. x   y;
 t) | 
 | |  | Thm*  t:Term, g:Label. term_mentions_guard(g;t)    | 
|  | 
| term_iterate | Def term_iterate(v;
 p;
 op;
 f;
 tr;
 a;
 t)
== t_iterate(  x.ts_case(x)
 var(a)= > v(a)
 var'(b)= > p(b)
 opr(c)= > op(c)
 fvar(d)= > f(d)
 trace(P)= > tr(P)
 end_ts_case ;a;t) | 
 | |  | Thm*  A:Type, v,op,f,p,tr:(Label   A), a:(A   A   A), t:Term. term_iterate(v;p;op;f;tr;a;t)  A | 
|  | 
| t_iterate | Def t_iterate(l;n;t)
 == Case(t)
 Case x;y = > 
 n(t_iterate(l;n;x),t_iterate(l;n;y))
 Case tree_leaf(x) = > 
 l(x)
 Default = >  True
 (recursive) | 
 | |  | Thm*  E,A:Type, l:(E   A), n:(A   A   A), t:Tree(E). t_iterate(l;n;t)  A | 
|  | 
| r_select | Def r.l == r(l) | 
 | |  | Thm*  d:Decl, r:{d}, l:Label. r.l  d(l) | 
|  | 
| clbl | Def $x == ptn_atom("$x") | 
|  | 
| lbl_pair | Def lbl_pr( < x, y > ) == ptn_pr( < x,y > ) | 
 | |  | Thm*  x,y:Pattern. lbl_pr( < x, y > )  Pattern | 
 | |  | Thm*  x,y:Label. lbl_pr( < x, y > )  Label | 
|  | 
| typ | Def t == tree_leaf(inl(t)) | 
 | |  | Thm*  t:Label. t  SimpleType | 
|  | 
| col_singleton | Def  < x > (y) == y = x  T | 
 | |  | Thm*  T:Type, x:T.  < x >  Collection(T) | 
|  | 
| assert | Def  b == if b  True else False fi | 
 | |  | Thm*  b:  . b  Prop | 
|  | 
| dec_typ | Def t.typ == 2of(t) | 
 | |  | Thm*  t:dec(). t.typ  SimpleType | 
|  | 
| pi2 | Def 2of(t) == t.2 | 
 | |  | Thm*  A:Type, B:(A   Type), p:(a:A  B(a)). 2of(p)  B(1of(p)) | 
|  | 
| ground_ptn | Def ground_ptn(p)
 == Case(p)
 Case ptn_var(v) = > 
 false  Case ptn_pr( < x, y > ) = > 
 ground_ptn(x)   ground_ptn(y)
 Default = >  true  (recursive) | 
 | |  | Thm*  p:Pattern. ground_ptn(p)    | 
|  | 
| ptn | Def Pattern == rec(T.ptn_con(T)) | 
 | |  | Thm* Pattern  Type | 
|  | 
| dbase | Def  x:y(a) == if a =  x  y else Top fi | 
 | |  | Thm*  x:Label, y:Type.  x:y  Decl | 
|  | 
| case_mk_dec | Def Case lbl : typ = >  body(lbl;typ)(x,z) == x/x2,x1. body(x2;x1) | 
|  | 
| st_eq | Def st_eq(s1;s2)
 == Case(s1)
 Case a;b = > 
 Case(s2)
 Case a';b' = > 
 st_eq(a;a')   st_eq(b;b')
 Default = >  false  Case tree_leaf(x) = > 
 Case(s2)
 Case a';b' = > 
 false  Case tree_leaf(y) = > 
 InjCase(x; x'. InjCase(y; y'. x' =  y'; b. false  ); a.
 InjCase(y; y'. false  ; b. true  ))
 Default = >  false  Default = >  false  (recursive) | 
 | |  | Thm*  s1,s2:SimpleType. st_eq(s1;s2)    | 
|  | 
| eq_lbl | Def l1 =  l2
 == Case(l1)
 Case ptn_atom(x) = > 
 Case(l2)
 Case ptn_atom(y) = > 
 x=  y  Atom
 Default = >  false  Case ptn_int(x) = > 
 Case(l2)
 Case ptn_int(y) = > 
 x=  y
 Default = >  false  Case ptn_var(x) = > 
 Case(l2)
 Case ptn_var(y) = > 
 x=  y  Atom
 Default = >  false  Case ptn_pr( < x, y > ) = > 
 Case(l2)
 Case ptn_pr( < u, v > ) = > 
 x =  u   y =  v
 Default = >  false  Default = >  false  (recursive) | 
 | |  | Thm*  l1,l2:Pattern. l1 =  l2    | 
|  | 
| ts_case | Def ts_case(x)
 var(a)= > v(a)
 var'(b)= > p(b)
 opr(f)= > op(f)
 fvar(x)= > f(x)
 trace(P)= > t(P)
 end_ts_case 
== Case(x)
 Case ts_var(a) = > 
 v(a)
 Case ts_pvar(b) = > 
 p(b)
 Case ts_op(f) = > 
 op(f)
 Case ts_fvar(x) = > 
 f(x)
 Case ts_trace(P) = > 
 t(P)
 Default = >  | 
 | |  | Thm*  A:Type, v,op,f,p,t:(Label   A), x:ts().
ts_case(x)var(a)= > v(a)var'(b)= > p(b)opr(f)= > op(f)fvar(y)= > f(y)trace(P)= > t(P)end_ts_case  A | 
|  | 
| case | Def Case(value) body == body(value,value) | 
|  | 
| filter | Def filter(P;l) == reduce(  a,v. if P(a)  [a / v] else v fi;nil;l) | 
 | |  | Thm*  T:Type, P:(T    ), l:T List. filter(P;l)  T List | 
|  | 
| reduce | Def reduce(f;k;as) == Case of as; nil  k ; a.as'  f(a,reduce(f;k;as'))  (recursive) | 
 | |  | Thm*  A,B:Type, f:(A   B   B), k:B, as:A List. reduce(f;k;as)  B | 
|  | 
| tree_con | Def tree_con(E;T) == E+(T  T) | 
 | |  | Thm*  E,T:Type. tree_con(E;T)  Type | 
|  | 
| top | Def Top == Void given Void | 
 | |  | Thm* Top  Type | 
|  | 
| case_default | Def Default = >  body(value,value) == body | 
|  | 
| case_tree_leaf | Def Case tree_leaf(x) = >  body(x) cont(x1,z)
== InjCase(x1; x2. body(x2); _. cont(z,z)) | 
|  | 
| case_node | Def Case x;y = >  body(x;y) cont(x1,z)
== InjCase(x1; _. cont(z,z); x2. x2/x3,x2@0. body(x3;x2@0)) | 
|  | 
| ptn_atom | Def ptn_atom(x) == inl(x) | 
 | |  | Thm*  T:Type, x:Atom. ptn_atom(x)  ptn_con(T) | 
 | |  | Thm*  x:Atom. ptn_atom(x)  Pattern | 
 | |  | Thm*  x:Atom. ptn_atom(x)  Label | 
|  | 
| ptn_pr | Def ptn_pr(x) == inr(inr(inr(x))) | 
 | |  | Thm*  T:Type, x:(T  T). ptn_pr(x)  ptn_con(T) | 
 | |  | Thm*  x,y:Pattern. ptn_pr( < x,y > )  Pattern | 
|  | 
| tree_leaf | Def tree_leaf(x) == inl(x) | 
 | |  | Thm*  E,T:Type, x:E. tree_leaf(x)  tree_con(E;T) | 
 | |  | Thm*  E:Type, x:E. tree_leaf(x)  Tree(E) | 
|  | 
| bor | Def p   q == if p  true  else q fi | 
 | |  | Thm*  p,q:  . (p   q)    | 
|  | 
| band | Def p   q == if p  q else false  fi | 
 | |  | Thm*  p,q:  . (p   q)    | 
|  | 
| case_lbl_pair | Def Case ptn_pr( < x, y > ) = >  body(x;y) cont(x1,z)
== InjCase(x1; _. cont(z,z); x2.
 InjCase(x2; _. cont(z,z); x2@0. InjCase(x2@0; _. cont(z,z); x2@1. x2@1/x3,x2@2. body(x3;x2@2)))) | 
|  | 
| case_ptn_var | Def Case ptn_var(x) = >  body(x) cont(x1,z)
== (  x1.inr(x2) = > 
 (  x1.inr(x2) = > 
 (  x1.inl(x2) = >  body(hd([x2 / tl(x1)])) cont(hd(x1),z))([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x1]) | 
|  | 
| ptn_con | Def ptn_con(T) == Atom+  +Atom+(T  T) | 
 | |  | Thm*  T:Type. ptn_con(T)  Type | 
|  | 
| col_none | Def  <  > (x) == False | 
 | |  | Thm*  T:Type.  <  >  Collection(T) | 
|  | 
| eq_atom | Def x=  y  Atom == if x=y  Atom  true  ; false  fi | 
 | |  | Thm*  x,y:Atom. x=  y  Atom    | 
|  | 
| eq_int | Def i=  j == if i=j  true  ; false  fi | 
 | |  | Thm*  i,j:  . (i=  j)    | 
|  | 
| case_ptn_int | Def Case ptn_int(x) = >  body(x) cont(x1,z)
== (  x1.inr(x2) = > 
 (  x1.inl(x2) = >  body(hd([x2 / tl(x1)])) cont(hd(x1),z))([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x1]) | 
|  | 
| case_ptn_atom | Def Case ptn_atom(x) = >  body(x) cont(x1,z)
== InjCase(x1; x2. body(x2); _. cont(z,z)) | 
|  | 
| case_ts_trace | Def Case ts_trace(x) = >  body(x) cont(x1,z)
== (  x1.inr(x2) = > 
 (  x1.inr(x2) = > 
 (  x1.inr(x2) = > 
 (  x1.inr(x2) = >  body(hd([x2 / tl(x1)])) cont(hd(x1),z))([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x1]) | 
|  | 
| case_ts_fvar | Def Case ts_fvar(x) = >  body(x) cont(x1,z)
== (  x1.inr(x2) = > 
 (  x1.inr(x2) = > 
 (  x1.inr(x2) = > 
 (  x1.inl(x2) = >  body(hd([x2 / tl(x1)])) cont(hd(x1),z))([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x1]) | 
|  | 
| case_ts_op | Def Case ts_op(x) = >  body(x) cont(x1,z)
== (  x1.inr(x2) = > 
 (  x1.inr(x2) = > 
 (  x1.inl(x2) = >  body(hd([x2 / tl(x1)])) cont(hd(x1),z))([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x1]) | 
|  | 
| case_ts_pvar | Def Case ts_pvar(x) = >  body(x) cont(x1,z)
== (  x1.inr(x2) = > 
 (  x1.inl(x2) = >  body(hd([x2 / tl(x1)])) cont(hd(x1),z))([x2 / tl(x1)])
 cont
 (hd(x1)
 ,z))
 ([x1]) | 
|  | 
| hd | Def hd(l) == Case of l; nil  "?" ; h.t  h | 
 | |  | Thm*  A:Type, l:A List. ||l||  1   hd(l)  A | 
 | |  | Thm*  A:Type, l:A List  . hd(l)  A | 
|  | 
| tl | Def tl(l) == Case of l; nil  nil ; h.t  t | 
 | |  | Thm*  A:Type, l:A List. tl(l)  A List | 
|  | 
| case_inl | Def inl(x) = >  body(x) cont(value,contvalue)
== InjCase(value; x. body(x); _. cont(contvalue,contvalue)) | 
|  | 
| case_inr | Def inr(x) = >  body(x) cont(value,contvalue)
== InjCase(value; _. cont(contvalue,contvalue); x. body(x)) | 
|  | 
| case_ts_var | Def Case ts_var(x) = >  body(x) cont(x1,z)
== InjCase(x1; x2. body(x2); _. cont(z,z)) |