Zulip Chat Archive
Stream: new members
Topic: the prime factorization of `n`
Nga Ngo (Mar 12 2019 at 03:58):
I don't understand this codes in Lean Library (data nat prime.lean -line 233-239)
/-- factors n
is the prime factorization of n
, listed in increasing order. -/
def factors : ℕ → list ℕ
| 0 := []
| 1 := []
| n@(k+2) :=
let m := min_fac n in have n / m < n := factors_lemma,
m :: factors (n / m)
What is n@(k+2) ?
Could someone explain for me? Thanks.
Mario Carneiro (Mar 12 2019 at 04:01):
It's a pattern match, so we are in the case where n = k+2
. The n@
notation allows us to also give a name to k+2
, the original argument of the function; you can replace n
with k+2
everywhere and it would be the same
Mii Nguyen (Mar 12 2019 at 04:19):
@Mario Carneiro what does it mean in have
in the loop?
Mario Carneiro (Mar 12 2019 at 04:20):
it's two statements:
let m := min_fac n in have n / m < n, from factors_lemma, m :: factors (n / m)
Last updated: Dec 20 2023 at 11:08 UTC