21
3
Apply an indefinite integral to a given string. The only rules you will be using are defined as such:
∫cx^(n)dx = (c/(n+1))x^(n+1) + C, n ≠ -1 c, C, and n are all constants.
Specifications:
- You must be able to integrate polynomials with any of the possible features:
- A coefficient, possibly a fraction in the format
(numerator/denominator)
. - Recognition that e and π are constants, and in their use, be able to form fractions or expressions containing them (can be held in a fraction like
(e/denominator)
or(numerator/e)
, or, if in exponents,x^(e+1)
)- Aside of these two special constants, all coefficients will be rational, real numbers.
- An exponent, possibly a fraction, in the format
x^(exponent)
- Expressions with
e
orπ
in them, aside of themselves, will not be in exponents. (you will not have to integrate stuff likex^(e+1)
, but you might integratex^(e)
)
- Expressions with
- Can use non-x 1-char variables (i.e.
f
)- This is only for ASCII ranges 65-90 and 97-122.
- You do not have to use chain rule or integrate
x^(-1)
.
- A coefficient, possibly a fraction in the format
- Output must have padding (separation between terms, i.e.
x^2 + x + C
. - If it is unknown how to integrate with the above features, the program should print out
"Cannot integrate "+input
. - It must be a full program.
Bonuses:
- -10% if you print out the "pretty" exponents formatted for markdown (instead of
x^2
,x<sup>2</sup>
). - -10% if you print out the equation (i.e.
∫xdx = (1/2)x^2 + C
)
Examples:
Input:
x
Output:
(1/2)x^(2) + C
Input:
-f^(-2)
Output:
f^(-1) + C
Input:
(1/7)x^(1/7) + 5
Output:
(1/56)x^(8/7) + 5x + C
Input:
πx^e
Output:
(π/(e+1))x^(e+1) + C
Input:
(f+1)^(-1)
Output:
Cannot integrate (f+1)^(-1)
1Surprised we don't already have this question - but I couldn't find a dup. +1 – Digital Trauma – 2015-12-15T21:34:24.680
@DigitalTrauma There is this, though.
– Addison Crump – 2015-12-15T21:35:06.5273>
e
andπ
, the only values in coefficients will be rational numbers? I.e. it's not necessary to handle multivariable polynomials? 2. When you say "non-x 1-char variables", are you restricting toa-zA-Z
or do you intend to include other Unicode ranges?Dang, I was going to post this at some point. Oh well. – Arcturus – 2015-12-15T21:37:23.547
1Do you think there should be a bonus if someone's program prints
ln(x) + C
for an input ofx^(-1)
? – Arcturus – 2015-12-15T21:38:25.1971@Ampora No - that opens up a whole can of worms dealing with coefficients of ln. – Addison Crump – 2015-12-15T21:39:01.483
Do you really need to print a 27-char string
Cannot integrate polynomial
? – xnor – 2015-12-15T21:39:55.447@xnor
Cannot integrate
, and yes. – Addison Crump – 2015-12-15T21:40:30.670What would
πe
integrate as? Woulde
be considered asexp(1)
, or as a variable? If the former, would we assumex
to be the variable? – Tom Carpenter – 2015-12-20T03:21:28.813@TomCarpenter
πe
would integrate as a constant, so it would integrate to(πe)x
. I wouldn't make a coefficient this complicated, so you may assume that this will be an untested input. – Addison Crump – 2015-12-20T14:51:04.087How are we supposed to solve the halting problem? – FUZxxl – 2015-12-23T14:18:47.517
@FlagAsSpam I misread your question. For the general case, computing integrals involves solving the halting problem since e^(ax^2) is integrable if and only if
a
is always 0, but being able to show that is equal to the halting problem. – FUZxxl – 2015-12-23T14:46:04.787So it is necessary for it to only solve the polynomial integrals? Are built-ins allowed? – TanMath – 2015-12-25T21:47:53.377
@TanMath Yes and yes, but make sure you do output "Cannot integrate " for things that are more difficult than just power rule. – Addison Crump – 2015-12-26T00:45:12.133
a few questions for clarification:
x^(e+1)
is given as an example of how transcendentals may appear in an exponent, but also as an example of how they won't. -> !? Also, could there ever be multiple letter variables, if so how to choose which to integrate over? May we usepi
orp
forπ
? Lastly, is the output supposed to be concise, and if so how is that defined? f.x. is(1/7)x^(1/7)
to(1/8)x^(1/7+1) + C
ok? – Leif Willerts – 2016-02-02T13:12:31.2801@LeifWillerts 1) I meant that
x^(e+1)
will not be an integrand, but it may be the result of an integration. 2) There will not be multiple letter variables. 3) Yes. 4) Yes, but it should be(1/56)x^(1/7+1) + C
(I made a mistake in the examples). – Addison Crump – 2016-02-02T13:31:58.503Now that I can comment: I assumed that C is also not going to be an input variable but reserved for the integration constant. Otherwise, of course, this would need to be clarified and the code changed accordingly. – senegrom – 2016-02-06T17:24:33.190
@senegrom Yes, that's correct. c: Nice answer, btw. – Addison Crump – 2016-02-06T17:32:29.657