simulate_theorem_producer.cpp

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  *\file simulate_theorem_producer.cpp
00004  *\brief Trusted implementation of the proof rules for symbolic simulator
00005  *
00006  * Author: Sergey Berezin
00007  *
00008  * Created: Tue Oct  7 10:55:24 2003
00009  *
00010  * <hr>
00011  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00012  * Junior University and by New York University. 
00013  *
00014  * License to use, copy, modify, sell and/or distribute this software
00015  * and its documentation for any purpose is hereby granted without
00016  * royalty, subject to the terms and conditions defined in the \ref
00017  * LICENSE file provided with this distribution.  In particular:
00018  *
00019  * - The above copyright notice and this permission notice must appear
00020  * in all copies of the software and related documentation.
00021  *
00022  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00023  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00024  * 
00025  * <hr>
00026  * 
00027  */
00028 /*****************************************************************************/
00029 
00030 // This code is trusted
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 // TheoryArith: trusted method for creating ArithTheoremProducer
00044 ////////////////////////////////////////////////////////////////////
00045 
00046 SimulateProofRules* TheorySimulate::createProofRules() {
00047   return new SimulateTheoremProducer(theoryCore()->getTM());
00048 }
00049   
00050 ////////////////////////////////////////////////////////////////////
00051 // Proof rules
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   // Compute f(f(...f(f(s0, I1(0), I2(0), ...), I1(1), ...), ... ),
00075   //           I1(n-1), ...)
00076   //
00077   // We do this by accumulating the expression in 'res':
00078   // res_{i+1} = func(res_i, I1(i), ..., Ik(i))
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 }

Generated on Thu Apr 13 16:57:33 2006 for CVC Lite by  doxygen 1.4.4