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 "simulate_theorem_producer.h"
00034 #include "theory_simulate.h"
00035 #include <algorithm>
00036
00037 using namespace std;
00038 using namespace CVCL;
00039
00040
00041
00042
00043
00044 SimulateProofRules* TheorySimulate::createProofRules(VCL* vcl) {
00045 return new SimulateTheoremProducer(vcl);
00046 }
00047
00048
00049
00050
00051
00052 Theorem SimulateTheoremProducer::expandSimulate(const Expr& e) {
00053 const int arity = e.arity();
00054 if (CHECK_PROOFS) {
00055 CHECK_SOUND(e.getKind() == SIMULATE,
00056 "SimulateTheoremProducer::expandSimulate: "
00057 "expected SIMULATE expression: "
00058 +e.toString());
00059 CHECK_SOUND(arity >= 3 && e[arity - 1].isRational() &&
00060 e[arity - 1].getRational().isInteger(),
00061 "SimulateTheoremProducer::expandSimulate: "
00062 "incorrect children in SIMULATE: " + e.toString());
00063 }
00064
00065 int n = e[arity - 1].getRational().getInt();
00066
00067 if(CHECK_PROOFS) {
00068 CHECK_SOUND(n >= 0, "SimulateTheoremProducer::expandSimulate: "
00069 "Requested negative number of iterations: "+int2string(n));
00070 }
00071
00072
00073
00074
00075
00076
00077 Expr res(e[1]);
00078 for(int i=0; i<n; ++i) {
00079 vector<Expr> args;
00080 args.push_back(res);
00081 Expr ri(newRatExpr(d_em, i));
00082 for(int j=2; j<arity-1; ++j)
00083 args.push_back(newApplyExpr(e[j], ri));
00084 res = newApplyExpr(e[0], args);
00085 }
00086
00087 Assumptions a;
00088 Proof pf;
00089 if(withProof())
00090 pf = newPf("expand_simulate", e);
00091 return newRWTheorem(e, res, a, pf);
00092 }