Parity

Author

Eric W. Weisstein
July 18, 2023

This notebook downloaded from http://mathworld.wolfram.com/notebooks/NumberTheory/Parity.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/Parity.html.

©2023 Wolfram Research, Inc. except for portions noted otherwise

Algorithms

Parity[n_]:=Mod[Total[IntegerDigits[n,2]],2]

Parity2[n_]:=Mod[DigitCount[n,2,1],2]

bug(285532): Optimize DigitCount[n, 2, 1])

Parity3[n_]:=Mod[Internal`BitCount[n],2]

ParityEvenOdd[n_]:=Mod[n,2]

Parity

par1=Array[Parity,(10^6)];//Timing

Parity2

par2=Array[Parity2,(10^6)];//Timing

par1===par2

par2list=Mod[DigitCount[Range[(10^6)],2,1],2];//Timing

par2list===par1

Parity3

par3=Array[Parity3,(10^6)];//Timing

par3===par1

par3list=Mod[Internal`BitCount[Range[(10^6)]],2];//Timing

par3list===par1

Table

Array[Parity,20]

Flatten/@Transpose[Partition[Table[{n,Parity[n]},{n,30}],10]]//TableForm

Recurrences

a[0]:=0
a[n_?EvenQ]:=a[n/2]
a[n_?OddQ]:=1-a[(n-1)/2]

Array[a,10]

Sums

P==(Mod[((∑_(k=0)^n)(Mod[(Binomial[n, k]), 2])), 3])-1

Sum[Mod[Binomial[n,k],2],{k,0,n}]

Table[-1+Mod[Sum[Mod[Binomial[n,k],2],{k,0,n}],3],{n,10}]

Generating Functions

(1/(1-x)-Product[1-x^(2^k),{k,0,∞}])/2

Series[(1/(1-x)-Product[1-x^(2^k),{k,0,20}])/2,{x,0,20}]

CoefficientList[%,x]

V10

$Version

(1/(1-x)-Product[1-x^(2^k),{k,0,∞}])/2

Thue-Morse

N[FromDigits[{Table[Parity[n],{n,1000}],-1},2],20]

N[Sum[Parity[n]/2^n,{n,0,100}]/2,20]

RealDigits[0.412454033640107597783361368258377`20,2]

Sum Identity

s[n_,r:0]:=Table[((-1)^Parity[k])(k+r)^n,{k,0,2^(n+1)-1}]

r=0

Table[Plus@@s[n],{n,10}]

Table[Plus@@s[n],{n,10}]

s[2]

Others r's

Table[Plus@@s[n,3],{n,10}]

Table[Plus@@s[n,11],{n,10}]