Polynomial long division: Difference between revisions

m
a bit more formatting of the header matter
m (tighten up some formatting)
m (a bit more formatting of the header matter)
Line 1:
{{task|Classic CS problems and programs}}{{Wikipedia}}
:<cite>In algebra, [[wp:Polynomial long division|polynomial long division]] is an algorithm for dividing a polynomial by another polynomial of the same or lower degree.</cite>
 
Let us suppose a polynomial is represented by a vector, <math>x</math> (i.e.g., seean ordered collection of [[wp:Coefficient|herecoefficients]]), thenso that the <math>i</math><sup>th</sup> element keeps the coefficient of <math>x^i</math>, and the multiplication by a monomial is a ''shift'' of the vector's elements "towards right" (injecting zeros from left) followed by a multiplication of each element by the coefficient of the monomial.
from left) followed by a multiplication of each element by the coefficient of the monomial.
 
Then a pseudocode for the polynomial long division could be:
Line 10 ⟶ 9:
'''return''' the index of the last non-zero element of '''P''';
if all elements are 0, return -∞
 
polynomial_long_division('''N''', '''D''') ''returns'' ('''q''', '''r'''):
<span class="co1">// '''N''', '''D''', '''q''', '''r''' are vectors</span>
Line 33 ⟶ 32:
 
* Error handling (for allocations or for wrong inputs) is not mandatory.
 
 
'''Example for clarification'''
<br>
 
This example is from Wikipedia, but changed to show how the given pseudocode works.
 
Anonymous user