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 "simulate_theorem_producer.h"
00034 #include "theory_simulate.h"
00035 #include <algorithm>
00036 
00037 using namespace std;
00038 using namespace CVCL;
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 // TheoryArith: trusted method for creating ArithTheoremProducer
00042 ////////////////////////////////////////////////////////////////////
00043 
00044 SimulateProofRules* TheorySimulate::createProofRules(VCL* vcl) {
00045   return new SimulateTheoremProducer(vcl);
00046 }
00047   
00048 ////////////////////////////////////////////////////////////////////
00049 // Proof rules
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   // Compute f(f(...f(f(s0, I1(0), I2(0), ...), I1(1), ...), ... ),
00073   //           I1(n-1), ...)
00074   //
00075   // We do this by accumulating the expression in 'res':
00076   // res_{i+1} = func(res_i, I1(i), ..., Ik(i))
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 }

Generated on Fri May 20 13:13:55 2005 for CVC Lite by  doxygen 1.3.9.1