Function of #cas

eulerPhi

Euler’s totient φ(n), the number of residues modulo n coprime to n, with a theorem about Mathlib’s Nat.totient.

#cas (eulerPhi n)
gives Euler’s totient φ(n) of the natural number n, the number of 0≤i<n coprime to n, and proves Nat.totient n = t.

eulerPhi computes Euler’s totient, the number of residues modulo n that are coprime to n. The theorem is about Mathlib’s Nat.totient itself, not a function of our own, so a proof about the totient can use the printed value directly.

Details and Options

  • n is a natural number, a literal or a closed integer expression such as 2 ^ 10. φ(0)=0 and φ(1)=1.
  • The theorem is Nat.totient n = t. CAS.NumberTheory.totient_eq_rangeSum writes φ(n) as a sum of indicators of gcd(n,d)=1 over [0,n), which the kernel evaluates. This route takes n≤100000.
  • A closed expression is evaluated with numbers of at most 10000 digits, the most that a call computes.
  • The call is evaluated when it is the whole input of #cas.
  • There are no options.

Examples (8)#

Basic Examples (1)

Forty of the residues modulo 100 are coprime to 100, and the theorem says so:

In[1]:=
#cas (eulerPhi 100)
Out[1]=

eulerPhi

40
Domain
ℕ
Input (natural numbers)
100

Checked by Lean’s kernel: eulerPhi

Nat.totient 100 = 40
The certificate: 1 checked step
  1. eulerPhi

    Nat.totient 100 = 40

    Checked by Lean’s kernel

Scope (3)

A closed integer expression is evaluated first. Modulo 210 the coprime residues are the odd ones, half of them:

In[2]:=
#cas (eulerPhi (2 ^ 10))
Out[2]=

eulerPhi

512
Domain
ℕ
Input (natural numbers)
1024

Checked by Lean’s kernel: eulerPhi

Nat.totient 1024 = 512
The certificate: 1 checked step
  1. eulerPhi

    Nat.totient 1024 = 512

    Checked by Lean’s kernel


Mathlib sets φ(0)=0:

In[3]:=
#cas (eulerPhi 0)
Out[3]=

eulerPhi

0
Domain
ℕ
Input (natural numbers)
0

Checked by Lean’s kernel: eulerPhi

Nat.totient 0 = 0
The certificate: 1 checked step
  1. eulerPhi

    Nat.totient 0 = 0

    Checked by Lean’s kernel


An expression may pass through large numbers, here 109000, and the argument is its value, 100:

In[4]:=
#cas (eulerPhi (10 ^ 9000 / 10 ^ 8998))
Out[4]=

eulerPhi

40
Domain
ℕ
Input (natural numbers)
100

Checked by Lean’s kernel: eulerPhi

Nat.totient 100 = 40
The certificate: 1 checked step
  1. eulerPhi

    Nat.totient 100 = 40

    Checked by Lean’s kernel

Applications (1)

In a proof, cas proves the equation. Only the three standard axioms are used:

In[5]:=
theorem totient_thirty_six : Nat.totient 36 = 12 := by
  cas

#print axioms totient_thirty_six
Out[5]=

totient_thirty_six depends on the axioms propext, Classical.choice, Quot.sound.

Properties and Relations (1)

The product formula φ(n)=n/∏p·∏(p−1) runs over the distinct prime factors p of n. For 360=23·32·5 it gives 36030·1·2·4=96:

In[6]:=
#cas (eulerPhi 360)
Out[6]=

eulerPhi

96
Domain
ℕ
Input (natural numbers)
360

Checked by Lean’s kernel: eulerPhi

Nat.totient 360 = 96
The certificate: 1 checked step
  1. eulerPhi

    Nat.totient 360 = 96

    Checked by Lean’s kernel

Possible Issues (2)

The expression 10 ^ 10000 / 10 ^ 9998 has the value 100, but 1010000 has 10001 digits:

In[7]:=
#cas (eulerPhi (10 ^ 10000 / 10 ^ 9998))
Out[7]=

Error

eulerPhi: `10 ^ 10000` has more than 10000 digits, the most that a call computes

A call inside another call is not evaluated, since gamma is evaluated only as the whole input of #cas:

In[8]:=
#cas (eulerPhi (gamma 3))
Out[8]=

Error

eulerPhi takes integer arguments; `gamma x` is evaluated as the whole input of `#cas (gamma x)`

See Also

divisorSigma · moebiusMu · factorInteger · divisors · powerMod