56 return tree(DEBRUIJN, body);
61 return isTree(t, DEBRUIJN, body);
67 return tree(DEBRUIJNREF,
tree(level));
74 if (
isTree(t, DEBRUIJNREF, u)) {
97 if (
isTree(t, SYMREC, var)) {
108 return tree(SYMREC,
id);
113 return isTree(t, SYMREC, v);
124 if (n == DEBRUIJNREF) {
132 }
else if (n == DEBRUIJN) {
134 return br[0]->fAperture - 1;
139 tvec::const_iterator b = br.begin();
140 tvec::const_iterator z = br.end();
142 if ((*b)->aperture() > rc) rc = (*b)->aperture();
156 static Tree _liftn(
Tree t,
int threshold);
160 fprintf(stderr,
"call of liftn(");
printSignal(t, stderr); fprintf(stderr,
", %d)\n", threshold);
161 Tree r = _liftn(t, threshold);
162 fprintf(stderr,
"return of liftn(");
printSignal(t, stderr); fprintf(stderr,
", %d) -> ", threshold);
191 }
else if (
isRef(t,n)) {
201 }
else if (
isRec(t,u)) {
209 for (
int i = 0; i < n; i++) {
245 }
else if (
isRef(t,var)) {
249 }
else if (
isRef(t,i)) {
251 fprintf(stderr,
"ERREUR, une reference de Bruijn touvee ! : ");
253 fprintf(stderr,
")\n");
263 for (
int i = 0; i < a; i++) {
293 if (
isRef(t,l))
return (l == level) ?
id : t;
299 for (
int i = 0; i < ar; i++) {
330 if (t->
aperture() == INT_MAX)
return;
333 for (
int i = 0; i < ar; i++) {
348 }
else if (
isRec(t, var, body)) {
359 for (
int i = 0; i<ar; i++) {
371 if (p == NULL)
return 0;
372 if (t == p->
fTree)
return 1;
376 if (t == p->
fTree)
return pos;
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
static void markOpen(Tree t)
Class Node = (type x (int + double + Sym + void*))
Tree rec(Tree body)
create a de Bruijn recursive tree
Tree deBruijn2Sym(Tree t)
static Tree liftn(Tree t, int threshold)
Tree ref(int level)
create a de Bruijn recursive reference
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
static int orderof(Tree t, Env *p)
void updateAperture(Tree t)
const Node & node() const
return the content of the tree
static Tree make(const Node &n, int ar, Tree br[])
return a new tree or an existing equivalent one
bool isClosed(Tree t)
t dont contain free de Bruijn ref
bool isRef(Tree t, int &level)
is t a de Bruijn recursive reference
static Tree calcliftn(Tree t, int threshold)
static Tree calcsubstitute(Tree t, int level, Tree id)
void setProperty(Tree key, Tree value)
int arity() const
return the number of branches (subtrees) of a tree
void printSignal(Tree sig, FILE *out, int prec=0)
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
static Tree calcDeBruijn2Sym(Tree t)
Symbols are unique objects with a name stored in a hash table.
static int calcTreeAperture(const Node &n, const tvec &br)
compute how open is a tree
bool isTree(const Tree &t, const Node &n)
static int recomputeAperture(Tree t, Env *p)
Symbol * symbol(const char *str)
Returns (and creates if new) the symbol of name str.
int aperture() const
return how "open" is a tree in terms of free variables
Tree getProperty(Tree key)
bool isInt(const Node &n)
Tree branch(int i) const
return the ith branch (subtree) of a tree
void setAperture(int a)
modify the aperture of a tree
static Tree substitute(Tree t, int n, Tree id)