1
\$\begingroup\$

Some languages do not have native ways of representing polynomials, others do. Many times a list of coefficients (in one or the other order) works well. In order to avoid explicitly specifying this over and over again in all challenge, I'd like add that to the tag info.

Please add your suggestions for default representations.

\$\endgroup\$
4
  • 4
    \$\begingroup\$ I'd avoid declaring a default format that needs to be looked up in the tag wiki or on meta. It should be clear from the challenge how I/O can be formatted. That said, having some guidance for the challenge author on what I/O formats to allow would certainly be helpful, much like the recent question on what outputs decision problems should allow. \$\endgroup\$ May 14 '17 at 17:09
  • \$\begingroup\$ I'm usually for defaults, but I think polynomials are something challenge authors should specify the format for. Our defaults are generally for common programmatic elements (inputs, strings, graphics) to be clarified and standardized across languages. But polynomials are something most languages don't have a existing concept for, so a default would really be making a definition from scratch. \$\endgroup\$
    – xnor
    May 14 '17 at 20:22
  • \$\begingroup\$ @xnor I disagree, many languages (certainly algebraic or numerical langauges) do have built in polynomial types or at least packages that support them. \$\endgroup\$
    – flawr
    May 14 '17 at 21:10
  • \$\begingroup\$ @MartinEnder I think there are just a few accepted ways to represent a polynomial anyway, and I think (similarly as in code-golf or string or popularity-contest or quine) to define a default would give us a base to avoid repeating the definition over and over again, as we also do not explicitly say that we use characters to measure code length by default. \$\endgroup\$
    – flawr
    May 14 '17 at 21:22
4
\$\begingroup\$

List of coefficients

A list of coefficients

  • in ascending order [a(0),a(1),a(2),...,a(n)] OR
  • in descending order [a(n),a(n-1),...,a(0)]

If the degree is known, it may be zero padded as

[a(0),...,a(n),0,...,0]

or

[0,...,0,a(n),...,a(0)]
\$\endgroup\$
2
  • \$\begingroup\$ And this 3*x^2*y+4*z; is it not a polynomial? \$\endgroup\$
    – user58988
    May 16 '17 at 5:19
  • \$\begingroup\$ Multivariable polynomials can be writen as polynomial in one variable with polynomials of the remaining variable as coefficients. \$\endgroup\$
    – flawr
    May 16 '17 at 18:24
2
\$\begingroup\$

Default representation in [language]

Many langauges, especially ones that include a CAS have native ways of representing polynomials.

\$\endgroup\$
-1
\$\begingroup\$

Beware function representations

Be careful about allowing a polynomial to be represented by a function that computes it, in languages where functions are objects. For example, in Python the polynomial 3*x^2+2 could be represented by the function object lambda x:3*x*x+2.

Take the challenge to compose polynomials. One could submit

Haskell, 3 bytes

(.)

where . is Haskell's function composition operator: if f and g are functions, then f.g is a function that takes x to f(g(x)). This would cut off the possibility for a much more interesting answer in the coefficient list representation.

Even a wordy language like Python could do better with

lambda f,g:lambda x:f(g(x))
\$\endgroup\$
2
  • \$\begingroup\$ I would also vote agains considering these functions as polynomials, because once they are defined, there is usually no way to retrieve the polynomial itself. \$\endgroup\$
    – flawr
    May 14 '17 at 21:13
  • \$\begingroup\$ Same goes for expressions representing the polynomial in languages with symbolic names, e.g. 3x^2+2 is a valid Mathematica expression that will remain unevaluated (unless it can be simplified). While not a function, it can be manipulated and evaluated quite easily. That said, most Mathematica answers would probably start by converting to this format first, so I'm not sure it's a bad thing to allow the expression right away. \$\endgroup\$ May 15 '17 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .