Computer programs

A forum where anything goes. Introduce yourselves to other members of the forums, discuss how your name evolves when written out in the Game of Life, or just tell us how you found it. This is the forum for "non-academic" content.
Post Reply
User avatar
PHPBB12345
Posts: 1096
Joined: August 5th, 2015, 11:55 pm
Contact:

Computer programs

Post by PHPBB12345 » June 24th, 2021, 11:01 am

Unbias a random generator (Javascript):

Code: Select all

function biased(n){return Math.random()<(1/n)};
function unbiased(n){var a;while((a=biased(n))==biased(n));return a};
Kogge-Stone adder (Javascript):

Code: Select all

function KoggeStoneAdd (A, B)
{
	// Addition without "+" operator
	var G, P;
	G = A & B;
	P = A ^ B;
	G |= P & (G << 1);
	P  = P & (P << 1);
	G |= P & (G << 2);
	P  = P & (P << 2);
	G |= P & (G << 4);
	P  = P & (P << 4);
	G |= P & (G << 8);
	P  = P & (P << 8);
	G |= P & (G << 16);
	return (A ^ B) ^ (G << 1);
}
function KoggeStoneSub (A, B)
{
	// Subtraction without "-" operator
	var G, P, T;
	T = ~A;
	G = T & B;
	P = T ^ B;
	G |= P & (G << 1);
	P  = P & (P << 1);
	G |= P & (G << 2);
	P  = P & (P << 2);
	G |= P & (G << 4);
	P  = P & (P << 4);
	G |= P & (G << 8);
	P  = P & (P << 8);
	G |= P & (G << 16);
	return (A ^ B) ^ (G << 1);
}
function KoggeStoneAdd3 (A, B, C)
{
	// Addition without "+" operator
	var T = A & B;
	B ^= A;
	A = B & C;
	return KoggeStoneAdd((T | A) << 1, B ^ C);
}
function RevIntKoggeStoneAdd (A, B)
{
	// Reversed integer addition
	var G, P;
	G = A & B;
	P = A ^ B;
	G |= P & (G >>> 1);
	P  = P & (P >>> 1);
	G |= P & (G >>> 2);
	P  = P & (P >>> 2);
	G |= P & (G >>> 4);
	P  = P & (P >>> 4);
	G |= P & (G >>> 8);
	P  = P & (P >>> 8);
	G |= P & (G >>> 16);
	return (A ^ B) ^ (G >>> 1);
}
function RevIntKoggeStoneSub (A, B)
{
	// Reversed integer subtraction
	var G, P, T;
	T = ~A;
	G = T & B;
	P = T ^ B;
	G |= P & (G >>> 1);
	P  = P & (P >>> 1);
	G |= P & (G >>> 2);
	P  = P & (P >>> 2);
	G |= P & (G >>> 4);
	P  = P & (P >>> 4);
	G |= P & (G >>> 8);
	P  = P & (P >>> 8);
	G |= P & (G >>> 16);
	return (A ^ B) ^ (G >>> 1);
}
function RevIntKoggeStoneAdd3 (A, B, C)
{
	// Reversed integer addition
	var T = A & B;
	B ^= A;
	A = B & C;
	return RevIntKoggeStoneAdd((T | A) >>> 1, B ^ C);
}
function BigIntKoggeStoneAdd (A, B)
{
	// Addition without "+" operator
	// A and B must be same sign
	var G, P, i, n1 = BigInt(1);
	A = BigInt(A);
	B = BigInt(B);
	i = n1;
	G = A & B;
	P = A ^ B;
	while (P)
	{
		G |= P & (G << i);
		P  = P & (P << i);
		i <<= n1;
	}
	return (A ^ B) ^ (G << n1);
}
Permuted Congruential Generator (Javascript, Use BigInt):

Code: Select all

function pcg32_constructor (state, inc)
{
	// PCG-XSH-RR 64/32 (LCG)
	let mult = BigInt("6364136223846793005");
	let n1 = BigInt(1), n18 = BigInt(18), n27 = BigInt(27), n59 = BigInt(59), mask = BigInt("18446744073709551615");
	inc = (BigInt(inc) & mask) | n1;
	state = BigInt(state) & mask;
	return function ()
	{
		let oldstate = state;
		state = (oldstate * mult + inc) & mask;
		let xorshifted = Number(((oldstate >> n18) ^ oldstate) >> n27) | 0;
		let rot = Number(oldstate >> n59);
		return (xorshifted >>> rot) | (xorshifted << (-rot & 31));
	};
};
// Usage:
pcg32 = pcg32_constructor("5573589319906701683", "1442695040888963407");
pcg32 (); // 676697322
pcg32 (); // 420258633
pcg32 (); // -876335118
Jacobian elliptic functions:

Code: Select all

// http://www.netlib.org/cephes/
var ellipj = (function() {
    let sqrt = Math.sqrt;
    let fabs = Math.abs;
    let sin = Math.sin;
    let cos = Math.cos;
    let asin = Math.asin;
    let tanh = Math.tanh;
    let sinh = Math.sinh;
    let cosh = Math.cosh;
    let atan = Math.atan;
    let exp = Math.exp;

    let PIO2 = Math.PI / 2;
    let MACHEP = Number.EPSILON / 2;

    return function(u, m) {
        let sn, cn, dn, ph;
        let ai, b, phi, t, twon;
        let a = []
          , c = [];
        let i;

        /* Check for special cases */

        if (m < 0.0 || m > 1.0) {
            return ({
                sn: NaN,
                cn: NaN,
                dn: NaN,
                ph: NaN
            });
        }
        if (m < 1.0e-9) {
            t = sin(u);
            b = cos(u);
            ai = 0.25 * m * (u - t * b);
            return ({
                sn: t - ai * b,
                cn: b + ai * t,
                ph: u - ai,
                dn: 1.0 - 0.5 * m * t * t
            });
        }

        if (m >= 0.9999999999) {
            ai = 0.25 * (1.0 - m);
            b = cosh(u);
            t = tanh(u);
            phi = 1.0 / b;
            twon = b * sinh(u);
            sn = t + ai * (twon - u) / (b * b);
            ph = 2.0 * atan(exp(u)) - PIO2 + ai * (twon - u) / b;
            ai *= t * phi;
            cn = phi - ai * (twon - u);
            dn = phi + ai * (twon + u);
            return ({
                sn: sn,
                cn: cn,
                dn: dn,
                ph: ph
            });
        }

        /*	A. G. M. scale		*/
        a[0] = 1.0;
        b = sqrt(1.0 - m);
        c[0] = sqrt(m);
        twon = 1.0;
        i = 0;

        while (fabs(c[i] / a[i]) > MACHEP) {
            if (i > 7) {
                console.warn("Overflow in ellipj");
                break;
            }
            ai = a[i];
            ++i;
            c[i] = (ai - b) / 2.0;
            t = sqrt(ai * b);
            a[i] = (ai + b) / 2.0;
            b = t;
            twon *= 2.0;
        }

        /* backward recurrence */
        phi = twon * a[i] * u;
        do {
            t = c[i] * sin(phi) / a[i];
            b = phi;
            phi = (asin(t) + phi) / 2.0;
        } while (--i);
        t = sin(phi);
        sn = t;
        cn = cos(phi);
        /* Thanks to Hartmut Henkel for reporting a bug here:  */
        dn = sqrt(1.0 - m * t * t);
        ph = phi;
        return ({
            sn: sn,
            cn: cn,
            dn: dn,
            ph: ph
        });
    }
})();
CVP problem:

Code: Select all

var nearest = (function() {
	"use strict";
	function norm(w) {
		return w[0] * w[0] + w[1] * w[1];
	}
	function proj(w1, w2) {
		return (w1[0] * w2[0] + w1[1] * w2[1]) / norm(w2);
	}
	function nint(x) {
		return Math.sign(x) * Math.ceil(Math.abs(x) - 0.5);
	}
	function reduce(w1, w2) {
		var i, t;
		w1 = [+w1[0], +w1[1]];
		w2 = [+w2[0], +w2[1]];
		if (norm(w1) > norm(w2)) t = w1, w1 = w2, w2 = t;
		for (i = 0; i < 1000; i++) {
			t = nint(proj(w2, w1));
			if (!t) break;
			w2[0] -= t * w1[0];
			w2[1] -= t * w1[1];
			t = w1, w1 = w2, w2 = t;
		}
		if (norm(w1) > norm(w2)) t = w1, w1 = w2, w2 = t;
		return [w1, w2];
	}
	function nearesti(p, w) {
		var n = nint(proj(p, w));
		p[0] -= n * w[0];
		p[1] -= n * w[1];
		return [n, norm(p)];
	}
	return function (p, w1, w2) {
		var w = reduce(w1, w2);
		var a = proj(w[1], w[0]);
		var b = proj(p, [w[1][0] - a * w[0][0], w[1][1] - a * w[0][1]]);
		var c = nint(b);
		var d = c + Math.sign(b - c);
		var e = nearesti([p[0] - c * w[1][0], p[1] - c * w[1][1]], w[0]);
		if (c !== d) {
			a = nearesti([p[0] - d * w[1][0], p[1] - d * w[1][1]], w[0]);
			if (e[1] > a[1]) c = d, e = a;
		}
		d = e[0];
		return [d * w[0][0] + c * w[0][1], d * w[1][0] + c * w[1][1]];
	}
})();
2Sum:

Code: Select all

function twosum(a, b) {
	let s = a + b;
	let v = s - a;
	let e = (a - (s - v)) + (b - v);
	return [s, e]
}
function split(a) {
	let t = 134217729 * a;
	let hi = t - (t - a);
	let lo = a - hi;
	return [hi, lo];
}
function twoprod(a, b) {
	let p = a * b;
	let [ahi, alo] = split(a);
	let [bhi, blo] = split(b);
	let e = ((ahi * bhi - p) + ahi * blo + alo * bhi) + alo * blo;
	return [p, e];
}
function fma(a, b, c) {
	[a, b] = twoprod(a, b);
	[b, c] = twosum(b, c);
	return a + b;
}
Gini index:

Code: Select all

function GiniIndex (list) {
	let i, n, sum, eps, max;
	list = Array.from(list).sort((x, y) => y - x);
	max = list[0];
	for (i = sum = eps = 0, n = list.length; i < n; i++) {
		let y = (max - list[i]) - eps;
		let t = sum + y;
		eps = (t - sum) - y;
		sum = t;
	}
	return sum / ((n - 1) * max);
}
Variants of Verlet integration:

Code: Select all

function integrator1 (a, b, h, f, steps) {
    a = +a; b = +b;
    for (let i = 0; i < steps; i++) {
        let c = f(a, b);
        a += h*(b+c*h/2);
        b += c*h;
        let d = f(a, b);
        b += (d-c)*h/2;
    }
    return [a, b];
}

function integrator2 (a, b, h, f, steps) {
    a = +a; b = +b;
    for (let i = 0; i < steps; i++) {
        let c = f(a, b);
        a += h*(b+c*h/2);
        b += c*h;
        let d = f(a, b);
        b += (d-c)*h/2;
        let e = f(a, b) - d;
        if (e !== 0) b += e/(1-e/(d-c))*h/2;
    }
    return [a, b];
}
Last edited by PHPBB12345 on March 28th, 2023, 11:28 am, edited 16 times in total.

ColorfulGabrielsp138
Posts: 288
Joined: March 29th, 2021, 5:45 am

Re: Computer programs

Post by ColorfulGabrielsp138 » July 15th, 2021, 6:00 am

Pixel characters (please send the output to CyberChef)

Code: Select all

#include <cstdio>
!0;
int i;

int main(){

for(i=0;i<=255;++i){
if(i%16==0){printf("0a \n");};
printf("28%02x ",i);
}

return 0;
}

Code: Select all

