
f():=[]; //Echo(CurrentLine());

Verify( CatalanNumber(6), 132 ); f();
Verify( CatalanNumber(10), 16796 ); f();


Testing("Integer logarithms and roots");

Verify(IntLog(23^45, 67), 33); f();

Verify(IntLog(1, 67), 0); f();
Verify(IntLog(2, 67), 0); f();
Verify(IntLog(0, 67), 0); f();
Verify(IntLog(1, 1), Undefined); f();
Verify(IntLog(2, 1), Undefined); f();
Verify(IntLog(256^8, 4), 32); f();
Verify(IntLog(256^8-1, 4), 31); f();
Verify(IntNthRoot(65537^33, 11), 281487861809153); f();

Testing("Factorial");
Verify(261! - 261*260!, 0); f();
Verify(300! / 250!, 251***300); f();

Verify(Repunit(3), 111 ); f();
Verify(HarmonicNumber(5), 137/60 ); f();

Verify( Subfactorial(0), 1 ); f();
Verify( Subfactorial(21), 18795307255050944540 ); f();

Verify( Divisors(180), 18 ); f();


Verify( IsAmicablePair(200958394875 ,209194708485 ), True ); f();
Verify( IsAmicablePair(220,284),True ); f();

Verify( IsComposite(100), True ); f();
Verify( IsComposite(1), False ); f();
Verify( IsComposite(37), False ); f();

Verify( IsTwinPrime(71), True ); f();
Verify( IsTwinPrime(1), False ); f();
Verify( IsTwinPrime(22), False ); f();

Verify( DigitalRoot(18), 9 ); f();
Verify( DigitalRoot(15), 6 ); f();

Verify( IsIrregularPrime(37), True ); f();
Verify( IsIrregularPrime(59), True ); f();
Verify( IsIrregularPrime(1), False ); f();
Verify( IsIrregularPrime(11), False ); f();

Verify( Gcd( 324 + 1608*I, -11800 + 7900*I ),Complex(-52,16) ); f();
// I changed from Complex(-4,4) to Complex(4,4) as the GaussianGcd algorithm suddenly returned this instead.
// However, as it turned out it was a bug in FloorN, introduced when
// we moved to the new number classes (so the numbers did not get converted
// to string and back any more). The number got prematurely truncated with
// this test case (regression test added to regress.yts also).
Verify( Gcd( 7300 + 12*I, 2700 + 100*I), Complex(-4,4) ); f();

VerifyGaussianGcd(x,y):=
[
  Local(gcd);
  gcd:=Gcd(x,y);
//  Echo(x/gcd);
//  Echo(y/gcd);
  Verify(IsGaussianInteger(x/gcd) And IsGaussianInteger(y/gcd),True);
];
VerifyGaussianGcd(324 + 1608*I, -11800 + 7900*I);
VerifyGaussianGcd(7300 + 12*I, 2700 + 100*I);
VerifyGaussianGcd(120-I*200,-336+50*I);
//TODO we can expand this with randomized tests

Verify( Lcm({7,11,13,17}), 7*11*13*17 ); f();
Verify( IsCoprime(11,13), True ); f();
Verify( IsCoprime(1 .. 10), False ); f();
Verify( IsCoprime({9,40}), True ); f();

Verify( IsCarmichaelNumber( {561,1105,1729,2465,2821,6601,8911} ),{True,True,True,True,True,True,True} ); f();
Verify( IsCarmichaelNumber( {0,1,2,1727,2463,2823,6603} ),{False,False,False,False,False,False,False} ); f();

Verify(IsSmallPrime(137),True); f();
Verify(IsSmallPrime(138),False); f();
Verify(IsSmallPrime(65537),True); f();
Verify(IsSmallPrime(65539),False); f();
Verify(IsPrime(65539),True); f();
Verify(RabinMiller(1037),False); f();
Verify(RabinMiller(1038),False); f();
Verify(RabinMiller(1039),True); f();
Verify(NextPrime(65537), 65539); f();
Verify(NextPrime(97192831),97192841); f();
Verify(NextPrime(14987234876128361),14987234876128369); f();
Verify(IsPrime(0),False); f();
Verify(IsPrime(-1),False); f();
Verify(IsPrime(1),False); f();
Verify(IsPrime(2),True); f();
Verify(IsPrime(3),True); f();
Verify(IsPrime(4),False); f();
Verify(IsPrime(5),True); f();
Verify(IsPrime(6),False); f();
Verify(IsPrime(7),True); f();
Verify(IsPrime(-60000000000),False); f();
Verify(IsPrime(6.1),False); f();


Testing("Random numbers");
Local(r1, r2, r3, x1, x2, x3);

r1:=RngCreate();	// create a default RNG object, return structure
 f();
r2:=RngCreate(12345);	// create RNG object with given seed
 f();
RandomSeed(12345);	// initialize the global RNG with the same seed
 f();
r3:=RngCreate(seed->12345, engine->advanced, dist->gauss);	// test advanced options
 f();
Rng(r1); f();
Rng(r1); f();
x1:=Rng(r2); f();
Verify(x1, Random()); f();
x2:=Rng(r2); f();
x3:=Rng(r3); f();

Verify(Rng(r3)=x3, False); f();
Verify(x1=x2, False); f();
RngSeed(r2, 12345); f();
Verify(Rng(r2), x1);	// reproducible number
Verify(Rng(r2), x2);	// reproducible number
RngSeed(r3, 12345);
Verify(Rng(r3), x3);	// reproducible number
 f();
Verify(PartitionsP(1),1); f();
Verify(PartitionsP(2),2); f();
Verify(PartitionsP(3),3); f();
Verify(PartitionsP(4),5); f();
Verify(PartitionsP(13),101); f();
// This takes about 18 seconds, useful for benchmarking
//Verify( PartitionsP(4096), 6927233917602120527467409170319882882996950147283323368445315320451 );

Verify(Euler(16),19391512145); f();
Verify(EulerArray(8), {1,0,-1,0,5,0,-61,0,1385}); f();

Verify(JacobiSymbol(165,1), 1); f();
Verify(JacobiSymbol(1,3), 1); f();
Verify(JacobiSymbol(1,13), 1); f();
Verify(JacobiSymbol(2,15), 1); f();
Verify(JacobiSymbol(3,15), 0); f();
Verify(JacobiSymbol(7,15), -1); f();
Verify(JacobiSymbol(3,7), -1); f();
Verify(JacobiSymbol(0,3), 0); f();
Verify(JacobiSymbol(0,1), 1); f();
Verify(JacobiSymbol(1323132412,31312317), -1); f();
Verify(JacobiSymbol(57173571,1976575123), 1); f();
Verify(JacobiSymbol(-3,5), -1); f();
