Unicode polynomial equation: Difference between revisions
(Normalise a polynomial: e.g. x⁵ - 2x⁴ + 42x³ + 40x + 1) |
m (misc tidy of desc) |
||
Line 1: | Line 1: | ||
{{Template:Draft task}}<!--{{Wikipedia|Polynomial}}--> |
{{Template:Draft task}}<!--{{Wikipedia|Polynomial}}--> |
||
The objective of this task is to parse in a difficult polynomial, and generate a "pretty" representation of polynomial in Unicode. |
The objective of this task is to parse in a difficult [[wp:polynomial|polynomial]], and generate a "pretty" representation of the polynomial in Unicode. |
||
In the target language define a " |
In the target language define a "polynomial" object (or structure or record). Using this object also define the routines for parsing a polynomial as input, and generating a normalised [[wp:Unicode|Unicode]] representation of the polynomial as output. |
||
'''Task details:''' |
'''Task details:''' |
||
Line 24: | Line 24: | ||
|"One" coefficients are normalised||1x⁵ - 2x⁴ + 42x³ + 40x + 1x⁰ |
|"One" coefficients are normalised||1x⁵ - 2x⁴ + 42x³ + 40x + 1x⁰ |
||
|- |
|- |
||
|Signs are normalised||+x⁺⁵ + -2x⁻⁻⁴ + 42x⁺⁺³ + 40x - -1 |
|Signs are normalised||+x⁺⁵ + -2x⁻⁻⁴ + 42x⁺⁺³ + +40x - -1 |
||
|- |
|- |
||
|ASCII representations are parsed||x^5 - 2x**4 + 42x^3 + 40x + 1 |
|ASCII representations are parsed||x^5 - 2x**4 + 42x^3 + 40x + 1 |
||
|- |
|- |
||
|Non-ASCII representations are parsed|| |
|Non-ASCII representations are parsed||x↑5 - 2.00·x⁴ + 42.00·x³ + 40·00·x + 1 (c.f. [[wp:Knuth's up-arrow notation|↑]] & [[wp:·#In_mathematics_and_science|·]]) |
||
|- |
|- |
||
|Terms with negative exponents are parsed and stored||x⁻⁵ - 2⁄x⁻⁴ + 42x⁻³ + 40/x + 1 (n.b. [[wp:Unicode_numerals#Fractions|Unicode Fraction]]) |
|Terms with negative exponents are parsed and stored||x⁻⁵ - 2⁄x⁻⁴ + 42x⁻³ + 40/x + 1 (n.b. [[wp:Unicode_numerals#Fractions|Unicode Fraction]]) |
||
Line 36: | Line 36: | ||
|Single commas are ignored in numbers||x⁵ - 2x⁴ + 0,042x³ + 40.000,000x + 1 |
|Single commas are ignored in numbers||x⁵ - 2x⁴ + 0,042x³ + 40.000,000x + 1 |
||
|- |
|- |
||
|A coefficient may be duplicated, zero, |
|A coefficient may be duplicated, zero, or missing||0x⁸ + 10x + 10x + x⁵ - 2x⁴ + 42x³ + 20x + 1 |
||
|- |
|- |
||
|Support Scientific notation |
|Support Scientific notation and optionall<BR>support [http://unicode.org/charts/PDF/U2300.pdf Unicode Decimal Exponent Symbol] [http://mailcom.com/unicode/DecimalExponent.ttf U+23E8/⏨] |
||
||1E0x⁵ - 2e0x⁴ + 4.2⏨1x³ + .40e-2x + 1 |
||1E0x⁵ - 2e0x⁴ + 4.2⏨1x³ + .40e-2x + 1 |
||
|- |
|- |
||
|Support the set minimum of Unicode characters as follows: ||⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁻ ⁺ · × ⁄ .<br> |
|Support the set minimum of Unicode characters as follows: ||⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁻ ⁺ · × ⁄ .<br>Where · & × are multiplication, and ⁄ is Unicode Fraction. |
||
|- |
|- |
||
|Optionally support [[wp:Number Forms|Unicode Vulgar fractions]] |
|Optionally support [[wp:Number Forms|Unicode Vulgar fractions]] for both input and output.<BR>¼ ½ ¾ ⅐ ⅑ ⅒ ⅓ ⅔ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ ↉ || x⁵ - ½x⁴ + 101¼x³ + 100¾x + 2½<BR>On output round decimal the to appropriate fraction. |
||
|} |
|} |
||
There are (at least) three possible ways of achieving this task. |
There are (at least) three possible ways of achieving this task. |
||
Line 49: | Line 49: | ||
* Using a built-in parsing/formatting library. |
* Using a built-in parsing/formatting library. |
||
* Coding a custom polynomial parsing routing. |
* Coding a custom polynomial parsing routing. |
||
Either one, or all of these approaches are |
Either one, or all of these approaches are accepted and appear as a subtitle. |
||
[[Category:Mathematics]] |
[[Category:Mathematics]] |
Revision as of 03:02, 17 November 2011
The objective of this task is to parse in a difficult polynomial, and generate a "pretty" representation of the polynomial in Unicode.
In the target language define a "polynomial" object (or structure or record). Using this object also define the routines for parsing a polynomial as input, and generating a normalised Unicode representation of the polynomial as output.
Task details:
Given a string containing any untidy Unicode polynomial, e.g.
-0.00x⁺¹⁰ + 1.0·x ** 5 + -2e0x^4 + +0,042.00 × x ⁺³ + +.0x² + 20.000 000 000x¹ - -1x⁺⁰ + .0x⁻¹ + 20.x¹
Coerce (or convert) the string into the "polynomial" object, at the same time normalise the polynomial to a canonical form. The ideal normalised output (in this example) would be:
x⁵ - 2x⁴ + 42x³ + 40x + 1
Description | Input Example |
---|---|
"Zero" coefficients are removed | x⁵ - 2x⁴ + 42x³ + 0x² + 40x + 1 |
"One" coefficients are normalised | 1x⁵ - 2x⁴ + 42x³ + 40x + 1x⁰ |
Signs are normalised | +x⁺⁵ + -2x⁻⁻⁴ + 42x⁺⁺³ + +40x - -1 |
ASCII representations are parsed | x^5 - 2x**4 + 42x^3 + 40x + 1 |
Non-ASCII representations are parsed | x↑5 - 2.00·x⁴ + 42.00·x³ + 40·00·x + 1 (c.f. ↑ & ·) |
Terms with negative exponents are parsed and stored | x⁻⁵ - 2⁄x⁻⁴ + 42x⁻³ + 40/x + 1 (n.b. Unicode Fraction) |
Spaces in numbers and between operators are ignored | x⁵ - 2x⁴ + 42.000 000x³ + 40x + 1 |
Single commas are ignored in numbers | x⁵ - 2x⁴ + 0,042x³ + 40.000,000x + 1 |
A coefficient may be duplicated, zero, or missing | 0x⁸ + 10x + 10x + x⁵ - 2x⁴ + 42x³ + 20x + 1 |
Support Scientific notation and optionall support Unicode Decimal Exponent Symbol U+23E8/⏨ |
1E0x⁵ - 2e0x⁴ + 4.2⏨1x³ + .40e-2x + 1 |
Support the set minimum of Unicode characters as follows: | ⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹ ⁻ ⁺ · × ⁄ . Where · & × are multiplication, and ⁄ is Unicode Fraction. |
Optionally support Unicode Vulgar fractions for both input and output. ¼ ½ ¾ ⅐ ⅑ ⅒ ⅓ ⅔ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ ↉ |
x⁵ - ½x⁴ + 101¼x³ + 100¾x + 2½ On output round decimal the to appropriate fraction. |
There are (at least) three possible ways of achieving this task.
- Using an external parsing library.
- Using a built-in parsing/formatting library.
- Coding a custom polynomial parsing routing.
Either one, or all of these approaches are accepted and appear as a subtitle.