Polynomials/Numbers: Difference between revisions
From charlesreid1
(Created page with "All of the real numbers of a given radix can also be expressed as a polynomial, where the variable is the radix. For example, in base 10, we can split a number up into its on...") |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
==Polynomial Representation of Numbers== | |||
All of the real numbers of a given radix can also be expressed as a polynomial, where the variable is the radix. | All of the real numbers of a given radix can also be expressed as a polynomial, where the variable is the radix. | ||
| Line 11: | Line 13: | ||
<math> | <math> | ||
n = 125 = 1 \times 10^2 + 2 \times 10^1 + 5 \times 10^0 | n = 125 = 1 \times 10^2 + 2 \times 10^1 + 5 \times 10^0 | ||
</math> | |||
and if we replace the 10 with an x, we get a polynomial: | |||
<math> | |||
n = 125 = x^2 + 2 x + 5 | |||
</math> | </math> | ||
| Line 50: | Line 58: | ||
11 \times 16^3 + 14 \times 16^2 + 14 \times 16^1 + 15 \times 16^0 = 48,879 | 11 \times 16^3 + 14 \times 16^2 + 14 \times 16^1 + 15 \times 16^0 = 48,879 | ||
</math> | </math> | ||
==Python for Radix Conversions== | |||
Note that the radix conversions above (some non-decimal base into decimal base) are straightforward to do with Python - when you create an integer object, you can pass a string containing the number, then pass a second argument that specifies the radix: | |||
<pre> | |||
$ python | |||
>>> int('101010',2) | |||
42 | |||
>>> int('BEEF',16) | |||
48879 | |||
>>> int('DEADBEEF',16) | |||
3735928559 | |||
</pre> | |||
==Flags== | |||
{{PolynomialsFlag}} | |||
Latest revision as of 21:52, 9 April 2017
Polynomial Representation of Numbers
All of the real numbers of a given radix can also be expressed as a polynomial, where the variable is the radix.
For example, in base 10, we can split a number up into its ones, tens, hundreds, and so on. Suppose we have a number n,
$ n = 125 = 1 \times 100 + 2 \times 10 + 5 \times 1 $
This is equivalent to a polynomial representation in terms of the radix (10):
$ n = 125 = 1 \times 10^2 + 2 \times 10^1 + 5 \times 10^0 $
and if we replace the 10 with an x, we get a polynomial:
$ n = 125 = x^2 + 2 x + 5 $
This generalizes to larger numbers:
$ n = 3,654,987 = 3 \times 10^6 + 6 \times 10^5 + 5 \times 10^4 + 4 \times 10^3 + 9 \times 10^2 + 8 \times 10^1 + 7 \times 10^0 $
That's just a polynomial with as many terms as digits, and the unknown $ x $ replacing the base:
$ n = 3 x^6 + 6 x^5 + 5 x^4 + 4 x^3 + 9 x^2 + 8 x + 7 $
It also generalizes to binary numbers or hex numbers:
$ n_{2} = 101010 = 1 \times 2^5 + 1 \times 2^3 + 1 \times 2^1 = 42 $
This number becomes the polynomial:
$ n_{2} = x^5 + x^3 + x $
(where, for binary numbers, the set of possible coefficients is just the set $ {0,1} $.)
Here is a hex number, converted to the equivalent polynomial:
$ n_{16} = BEEF = B \times 16^3 + E \times 16^2 + E \times 16^1 + F \times 16^0 $
Replacing the letters with their decimal equivalents, we get the base 10 equivalent number:
$ 11 \times 16^3 + 14 \times 16^2 + 14 \times 16^1 + 15 \times 16^0 = 48,879 $
Python for Radix Conversions
Note that the radix conversions above (some non-decimal base into decimal base) are straightforward to do with Python - when you create an integer object, you can pass a string containing the number, then pass a second argument that specifies the radix:
$ python
>>> int('101010',2)
42
>>> int('BEEF',16)
48879
>>> int('DEADBEEF',16)
3735928559
Flags
| polynomials useful mathematical objects, common enough for everyone, complex enough to keep you busy
Polynomials/Numbers - polynomial representations of numbers
Polynomials/Java - implementing a Polynomial class in Java Polynomials/Inheritance - using polynomials to illustrate inheritance (Java) Polynomials/Interface - using polynomials to illustrate interfaces (Java and Go)
Polynomials/Test Driven Development - how to write tests, explained using polynomials Polynomials/Timing - how to time code to measure performance
|