b_rewrite_rule(mandatory,['S'],['tt'],[additional_rhs_infos([prob_annotation('SYMBOLIC')])],
'tree(S) = {tr|[]:dom(tr) & !(tt).(tt : dom(tr) => tt : seq(NATURAL1) & (tt /= [] => front(tt) : dom(tr) & (last(tt) > 1 => front(tt) <- last(tt) - 1 : dom(tr)))) & ran(tr) <: S}').
b_rewrite_rule(mandatory,['S'],['tt'],[additional_rhs_infos([prob_annotation('SYMBOLIC')])],
'btree(S) = {tr|[]:dom(tr) & !(tt).(tt : dom(tr) => tt : seq(NATURAL1) & (tt /= [] => (front(tt) : dom(tr) & last(tt) : 1..2 & front(tt) <- (3-last(tt)) : dom(tr)))) & ran(tr) <: S}').
b_rewrite_rule(mandatory,['S'],[],[],
'top(S) = S([])').
b_rewrite_rule(mandatory,['T','N'],[],[],
'N:dom(T) => rank(T,N) = last(N)'). % should we check T:tree(_) ?
b_rewrite_rule(mandatory,['T','N'],[],[],
'N:dom(T) => father(T,N) = front(N)'). % should we check T:tree(_) ?
b_rewrite_rule(mandatory,['T','N','I'],[],[],
'(N:dom(T) & N <- I:dom(T)) => son(T,N,I) = N <- I'). % should we check T:tree(_) ?
b_rewrite_rule(mandatory,['X','Q'],[const_i,p,a,pi],[],
'const(X,Q) = { [] |-> X} \\/ UNION(const_i).(const_i:dom(Q)| dom({pi,a,p| (p,a):Q(const_i) & pi=const_i->p}))').
b_rewrite_rule(mandatory,['T'],[son_x],[],
'[] : dom(T) => sons(T) = dom({son_x,r,si|si:dom(T) & si/=[] & son_x=first(si) & r= {p,a|(son_x->p,a):T}})').
b_rewrite_rule(mandatory,['X'],[],[],'bin(X) = const(X,[])').
b_rewrite_rule(mandatory,['X','L','R'],[],[],'bin(L,X,R) = const(X,[L,R])').
b_rewrite_rule(mandatory,['X'],[],[],'left(X) = first(sons(X))').
b_rewrite_rule(mandatory,['X'],[],[],'right(X) = last(sons(X))').
b_rewrite_rule(mandatory,['T','N'],[],[],'subtree(T,N) = (%u.(u:(INTEGER<->INTEGER)|N^u) ; T)').
b_rewrite_rule(mandatory,['T','N'],[],[],'arity(T,N) = size(sons(subtree(T,N)))').
b_rewrite_rule(mandatory,['T'],[],[],'[]:dom(T) => sizet(T) = card(T)'). % TO DO: either recursive definition or better WD check
b_rewrite_rule(mandatory,['T'],['st','sn'],[],'prefix(T) = closure1(/*@ symbolic */ %(st,sn).(sn:(INTEGER<->ran(T)) & st /= [] & st:(INTEGER<->POW((INTEGER<->INTEGER)*ran(T))) | ((sons(first(st))^tail(st)) , sn <- top(first(st)) )))[{([T],[])}]([])'). % we could remove ran(T) typing
b_rewrite_rule(mandatory,['T'],['st','sn'],[],'postfix(T) = rev(closure1(/*@ symbolic */ %(st,sn).(sn:(INTEGER<->ran(T)) & st /= [] & st:(INTEGER<->POW((INTEGER<->INTEGER)*ran(T))) | ((rev(sons(first(st)))^tail(st)) , sn <- top(first(st)) )))[{([T],[])}]([]))'). % we could remove ran(T) typing
b_rewrite_rule(mandatory,['r'],[fnc_x],[],
'fnc(r) = %(fnc_x).(fnc_x:dom(r)|r[{fnc_x}])'). % TO DO introduce LET for r if complex ?
b_rewrite_rule(mandatory,['r'],[rel_x,rel_y],[],
'rel(r) = {rel_x,rel_y| rel_x:dom(r) & rel_y: union(r[{rel_x}])}').
b_rewrite_rule(optimize,['S'],[], [], '[] ^ S = S'). % TO DO: add SIDE CONDITION
b_rewrite_rule(optimize,['S'],[], [], 'S ^ [] = S'). % TO DO: add SIDE CONDITION
b_rewrite_rule(optimize,['X','D','R'],[xtf], [], 'D-->{R} = {%xtf.(xtf:D|R)}').
b_rewrite_rule(normalize,['X'],[pow_x],[],'POW(X) = {pow_x|pow_x<:X}').
b_rewrite_rule(normalize,['X'],[pow1_x],[],'POW1(X) = {pow1_x|pow1_x /= {} & pow1_x<:X}').
b_rewrite_rule(normalize,[],[],[],'NAT = 0..MAXINT').
b_rewrite_rule(normalize,[],[],[],'NAT1 = 1..MAXINT').
b_rewrite_rule(normalize,[],[],[],'INT = MININT..MAXINT').
b_rewrite_rule(normalize,[],[nat],[],'NATURAL = {nat|nat>=0}').
b_rewrite_rule(normalize,[],[nat1],[],'NATURAL1 = {nat1|nat1>=1}').
b_rewrite_rule(normalize,[],[id_x],[],'id(S) = %id_x.(id_x:S|id_x)').