example1.cc

This is an example showing the use of the ceta.hh. We create a theory and build three different automata using that theory, each extending the other. Then we perform boolean operations on the languages and test for emptiness.

00001 #include <iostream>
00002 #include <ceta/ceta.hh>
00003 
00004 using namespace ceta;
00005 using namespace std;
00006 
00007 int main(int argc, char **argv) {
00008   // Construct theory with constants a and b and AC symbol f.
00009   theory_t theory;
00010   kind_t k = *add_kind(theory, kind_t("k"));
00011   op_t a = *add_op(theory, make_constant("a", k));
00012   op_t b = *add_op(theory, make_constant("b", k));
00013   op_t f = *add_op(theory, make_binary_op("f", k, k, k));
00014   set_axioms(theory, f, assoc() | comm());
00015 
00016   // Construct automata with given theory with states qa and qb.
00017   ta_t ta_base(theory);
00018   state_t qa = *add_state(ta_base, state_t(k, "qa"));
00019   state_t qb = *add_state(ta_base, state_t(k, "qb"));
00020   // Add rules so that in ta_base, q -> qa and b -> qe.
00021   add_rule(ta_base, make_constant_rule(a, qa));
00022   add_rule(ta_base, make_constant_rule(b, qb));
00023 
00024   // Construct tree automaton that recognizes flattened terms where number of
00025   // occurences of a and b are equal.
00026   ta_t ta_eq = ta_base;
00027   // Declare and add state qe.
00028   state_t qe = *add_state(ta_eq, state_t(k, "qe"));
00029   set_predicate(ta_eq, qe);
00030   // Add rule: f(qa, qb) -> qe and f(qe, qe) -> qe
00031   add_rule(ta_eq, make_binary_rule(f, qa, qb, qe));
00032   add_rule(ta_eq, make_binary_rule(f, qe, qe, qe));
00033 
00034   // Construct tree automaton by extending ta_eq that recognizes flattened
00035   // terms where number of occurences of a are greater than number of
00036   // occurences of b.
00037   ta_t ta_gt = ta_eq;
00038   state_t qge = *add_state(ta_gt, state_t(k, "qge"));
00039   set_predicate(ta_gt, qge & !qe);
00040   // Add rules so qge accepts terms where number of occurences of a >= number
00041   // of occurences of b.
00042   add_erule(ta_gt, erule_t(qe, qge));
00043   add_rule(ta_gt, make_binary_rule(f, qa, qge, qge));
00044 
00045   // Verify that ta_eq & ta_gt is empty.
00046   test_result_t result = test_emptiness(ta_eq & ta_gt);
00047   if (!result)
00048     cerr << "ta_eq & ta_gt expected to be empty." << endl;
00049   // Verify that !ta_eq & ta_gt is not empty.
00050   result = test_emptiness(!ta_eq & ta_gt);
00051   if (result) {
00052     cerr << "!ta_eq & ta_gt expected to be not empty." << endl;
00053   } else {
00054     //Print counterexample and satisifying state set.
00055     cerr << "counterexample: " << counterexample(result)
00056          << " set: " << reachable_set(result)
00057          << endl; 
00058   }
00059 
00060 }

Generated on Fri Mar 3 14:38:58 2006 for libceta by  doxygen 1.4.6