!
⠀⠁⠂⠃⠄⠅⠆⠇⠈⠉⠊⠋⠌⠍⠎⠏
⠐⠑⠒⠓⠔⠕⠖⠗⠘⠙⠚⠛⠜⠝⠞⠟
⠠⠡⠢⠣⠤⠥⠦⠧⠨⠩⠪⠫⠬⠭⠮⠯
⠰⠱⠲⠳⠴⠵⠶⠷⠸⠹⠺⠻⠼⠽⠾⠿
⡀⡁⡂⡃⡄⡅⡆⡇⡈⡉⡊⡋⡌⡍⡎⡏
⡐⡑⡒⡓⡔⡕⡖⡗⡘⡙⡚⡛⡜⡝⡞⡟
⡠⡡⡢⡣⡤⡥⡦⡧⡨⡩⡪⡫⡬⡭⡮⡯
⡰⡱⡲⡳⡴⡵⡶⡷⡸⡹⡺⡻⡼⡽⡾⡿
⢀⢁⢂⢃⢄⢅⢆⢇⢈⢉⢊⢋⢌⢍⢎⢏
⢐⢑⢒⢓⢔⢕⢖⢗⢘⢙⢚⢛⢜⢝⢞⢟
⢠⢡⢢⢣⢤⢥⢦⢧⢨⢩⢪⢫⢬⢭⢮⢯
⢰⢱⢲⢳⢴⢵⢶⢷⢸⢹⢺⢻⢼⢽⢾⢿
⣀⣁⣂⣃⣄⣅⣆⣇⣈⣉⣊⣋⣌⣍⣎⣏
⣐⣑⣒⣓⣔⣕⣖⣗⣘⣙⣚⣛⣜⣝⣞⣟
⣠⣡⣢⣣⣤⣥⣦⣧⣨⣩⣪⣫⣬⣭⣮⣯
⣰⣱⣲⣳⣴⣵⣶⣷⣸⣹⣺⣻⣼⣽⣾⣿.
Last edited by ColorfulGabrielsp138 on August 12th, 2021, 8:38 am, edited 1 time in total.

Code: Select all

x = 21, y = 21, rule = LifeColorful
11.E$10.3E$10.E.2E$13.E4$2.2B$.2B$2B$.2B15.2D$19.2D$18.2D$17.2D4$7.C$
7.2C.C$8.3C$9.C!
I have reduced the glider cost of quadratic growth to eight and probably to seven. Looking for conduits...

User avatar
PHPBB12345
Posts: 1096
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 » July 19th, 2021, 11:44 pm

SSE2 hypot/hypotf (i386 fasm assembly):

Code: Select all

format PE Console 4.0
entry start

include 'win32a.inc'

section '.text' code readable executable

start:
        push dword 3.0
        push dword 4.0
        call hypotf_sse2
        push $40100000
        push 0
        push $40080000
        push 0
        call hypot_sse2
        ud2
        align 4

 hypotf_sse2:
        push ebp
        mov ebp, esp
        sub esp, 4
        mov eax, [ebp+8]
        mov ecx, [ebp+12]
        and eax, 0x7FFFFFFF
        and ecx, 0x7FFFFFFF
        movd xmm0, eax
        or eax, ecx
        jz .return
        movd xmm1, ecx
        movss xmm2, xmm0
        maxss xmm0, xmm1
        minss xmm1, xmm2
        ; assume xmm0 >= xmm1
        mov eax, 1.0
        movd xmm2, eax
        divss xmm1, xmm0
        mulss xmm1, xmm1
        addss xmm1, xmm2
        sqrtss xmm1, xmm1
        mulss xmm0, xmm1
  .return:
        movss [ebp-12], xmm0
        fld dword [ebp-12]
        mov esp, ebp
        pop ebp
        ret
        align 4

 hypot_sse2:
        push ebp
        mov ebp, esp
        sub esp, 8
        and esp, -16
        movupd xmm0, [ebp+8]
        pcmpeqb xmm1, xmm1
        psrlq xmm1, 1
        pand xmm0, xmm1
        ptest xmm0, xmm0
        jz .return
        pshufd xmm1, xmm0, 0xEE
        movsd xmm2, xmm0
        maxsd xmm0, xmm1
        minsd xmm1, xmm2
        ; assume xmm0 >= xmm1
        movsd xmm2, [.const.1]
        divsd xmm1, xmm0
        mulsd xmm1, xmm1
        addsd xmm1, xmm2
        sqrtsd xmm1, xmm1
        mulsd xmm0, xmm1
  .return:
        movsd [esp], xmm0
        fld qword [esp]
        mov esp, ebp
        pop ebp
        ret
        align 16
  .const.1 dq 1.0

 hypotl:
        ; 80-bit floating point via x87 stack?
        ; For higher precision floating point, use GMP's mpf_xxx functions
Boot code cause VirtualBox shutdown (x86 fasm assembly):

Code: Select all

org 0x7c00

        cli
        mov ax,cs
        mov ds,ax
        mov es,ax
        mov ss,ax
        mov sp,0x7c00
        sti
        call push_str
        db "Shutdown"
 push_str:
        pop si
        mov cx,8
        mov dx,1039
        cld
        rep outsb
 halt:
        hlt
        jmp halt

        times 510 - ($ - $$) db 0
        dw 0aa55h
SEH trampoline (x86-64 assembly):

Code: Select all

        lea rax, [scopetable]
        mov [r9+56], rax
        jmp [__C_specific_handler]
Last edited by PHPBB12345 on August 22nd, 2021, 2:53 am, edited 1 time in total.

ColorfulGabrielsp138
Posts: 288
Joined: March 29th, 2021, 5:45 am

Re: Computer programs

Post by ColorfulGabrielsp138 » July 29th, 2021, 6:30 am

Code: Select all

#include <cstdio>
!0;
int list[]=
{ 0,  00,02,03,00,05, 00,07,00,00,
  0,  11,00,13,00,00, 00,17,00,19,
  0,  00,00,23,00,00, 00,00,00,29,
  0,  31,00,00,00,00, 00,37,00,00,
  0,  41,00,43,00,0 , 00,47,00,00,
  0,  00,00,53,00,00, 00,00,00,59,
  0,  61,00,00,00,00, 00,67,00,00,
  0,  71, 0,73,00,00, 00,00,00,79,
  0,  00,00,83,00,00, 00,00,00,89,
  0,  00,00,00,00,00, 00,97,00,00,
  0};

int a=0;

int main(){

for(a=32;a<100;++a){
if(list[a]==0){
printf("===%i===\n",a);
printf("<div style=\"border:2px solid #ff00ff;\">\n\n");
printf("</div>\n\n\n");
} else {
printf("===%i===\n",a);
printf("<div style=\"border:2px solid blue;\">\n\n");
printf("</div>\n\n\n");
}
}
 
return 0;
}

Code: Select all

x = 21, y = 21, rule = LifeColorful
11.E$10.3E$10.E.2E$13.E4$2.2B$.2B$2B$.2B15.2D$19.2D$18.2D$17.2D4$7.C$
7.2C.C$8.3C$9.C!
I have reduced the glider cost of quadratic growth to eight and probably to seven. Looking for conduits...

ColorfulGabrielsp138
Posts: 288
Joined: March 29th, 2021, 5:45 am

Re: Computer programs

Post by ColorfulGabrielsp138 » August 16th, 2021, 7:59 am

