Skip to content

Instantly share code, notes, and snippets.

@standarddeviant
Created March 6, 2021 17:53
Show Gist options
  • Save standarddeviant/85325bce394f2fe3dc8bf663c18fae5f to your computer and use it in GitHub Desktop.
Save standarddeviant/85325bce394f2fe3dc8bf663c18fae5f to your computer and use it in GitHub Desktop.
Polynomial Long Division

Polynomial Division Pseudo-Code

The below steps assume that there's some polynomial type (could just be a length-N list) and support functions that are aware of that type.

Necessary support functions

  • order(p1) - returns the order of polynomial p1
  • highest(p1) - highest order coefficient of p1
  • add(p1, p2) - adds two polynomials
  • sub(p1, p2) - subtracts two polynomials
  • mult(p1, p2) - multiplies two polynomials
  • scale(p2, C) - multiplies a polynomial by a real constant, C

Long Division Steps

  1. Establish variables
    • numerator, n
    • denominator, d
    • quotient, q - i.e. the answer
    • remainder, r
  2. Get remainder: r = highest(n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment