1 #include <AD/pretty/postream.h>
5 ///////////////////////////////////////////////////////////////////////////////
7 // Constructor and destructor for projection recognition
9 ///////////////////////////////////////////////////////////////////////////////
10 Projection::Projection() {}
11 Projection::~Projection() {}
13 ///////////////////////////////////////////////////////////////////////////////
15 // Method to invoke projection recognition
17 ///////////////////////////////////////////////////////////////////////////////
18 Exp Projection::projection_recognition(Exp e)
19 { message("Projection recognition phase", e); (*this)(e); return e;
22 ///////////////////////////////////////////////////////////////////////////////
24 // Method to create a projection
26 ///////////////////////////////////////////////////////////////////////////////
27 Exp Projection::make_projection
28 (const IdSet& Invisible, Ids xs, Exps As, Exp P, Exp exp)
29 { Ids visible_xs = #[];
30 Exps visible_As = #[];
31 match while (xs) and (As) of
32 #[a ... b], #[c ... d]:
33 { if (Invisible.contains(a))
34 { P = EXISTS(a,c,P); }
36 { visible_xs = #[a ... visible_xs];
37 visible_As = #[c ... visible_As];
43 Exp body = P == True ? exp : GUARD(P,exp);
44 return GENERATOR(rev(visible_xs),rev(visible_As),body);
47 ///////////////////////////////////////////////////////////////////////////////
49 // Transformation to recongize projections and transform them into
50 // existential queries. Assume the set comprehensions are in flatten form.
52 ///////////////////////////////////////////////////////////////////////////////
56 // Locate all set comprehension quantifiers.
58 // { es : xs in As | p } where FV(xs) - FV(es) > 0
60 GENERATOR(xs,As,GUARD(p,e)) | length(xs) == length(As):
66 if (S1.size() > 0) rewrite(make_projection(S1,xs,As,p,e));
68 | GENERATOR(xs,As,e) | length(xs) == length(As):
74 if (S1.size() > 0) rewrite(make_projection(S1,xs,As,True,e));