Example of polynom read from user input.
- See also
- Multivariate polynomials
* $ ./examples/math/polynomial-read
* Type any multi-variate polynomial, then press return.
* Examples: xyz^3-4yz, (x+y+z)*(x-y-z)^2.
* (x-3)^2 + (y-2)^2 - 4
* Ok : ((9 + -4 X_1 + 1 X_1^2) + -6 X_0 + 1 X_0^2)
*
#include <iostream>
#include <iomanip>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/math/MPolynomial.h"
#include "DGtal/io/readers/MPolynomialReader.h"
{
typedef double Ring;
string str;
std::cout << "Type any multi-variate polynomial, then press return." << std::endl
<< "Examples: xyz^3-4yz, (x+y+z)*(x-y-z)^2." << std::endl;
do {
getline( cin, str );
if ( cin.good() && ( ! str.empty() ) )
{
std::string::const_iterator iter
= reader.
read( P, str.begin(), str.end() );
bool ok = iter == str.end();
if ( ! ok )
{
std::cerr << "ERROR: I read only <"
<< str.substr( 0, iter - str.begin() )
<< ">, and I built P=" << P << std::endl;
}
std::cout << (ok ? "Ok : " : "Err: ") << P << std::endl;
}
} while ( ! str.empty() );
return 0;
}
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Iterator read(Polynomial &p, Iterator begin, Iterator end)
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
DGtal is the top-level namespace which contains all DGtal functions and types.