DGtal 1.3.0
Loading...
Searching...
No Matches
math/polynomial-read.cpp
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"
using namespace std;
using namespace DGtal;
// Standard services - public :
int main( int /*argc*/, char** /*argv*/ )
{
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.
Definition: MPolynomial.h:955
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
int main()
Definition: testBits.cpp:56