1 /* $Id: pres_rear.c,v 1.2 2006/05/04 08:59:31 boulet Exp $ */
3 #include <omega/pres_tree.h>
4 #include <omega/pres_conj.h>
5 #include <omega/Relation.h>
6 #include <omega/omega_i.h>
8 /////////////////////////
10 // Rearrange functions //
12 /////////////////////////
16 // ~ (f1 | f2 | ... | fn) = ~f1 & ~f2 & ... & fn
18 // Forall v: f = ~ (Exists v: ~ f)
19 // Exists v: (f1 | ... | fn) = (Exists v: f1) | ... | (Exists v: fn)
22 void Rel_Body::rearrange() {
23 assert(children().length()==1);
25 skip_finalization_check
++;
26 formula()->rearrange();
27 skip_finalization_check
--;
30 fprintf(DebugFile
, "\n=== Rearranged TREE ===\n");
31 prefix_print(DebugFile
);
35 void Formula::rearrange()
37 // copy list of children, as they may be removed as we work
38 List
<Formula
*> kiddies
= myChildren
;
40 for(List_Iterator
<Formula
*> c(kiddies
); c
; c
++)
45 // Push nots down the tree until quantifier or conjunct, rearrange kids
47 void F_Not::rearrange() {
48 Formula
*child
= children().front();
49 Formula
*new_child
, *f
;
51 switch(child
->node_type()) {
53 parent().remove_child(this);
54 new_child
= parent().add_and();
55 while(!child
->children().empty()) {
56 f
= child
->children().remove_front();
57 F_Not
*new_not
= new_child
->add_not();
58 new_not
->add_child(f
);
63 // parent().remove_child(this);
64 // new_child = parent().add_or();
65 // while(!child->myChildren.empty()) {
66 // f = child->myChildren.remove_front();
67 // F_Not *new_not = new_child->add_not();
68 // new_not->add_child(f);
73 parent().remove_child(this);
74 f
= child
->children().remove_front();
75 parent().add_child(f
);
84 new_child
->rearrange();
88 // Convert a universal quantifier to "not exists not".
89 // Forall v: f = ~ (Exists v: ~ f)
91 void F_Forall::rearrange() {
92 Formula
&p
= parent();
95 F_Not
*topnot
= p
.add_not();
96 F_Exists
*exist
= topnot
->add_exists();
97 for (Variable_ID_Iterator
VI(myLocals
); VI
; VI
++)
98 (*VI
)->set_kind(Exists_Var
);
99 exist
->myLocals
.join(myLocals
);
101 F_Not
*botnot
= exist
->add_not();
102 Formula
*f
= children().remove_front();
103 botnot
->add_child(f
);
111 // Exists v: (f1 | ... | fn) = (Exists v: f1) | ... | (Exists v: fn)
113 void F_Exists::rearrange() {
114 Formula
* child
= children().front();
115 switch(child
->node_type()) {
119 child
->push_exists(myLocals
);
120 parent().remove_child(this);
121 parent().add_child(child
);
122 children().remove_front();