00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #define _CVCL_TRUSTED_
00032
00033 #include <algorithm>
00034
00035 #include "simulate_theorem_producer.h"
00036 #include "theory_simulate.h"
00037 #include "theory_core.h"
00038
00039 using namespace std;
00040 using namespace CVCL;
00041
00042
00043
00044
00045
00046 SimulateProofRules* TheorySimulate::createProofRules() {
00047 return new SimulateTheoremProducer(theoryCore()->getTM());
00048 }
00049
00050
00051
00052
00053
00054 Theorem SimulateTheoremProducer::expandSimulate(const Expr& e) {
00055 const int arity = e.arity();
00056 if (CHECK_PROOFS) {
00057 CHECK_SOUND(e.getKind() == SIMULATE,
00058 "SimulateTheoremProducer::expandSimulate: "
00059 "expected SIMULATE expression: "
00060 +e.toString());
00061 CHECK_SOUND(arity >= 3 && e[arity - 1].isRational() &&
00062 e[arity - 1].getRational().isInteger(),
00063 "SimulateTheoremProducer::expandSimulate: "
00064 "incorrect children in SIMULATE: " + e.toString());
00065 }
00066
00067 int n = e[arity - 1].getRational().getInt();
00068
00069 if(CHECK_PROOFS) {
00070 CHECK_SOUND(n >= 0, "SimulateTheoremProducer::expandSimulate: "
00071 "Requested negative number of iterations: "+int2string(n));
00072 }
00073
00074
00075
00076
00077
00078
00079 Expr res(e[1]);
00080 for(int i=0; i<n; ++i) {
00081 vector<Expr> args;
00082 args.push_back(res);
00083 Expr ri(d_em->newRatExpr(i));
00084 for(int j=2; j<arity-1; ++j)
00085 args.push_back(Expr(e[j].mkOp(), ri));
00086 res = Expr(e[0].mkOp(), args);
00087 }
00088
00089 Assumptions a;
00090 Proof pf;
00091 if(withProof())
00092 pf = newPf("expand_simulate", e);
00093 return newRWTheorem(e, res, a, pf);
00094 }