67
votes
26
votes
23
votes
Accepted
Find the rate of change at a point on a polynomial
Mathematica, 6 bytes
#'@#2&
(Beat THAT, MATL and 05AB1E)
The first argument must be a polynomial, with # as its variable ...
14
votes
Pi == 3.2
Python + scipy, 92 bytes
from scipy.integrate import*
lambda p:2/p*quad(lambda x:(x/x**p+(1-x)**(1-p))**(1/p),0,1)[0]
Formula is from this math.SE question.
13
votes
13
votes
The Lehmer-Comtet sequence
Haskell, 77 75 bytes, no differentiation builtins
x@(a:b)&y@(c:d)=a*c:zipWith(+)(b&y)(x&d)
s=1:s&(1:scanl(*)1[-1,-2..])
(s!!)
Try it online!
How ...
12
votes
Derivative of a product
Python, 54 bytes
lambda s:((l:=len(s))*(l*"'"+-~l*(s+"+")))[-~l*~l::-l]
Attempt This Online!
Python, 56 bytes
lambda s:((l:=-~len(s))*(l*(s+"+")+-~l*"'")...
11
votes
Pi == 3.2
MATL, 31 bytes
0:1e-3:1lyG^-lG/^v!d|G^!slG/^sE
Try it online! Or verify all test cases.
Explanation
This generates the x,y coordinates of one quarter of the ...
11
votes
Compute Dickman
Python, 141 bytes
g=lambda x,p=[1]+[0]*99,I=2,z=0,i=0:x<1and sum(a*(1-x)**~-(i:=i+1)for a in p)or g(x-1,[p[0]-sum(A:=[(z:=(z+w)/I)/(i:=i+1)for w in p])]+A,I+1)
...
10
votes
Write a Sine-Deriving Machine
Python, 42 bytes
from math import*
lambda x,n:sin(x+pi/2*n)
Uses the fact that differentiating shifts the function by pi/2 ...
10
votes
Pi == 3.2
Wolfram Language (Mathematica), 49 46 45 bytes
3 bytes saved thanks to alephalpha.
1 byte saved thanks to att.
\!\(2N@∫\_0\%1\@+++(a^-#-1)^(1-#)\%#a\)&
Try it ...
10
votes
The Pedant's Cosine
Mathematica, 49 41 39 31 bytes
Sum[(-#^2)^k/(2k)!,{k,0,#2-1}]&
Old, more "fun" version: (39 bytes)
...
10
votes
The Pedant's Cosine
MATL, 14 bytes
U_iqE:2ep/YpsQ
Try it online! Or verify all test cases.
Explanation with example
All numbers have double precision (this is the default).
Consider ...
10
votes
Approximate definite integrals using Riemann sums
R, 69 65 63 57 bytes
function(a,b,n,k,f,w=(b-a)/n)sum(sapply(a+w*(1:n-k),f))*w
Try it online!
Takes k=FALSE for right-hand ...
10
votes
Derivative of a product
C (clang), 69 64 59 bytes
-10 thanks to @Noodle9 and @ceilingcat
l;f(char*a){for(l=0;a[l];)printf("+%.*s'%s"+!l,++l,a,a+l);}
Try it online!
9
votes
9
votes
Accepted
Definite integral of polynomial functions
Jelly, \$\frac {30} 7 = 4.29\$
÷J$ŻUḅI
Try it online!
Takes the polynomial as a list of coefficients in little-endian format (i.e. the example is ...
8
votes
Find the rate of change at a point on a polynomial
MATL, 8 6 bytes
yq^**s
Input is: array of exponents, number, array of coefficients.
Try it online! Or verify all test cases: 1, 2 3, 4, 5.
Explanation
Consider ...
8
votes
The Pedant's Cosine
Jelly, 22 bytes
-*ð×ø⁹*⁸²ð÷ø⁸Ḥ!
⁸R’Ç€S
This is a full program which takes n as the first argument and x as the second.
Explanation:
...
8
votes
Solve a separable differential equation
Python 2, 123 122 bytes
def f(p,P):R=[[[a/-~b,b+1]for a,b in F]for F in P];a,b=map(lambda F,x:sum(a*x**b for a,b in F),R,p);R[1]+=[a-b,0],;print R
Try it online!
...
8
votes
8
votes
Derivative of a product
Python, 47 bytes
lambda s:"+".join(s.replace(c,c+"'")for c in s)
Attempt This Online!
How it works:
...
7
votes
Find the rate of change at a point on a polynomial
Julia, 45 42 40 37 bytes
f(p,x)=sum(i->prod(i)x^abs(i[2]-1),p)
This is a function that acceps a vector of tuples and a number and returns a number. The ...
7
votes
The Pedant's Cosine
Python, 54 bytes
f=lambda x,n,t=1,p=1:n and t+f(x,n-1,-t*x*x/p/-~p,p+2)
If using Python 2, be sure to pass x as a float, not an integer, but I my understanding ...
7
votes
The Lehmer-Comtet sequence
Mathematica, 19 bytes
D[x^x,{x,#-1}]/.x->1&
-18 bytes from @Not a tree
7
votes
Polynomial Laplace transform
Haskell, 25 bytes
zipWith(*)$scanl(*)1[1..]
Try it online!
Pretty straightforward: Generates the list of factorials ...
6
votes
Solve the Laplace equation
Matlab, 84, 81.2 79.1 bytes = 113 - 30%
function u=l(f,N,a,b);A=toeplitz([2,-1,(3:N)*0]);A([1,2,end-[1,0]])=eye(2);u=[a,f((1:N-2)/N)*(N-1)^2,b]/A;plot(u)
Note ...
6
votes
6
votes
Pi == 3.2
PARI/GP, 48 43 bytes
It's easy after @orlp has found the formula, and @alephalpha's version saves 5 bytes:
p->2*intnum(u=0,1,(1+(u^-p-1)^(1-p))^(1/p))
To add ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
calculus × 36code-golf × 34
math × 21
string × 7
polynomials × 6
ascii-art × 2
code-challenge × 2
sequence × 2
parsing × 2
cops-and-robbers × 2
trigonometry × 2
integer × 1
geometry × 1
primes × 1
interpreter × 1
fractal × 1
probability-theory × 1
complex-numbers × 1
function × 1
approximation × 1
equation × 1