Function of #cas
factorial
The factorial of a natural number, with a theorem about Mathlib’s Nat.factorial.
#cas (factorial n)Nat.factorial n = f.factorial computes and proves the value of Mathlib’s Nat.factorial. It’s a small call, but the number you see is the number Mathlib means, so a proof can use it as it stands. When you need the factorial beyond the natural numbers, gamma extends it, with .
Examples (11)#
Basic Examples (1)
Ten factorial, with the theorem that the kernel checked:
#cas (factorial 10)
factorial
3628800- Domain
ℕ- Input (natural numbers)
10
Checked by Lean’s kernel: factorial
Nat.factorial 10 = 3628800
The certificate: 1 checked step
factorial
Nat.factorial 10 = 3628800
Scope (4)
A value with 33 digits:
#cas (factorial 30)
factorial
265252859812191058636308480000000- Domain
ℕ- Input (natural numbers)
30
Checked by Lean’s kernel: factorial
Nat.factorial 30 = 265252859812191058636308480000000
The certificate: 1 checked step
factorial
Nat.factorial 30 = 265252859812191058636308480000000
The empty product, :
#cas (factorial 0)
factorial
1- Domain
ℕ- Input (natural numbers)
0
Checked by Lean’s kernel: factorial
Nat.factorial 0 = 1
The certificate: 1 checked step
factorial
Nat.factorial 0 = 1
In ℕ the subtraction is truncated to 0, so the argument is 3:
#cas (factorial ((1 - 2 : ℕ) + 3))
factorial
6- Domain
ℕ- Input (natural numbers)
3
Checked by Lean’s kernel: factorial
Nat.factorial 3 = 6
The certificate: 1 checked step
factorial
Nat.factorial 3 = 6
In ℤ the subtraction gives , and the argument is 2:
#cas (factorial ((1 - 2 : ℤ) + 3))
factorial
2- Domain
ℕ- Input (natural numbers)
2
Checked by Lean’s kernel: factorial
Nat.factorial 2 = 2
The certificate: 1 checked step
factorial
Nat.factorial 2 = 2
Applications (1)
Properties and Relations (2)
, so gamma at 5 gives :
#cas (gamma 5)
exact value of Γ
24- Input (rational number)
5
Checked by Lean’s kernel: Gamma by a closed formula
Real.Gamma 5 = 24
The certificate: 1 checked step
Gamma by a closed formula
Real.Gamma 5 = 24
extends the factorial to the half-integers, with :
#cas (gamma (7/2))
exact value of Γ
15√π/8- Input (rational number)
7/2
Checked by Lean’s kernel: Gamma by a closed formula
Real.Gamma (7 / 2) = 15 * √Real.pi / 8
The certificate: 1 checked step
Gamma by a closed formula
Real.Gamma (7 / 2) = 15 * √Real.pi / 8
Possible Issues (3)
Nat.factorial is defined on natural numbers, and a negative argument is refused:
#cas (factorial (-1))
Error
factorial takes a natural number as its argument; `-1` is negative
The ascriptions of an integer argument are ℕ and ℤ, and the ascription ℝ is refused even when the value is an integer:
#cas (factorial (3 : ℝ))
Error
factorial takes integer arguments; `(3 : ℝ)` has the type `ℝ`, and the ascriptions of an integer argument are `ℕ` and `ℤ`
The value has at most 10000 digits, and has 16326:
#cas (factorial 5000)
Error
factorial: the value has more than 10000 digits, the most that a call computes
