Shorten an already short mathematical expression
Emotinomicon, 48 bytes / 13 characters
I do it, not because it is short, but because it is fun. Try it here. You'll have to copy+paste it into the textbox.
⏪✖➕⏩
Explanation:
⏪ ✖ ➕ ⏩ explanation
take numeric input
⏪ open loop
duplicate top of stack
push pi
✖ multiply top two elements on stack
reverse stack
pop N, push e^N
➕ add top two elements on stack
take numeric input
duplicate top of stack
pop N, push N+1
⏩ close loop
Here is the program in its native environment, the mobile phone:
Dyalog APL, 3 characters
As a tacit phrase.
○+*
Monadic ○
multiplies its argument with π, monadic *
is the exponential function exp
. ○+*
is a train such that (○+*)ω
is equal to (○ω)+(*ω)
. Since this is APL, the phrase works for arguments of arbitrary shape, e. g. you can pass a vector of arbitrary length.
The same solution is possible in J as o.+^
with o.
being ○
and ^
being *
.
R, 25 24 bytes
cat(exp(x<-scan())+pi*x)
Is this it? It gets input from user, assign it to x
, calculates its exponential multiply it to pi
, and finally cat()
prints the result.
edit: 1 bytes saved thanks to Alex A.