Macro Library poly3

Polynomial Division
Mike Jenck, Originally developed July 25-27, 2018
licensed under GPL version 2 or later
File Version : 6

formpoly3fromstring

function formpolyfromstring(variable, polynomialstring, [IsFraction=true])
Creates an array of coefficients whose position in the array corresponds to the power of the variable Each element is stored in the form of an array(numerator, denominator).

INPUTS:
variable: a string that contains the variable
polynomialstring: a string that contains the polynomial

Optional
IsFraction: a boolan that stores the the coeificients as fractions

Example: $dividend = formpolyfromstring("x","3x^4+2x^2+1")
$dividend = array("1,0,2,0,3")

formpoly3fromresults

Creates an array of coefficients whose position in the array corresponds to the power of the variable Each element is stored in the form of an array(numerator, denominator).

INPUTS:
$results: from dividepoly3 $results[*][1]

Optional
IsFraction: a boolan that stores the the coeificients as fractions

Example: $quotient = formpoly3fromstring($results[0][1])

writepoly3

writepoly3(poly3, [variable="x", IsFraction=true, HideZero=true])
Creates a string that represents the polynomial

Each element is stored in the form of an array(numerator, denominator).

INPUTS:
variable: a string that contains the variable
poly3: an array of coeficients to build the polynomial

Optional
IsFraction: a boolan that stores the the coeificients as fractions
HideZero: a boolean that stores a flag to show zero coefinents

Example: $dividend = writepoly3("x",array("1,0,2,0,3"))
$dividend = "3x^4+2x^2+1"

dividepoly3

dividepoly3(dividend, divisor [, IsFraction=true])
Does the polynomial long division and returns an array of results

INPUTS:
dividend: a poly3 formed dividend
divisor: a poly3 formed divisor

Optional
IsFraction: a boolan that stores the the coeificients as fractions

Example: $result = dividepoly3($dividend, $divisor);

$result will contain an array in the following form
$result[0][0] = $dividend
$result[0][1] = the power, array(numerator, denominator)
$result[0][2] = a poly3 polynomial by multipling $result[0][1] and the divisor
$result[0][3] = the poly3 polynomial that needs to be subtracted (-$result[0][2])
$result[1][0] = the resultant divided (at least 1 power smaller than the previous
etc.

longdivisionpoly3

longdivisionpoly3(dividend, divisor, variable="x", [displayASCIIticks=true, IsFraction=true, HideZero=true, ShowAsSubtraction=false])

Does the long division and returns a string of the results

INPUTS:
dividend: a poly3 formed dividend
divisor: a poly3 formed divisor
variable: a string that contains the variable

Optional
displayASCIIticks: a boolean flag to put tick marks around each monomial
IsFraction: a boolan that stores the the coeificients as fractions
HideZero: a boolean that stores a flag to show zero coefinents
ShowAsSubtraction : a boolean that when set to true show the subtraction

Example: $result = longdivisionpoly3($dividend, $divisor);
$result will contain a string of HTML table code that can be displayed in the answer.