Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1 @@
fibonacci(n)

View file

@ -0,0 +1,8 @@
fib(n)={
if(n<2,
n
,
my(s=self());
s(n-2)+s(n-1)
)
};

View file

@ -0,0 +1 @@
apply(n->if(n<2,n,my(s=self());s(n-2)+s(n-1)), [1..10])

View file

@ -0,0 +1,13 @@
F=[];
fib(n)={
if(n>#F,
F=concat(F, vector(n-#F));
F[n]=fib(n-1)+fib(n-2)
,
if(n<2,
n
,
if(F[n],F[n],F[n]=fib(n-1)+fib(n-2))
)
);
}

View file

@ -0,0 +1,11 @@
fib(n)={
if(n<0,return((-1)^(n+1)*fib(n)));
my(a=0,b=1,t);
while(n,
t=a+b;
a=b;
b=t;
n--
);
a
};

View file

@ -0,0 +1 @@
fib(n)=n--;polchebyshev(n,2,I/2)*I^n;

View file

@ -0,0 +1 @@
fib(n)=abs(polchebyshev(n-1,2,I/2));

View file

@ -0,0 +1,7 @@
matantihadamard(n)={
matrix(n,n,i,j,
my(t=j-i+1);
if(t<1,t%2,t<3)
);
}
fib(n)=matdet(matantihadamard(n))

View file

@ -0,0 +1,7 @@
fib(n)=
{
my(g=2^(n+1)-1);
sum(i=2^(n-1),2^n-1,
bitor(i,i<<1)==g
);
}

View file

@ -0,0 +1 @@
fib(n)=my(k=0);while(n--,k++;while(!issquare(5*k^2+4)&&!issquare(5*k^2-4),k++));k

View file

@ -0,0 +1 @@
fib(n)=([1,1;1,0]^n)[1,2]

View file

@ -0,0 +1 @@
fib(n)=my(phi=(1+sqrt(5))/2);round((phi^n-phi^-n)/sqrt(5))

View file

@ -0,0 +1 @@
fib(n)=round(((1+sqrt(5))/2)^n/sqrt(5))

View file

@ -0,0 +1 @@
fib(n)=imag(quadgen(5)^n)

View file

@ -0,0 +1 @@
fib(n)=my(phi=quadgen(5));(phi^n-(-1/phi)^n)/(2*phi-1)

View file

@ -0,0 +1 @@
fib(n)=polcoeff(x/(1-x-x^2)+O(x^(n+1)),n)

View file

@ -0,0 +1,18 @@
fib(n)={
if(n<=0,
if(n,(-1)^(n+1)*fib(n),0)
,
my(v=lucas(n-1));
(2*v[1]+v[2])/5
)
};
lucas(n)={
if (!n, return([2,1]));
my(v=lucas(n >> 1), z=v[1], t=v[2], pr=v[1]*v[2]);
n=n%4;
if(n%2,
if(n==3,[v[1]*v[2]+1,v[2]^2-2],[v[1]*v[2]-1,v[2]^2+2])
,
if(n,[v[1]^2+2,v[1]*v[2]+1],[v[1]^2-2,v[1]*v[2]-1])
)
};

View file

@ -0,0 +1,7 @@
fib(n)={
if(n<2,
n
,
fib(n-1)+fib(n)
)
};