# Vocabulary/pdot

 p. y Roots

Rank 1 -- operates on lists of y, producing a list for each one -- WHY IS THIS IMPORTANT?

Converts the polynomial y between coefficient and multiplier-and-roots form.

Example: The roots of 2y2 - 16y + 30 = 2(y-5)(y-3) = 0 are 5 and 3

```   c=: 30 _16 2       NB. coefficients (in ascending powers)
]z=: p. c          NB. coefficients as argument yield roots
+-+---+
|2|5 3|
+-+---+
p. z               NB. (multiplier and) roots as [boxed] argument yield coefficients
30 _16 2
```

The coefficient form of a polynomial is the list of coefficients of ascending powers of y representing the polynomial c0+c1y1+ ... +cnyn

30 _16 230 - 16y + 2y2

The multiplier-and-roots form of a polynomial is a two-atom boxed list  m;r representing the polynomial m(y-r0)(y-r1)...(y-rn)

2;5 32(y-5)(y-3)

### Common uses

1. Solve a polynomial equation whose right side is 0 (the solutions are the roots).

2. Convert a polynomial into its different forms.

1. y may also be in exponent form, which is a singleton box (either an atom or a 1-atom list) containing a table. Each row of the table is a 2-atom list c,n representing the term cyn (c is the coefficient, n the nonnegative integer exponent).

If y is in exponent form, p. y produces the corresponding coefficient form.

```   ]p =. <_2 ]\ _16 1 2 2 30 0  NB. three (c,n) pairs; order of powers doesn't matter
+-----+
|_16 1|
|  2 2|
| 30 0|
+-----+
p. p
30 _16 2
```

### Details

1. If y is a single boxed atom containing a list, it is assumed to be roots with an omitted multiplier of 1:

```   ]z=. < -: 1&(+,-) %:5      NB. roots [Phi,-phi]
+-----------------+
|1.61803 _0.618034|
+-----------------+
p. z
_1 _1 1
```

2. If in exponent form powers appear repeated, the last occurring (c,n) pair for that power is used:

```   ]p =. < _16 1 ,99 2 ,30 0 ,:2 2
+-----+
|_16 1|
| 99 2|
| 30 0|
|  2 2|
+-----+
p. p
30 _16 2
```

 x p. y Polynomial

Rank 1 0 -- operates on lists of x, and individual atoms of y -- WHY IS THIS IMPORTANT?

Evaluates polynomial x for given value(s) of y.

Argument x can be in coefficient, multiplier-and-roots, exponent, or multinomial form.

Remember, the powers of y in coefficient form are in ascending order.

Example: The roots of 2y2 - 16y + 30 = 2(y-5)(y-3) = 0 are 5 and 3

See above for conversion of this polynomial between forms

```   y=: i. 6
30 _16 2 p. y                 NB. coefficient form
30 16 6 0 _2 0
(2;5 3) p. y                  NB. m&r form
30 16 6 0 _2 0
(<_2 ]\ 2 2 _16 1 30 0) p. y  NB. exponent form
30 16 6 0 _2 0
```

### Common uses

1. The usual ways to evaluate a polynomial

```   c=: 15 _8 1             NB. coefficients for case: multiplier 1, roots 5 and 3
y=: i. 9                NB. range [0..8]

y,:(c p. y)             NB. the 'short' way
0 1 2 3  4 5 6 7  8
15 8 3 0 _1 0 3 8 15
+/"1 c *"1 y^/i.#c      NB. the 'long' way
15 8 3 0 _1 0 3 8 15
y #.("0 1) |. c         NB. the 'tricky' way, useful if the coefficients are in descending exponent order
15 8 3 0 _1 0 3 8 15
```

### Related Primitives

Base (x #. y)

1. Multinomial form is an extension of exponent form to multiple independent variables.

Argument x is a singleton box containing a table. Each row of the table is a list c,e0,e1... representing the term (cy,,0,,^e0^y,,1,,^e1^...) (c is the coefficient, e the exponents). The result is the sum of the terms.

When x is in multinomial form, y must be a boxed list of y,,0,,, y,,1,,, ... with one atom for each e-column of the table  >x .

```   ]multi =: <1 2 0,:2 0 2  NB. x^2 + 2y^2
+-----+
|1 2 0|
|2 0 2|
+-----+
]pts =: 0 0;1 0;0 1;1 1;3 0;4 4
+---+---+---+---+---+---+
|0 0|1 0|0 1|1 1|3 0|4 4|
+---+---+---+---+---+---+
multi p. pts             NB. Evaluate each point
0 1 2 3 9 48

]multi2 =: <1 2 1,:2 0 2  NB. (x^2)y + 2y^2
┌─────┐
│1 2 1│
│2 0 2│
└─────┘
multi2 p. 0 0;2 2;1 3;1 2;3 1;4 4
0 16 21 10 11 96
```

### Details

1. When x is in multinomial form, the result is (|:c) +/ .* e */ .(^~) >y. If  >y is an atom it is treated as a 1-atom list.

2. Boolean x and y are always promoted to floating-point. For an alternative, see x #. y.