Exemple #1
0
	polynomial operator -(const polynomial& p1, const polynomial& p2)
	{
		size_t j=p1.degree( );
		size_t q= p2.degree( );
		polynomial answer;

		if(j>=q)
		{
			answer.reserve(j+1);
			size_t i;
			for (i=0; i<=j; i++)
			{
				answer.add_to_coef((p1.coefficient(i)-p2.coefficient(i)),(i));
			}
		}
		else
		{
			answer.reserve(q+1);
			size_t i;
			for (i=0; i<=q; i++)
			{
				answer.add_to_coef((p1.coefficient(i)-p2.coefficient(i)),(i));
			}
		}
		return answer;
	}
Exemple #2
0
	polynomial operator *(const polynomial& p1, const polynomial& p2)
	{
		polynomial answer;
		size_t k=p1.degree( );
		size_t q=p2.degree( );
		answer.reserve((k+q)+2);
		
		size_t i;
		size_t j;

		for (i=0; i<=k; i++)
		  {
			  for (j=0; j<=q; j++)
				{

					answer.add_to_coef((p1.coefficient(i)*p2.coefficient(j)),(i+j));
					
				}
		}
		return answer;

	}
        int descartes_rule(const polynomial<data__> &f, bool positive)
        {
          // catch special case
          if (f.degree()==0)
            return 0;

          // get the coefficients from the polynomial
          std::vector<data__> a(f.degree()+1);
          for (size_t i=0; i<a.size(); ++i)
          {
            a[i]=f.coefficient(i);

            // change the sign of odd powers if want the negative root count
            if (!positive && i%2==1)
              a[i]*=-1;
          }

          return eli::mutil::poly::root::sign_changes(a.begin(), a.end());
        }