InutitionTC  0.30
checker.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2016 by University of Warsaw *
3  * *
4  * This file is part of IntuitionTC. *
5  * *
6  ****************************************************************************/
15 #ifndef _CHECKER_H
16 #define _CHECKER_H 1
17 #include <stdlib.h>
18 #ifdef _FRAMAC_
19 #include <__fc_string_axiomatic.h>
20 #include "errorMessages.h"
21 #endif
22 
23 extern const size_t DEFAULT_SIZE;
24 //@ predicate default_size_inv(size_t ds) = ds == 100;
25 
26 
27 /*@ axiomatic string_additional {
28  @ lemma strcmp_equal{L}:
29  @ \forall char *s; valid_string(s) ==> strcmp(s, s) == 0;
30  @ }
31  @*/
32 
34 struct Type;
35 typedef struct Type Type;
36 struct Kind;
37 typedef struct Kind Kind;
38 struct Term;
39 typedef struct Term Term;
40 struct Bind;
41 typedef struct Bind Bind;
42 struct Any;
43 typedef struct Any Any;
44 
46 typedef char* Name;
47 /*@ predicate eqName(Name n1, Name n2) =
48  @ (n1 == n2) || (n1 != \null && n2 != \null && strcmp(n1,n2) == 0);
49  @*/
50 
52 /* data Kind = Kstar
53  | Kpi Name Type Kind */
54 typedef enum { eKstar, eKpi } eKind;
55 
57 typedef struct Kstar { int nothing; } Kstar;
58 // something must be inside a structure for WHY3 to digest
59 
61 typedef struct Kpi {
62  Name name;
63  Type* type;
64  Kind* kind;
65 } Kpi;
66 
68 struct Kind {
69  eKind which;
70  Kstar kStar;
71  Kpi kPi;
72 };
73 
75 /*
76 data Type = Tvar Name
77  | Tall Name Type Type
78  | Tapp Type Term
79  | Texi Name Type Type
80  | Tand Type Type
81  | Tor Type Type
82  | Tbot
83 */
84 typedef enum { etVar, etAll, etApp, etExi, etAnd, etOr, etBot } eType;
85 
87 /* data Type = Tvar Name */
88 typedef struct Tvar {
89  Name name;
90 } Tvar;
91 
92 
94 /* | Tall Name Type Type */
95 typedef struct Tall {
96  Name name;
97  Type* type1;
98  Type* type2;
99 } Tall;
100 
103 /* | Tapp Type Term */
104 typedef struct Tapp {
105  Type* type;
106  Term* term;
107 } Tapp;
108 
110 /* | Texi Name Type Type */
111 typedef struct Texi {
112  Name name;
113  Type* type1;
114  Type* type2;
115 } Texi;
116 
118 /* | Tand Type Type */
119 typedef struct Tand {
120  Type* type1;
121  Type* type2;
122 } Tand;
123 
125 /* | Tor Type Type */
126 typedef struct Tor {
127  Type* type1;
128  Type* type2;
129 } Tor;
130 
132 /* | Tbot */
133 typedef struct Tbot { int nothing; } Tbot;
134 // something must be inside a structure for WHY3 to digest
135 
137 /*
138 data Type = Tvar Name
139  | Tall Name Type Type
140  | Tapp Type Term
141  | Texi Name Type Type
142  | Tand Type Type
143  | Tor Type Type
144  | Tbot
145 */
146 struct Type {
147  eType which;
148  Tvar tVar;
149  Tall tAll;
150  Tapp tApp;
151  Texi tExi;
152  Tand tAnd;
153  Tor tOr;
154  Tbot tBot;
155 };
156 
157 
159 /*
160 data Term = Mvar Name
161  | Mapp Term Term
162  | Mlam Name Type Term
163  | Mwit Type Term Term -- [m1,m2]_{∃ x:phi1.phi2}
164  | Mabs Name Type Name Type Term Term
165  -- abstract <x:phi1,y:phi2> = m1 in m2
166  | Mtup Type Term Term
167  | Mpi1 Term
168  | Mpi2 Term
169  | Min1 Type Term
170  | Min2 Type Term
171  | Mcas Term (Name,Type,Term) (Name,Type,Term)
172 */
173 typedef enum {emVar, emApp, emLam, emWit, emAbs, emTup, emPi1, emPi2, emIn1,
174  emIn2, emCas, emEps} eTerm;
175 
177 /* data Term = Mvar Name */
178 typedef struct Mvar {
179  Name name;
180 } Mvar;
181 
184 /* | Mapp Term Term */
185 typedef struct Mapp {
186  Term* term1;
187  Term* term2;
188 } Mapp;
189 
191 /* | Mlam Name Type Term*/
192 typedef struct Mlam {
193  Name name;
194  Type* type;
195  Term* term;
196 } Mlam;
197 
200 /* | Mwit Type Term Term -- [m1,m2]_{∃ x:phi1.phi2}*/
201 typedef struct Mwit {
202  Type* type;
203  Term* term1;
204  Term* term2;
205 } Mwit;
206 
209 /* | Mabs Name Type Name Type Term Term
210  -- abstract <x:phi1,y:phi2> = m1 in m2*/
211 typedef struct Mabs {
212  Name name1;
213  Type* type2;
214  Name name3;
215  Type* type4;
216  Term* term5;
217  Term* term6;
218 } Mabs;
219 
222 /* | Mtup Type Term Term*/
223 typedef struct Mtup {
224  Type* type;
225  Term* term1;
226  Term* term2;
227 } Mtup;
228 
231 /* | Mpi1 Term*/
232 typedef struct Mpi1 {
233  Term* term;
234 } Mpi1;
235 
238 /* | Mpi2 Term*/
239 typedef struct Mpi2 {
240  Term* term;
241 } Mpi2;
242 
245 /* | Min1 Type Term*/
246 typedef struct Min1 {
247  Type* type;
248  Term* term;
249 } Min1;
250 
253 /* | Min2 Type Term*/
254 typedef struct Min2 {
255  Type* type;
256  Term* term;
257 } Min2;
258 
260 /* | Mcas Term (Name,Type,Term) (Name,Type,Term)*/
261 typedef struct McasIn {
262  Name name;
263  Type* type;
264  Term* term;
265 } McasIn;
266 
269 typedef struct Mcas {
270  Term* term;
271  McasIn casIn1;
272  McasIn casIn2;
273 } Mcas;
274 
277 /* | Meps Type Term*/
278 typedef struct Meps {
279  Type* type;
280  Term* term;
281 } Meps;
282 
284 /*
285 data Term = Mvar Name
286  | Mapp Term Term
287  | Mlam Name Type Term
288  | Mwit Type Term Term -- [m1,m2]_{∃ x:phi1.phi2}
289  | Mabs Name Type Name Type Term Term
290  -- abstract <x:phi1,y:phi2> = m1 in m2
291  | Mtup Type Term Term
292  | Mpi1 Term
293  | Mpi2 Term
294  | Min1 Type Term
295  | Min2 Type Term
296  | Mcas Term (Name,Type,Term) (Name,Type,Term)
297 */
298 struct Term {
299  eTerm which;
300  Mvar mVar;
301  Mapp mApp;
302  Mlam mLam;
303  Mwit mWit;
304  Mabs mAbs;
305  Mtup mTup;
306  Mpi1 mPi1;
307  Mpi2 mPi2;
308  Min1 mIn1;
309  Min2 mIn2;
310  Mcas mCas;
311  Meps mEps;
312 };
313 
315 struct Bind {
316  Name name;
317  Type*type;
318  Any *any;
319 };
320 
321 
324 typedef enum { eAnyType, eAnyTerm, eAnyKind, eAnyName, eAnyBind} eAny;
325 
329 struct Any {
330  eAny which;
331  Type* mType;
332  Term* mTerm;
333  Kind* mKind;
334  Name mName;
335  Bind mBind;
336 };
337 
338 
339 
340 
341 /*@ axiomatic checker {
342  @
343  @ predicate valid_Type_ptr{L}(Type *t);
344  @
345  @ predicate valid_Kind_ptr{L}(Kind *k);
346  @
347  @ predicate valid_Term_ptr{L}(Term *t);
348  @
349  @ predicate valid_Name{L}(Name n) = valid_string{L}(n);
350  @
351  @ predicate valid_Kstar{L}(Kstar k) = \true;
352  @
353  @ predicate valid_Kpi(Kpi k) =
354  @ valid_Name(k.name) &&
355  @ valid_Type_ptr(k.type) &&
356  @ valid_Kind_ptr(k.kind);
357  @
358  @ predicate valid_Kind{L}(Kind k) =
359  @ (k.which == eKstar || k.which == eKpi) &&
360  @ (k.which == eKstar ==> valid_Kstar(k.kStar)) &&
361  @ (k.which == eKpi ==> valid_Kpi(k.kPi));
362  @
363  @ predicate isShallowCopyOfKind{L,M}(Kind k1, Kind k2) =
364  @ \at(k1.which,L) == \at(k2.which,M) &&
365  @ \at(k1.kStar,L) == \at(k2.kStar,M) &&
366  @ \at(k1.kPi,L) == \at(k2.kPi,M);
367  @
368  @ axiom valid_Kind_ptr_def{L}: \forall Kind *k;
369  @ valid_Kind_ptr{L}(k) <==> \valid(k) && valid_Kind{L}(*k);
370  @
371  @
372  @ predicate valid_Tvar{L}(Tvar t) =
373  @ valid_Name(t.name);
374  @
375  @
376  @ predicate valid_Tall{L}(Tall t) =
377  @ valid_Name(t.name) &&
378  @ \valid(t.type1) &&
379  @ valid_Type_ptr(t.type1) &&
380  @ \valid(t.type2) &&
381  @ valid_Type_ptr(t.type2);
382  @
383  @
384  @ predicate valid_Tapp{L}(Tapp t) =
385  @ \valid(t.type) &&
386  @ valid_Type_ptr(t.type) &&
387  @ \valid(t.term) &&
388  @ valid_Term_ptr(t.term);
389  @
390  @
391  @ predicate valid_Texi{L}(Texi t) =
392  @ valid_Name(t.name) &&
393  @ \valid(t.type1) &&
394  @ valid_Type_ptr(t.type1) &&
395  @ \valid(t.type2) &&
396  @ valid_Type_ptr(t.type2);
397  @
398  @
399  @ predicate valid_Tand{L}(Tand t) =
400  @ \valid(t.type1) &&
401  @ valid_Type_ptr(t.type1) &&
402  @ \valid(t.type2) &&
403  @ valid_Type_ptr(t.type2);
404  @
405  @
406  @ predicate valid_Tor{L}(Tor t) =
407  @ \valid(t.type1) &&
408  @ valid_Type_ptr(t.type1) &&
409  @ \valid(t.type2) &&
410  @ valid_Type_ptr(t.type2);
411  @
412  @
413  @ predicate valid_Tbot{L}(Tbot t) = \true;
414  @
415  @
416  @ predicate valid_Type{L}(struct Type t) =
417  @ (t.which == etVar || t.which == etAll || t.which == etApp ||
418  @ t.which == etExi || t.which == etAnd || t.which == etOr ||
419  @ t.which == etBot) &&
420  @ (t.which == etVar ==> valid_Tvar(t.tVar)) &&
421  @ (t.which == etAll ==> valid_Tall(t.tAll)) &&
422  @ (t.which == etApp ==> valid_Tapp(t.tApp)) &&
423  @ (t.which == etExi ==> valid_Texi(t.tExi)) &&
424  @ (t.which == etAnd ==> valid_Tand(t.tAnd)) &&
425  @ (t.which == etOr ==> valid_Tor(t.tOr)) &&
426  @ (t.which == etBot ==> valid_Tbot(t.tBot));
427  @
428  @ predicate isShallowCopyOfType{L,M}(Type t1, Type t2) =
429  @ \at(t1.which,L) == \at(t2.which,M) &&
430  @ \at(t1.tVar,L) == \at(t2.tVar,M) &&
431  @ \at(t1.tAll,L) == \at(t2.tAll,M) &&
432  @ \at(t1.tApp,L) == \at(t2.tApp,M) &&
433  @ \at(t1.tExi,L) == \at(t2.tExi,M) &&
434  @ \at(t1.tAnd,L) == \at(t2.tAnd,M) &&
435  @ \at(t1.tOr,L) == \at(t2.tOr,M) &&
436  @ \at(t1.tBot,L) == \at(t2.tBot,M);
437  @
438  @ axiom valid_Type_ptr_def{L}: \forall Type *t;
439  @ valid_Type_ptr{L}(t) <==> \valid(t) && valid_Type{L}(*t);
440  @
441  @ predicate valid_Mvar{L}(Mvar m) =
442  @ valid_Name(m.name);
443  @
444  @ predicate valid_Mapp{L}(Mapp m) =
445  @ \valid(m.term1) &&
446  @ valid_Term_ptr(m.term1) &&
447  @ \valid(m.term2) &&
448  @ valid_Term_ptr(m.term2);
449  @
450  @ predicate valid_Mlam{L}(Mlam m) =
451  @ valid_Name(m.name) &&
452  @ \valid(m.type) &&
453  @ valid_Type_ptr(m.type) &&
454  @ \valid(m.term) &&
455  @ valid_Term_ptr(m.term);
456  @
457  @ predicate valid_Mwit{L}(Mwit m) =
458  @ \valid(m.type) &&
459  @ valid_Type_ptr(m.type) &&
460  @ \valid(m.term1) &&
461  @ valid_Term_ptr(m.term1) &&
462  @ \valid(m.term2) &&
463  @ valid_Term_ptr(m.term2);
464  @
465  @ predicate valid_Mabs{L}(Mabs m) =
466  @ valid_Name(m.name1) &&
467  @ \valid(m.type2) &&
468  @ valid_Type_ptr(m.type2) &&
469  @ valid_Name(m.name3) &&
470  @ \valid(m.type4) &&
471  @ valid_Type_ptr(m.type4) &&
472  @ \valid(m.term5) &&
473  @ valid_Term_ptr(m.term5) &&
474  @ \valid(m.term6) &&
475  @ valid_Term_ptr(m.term6);
476  @
477  @ predicate valid_Mtup{L}(Mtup m) =
478  @ \valid(m.type) &&
479  @ valid_Type_ptr(m.type) &&
480  @ \valid(m.term1) &&
481  @ valid_Term_ptr(m.term1) &&
482  @ \valid(m.term2) &&
483  @ valid_Term_ptr(m.term2);
484  @
485  @ predicate valid_Mpi1{L}(Mpi1 m) =
486  @ \valid(m.term) &&
487  @ valid_Term_ptr(m.term);
488  @
489  @ predicate valid_Mpi2{L}(Mpi2 m) =
490  @ \valid(m.term) &&
491  @ valid_Term_ptr(m.term);
492  @
493  @ predicate valid_Min1{L}(Min1 m) =
494  @ \valid(m.type) &&
495  @ valid_Type_ptr(m.type) &&
496  @ \valid(m.term) &&
497  @ valid_Term_ptr(m.term);
498  @
499  @ predicate valid_Min2{L}(Min2 m) =
500  @ \valid(m.type) &&
501  @ valid_Type_ptr(m.type) &&
502  @ \valid(m.term) &&
503  @ valid_Term_ptr(m.term);
504  @
505  @ predicate valid_McasIn{L}(McasIn m) =
506  @ valid_Name(m.name) &&
507  @ \valid(m.type) &&
508  @ valid_Type_ptr(m.type) &&
509  @ \valid(m.term) &&
510  @ valid_Term_ptr(m.term);
511  @
512  @ predicate valid_Mcas{L}(Mcas m) =
513  @ \valid(m.term) &&
514  @ valid_Term_ptr(m.term) &&
515  @ valid_McasIn(m.casIn1) &&
516  @ valid_McasIn(m.casIn2);
517  @
518  @ predicate valid_Meps{L}(Meps m) =
519  @ \valid(m.type) &&
520  @ valid_Type_ptr(m.type) &&
521  @ \valid(m.term) &&
522  @ valid_Term_ptr(m.term);
523  @
524  @ predicate valid_Term{L}(struct Term t) =
525  @ (t.which == emVar || t.which == emApp || t.which == emLam ||
526  @ t.which == emWit || t.which == emAbs || t.which == emTup ||
527  @ t.which == emPi1 || t.which == emPi2 || t.which == emIn1 ||
528  @ t.which == emIn2 || t.which == emCas || t.which == emEps) &&
529  @ (t.which == emVar ==> valid_Mvar(t.mVar)) &&
530  @ (t.which == emApp ==> valid_Mapp(t.mApp)) &&
531  @ (t.which == emLam ==> valid_Mlam(t.mLam)) &&
532  @ (t.which == emWit ==> valid_Mwit(t.mWit)) &&
533  @ (t.which == emAbs ==> valid_Mabs(t.mAbs)) &&
534  @ (t.which == emTup ==> valid_Mtup(t.mTup)) &&
535  @ (t.which == emPi1 ==> valid_Mpi1(t.mPi1)) &&
536  @ (t.which == emPi2 ==> valid_Mpi2(t.mPi2)) &&
537  @ (t.which == emIn1 ==> valid_Min1(t.mIn1)) &&
538  @ (t.which == emIn2 ==> valid_Min2(t.mIn2)) &&
539  @ (t.which == emCas ==> valid_Mcas(t.mCas)) &&
540  @ (t.which == emEps ==> valid_Meps(t.mEps));
541  @
542  @ predicate isShallowCopyOfTerm{L,M}(Term t1, Term t2) =
543  @ \at(t1.which,L) == \at(t2.which,M) &&
544  @ \at(t1.mVar,L) == \at(t2.mVar,M) &&
545  @ \at(t1.mApp,L) == \at(t2.mApp,M) &&
546  @ \at(t1.mLam,L) == \at(t2.mLam,M) &&
547  @ \at(t1.mWit,L) == \at(t2.mWit,M) &&
548  @ \at(t1.mAbs,L) == \at(t2.mAbs,M) &&
549  @ \at(t1.mTup,L) == \at(t2.mTup,M) &&
550  @ \at(t1.mPi1,L) == \at(t2.mPi1,M) &&
551  @ \at(t1.mPi2,L) == \at(t2.mPi2,M) &&
552  @ \at(t1.mIn1,L) == \at(t2.mIn1,M) &&
553  @ \at(t1.mIn2,L) == \at(t2.mIn2,M) &&
554  @ \at(t1.mCas,L) == \at(t2.mCas,M) &&
555  @ \at(t1.mEps,L) == \at(t2.mEps,M);
556  @
557  @ axiom valid_Term_ptr_def:
558  @ \forall Term *t; valid_Term_ptr(t) <==>
559  @ \valid(t) && valid_Term(*t);
560  @
561  @
562  @ predicate valid_Any{L}(struct Any t) =
563  @ (t.which == eAnyType || t.which == eAnyTerm || t.which == eAnyKind ||
564  @ t.which == eAnyName || t.which == eAnyBind) &&
565  @ (t.which == eAnyType ==> valid_Type_ptr(t.mType)) &&
566  @ (t.which == eAnyTerm ==> valid_Term_ptr(t.mTerm)) &&
567  @ (t.which == eAnyKind ==> valid_Kind_ptr(t.mKind)) &&
568  @ (t.which == eAnyName ==> valid_Name(t.mName)); // &&
569  @ //(t.which == eAnyBind ==> valid_Bind(t.mBind));
570  @
571  @ predicate isShallowCopyOfAny{L,M}(Any a1, Any a2) =
572  @ \at(a1.which,L) == \at(a2.which,M) &&
573  @ \at(a1.mType,L) == \at(a2.mType,M) &&
574  @ \at(a1.mTerm,L) == \at(a2.mTerm,M) &&
575  @ \at(a1.mKind,L) == \at(a2.mKind,M) &&
576  @ \at(a1.mName,L) == \at(a2.mName,M) &&
577  @ \at(a1.mBind,L) == \at(a2.mBind,M);
578  @
579  @ predicate valid_Any_ptr{L}(Any *t) =
580  @ t != \null &&
581  @ \valid(t) &&
582  @ valid_Any{L}(*t);
583  @
584  @ predicate valid_Bind{L}(Bind b) =
585  @ (valid_Name{L}(b.name)) &&
586  @ (valid_Type_ptr{L}(b.type)) &&
587  @ (valid_Any_ptr{L}(b.any));
588 
589  } //axiomatic checker @*/
590 
591 //----------------------------------------------------------------------
592 
593 /*@ axiomatic wellfounded {
594  @
595  @
596  @ logic integer depth_Type(Type *t);
597  @ logic integer depth_Term(Term *t);
598  @ logic integer depth_Kind(Kind *t);
599  @ logic integer depth_Any(Any *a);
600  @
601  @ // for Type
602  @
603  @ logic integer depth_Tvar(Tvar t) = 1;
604  @
605  @ logic integer depth_Tall(Tall t) = 1 +
606  @ maximum(depth_Type(t.type1), depth_Type(t.type2));
607  @
608  @ logic integer depth_Tapp(Tapp t) = 1 +
609  @ maximum(depth_Type(t.type), depth_Term(t.term));
610  @
611  @ logic integer depth_Texi(Texi t) = 1 +
612  @ maximum(depth_Type(t.type1), depth_Type(t.type2));
613  @
614  @ logic integer depth_Tand(Tand t) = 1 +
615  @ maximum(depth_Type(t.type1), depth_Type(t.type2));
616  @
617  @ logic integer depth_Tor(Tor t) = 1 +
618  @ maximum(depth_Type(t.type1), depth_Type(t.type2));
619  @
620  @ logic integer depth_Tbot(Tbot t) = 1;
621  @
622  @ // for Term
623  @
624  @ logic integer depth_Mvar(Mvar t) = 1;
625  @
626  @ logic integer depth_Mapp(Mapp t) = 1 +
627  @ maximum(depth_Term(t.term1), depth_Term(t.term2));
628  @
629  @ logic integer depth_Mlam(Mlam t) = 1 +
630  @ maximum(depth_Type(t.type), depth_Term(t.term));
631  @
632  @ logic integer depth_Mwit(Mwit t) = 1 +
633  @ maximum(depth_Type(t.type),
634  @ maximum(depth_Term(t.term1), depth_Term(t.term2)));
635  @
636  @ logic integer depth_Mabs(Mabs t) = 1 +
637  @ maximum(
638  @ maximum(depth_Type(t.type2), depth_Type(t.type4)),
639  @ maximum(depth_Term(t.term5), depth_Term(t.term6)));
640  @
641  @ logic integer depth_Mtup(Mtup t) = 1 +
642  @ maximum(depth_Term(t.term1), depth_Term(t.term2));
643  @
644  @ logic integer depth_Mpi1(Mpi1 t) = 1 +
645  @ depth_Term(t.term);
646  @
647  @ logic integer depth_Mpi2(Mpi2 t) = 1 +
648  @ depth_Term(t.term);
649  @
650  @ logic integer depth_Min1(Min1 t) = 1 +
651  @ maximum(depth_Type(t.type), depth_Term(t.term));
652  @
653  @ logic integer depth_Min2(Min2 t) = 1 +
654  @ maximum(depth_Type(t.type), depth_Term(t.term));
655  @
656  @ logic integer depth_McasIn(McasIn t) =
657  @ maximum(depth_Type(t.type), depth_Term(t.term));
658  @
659  @ logic integer depth_Mcas(Mcas t) =
660  @ maximum(depth_Term(t.term),
661  @ maximum(depth_McasIn(t.casIn1),
662  @ depth_McasIn(t.casIn2)));
663  @
664  @ logic integer depth_Meps(Meps t) = 1 +
665  @ maximum(depth_Type(t.type), depth_Term(t.term));
666  @
667  @ logic integer depth_Bind(Bind b) = 1 +
668  @ maximum(depth_Type(b.type), depth_Any(b.any));
669  @
670  @
671  @ axiom depth_Type_def{M}:
672  @ \forall Type *t;
673  @ ((t->which==etVar) ==> depth_Type(t) == depth_Tvar(t->tVar)) &&
674  @ ((t->which==etAll) ==> depth_Type(t) == depth_Tall(t->tAll)) &&
675  @ ((t->which==etApp) ==> depth_Type(t) == depth_Tapp(t->tApp)) &&
676  @ ((t->which==etExi) ==> depth_Type(t) == depth_Texi(t->tExi)) &&
677  @ ((t->which==etAnd) ==> depth_Type(t) == depth_Tand(t->tAnd)) &&
678  @ ((t->which==etOr ) ==> depth_Type(t) == depth_Tor(t->tOr)) &&
679  @ ((t->which==etBot) ==> depth_Type(t) == depth_Tbot(t->tBot)) &&
680  @ ((\exists integer n; depth_Type(t)==n) ==>
681  @ (t->which==etVar) ||
682  @ (t->which==etAll) ||
683  @ (t->which==etApp) ||
684  @ (t->which==etExi) ||
685  @ (t->which==etAnd) ||
686  @ (t->which==etOr ) ||
687  @ (t->which==etBot));
688  @
689  @
690  @ axiom depth_Term_def{M}:
691  @ \forall Term *t;
692  @ ((t->which==emVar) ==> depth_Term(t) == depth_Mvar(t->mVar)) &&
693  @ ((t->which==emApp) ==> depth_Term(t) == depth_Mapp(t->mApp)) &&
694  @ ((t->which==emLam) ==> depth_Term(t) == depth_Mlam(t->mLam)) &&
695  @ ((t->which==emWit) ==> depth_Term(t) == depth_Mwit(t->mWit)) &&
696  @ ((t->which==emAbs) ==> depth_Term(t) == depth_Mabs(t->mAbs)) &&
697  @ ((t->which==emTup) ==> depth_Term(t) == depth_Mtup(t->mTup)) &&
698  @ ((t->which==emPi1) ==> depth_Term(t) == depth_Mpi1(t->mPi1)) &&
699  @ ((t->which==emPi2) ==> depth_Term(t) == depth_Mpi2(t->mPi2)) &&
700  @ ((t->which==emIn1) ==> depth_Term(t) == depth_Min1(t->mIn1)) &&
701  @ ((t->which==emIn2) ==> depth_Term(t) == depth_Min2(t->mIn2)) &&
702  @ ((t->which==emCas) ==> depth_Term(t) == depth_Mcas(t->mCas)) &&
703  @ ((t->which==emEps) ==> depth_Term(t) == depth_Meps(t->mEps)) &&
704  @ ((\exists integer n; depth_Term(t)==n) ==>
705  @ ((t->which==emVar) ||
706  @ (t->which==emApp) ||
707  @ (t->which==emLam) ||
708  @ (t->which==emWit) ||
709  @ (t->which==emAbs) ||
710  @ (t->which==emTup) ||
711  @ (t->which==emPi1) ||
712  @ (t->which==emPi2) ||
713  @ (t->which==emIn1) ||
714  @ (t->which==emIn2) ||
715  @ (t->which==emCas) ||
716  @ (t->which==emEps)));
717  @
718  @
719  @ axiom depth_Kind_def{M}:
720  @ \forall Kind *t;
721  @ ((t->which==eKstar) ==> depth_Kind(t) == 1) &&
722  @ ((t->which==eKpi) ==> depth_Kind(t) ==
723  @ 1 + maximum(depth_Type(t->kPi.type),
724  @ depth_Kind(t->kPi.kind))) &&
725  @ ((\exists integer n; depth_Kind(t)==n) ==>
726  @ (t->which==eKstar || (t->which==eKpi)));
727  @
728  @
729  @ axiom depth_Any_def{M}:
730  @ \forall Any* a;
731  @ ((a->which==eAnyType) ==> depth_Any(a) == depth_Type(a->mType)) &&
732  @ ((a->which==eAnyTerm) ==> depth_Any(a) == depth_Term(a->mTerm)) &&
733  @ ((a->which==eAnyKind) ==> depth_Any(a) == depth_Kind(a->mKind)) &&
734  @ ((a->which==eAnyName) ==> depth_Any(a) == 0) &&
735  @ ((a->which==eAnyBind) ==> depth_Any(a) == depth_Bind(a->mBind)) &&
736  @ ((\exists integer n; depth_Any(a) ==n) ==>
737  @ (a->which==eAnyType ||
738  @ a->which==eAnyTerm ||
739  @ a->which==eAnyKind ||
740  @ a->which==eAnyName ||
741  @ a->which==eAnyBind));
742  @
743  @ }
744  @*/
745 
746 //----------------------------------------------------------------------
747 
748 /*@ axiomatic checker_separation {
749  @
750  @ predicate separated_Type{L}(char** keys, size_t len, Type *t);
751  @ predicate separated_Term{L}(char** keys, size_t len, Term *t);
752  @
753  @ predicate separated_Name{L}(char** keys, size_t len, Name n) =
754  @ \separated(keys+(0..(sizeof(char*)*len)-1), n+(0..strlen(n)));
755  @
756  @ predicate separated_Tvar{L}(char** keys, size_t len, Tvar t) =
757  @ \separated(keys+(0..(sizeof(char*)*len)-1), t.name+(0..strlen(t.name)));
758  @
759  @ predicate separated_Tall{L}(char** keys, size_t len, Tall t) =
760  @ separated_Name(keys, len, t.name) &&
761  @ \separated(keys+(0..(sizeof(char*)*len)-1), t.type1) &&
762  @ \separated(keys+(0..(sizeof(char*)*len)-1), t.type2) &&
763  @ separated_Type(keys, len, t.type1) &&
764  @ separated_Type(keys, len, t.type2);
765  @
766  @
767  @ predicate separated_Tapp{L}(char** keys, size_t len, Tapp t) =
768  @ separated_Type(keys, len, t.type) &&
769  @ separated_Term(keys, len, t.term);
770  @
771  @
772  @ predicate separated_Texi{L}(char** keys, size_t len, Texi t) =
773  @ separated_Name(keys, len, t.name) &&
774  @ separated_Type(keys, len, t.type1) &&
775  @ separated_Type(keys, len, t.type2);
776  @
777  @ predicate separated_Tand{L}(char** keys, size_t len, Tand t) =
778  @ separated_Type(keys, len, t.type1) &&
779  @ separated_Type(keys, len, t.type2);
780  @
781  @ predicate separated_Tor{L}(char** keys, size_t len, Tor t) =
782  @ separated_Type(keys, len, t.type1) &&
783  @ separated_Type(keys, len, t.type2);
784  @
785  @ predicate separated_Tbot{L}(char** keys, size_t len, Tbot t) = \true;
786  @
787  @ axiom separated_Type_def{L}:
788  @ \forall char** keys, size_t len, Type *t;
789  @ separated_Type(keys, len, t) <==>
790  @ \separated(keys+(0..(sizeof(char*)*len)-1), t) &&
791  @ (t->which == etVar ==> separated_Tvar(keys, len, t->tVar)) &&
792  @ (t->which == etAll ==> separated_Tall(keys, len, t->tAll)) &&
793  @ (t->which == etApp ==> separated_Tapp(keys, len, t->tApp)) &&
794  @ (t->which == etExi ==> separated_Texi(keys, len, t->tExi)) &&
795  @ (t->which == etAnd ==> separated_Tand(keys, len, t->tAnd)) &&
796  @ (t->which == etOr ==> separated_Tor(keys, len, t->tOr)) &&
797  @ (t->which == etBot ==> separated_Tbot(keys, len, t->tBot));
798  @
799  @
800  @ predicate separated_Mvar{L}(char** keys, size_t len, Mvar m) =
801  @ separated_Name(keys, len, m.name);
802  @
803  @ predicate separated_Mapp{L}(char** keys, size_t len, Mapp m) =
804  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term1) &&
805  @ separated_Term(keys, len, m.term1) &&
806  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term2) &&
807  @ separated_Term(keys, len, m.term2);
808  @
809  @ predicate separated_Mlam{L}(char** keys, size_t len, Mlam m) =
810  @ separated_Name(keys, len, m.name) &&
811  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type) &&
812  @ separated_Type(keys, len, m.type) &&
813  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
814  @ separated_Term(keys, len, m.term);
815  @
816  @ predicate separated_Mwit{L}(char** keys, size_t len, Mwit m) =
817  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type) &&
818  @ separated_Type(keys, len, m.type) &&
819  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term1) &&
820  @ separated_Term(keys, len, m.term1) &&
821  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term2) &&
822  @ separated_Term(keys, len, m.term2);
823  @
824  @ predicate separated_Mabs{L}(char** keys, size_t len, Mabs m) =
825  @ separated_Name(keys, len, m.name1) &&
826  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type2) &&
827  @ separated_Type(keys, len, m.type2) &&
828  @ separated_Name(keys, len, m.name3) &&
829  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type4) &&
830  @ separated_Type(keys, len, m.type4) &&
831  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term5) &&
832  @ separated_Term(keys, len, m.term5) &&
833  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term6) &&
834  @ separated_Term(keys, len, m.term6);
835  @
836  @ predicate separated_Mtup{L}(char** keys, size_t len, Mtup m) =
837  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type) &&
838  @ separated_Type(keys, len, m.type) &&
839  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term1) &&
840  @ separated_Term(keys, len, m.term1) &&
841  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term2) &&
842  @ separated_Term(keys, len, m.term2);
843  @
844  @ predicate separated_Mpi1{L}(char** keys, size_t len, Mpi1 m) =
845  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
846  @ separated_Term(keys, len, m.term);
847  @
848  @ predicate separated_Mpi2{L}(char** keys, size_t len, Mpi2 m) =
849  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
850  @ separated_Term(keys, len, m.term);
851  @
852  @ predicate separated_Min1{L}(char** keys, size_t len, Min1 m) =
853  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type) &&
854  @ separated_Type(keys, len, m.type) &&
855  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
856  @ separated_Term(keys, len, m.term);
857  @
858  @ predicate separated_Min2{L}(char** keys, size_t len, Min2 m) =
859  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type) &&
860  @ separated_Type(keys, len, m.type) &&
861  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
862  @ separated_Term(keys, len, m.term);
863  @
864  @ predicate separated_McasIn{L}(char** keys, size_t len, McasIn m) =
865  @ separated_Name(keys, len, m.name) &&
866  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type) &&
867  @ separated_Type(keys, len, m.type) &&
868  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
869  @ separated_Term(keys, len, m.term);
870  @
871  @ predicate separated_Mcas{L}(char** keys, size_t len, Mcas m) =
872  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
873  @ separated_Term(keys, len, m.term) &&
874  @ separated_McasIn(keys, len, m.casIn1) &&
875  @ separated_McasIn(keys, len, m.casIn2);
876  @
877  @ predicate separated_Meps{L}(char** keys, size_t len, Meps m) =
878  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.type) &&
879  @ separated_Type(keys, len, m.type) &&
880  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.term) &&
881  @ separated_Term(keys, len, m.term);
882  @
883  @ axiom separated_Term_def{L}:
884  @ \forall char** keys, size_t len, Term *t;
885  @ separated_Term(keys, len, t) <==>
886  @ \separated(keys+(0..(sizeof(char*)*len)-1), t) &&
887  @ (t->which == emVar ==> separated_Mvar(keys, len, t->mVar)) &&
888  @ (t->which == emApp ==> separated_Mapp(keys, len, t->mApp)) &&
889  @ (t->which == emLam ==> separated_Mlam(keys, len, t->mLam)) &&
890  @ (t->which == emWit ==> separated_Mwit(keys, len, t->mWit)) &&
891  @ (t->which == emAbs ==> separated_Mabs(keys, len, t->mAbs)) &&
892  @ (t->which == emTup ==> separated_Mtup(keys, len, t->mTup)) &&
893  @ (t->which == emPi1 ==> separated_Mpi1(keys, len, t->mPi1)) &&
894  @ (t->which == emPi2 ==> separated_Mpi2(keys, len, t->mPi2)) &&
895  @ (t->which == emIn1 ==> separated_Min1(keys, len, t->mIn1)) &&
896  @ (t->which == emIn2 ==> separated_Min2(keys, len, t->mIn2)) &&
897  @ (t->which == emCas ==> separated_Mcas(keys, len, t->mCas)) &&
898  @ (t->which == emEps ==> separated_Meps(keys, len, t->mEps));
899  @
900  @ predicate separated_Kind{L}(char** keys, size_t len, Kind *t);
901  @
902  @ predicate separated_Kpi{L}(char** keys, size_t len, Kpi m) =
903  @ \separated(keys+(0..(sizeof(char*)*len)-1), m.name) &&
904  @ separated_Type(keys, len, m.type) &&
905  @ separated_Kind(keys, len, m.kind);
906 
907  @ axiom separated_Kind_def{L}:
908  @ \forall char** keys, size_t len, Kind *t;
909  @ separated_Kind(keys, len, t) <==>
910  @ \separated(keys+(0..(sizeof(char*)*len)-1), t) &&
911  @ (t->which == eKstar ==> \true) &&
912  @ (t->which == eKpi ==> separated_Kpi(keys, len, t->kPi));
913 
914  @ predicate separated_Bind{L}(char** keys, size_t len, Bind t);
915  @
916  @ predicate separated_Any{L}(char** keys, size_t len, Any *t) =
917  @ \separated(keys+(0..(sizeof(char*)*len)-1), t) &&
918  @ (t->which == eAnyType ==> separated_Type(keys, len, t->mType)) &&
919  @ (t->which == eAnyTerm ==> separated_Term(keys, len, t->mTerm)) &&
920  @ (t->which == eAnyKind ==> separated_Kind(keys, len, t->mKind)) &&
921  @ (t->which == eAnyName ==> separated_Name(keys, len, t->mName)) &&
922  @ (t->which == eAnyBind ==> separated_Bind(keys, len, t->mBind));
923  @
924  @
925  @ }
926  @*/
927 
928 /*@ axiomatic destruct_validity {
929  @ lemma valid_Term_to_valid_App:
930  @ \forall Term *t; valid_Term_ptr(t) && t->which == emApp ==>
931  @ valid_Term_ptr(t->mApp.term1);
932  @ }
933  @*/
934 
935 
936 /*@ requires valid_Term_ptr(t);
937  @ assigns \nothing;
938  @ ensures valid_Any(\result);
939  @*/
940 Any anyOfTerm(Term *t);
941 
942 /*@ requires valid_Type_ptr(t);
943  @ assigns \nothing;
944  @ ensures valid_Any(\result);
945  @*/
946 Any anyOfType(Type *t);
947 
948 /*@ requires valid_Kind_ptr(t);
949  @ assigns \nothing;
950  @ ensures valid_Any(\result);
951  @*/
952 Any anyOfKind(Kind *t);
953 
954 /*@ requires valid_Name(t);
955  @ assigns \nothing;
956  @ ensures valid_Any(\result);
957  @*/
958 Any anyOfName(Name t);
959 
960 /*@ requires valid_Bind(b);
961  @ assigns \nothing;
962  @ ensures valid_Any(\result);
963  @ */
964 Any anyOfBind(const Bind b);
965 
966 /*@ requires valid_Name(n);
967  @ requires valid_string((char*)errorBuffer) && 0 <= errorNum < 2147483647;
968  @ requires strlen((char*)errorBuffer) < L_BUFFER_LEN;
969  @ requires is_allocable((size_t)sizeof(Term),(size_t)1);
970  @ assigns errorBuffer[0..L_BUFFER_LEN-1], errorNum;
971  @ assigns __allocated[0..MAX_ALLOCS], __size_allocated, __num_allocated;
972  @ ensures valid_Term_ptr(\result);
973  @ ensures \at(__num_allocated,Pre)+1==\at(__num_allocated,Post);
974  @ ensures \forall size_t n,s; is_allocable{Pre}(n,s) <==> is_allocable{Post}((size_t)(n-sizeof(Term)),(size_t)(s-1));
975  @*/
976 Term *mMvar(Name n);
977 
978 /*@ requires valid_Name(n);
979  @ requires valid_string((char*)errorBuffer) && 0 <= errorNum < 2147483647;
980  @ requires strlen((char*)errorBuffer) < L_BUFFER_LEN;
981  @ requires is_allocable((size_t)sizeof(Type),(size_t)1);
982  @ assigns errorBuffer[0..L_BUFFER_LEN-1], errorNum;
983  @ assigns __allocated[0..MAX_ALLOCS], __size_allocated, __num_allocated;
984  @ ensures \at(__num_allocated,Pre)+1==\at(__num_allocated,Post);
985  @ ensures valid_Type_ptr(\result);
986  @*/
987 Type *tTvar(Name n);
988 
989 /*@ requires valid_Name(n) && valid_Type_ptr(t) && valid_Any_ptr(a);
990  @ assigns \result;
991  @ ensures valid_Bind(\result);
992  @ ensures \forall size_t n,s; is_allocable{Pre}(n,s) <==> is_allocable{Post}(n,s);
993  @*/
994 Bind mBind(Name n, Type *t, Any *a);
995 
996 #endif
The representation of the pi Kind.
Definition: checker.h:61
The representation of the abstraction (i.e. existential quantifier elimination) Term.
Definition: checker.h:211
The representation of the case subexpression.
Definition: checker.h:261
struct Tbot Tbot
The representation of the bottom/falsity Type.
struct Meps Meps
The representation of the ex falso quod libet (i.e. falsity elimination) Term.
The representation of the universal quantifier Type.
Definition: checker.h:95
eKind
Values to indicate different species of Kind elements.
Definition: checker.h:54
struct Mpi1 Mpi1
The representation of the first projection (i.e. conjunction elimination) Term.
struct Mlam Mlam
The representation of the lambda abstraction Term.
struct Mabs Mabs
The representation of the abstraction (i.e. existential quantifier elimination) Term.
struct Mvar Mvar
The representation of the proof term variable/axiom in Term.
The representation of the exists (i.e. existential quantifier introduction) Term. ...
Definition: checker.h:201
eAny
Values to indicate different species of data held in Any structures.
Definition: checker.h:324
The representation of the first injection (i.e. disjunction introduction) Term.
Definition: checker.h:246
struct Min1 Min1
The representation of the first injection (i.e. disjunction introduction) Term.
struct Kstar Kstar
The representation of the star Kind.
The representation of the application of Type to Term; it is one of the species of Type...
Definition: checker.h:104
The representation of the kinds in the typesystem.
Definition: checker.h:68
The representation of the application of a Term to a Term; it is one of the species of Term...
Definition: checker.h:185
struct Mcas Mcas
The representation of the case analysis (i.e. disjunction elimination) Term.
struct McasIn McasIn
The representation of the case subexpression.
The representation of the conjunction Type.
Definition: checker.h:119
struct Mtup Mtup
The representation of the tuple (i.e. conjunction introduction) Term.
The representation of the tuple (i.e. conjunction introduction) Term.
Definition: checker.h:223
The representation of the existential quantifier Type.
Definition: checker.h:111
The representation of the bottom/falsity Type.
Definition: checker.h:133
struct Kpi Kpi
The representation of the pi Kind.
The representation of the second injection (i.e. disjunction introduction) Term.
Definition: checker.h:254
struct Tor Tor
The representation of the disjunction Type.
struct Mwit Mwit
The representation of the exists (i.e. existential quantifier introduction) Term. ...
The representation of the case analysis (i.e. disjunction elimination) Term.
Definition: checker.h:269
struct Mapp Mapp
The representation of the application of a Term to a Term; it is one of the species of Term...
Implementation of procedures that handle printing of error messages.
The representation of the types in the typesystem.
Definition: checker.h:146
The representation of the first projection (i.e. conjunction elimination) Term.
Definition: checker.h:232
The representation of the type variable in Type.
Definition: checker.h:88
The representation of the proof term variable/axiom in Term.
Definition: checker.h:178
struct Texi Texi
The representation of the existential quantifier Type.
The representation of the ex falso quod libet (i.e. falsity elimination) Term.
Definition: checker.h:278
The representation of the disjunction Type.
Definition: checker.h:126
The representation of the star Kind.
Definition: checker.h:57
struct Tvar Tvar
The representation of the type variable in Type.
eType
Values to indicate different species of Type elements.
Definition: checker.h:84
The wrapper that makes it possible to store in envmap different species of elements that occur in typ...
Definition: checker.h:329
struct Min2 Min2
The representation of the second injection (i.e. disjunction introduction) Term.
The representation of the proof terms in the typesystem.
Definition: checker.h:298
struct Tapp Tapp
The representation of the application of Type to Term; it is one of the species of Type...
char * Name
The type to structurally represent identifier names.
Definition: checker.h:46
struct Tall Tall
The representation of the universal quantifier Type.
struct Mpi2 Mpi2
The representation of the second projection (i.e. conjunction elimination) Term.
The representation of the second projection (i.e. conjunction elimination) Term.
Definition: checker.h:239
The representation of the lambda abstraction Term.
Definition: checker.h:192
The structure to represent binders. (For future use.)
Definition: checker.h:315
struct Tand Tand
The representation of the conjunction Type.
eTerm
Values to indicate different species of Term elements.
Definition: checker.h:173