SquareFreeQ, PrimePowerQ, KroneckerSymbol, ChineseRemainder, and PrimitiveRoot have been added to the built-in Mathematica kernel functions.
NextPrime and PreviousPrime are now available as the newly added built-in Mathematica kernel function NextPrime.
Random[Prime,…] is now available as the newly added built-in Mathematica kernel function RandomPrime.
The functionality of PrimeFactorList is available in the enhanced built-in Mathematica kernel function FactorInteger.
SqrtMod is now available as the built-in Mathematica kernel function PowerMod.
SqrtModList is now available as the newly added built-in Mathematica kernel function PowerModList.
ClassNumber is now available as the newly added built-in Mathematica kernel function NumberFieldClassNumber.
SumOfSquaresR is now available as the built-in Mathematica kernel function SquaresR.
OrderedSumOfSquaresRepresentations is now available as the built-in Mathematica kernel function PowersRepresentations.
SquareFreeQ
A product of distinct primes contains no squared factors:
SquareFreeQ[2 * 3 * 5 * 7]NextPrime and PreviousPrime
The next prime after one million:
NextPrime[1000000]The last prime before one million:
NextPrime[1000000, -1]Random[Prime, ...]
A random prime number between 10 and 100:
RandomPrime[{10, 100}]PrimeFactorList
Find the list of prime factors of a rational number:
FactorInteger[713 / 41][[All, 1]]PrimePowerQ
Here is a number that is a power of a single prime:
PrimePowerQ[12167]ChineseRemainder
The smallest positive integer x so that x is equal to 3 modulo 4 and x is equal to 4 modulo 5:
ChineseRemainder[{3, 4}, {4, 5}]SqrtMod and SqrtModList
This finds the smallest non-negative integer
so that
is equal to 3 modulo 11:
PowerMod[3, 1 / 2, 11]This returns all integers less than 11 that satisfy the relation:
PowerModList[3, 1 / 2, 11]ClassNumber
Find the class number for the algebraic number field
generated by
:
NumberFieldClassNumber[Sqrt[-10099]]FundamentalDiscriminantQ
FundamentalDiscriminantQ can be replaced by the following definition:
FundamentalDiscriminantQ[n_] :=
n ≠ 1 && Mod[n, 4] == 1 && SquareFreeQ[n] ||
!(Mod[n, 16] ≠ 8 ≠ 12) && SquareFreeQ[Quotient[n, 4]]
FundamentalDiscriminantQ[3243601]ClassList
ClassList can be replaced by the following definition:
ClassList[n_ ? Negative] :=
Select[Flatten[#, 1]&@Table[
{i, j, (j ^ 2 - n) / (4i)}, {i, Sqrt[-n / 3]}, {j, 1 - i, i}],
Mod[#3, 1] == 0 && #3 ≥ # && GCD[##] == 1 && !(# == #3 && #2 < 0)&@@#&]
ClassList[-403]KroneckerSymbol
KroneckerSymbol[5, 3]SumOfSquares
Number of ways to represent 100 as a sum of 3 squares:
SquaresR[3, 100]SumOfSquaresRepresentations
SumOfSquaresRepresentations can be replaced by the following definition:
SumOfSquaresRepresentations[d_, n_] := Module[{x, a, sol}, a = Array[x, d];
sol = Reduce[a.a == n, a, Integers];If[sol === False, {}, a /. {ToRules[sol]}]]SumOfSquaresRepresentations[3, 100]OrderedSumOfSquaresRepresentations
Here is an ordered list of the representations of 100 as a sum of 3 squares:
Reverse /@ PowersRepresentations[100, 3, 2]LeastPrimeFactor
LeastPrimeFactor can be replaced by the following definition:
LeastPrimeFactor[n_Integer /; n > 1] :=
Prime@NestWhile[# + 1&, 1, Mod[n, Prime[#]] ≠ 0&]
LeastPrimeFactor[3243601]QuadraticRepresentation
QuadraticRepresentation can be replaced by the following definition:
QuadraticRepresentation[d_, n_] := Module[{x, y, ans},
ans = FindInstance[{x ^ 2 + d y ^ 2 == n, x ≥ 0, y ≥ 0}, {x, y}, Integers, 1];
({x, y} /. ans[[1]]) /; Head@ans =!= FindInstance]
QuadraticRepresentation[3, 4410796736359]Verify that this is indeed one of the possible representations:
{1, 3}.% ^ 2 == 4410796736359SumOfFactors
Compute the sum of factors of
that are less than
:
DivisorSigma[1, 360] - 360WhichRootOfUnity
WhichRootOfUnity can be replaced by the following definition:
WhichRootOfUnity[z_] := Module[{d, ans},
If[z == 1, Return[{1, 1}]];
(ans = FullSimplify[Arg[z] / (2Pi)];
{d = Denominator[ans], Mod[Numerator[ans], d]} /;
MatchQ[ans, _Rational]) /;
PossibleZeroQ[Abs[z] - 1]]
WhichRootOfUnity[Sqrt[(5 - Sqrt[5]) / 8] - I(1 + Sqrt[5]) / 4]AliquotSequence
AliquotSequence can be replaced by the following definition:
AliquotSequence[n_] :=
NestWhileList[DivisorSigma[1, #] - #&, n, Unequal[##, 0]&, All]
AliquotSequence[220]AliquotCycle
AliquotCycle can be replaced by the following definition:
AliquotCycle[n_] :=
NestWhileList[DivisorSigma[1, #] - #&, n, Unequal[##, 0]&, All] /.
{{___, 0} :> {0},
{___, i_, s___, i_} :> RotateLeft[{i, s},
Position[{i, s}, Min@{i, s}, {1}, 1][[1, 1]] - 1]}
AliquotCycle[562]The original package is now available on the web at library.wolfram.com/infocenter/MathSource/6774.