Пример #1
0
void FormulaDerivatives::print(const OperationTree& otree) const
{
	for (Tfmiintmap::const_iterator it = ind2der.begin();
		 it != ind2der.end(); ++it) {
		printf("derivative ");
		(*it).first.print();
		printf(" is formula %d\n", tder[(*it).second]);
		otree.print_operation(tder[(*it).second]);
	}
}
Пример #2
0
void Constants::import_constants(const Constants& c, OperationTree& otree, Tintintmap& tmap)
{
	for (Tconstantmap::const_iterator it = c.cmap.begin();
		 it != c.cmap.end(); ++it) {
		int told = (*it).first;
		int tnew = otree.add_nulary();
		tmap.insert(Tintintmap::value_type(told, tnew));
		add_constant(tnew, (*it).second);
	}
}
Пример #3
0
void StaticAtoms::import_atoms(const DynamicAtoms& da, OperationTree& otree, Tintintmap& tmap)
{
	Constants::import_constants(da, otree, tmap);

	for (int i = 0; i < da.get_name_storage().num(); i++) {
		const char* name = da.get_name_storage().get_name(i);
		register_name(name);
		int tnew = otree.add_nulary();
		assign(name, tnew);
		try {
			const DynamicAtoms::Tlagmap& lmap = da.lagmap(name);
			for (DynamicAtoms::Tlagmap::const_iterator it = lmap.begin();
				 it != lmap.end(); ++it) {
				int told = (*it).second;
				tmap.insert(Tintintmap::value_type(told, tnew));
			}
		} catch (const ogu::Exception& e) {
		}
	}
}
Пример #4
0
/** This constructor makes a vector of indices for formulas
 * corresponding to derivatives of the given formula. The formula is
 * supposed to belong to the provided tree, the created derivatives
 * are added to the tree. 
 *
 * The algorithm is as follows. todo: update description of the
 * algorithm
*/
FormulaDerivatives::FormulaDerivatives(OperationTree& otree,
									   const vector<int>& vars, int f, int max_order)
	: nvar(vars.size()), order(max_order)
{
	FoldMultiIndex fmi_zero(nvar);
	tder.push_back(f);
	indices.push_back(fmi_zero);
	unsigned int last_order_beg = 0;
	unsigned int last_order_end = tder.size();

	for (int k = 1; k <= order; k++) {
		// interval <last_order_beg,last_order_end) is guaranteed
		// here to contain at least one item
		for (unsigned int run = last_order_beg; run < last_order_end; run++) {
			// shift one order from the run
			FoldMultiIndex fmi(indices[run], 1);
			// set starting variable from the run, note that if k=1,
			// the shift order ctor of fmi will set it to zero
			int ivar_start = fmi[k-1];
			for (int ivar = ivar_start; ivar < nvar; ivar++, fmi.increment()) {
				int der = otree.add_derivative(tder[run], vars[ivar]);
				if (der != OperationTree::zero) {
					tder.push_back(der);
					indices.push_back(fmi);
				}
			}
		}

		// set new last_order_beg and last_order_end
		last_order_beg = last_order_end;
		last_order_end = tder.size();
		// if there was no new derivative, break out from the loop
		if (last_order_beg >= last_order_end)
			break;
	}

	// build ind2der map
	for (unsigned int i = 0; i < indices.size(); i++)
		ind2der.insert(Tfmiintmap::value_type(indices[i], i));

}