A sample polynomial calculation

This is a demonstration of how a polynomial can be calculated from an arithmetic expression having a single distinguished variable. We use red to highlight the part of the term currently being translated as we work through the term. Throughout, we display polynomial terms in square brackets, but the left and right sides display the polynomial terms themselves differently. On the left, we set polynomial terms in green and display them in the usual mathematical style with x as the variable and the exponents written as superscripts; on the right, we set polynomial terms in blue and enclose them in square brackets, but display them as they are represented internally, namely as lists of integer coefficients.

((x + 2) · (3·x)) + (5 · (x + 4))

  =   ((x + 2) · (3·x)) + (5 · (x + [ 4 ] ))

  =   ((x + 2) · (3·x)) + (5 · ( [ x ] + [ 4 ] ))

  =   ((x + 2) · (3·x)) + (5 · [ x + 4 ] )

  =   ((x + 2) · (3·x)) + ( [ 5 ] · [ x + 4 ] )

  =   ((x + 2) · (3·x)) + [ 5x + 20 ]

  =   ((x + 2) · (3 · [ x ] )) + [ 5x + 20 ]

  =   ((x + 2) · ( [ 3 ] · [ x ] )) + [ 5x + 20 ]

  =   ((x + 2) · [ 3x ] ) + [ 5x + 20 ]

  =   ((x + [ 2 ] ) · [ 3x ] ) + [ 5x + 20 ]

  =   (( [ x ] + [ 2 ] ) · [ 3x ] ) + [ 5x + 20 ]

  =   ( [ x + 2 ] · [ 3x ] ) + [ 5x + 20 ]

  =  [ 3x2 + 6x ] + [ 5x + 20 ]

  =  [ 3x2 + 11x + 20 ]

((x + 2) · (3·x)) + (5 · (x + 4))

  =   ((x + 2) · (3·x)) + (5 · (x + [4] ))

  =   ((x + 2) · (3·x)) + (5 · ( [0,1] + [4] ))

  =   ((x + 2) · (3·x)) + (5 · [4,1] )

  =   ((x + 2) · (3·x)) + ( [5] · [4,1] )

  =   ((x + 2) · (3·x)) + [20,5]

  =   ((x + 2) · (3 · [0,1] )) + [20,5]

  =   ((x + 2) · ( [3] · [0,1] )) + [20,5]

  =   ((x + 2) · [0,3] ) + [20,5]

  =   ((x + [2] ) · [0,3] ) + [20,5]

  =   (( [0,1] + [2] ) · [0,3] ) + [20,5]

  =   ( [2,1] · [0,3] ) + [20,5]

  =  [0,6,3] + [20,5]

  =  [20,11,3]

Notes