Code: Select all

x = 35, y = 5, rule = Wireworld5
FBCIJABCDE.BCDEABC.E.BCDEABCDEABCDE$10.A6.CD.A$11.BC3.BC3.BC$12.CD.A6.
CD$AGCDJABCDEABC.E.BCDEABC.EABCDEABCDE!
A WireWorld5 Crossover based on this C++ code:

Code: Select all

#include <cstdio>
!0;
int a,b;
int main(){
scanf("%d%d",&a,&b);
a^=b;b^=a;a^=b;
printf("%d %d",a,b);
return 0;}

Code: Select all

x = 21, y = 21, rule = LifeColorful
11.E$10.3E$10.E.2E$13.E4$2.2B$.2B$2B$.2B15.2D$19.2D$18.2D$17.2D4$7.C$
7.2C.C$8.3C$9.C!
I have reduced the glider cost of quadratic growth to eight and probably to seven. Looking for conduits...

User avatar
PHPBB12345
Posts: 1096
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 » February 14th, 2023, 12:15 pm

Code: Select all

{
\\ Jacobi theta functions
theta1=((q,z)->theta(q,z));
theta2=((q,z)->2*q^(1/4)*suminf(n=0,q^(n*n+n)*cos((2*n+1)*z)));
theta3=((q,z)->1+2*suminf(n=1,q^n^2*cos(2*n*z)));
theta4=((q,z)->theta3(-q,z));
\\ Lattice reduction
ellreducez=((w,z)->my(t=ellperiods(w),a,b);b=Mat([real(t),imag(t)]~);a=round(Mat([real(w),imag(w)]~)^(-1)*b);b=round(b^(-1)*[real(z),imag(z)]~);[z-t*b,a*b]);
ellperiodratio=((w)->w=ellperiods(w);w[1]/w[2]);
\\ Elliptic nome
ellnome=((k)->if(k,exp(-Pi*agm(1,sqrt(1-k^2))/agm(1,k)),(k^2)/2));
invellnome=((q)->my(s=4*q^(1/2),t);if(s,t=log(q)/(Pi*I);s*=(eta(t/2)*eta(2*t)^2/eta(t)^3)^4);s);
nometomodularangle=((q)->q=sqrt(q);4*suminf(n=0,my(t=2*n+1);(-1)^n*q^t/(t*(1+q^(2*t)))));
\\ j-invariant
invellj=((j)->my(prec=bitprecision(j));if(exponent(j)>getlocalbitprec()/2+10,return(I*log(1.*j-744)/(2*Pi)));if(prec<oo,j=bitprecision(j,prec+64));ellperiodratio(ellinit(ellfromj(j))));
\\ Logarithm of Dedekind eta function
logeta=((t)->
	if(imag(t)<=0,error("domain error in modular function: Im(argument) <= 0"));
	my(w=[t,1],a,b,c,d,M);t=ellperiods(w);M=round(Mat([real(t),imag(t)]~)^(-1)*Mat([real(w),imag(w)]~));c=M[1,2];t=t[1]/t[2];if(c,M*=sign(c);a=M[1,1];b=M[2,1];c=M[1,2];d=M[2,2];I*Pi*((a+d)/(12*c)+sumdedekind(-d,c))+log(-I*(c*t+d))/2,I*Pi*M[2,1]/12)+Pi*I*t/12+log(eta(t))
);
\\ Neville theta functions
thetaS=((k,z)->if(k,my(m=k^2,a=agm(1,sqrt(1-m)),q=exp(-Pi*a/agm(1,k)));theta1(q,z*a)*sqrt(a)*m^(-1/4)*(1-m)^(-1/4),sin(z)));
thetaC=((k,z)->if(k,my(m=k^2,a=agm(1,sqrt(1-m)),q=exp(-Pi*a/agm(1,k)));theta2(q,z*a)*sqrt(a)*m^(-1/4),cos(z)));
thetaD=((k,z)->if(k,my(m=k^2,a=agm(1,sqrt(1-m)),q=exp(-Pi*a/agm(1,k)));theta3(q,z*a)*sqrt(a),1.));
thetaN=((k,z)->if(k,my(m=k^2,a=agm(1,sqrt(1-m)),q=exp(-Pi*a/agm(1,k)));theta4(q,z*a)*sqrt(a)*(1-m)^(-1/4),1.));
\\ Jacobi elliptic functions
jacobiSN=((k,z)->thetaS(k,z)/thetaN(k,z));
jacobiCN=((k,z)->thetaC(k,z)/thetaN(k,z));
jacobiTN=((k,z)->thetaS(k,z)/thetaC(k,z));
jacobiDN=((k,z)->thetaD(k,z)/thetaN(k,z));
jacobiZN=((k,z)->((z)->thetaN(bitprecision(k,getlocalbitprec()),z))'(z)/thetaN(k,z));
jacobiEpsilon=((k,z)->jacobiZN(k,z)+z*ellE(k)/ellK(k));
jacobiAM=((k,z)->if(k,my(c=thetaC(k,z),s=thetaS(k,z),a=c+I*s,b=c-I*s,t=norm(a)-norm(b));z=if(t<0,I,-I)*log(if(t<0,b,a)/thetaN(k,z));if(t,z,real(z)),z));
\\ Alternative implementations
jacobiSN=((k,z)->my(w,p,t,m=k^2);if(m==0,return(sin(z)),m==1,return(tanh(z)));w=2*[ellK(k),I*ellK(sqrt(1-m))];[z,t]=ellreducez(w,z);t=(-1)^t[1];z*=1.;my(lp=getlocalbitprec(),m1=1+m,e=exponent(z));if(!z||max(0,exponent(m1))+2*e<-lp,return(t*z));w=ellperiods(w);e-=exponent(w[2]);if(e<0,[w,z]=bitprecision([w,z],lp-e));p=iferr(ellwp(w,z/2,1),E,return(t*z),errname(E)=="e_DOMAIN");t*p[2]/(m-(p[1]+m1/3)^2));
jacobiCN=((k,z)->my(w,p,t,m=k^2);if(m==0,return(cos(z)),m==1,return(1/cosh(z)));w=2*[ellK(k),I*ellK(sqrt(1-m))];[z,t]=ellreducez(w,z);t=(-1)^(t[1]+t[2]);p=iferr(ellwp(w,z/2),E,return(t*1.),errname(E)=="e_DOMAIN");t*(1+2*(p+(1-2*m)/3)/(m-(p+(1+m)/3)^2)));
jacobiTN=((k,z)->my(w,p,t,m=k^2);if(m==0,return(tan(z)),m==1,return(sinh(z)));w=2*[ellK(k),I*ellK(sqrt(1-m))];[z,t]=ellreducez(w,z);t=(-1)^t[2];z*=1.;my(lp=getlocalbitprec(),m1=2-m,e=exponent(z));if(!z||max(0,exponent(m1))+2*e<-lp,return(t*z));w=ellperiods(w);e-=exponent(w[2]);if(e<0,[w,z]=bitprecision([w,z],lp-e));p=iferr(ellwp(w,z/2,1),E,return(t*z),errname(E)=="e_DOMAIN");t*p[2]/(1-m-(p[1]-m1/3)^2));
jacobiDN=((k,z)->my(w,p,t,m=k^2);if(m==0,return(1.),m==1,return(1/cosh(z)));w=2*[ellK(k),I*ellK(sqrt(1-m))];[z,t]=ellreducez(w,z);t=(-1)^t[2];p=iferr(ellwp(w,z/2),E,return(t*1.),errname(E)=="e_DOMAIN");t*(1+2*m*((m-2)/3+p)/(m-(p+(1+m)/3)^2)));
jacobiZN=((k,z)->if(k==0,return(0.),k^2==1,return(tanh(z)));my(a=ellK(k),b=I*ellK(sqrt(1-k^2)),w=2*[a,b]);ellzeta(w,z+b)-ellzeta(w,b)-ellzeta(w,a)/a*z);
jacobiEpsilon=((k,z)->if(k==0,return(z),k^2==1,return(tanh(z)));my(a=ellK(k),b=I*ellK(sqrt(1-k^2)),w=[2*a,2*b]);ellzeta(w,z+b)-ellzeta(w,b)+z*(2-k^2)/3);
jacobiAM=((k,z)->if(k,my(m=k^2,a=agm(1,if(real(k)<0,-k,k)),b=agm(1,sqrt(1-m)),c,d,t,rb);if(real(m)<0.5,z*=2*I*b;b*=Pi/a;rb=real(b);t=real(z)\/(2*rb);z-=2*t*b;d=bitprecision(z);c=sum(n=0,ceil(log(2)*(if(d==oo,getlocalbitprec(),d)/2+abs(real(z)))/rb)+1,my(s=(2*n+1)*b);(-1)^n*(log(-expm1(z-s))-log(-expm1(-z-s))))-z/2;c=if(t%2,c=((imag(z)-real(z)*imag(b)/rb)\(2*Pi)*2+1)*Pi-I*c,I*c);if(imag(m)||real(z),c,real(c)),c=a*z/2;if(b,b=a*Pi/(2*b);t=real(c)\/real(b);if(t,c-=t*b;t*=Pi));t+2*(atan(tanh(c))+if(b,suminf(i=1,atan(tanh(c+i*b))+atan(tanh(c-i*b))),0))),z));
\\ Elliptic exponential and logarithm
ellexpnum=((E,z)->my(P=ellztopoint(E,z));if(#P<2,0.,-P[1]/P[2]));
elllognum=((E,z)->if(!z,return(z));my(R=polroots(E.a6*z^2+(E.a3*z+E.a4*z^2)*x+(-1+E.a1*z+E.a2*z^2)*x^2+z^2*x^3),r,x);foreach(R,t,my(a=abs(t));if(a>r,r=a;x=t));ellreducez(E.omega,ellpointtoz(E,[x,-x/z]))[1]);
\\ Incomplete elliptic integrals
incellF=((k,phi)->my(m=k^2,t,s,c,d,E);if(m==1,2*atanh(tan(phi/2)),m,t=round(real(phi)/Pi);phi-=t*Pi;if(!phi,return(1.*phi+2*t*ellK(k)));s=sin(phi);c=s^2/(1+cos(phi));d=1+sqrt(1-m*s^2);E=ellinit(-[(1-m+m^2)/3,(2-3*m-3*m^2+2*m^3)/27]);2*(ellreducez(E.omega,ellpointtoz(E,[d/c-(1+m)/3,s*(m*c-d)/c^2]))[1]+t*ellK(k)),phi*1.));
incellE=((k,phi)->jacobiEpsilon(k,incellF(k,phi)));
incellD=((k,phi)->my(u=incellF(k,phi));(u-jacobiEpsilon(k,u))/k^2);
jacobiZeta=((k,phi)->jacobiZN(k,incellF(k,phi)));
invellwp=((w,z)->w=ellperiods(w);my(g2=elleisnum(w,4,1),g3=elleisnum(w,6,1),E=ellinit(-[g2,g3]/4),x,y,l);z=Vec(z);x=z[1];l=#z<2;y=if(l,sqrt(4*x^3-x*g2-g3),z[2]);z=ellreducez(w,ellpointtoz(E,[x,-y/2]))[1];if(l&&real(z)>=0,z,-z));
invjacobiSN=((k,v)->incellF(k,asin(v)));
invjacobiCN=((k,v)->incellF(k,acos(v)));
invjacobiTN=((k,v)->incellF(k,atan(v)));
invjacobiDN=((k,v)->incellF(1/k,acos(v))/k);
\\ Carlson elliptic integrals
my(ellR_=((x,y,z)->my(t=(x+y+z)/3,[e1,e2,e3]=[x-t,y-t,z-t],E=ellinit([e1*e2+e1*e3+e2*e3,e1*e2*e3]),c);c=ellreducez(E.omega,ellpointtoz(E,[t,-sqrt(x)*sqrt(y)*sqrt(z)]))[1];[c,t,E]));
ellRC=((x,y)->if(x==y,1/sqrt(x),my(sx=sqrt(x),sy=sqrt(y));acos(sx/sy)/(sqrt(1-x/y)*sy)));
ellRD=((x,y,z)->my([u,P,E]=ellR_(x,y,z));3*(u*(z-P)-ellzeta(E,u)+sqrt(x)*sqrt(y)/sqrt(z))/((x-z)*(y-z)));
ellRE=((x,y)->my(sx=sqrt(x),sy=sqrt(y),t=sx*sy);2*((sx+sy)*ellE((sx-sy)/(sx+sy))/Pi-if(t,t/(2*agm(sx,sy)),0)));
ellRF=((x,y,z)->ellR_(x,y,z)[1]);
ellRG=((x,y,z)->my([u,P,E]=ellR_(x,y,z));(u*P+ellzeta(E,u))/2);
ellRJ=((x,y,z,p)->my(c=(!x+!y+!z)/2+!p);3/2*intnum(t=[0,-c],[oo,-5/2],1/(sqrt(t+x)*sqrt(t+y)*sqrt(t+z)*(t+p))));
ellRK=((x,y)->1/agm(sqrt(x),sqrt(y)));
ellRM=((x,y,p)->4/(3*Pi)*ellRJ(0,x,y,p));
\\ Complete elliptic integrals
ellD=((k)->(ellK(k)-ellE(k))/k^2);
\\ Lemniscatic elliptic functions
sinlemn=((z)->my(w=2*ellK(I),q=round(z/w),s=(-1)^(real(q)+imag(q)),p,r);z=1.*(z-q*w);if(z&&-2*(q=exponent(z))<(r=bitprecision(z)),[w,z]=bitprecision([w*[1+I,1-I],z],r-q);iferr(p=ellwp(w,z,1),E,,errname(E)=="e_DOMAIN"));s*if(p,-bitprecision(2*p[1]/p[2],r),z));
coslemn=((z)->my(p=2*ellK(I),q=round(z/p),s=(-1)^(real(q)+imag(q)));z-=q*p;iferr(p=ellwp(p*[1+I,1-I],z),E,return(s*1.),errname(E)=="e_DOMAIN");s*(1-2/(2*p+1)));
asinlemn=((z)->z*hypergeom([1/4,1/2],5/4,z^4));
acoslemn=((z)->ellK(I)-asinlemn(z));
\\ Associated Weierstrass sigma functions
my(ellsigma_=((w,z,i)->my([t,e]=ellperiods(w,1),a=Mat([real(t),imag(t)]~),b=round(a^(-1)*Mat([real(w),imag(w)]~))*Col(i)%2,c);if(real(t[1]/t[2])>0,b[2]*=-1);[a,e]=[t*b,e*b]/2;c=real(z*conj(a));if(iferr(c>0,E,c=t;c[2-b[1]]=a;return(exp(-ellwp(t,a)*z^2/2)*ellsigma(c,z)/ellsigma(t,z)),errname(E)=="e_TYPE2"),z=-z);ellsigma(w,z+a)/ellsigma(w,a)*exp(-z*e)));
ellsigma1=((w,z)->ellsigma_(w,z,[1,0]));
ellsigma2=((w,z)->ellsigma_(w,z,[0,1]));
ellsigma3=((w,z)->ellsigma_(w,z,[1,1]));
\\ Dixon elliptic functions
DixonLambda=((a)->if(a==-1,return([2*Pi/sqrt(27)]));my(s=sqrt(3),g=gamma(1/3)^3,m=g*hypergeom([1/3,1/3],2/3,-a^3)/Pi,n=Pi^2*a*hypergeom([2/3,2/3],4/3,-a^3)/(3*g));[s*m/6+4*n,-(s-3*I)*m/12-2*(1+s*I)*n,-(s+3*I)*m/12-2*(1-s*I)*n]);
DixonKappa=((a)->if(a==-1,return([2*Pi/sqrt(27)-1]));my(s=sqrt(3),g=gamma(1/3)^3,m=Pi^2*hypergeom([-1/3,2/3],1/3,-a^3)/(3*g),n=a^2*g*hypergeom([1/3,4/3],5/3,-a^3)/Pi);[a+4*m+s*n/12,a-2*(1+s*I)*m-(s-3*I)*n/24,a-2*(1-s*I)*m-(s+3*I)*n/24]);
DixonSM=((a,z)->if(a==-1,z*=sqrt(3)/2;return(sin(z)/sin(Pi/3+z)));my(x,y,b=a^3);iferr([x,y]=ellwp(ellinit([a*(8-b)/48,(b*(20+b)-8)/864]),z,1),E,return(.),errname(E)=="e_DOMAIN");-(a^2/2+2*x)/(y+a*x-(a^3+4)/12));
DixonCM=((a,z)->if(a==-1,z*=sqrt(3)/2;return(sin(Pi/3-z)/sin(Pi/3+z)));my(x,y,b=a^3);iferr([x,y]=ellwp(ellinit([a*(8-b)/48,(b*(20+b)-8)/864]),z,1),E,return(1.),errname(E)=="e_DOMAIN");b=(a^3+4)/12;(y-a*x+b)/(y+a*x-b));
DixonF=((a,z)->if(a==-1,my(t=z*sqrt(3)/2);return(z-sin(t)/sin(Pi/3+t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]),l=DixonLambda(a)[1],k=DixonKappa(a)[1]);3/4*a*(2+a*(z+l))+ellzeta(E,z+l)-k);
DixonThetaS=((a,z)->if(a==-1,my(t=sqrt(3)/2);return(exp(z*(z-1)/2)/t*sin(z*t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]));exp((4*a*z+3*a^2*z^2)/8)*ellsigma(E,z));
DixonThetaC=((a,z)->if(a==-1,my(t=sqrt(3)/2);return(exp(z*(z-1)/2)/t*sin(Pi/3-z*t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]),l=DixonLambda(a)[1],k=DixonKappa(a)[1]);exp((4*a*z+3*a^2*(l-z)^2-4*(k-a)*(l-2*z))/8)*ellsigma(E,l-z));
DixonThetaM=((a,z)->if(a==-1,my(t=sqrt(3)/2);return(exp(z*(z-1)/2)/t*sin(Pi/3+z*t)));my(E=ellinit([-a*(24+a^3*27)/16,(8+a^3*(36+a^3*27))/32]),l=DixonLambda(a)[1],k=DixonKappa(a)[1]);exp((4*a*z+3*a^2*(l+z)^2-4*(k-a)*(l+2*z))/8)*ellsigma(E,l+z));
\\ q-Pochhammer
qpoch=((a,q)->my(p=getlocalbitprec(),r=1,t=1);[a,q]=precision([-a,q],p+10);localbitprec(p+10);bitprecision((1+a)*(1+suminf(i=1,r*=q;t*=a*r/(1-r);t)),p));
\\ Genus 2 arithmetic geometric mean
genus2agm=((args[..])->my(p=getlocalbitprec());localbitprec(p+64);bitprecision(if(
	#args==4,my([a,b,c,d]=bitprecision(args,p+64));while(exponent(abs(b-a)+abs(c-a)+abs(d-a))-exponent(a)>=-p,my(sa=sqrt(a),sb=sqrt(b),sc=sqrt(c),sd=sqrt(d));[a,b,c,d]=[(a+b+c+d)/4,(sa*sb+sc*sd)/2,(sa*sc+sb*sd)/2,(sa*sd+sb*sc)/2]);a,
	#args==6,my([a,b,c,d,e,f]=bitprecision(args,p+64));while(exponent(abs(a-b)+abs(c-d)+abs(e-f))-exponent([a,b,c,d,e,f])>=-p,my(ab=a*b,cd=c*d,ef=e*f,ac=a-c,ad=a-d,ae=a-e,af=a-f,bc=b-c,bd=b-d,be=b-e,bf=b-f,ce=c-e,cf=c-f,de=d-e,df=d-f,n1=ab-cd,n2=ab-ef,n3=cd-ef,d1=ac+bd,d2=ae+bf,d3=ce+df,s1=sqrt(ac)*sqrt(ad)*sqrt(bc)*sqrt(bd),s2=sqrt(ae)*sqrt(af)*sqrt(be)*sqrt(bf),s3=sqrt(ce)*sqrt(cf)*sqrt(de)*sqrt(df),r1=[n1+s1,n1-s1]/d1,r2=[n2+s2,n2-s2]/d2,r3=[n3+s3,n3-s3]/d3,E=oo);for(i=1,2,for(j=1,2,for(k=1,2,my(t=abs(r2[i]-r1[j])+abs(r1[3-j]-r3[k])+abs(r3[3-j]-r2[3-k]));if(E>t,E=t;a=r2[i];b=r1[j];c=r1[3-j];d=r3[i];e=r3[3-i];f=r2[3-i];break)))));[a,c,e],
	error("genus2agm: must be 4 or 6 arguments")
),p));
}

Code: Select all

\\ Scaled complementary error function
erfcx(x) = {
  if(real(x) < 0, return(erfc(x) * exp(x^2)));
  my(h, h2, eh2, denom, res, lambda, u, v, D, npoints, k, t, Uk, Vk, prec);
  prec = getlocalbitprec();
  localbitprec(64);
  D = prec * log(2);
  npoints = ceil(D / Pi) + 1;
  t = exp(-2 * sqr(Pi) / D);
  v = 30;
  u = floor(t << v);
  localbitprec(prec + 64);
  x = bitprecision(x * 1., prec + 64);
  eh2 = sqrt(shiftmul(u, -v));
  h2 = -log(eh2);
  h = sqrt(h2);
  lambda = x / h;
  denom = sqr(lambda);
  Vk = eh2;
  denom = 1 + denom;
  Uk = Vk;
  Vk = shiftmul(u * Vk, -v);
  res = Uk / denom;
  for (k = 1, npoints - 1, 
    denom += 2 * k + 1;
    Uk *= Vk;
    Vk = shiftmul(u * Vk, -v);
    res = res + Uk / denom;
  );
  res *= 2 * lambda;
  res += 1 / lambda;
  res /= Pi;
  if (real(x) < sqrt(D),
    t = (2 * Pi / h) * x;
    res = res - (2 * exp(sqr(x))) / expm1(t)
  );
  return(bitprecision(res, prec));
}
Last edited by PHPBB12345 on April 14th, 2024, 10:28 am, edited 93 times in total.

User avatar
PHPBB12345
Posts: 1096
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 » February 15th, 2023, 12:15 am

Code: Select all

var parseRule = function (rule_str) {
var table = [], tablecnt = [];
var add4f = function (n, v) {
  var r = n & 0x88 | (n * 0x101 >> 4) & 0x77;
  r = r & 0xAA | (r << 2) & 0x44 | (r >> 2) & 0x11;
  var n2 = n * 0x101, r2 = r * 0x101;
  table[n] = v, table[r] = v;
  table[(n2>>2)&255] = v, table[(r2>>2)&255] = v;
  table[(n2>>4)&255] = v, table[(r2>>4)&255] = v;
  table[(n2>>6)&255] = v, table[(r2>>6)&255] = v;
}
for (var i = 0, j; i < 256; ++i) {
  j = (i & 0x55) + ((i>>1) & 0x55);
  j = (j & 0x33) + ((j>>2) & 0x33);
  tablecnt[i] = (j + (j>>4)) & 15;
}
var nbrhd = [
  {c: 0x00},
  {c: 0x01, e: 0x02},
  {c: 0x05, e: 0x0a, k: 0x09, a: 0x03, i: 0x22, n: 0x11},
  {c: 0x15, e: 0x2a, k: 0x29, a: 0x0e, i: 0x07, n: 0x0d, y: 0x49, q: 0x13, j: 0x0b, r: 0x23},
  {c: 0x55, e: 0xaa, k: 0x4b, a: 0x0f, i: 0x36, n: 0x17, y: 0x35, q: 0x39, j: 0x2b, r: 0x2e, t: 0x27, w: 0x1b, z: 0x33},
  {c: 0xea, e: 0xd5, k: 0xd6, a: 0xf1, i: 0xf8, n: 0xf2, y: 0xb6, q: 0xec, j: 0xf4, r: 0xdc},
  {c: 0xfa, e: 0xf5, k: 0xf6, a: 0xfc, i: 0xdd, n: 0xee},
  {c: 0xfe, e: 0xfd},
  {c: 0xff}
]
var nbrcnt = [1,2,6,10,13,10,6,2,1];
var nbrstr = "cekainyqjrtwz".split("");
var parsePartRule = function (pstr) {
  var pstr = pstr.split(""), index = -1, n = [[0],[0,0],[0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0],[0,0],[0]], nstr = "", m, invert, nh, exist = [false,false,false,false,false,false,false,false,false];
  for (var i = 0; i < 256; ++i) {
    table[i] = 0;
  }
  for (var i = pstr.length - 1; i >= 0; i--) {
    nstr += pstr[i];
    if (pstr[i] >= '0' && pstr[i] <= '8') {
      nh = +pstr[i];
      if (exist[nh]) { throw(Error("Repeated number found")); }
      exist[nh] = true
      invert = false
      m = nstr.length - 1;
      if (m === 0 || nh === 0 || nh === 8) { invert = true; } else {
        if (nstr[m - 1] === "-") {
          invert = true;
          m--;
        }
        for (var i2 = 0; i2 < m; ++i2) {
          var indstr = nbrstr.indexOf(nstr[i2]);
          n[nh][indstr] = 1
        }
      }
      if (invert) {
        for (var i3 = nbrcnt[nh]-1; i3 >= 0; i3--) { n[nh][i3] ^= 1; }
      }
      for (i3 = nbrcnt[nh]-1; i3 >= 0; i3--) { (m = n[nh][i3]) && add4f(nbrhd[nh][nbrstr[i3]], 1) }
      nstr = "";
    }
  }
  return table;
}
return (function (rstr) {
  rstr = rstr.replace(/\//g, "_");
  var params = rstr.split("_");
  if (params.length === 1) {params[1] = "";}
  if (params[0].charAt(0).toUpperCase() === "B" || params[1].charAt(0).toUpperCase() === "S") {
    syntax = [params[0], params[1]];
  } else {
    syntax = [params[1], params[0]];
  }
  var m2, arr, syntax;
  parsePartRule(syntax[0]); arr = table.slice();
  parsePartRule(syntax[1]); return [arr, table];
})(rule_str);
}
function random_rule() {
  var nbrcnt = [1,2,6,10,13,10,6,2,1];
  var nbrstr = "cekainyqjrtwz".split("");
  var b, i, j, k, s = "", t;
  for (b = 1; b >= 0; b--)
  {
    s += b ? "B" : "/S";
    for (i = b; i < 9; i++) {
      t = "";
      k = nbrcnt[i] - 1;
      for (j = 0; j <= k; j++) {
        if (Math.random() < 0.5)
          t += nbrstr[j];
      }
      if (t.length)
      {
        s += i;
        if (t.length <= k)
          s += t;
      }
    }
  }
  return s;
}

User avatar
PHPBB12345
Posts: 1096
Joined: August 5th, 2015, 11:55 pm
Contact:

Re: Computer programs

Post by PHPBB12345 » March 3rd, 2023, 7:12 am

Code: Select all

#include <algorithm>
#include <stdint.h>
#include <iostream>
#include <type_traits>

#if !(defined(__GNUC__) && defined(__x86_64__))
static uint64_t AddDiv64 (uint64_t a, uint64_t b, uint64_t m, uint64_t &s)
{
	s = a + b;
	uint64_t q = s < a || s >= m;
	s -= m & -q;
	return q;
}
#endif

void MulDiv32 (uint32_t a, uint32_t b, uint32_t m, uint32_t &q, uint32_t &r)
{
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
	__asm__("mull %3":"=a"(a),"=d"(b):"%a"(a),"rm"(b):"flags");
	__asm__("divl %4":"=a"(q),"=d"(r):"a"(a),"d"(b),"rm"(m):"flags");
#else
	uint64_t t = (uint64_t)a * (uint64_t)b;
	q = t / m;
	r = t - q * m;
#endif
}

void MulDiv64 (uint64_t a, uint64_t b, uint64_t m, uint64_t &q, uint64_t &r)
{
#if defined(__GNUC__) && defined(__x86_64__)
	__asm__("mulq %3":"=a"(a),"=d"(b):"%a"(a),"rm"(b):"flags");
	__asm__("divq %4":"=a"(q),"=d"(r):"a"(a),"d"(b),"rm"(m):"flags");
#else
	if (a < b) ::std::swap(a, b);
	uint64_t c = a / m, d, e;
	d = a - c * m;
	e = r = 0;
	q = b * c;
	while (b)
	{
		if (b & 1)
			q += e + AddDiv64(d, r, m, r);
		b >>= 1;
		if (!b)
			break;
		e += e + AddDiv64(d, d, m, d);
	}
#endif
}

template <typename T>
typename std::enable_if<std::is_unsigned<T>::value && (sizeof(T) <= 4)>::type
MulDiv (T a, T b, T m, T &q, T &r)
{
	uint32_t _q;
	uint32_t _r;
	MulDiv32((uint32_t)a, (uint32_t)b, (uint32_t)m, _q, _r);
	q = _q;
	r = _r;
}

template <typename T>
typename std::enable_if<std::is_unsigned<T>::value && (sizeof(T) == 8)>::type
MulDiv (T a, T b, T m, T &q, T &r)
{
	uint64_t _q;
	uint64_t _r;
	MulDiv64((uint32_t)a, (uint32_t)b, (uint32_t)m, _q, _r);
	q = _q;
	r = _r;
}

template <typename T>
typename std::enable_if<std::is_signed<T>::value && std::is_integral<T>::value>::type
MulDiv (T a, T b, T m, T &q, T &r)
{
	using U = std::make_unsigned<T>::type;
	U _a = ::std::abs(a);
	U _b = ::std::abs(b);
	U _m = ::std::abs(m);
	U _q;
	U _r;
	MulDiv(_a, _b, _m, _q, _r);
	q = _q;
	r = _r;
	if ((a ^ b) < 0)
	{
		q = -q;
		r = -r;
	}
}

int main ()
{
	uint64_t a, b, m, q, r;
	::std::cin >> a >> b >> m;
	MulDiv(a, b, m, q, r);
	::std::cout << q << " " << r;
	return 0;
}

User avatar
PHPBB12345
Posts: 1096
Joined: August 5th, 2015, 11:55 pm
Contact:

Hypergeometric series

Post by PHPBB12345 » April 16th, 2023, 3:12 am

Code: Select all

sqrt_impl(x)=hypergeom([-1/2],[],1-x)
pow_impl(x,y)=hypergeom([-y],[],1-x)
exp_impl(x)=hypergeom([],[],x)
log_impl(x)=(x-1)*hypergeom([1,1],[2],1-x)
sin_impl(x)=x*hypergeom([],[3/2],-x^2/4)
cos_impl(x)=hypergeom([],[1/2],-x^2/4)
tan_impl(x)=sin(x)/cos(x)
sinh_impl(x)=x*hypergeom([],[3/2],x^2/4)
cosh_impl(x)=hypergeom([],[1/2],x^2/4)
tanh_impl(x)=sinh(x)/cosh(x)
asin_impl(x)=x*hypergeom([1/2,1/2],[3/2],x^2)
acos_impl(x)=Pi/2-asin(x)
atan_impl(x)=x*hypergeom([1,1/2],[3/2],-x^2)
asinh_impl(x)=x*hypergeom([1/2,1/2],[3/2],-x^2)
acosh_impl(x)=log(2*x)-hypergeom([3/2,1,1],[2,2],1/x^2)/(4*x^2)
atanh_impl(x)=x*hypergeom([1,1/2],[3/2],x^2)

Post Reply