Zulip Chat Archive

Stream: Is there code for X?

Topic: Double factorials


Jake Levinson (May 11 2023 at 20:54):

I'm going to introduce a PR for double factorials shortly, intended for use in a later PR on an explicit formula for the coefficient of a Hermite polynomial. Any suggestions on API? Here's the working definition:

@[simp] def double_factorial :   
| 0       := 1
| 1       := 1
| (k + 2) := (k + 2) * double_factorial k

notation n `‼`:10000 := double_factorial n -- this is \!! not two !'s

So far I only plan to have

lemma double_factorial_def (n : ) : (n + 2)  = (n + 2) * n  := rfl
lemma double_factorial_def' (n : ) : (n + 1)  = (n + 1) * (n - 1)  := by { cases n; refl }

Adam Topaz (May 11 2023 at 20:59):

maybe n!!(n+1)!!=(n+1)!n!! * (n+1)!! = (n+1)! is another useful lemma? Where do these show up besides Hermite polynomials? Is the genrealization from parity to congruence modulo mm for general mm useful at all?

Jake Levinson (May 11 2023 at 21:05):

Hmm, I think of double factorials as showing up in combinatorics. For example there are (2n+1)!!(2n+1)!! leaf-labeled trivalent trees on n+3n+3 labels. (Also the moduli space of genus 0 stable curves.)

Jake Levinson (May 11 2023 at 21:06):

They also come up in Catalan combinatorics, which means they get involved in various objects that involve associativity.

Jake Levinson (May 11 2023 at 21:08):

Hmm, another useful lemma would be (2n)!!=2nn!(2n)!! = 2^n n!.

I don't think I've encountered the variant with congruence mod mm.

Adam Topaz (May 11 2023 at 21:09):

I see. Maybe some of our resident combinatorialists (I'm certainly not one of them ;)) have some ideas as well?

Kyle Miller (May 11 2023 at 21:16):

We should probably have double_factorial n = prod i in range ((n + 1) / 2), (n - 2*i), or whatever the correct statement is

Jake Levinson (May 11 2023 at 21:22):

Ugh, nat.sub

Jake Levinson (May 11 2023 at 21:22):

How about a subtraction-free version (dependent on whether n is even or odd)?

Kyle Miller (May 11 2023 at 21:45):

I'd be happy with a (2n)!!(2n)!! and a (2n+1)!!(2n+1)!! formula (that way it also avoids nat division)

Yaël Dillies (May 11 2023 at 21:51):

Can we skip double factorials and directly go to m-factorials? 1-factorials are factorials, 2-factorials are double factorials, etc... Most of the lemmas you can write about double factorials directly generalise to those.

Adam Topaz (May 11 2023 at 22:01):

That's what I meant about congruence mod m above. Where do these m factorials show up (just curious)?

Kyle Miller (May 11 2023 at 22:12):

For general $m$, I think mostly you see mnn!m^nn! for the "mm-factorial" of mnmn, and they quickly show up when you do things with the generalized binomial theorem. I'm not sure I've really encountered the other m1m-1 of them.

Kyle Miller (May 11 2023 at 22:13):

though a priori they're a way to partition a factorial into mm products, which seems like it must have been useful to someone at some point

Eric Wieser (May 11 2023 at 22:44):

I don't think replacing nat.factorial with nat.factorial' 1 is worth the churn (especially mid-port), but I can see the appeal of skipping 2-factorials and having just the 1- special case and the general n- version.

Jake Levinson (May 11 2023 at 22:45):

I asked a combinatorialist colleague and she had never encountered the $m$-variation. One thing that's special about m=2m=2 is that the formula @Adam Topaz gave, combined with the formula I gave, means that both (2n)!!(2n)!! and (2n+1)!!(2n+1)!! show up individually in various formulas where you can divide out a power of 2. In contrast for m>2m > 2 I don't know where the other terms would show up individually.

Eric Wieser (May 11 2023 at 22:54):

Don't all the formulae up-thread hold with the 2s replaced with mm?

Kyle Miller (May 11 2023 at 23:04):

No, n!m(n+1)!m=(n+1)!n!_m \cdot (n+1)!_m = (n+1)! doesn't hold (I replaced 2 with mm), though n!m(n+1)!m(n+m1)!m=(n+m1)!n!_m\cdot(n+1)!_m\cdots (n+m-1)!_m=(n+m-1)! does (I made up the notation here).

When m=2m=2 the reason (n+1)!!(n+1)!! seems to be interesting is that it's the complement of n!!n!! in (n+1)!(n+1)!, like Jake said.

Kyle Miller (May 11 2023 at 23:06):

Besides it seeming like there's no math about it yet, one reason against defining nat.factorial' is the question of what nat.factorial' 0 should be...

Adam Topaz (May 11 2023 at 23:38):

n!0n!_0 is the empty product, right? So it should be 1?

Adam Topaz (May 11 2023 at 23:39):

Isn’t there some generalized gamma function behind the scenes? That should give us a hint about what this should be.

Kyle Miller (May 11 2023 at 23:42):

Isn't the formula n!m=n(nm)(n2m)n!_m = n(n-m)(n-2m)\cdots where the product continues until you get to something less than mm? There are roughly n/mn/m terms, so n!0n!_0 is the infinite product n(n0)(n20)(n30)n(n-0)(n-2\cdot 0)(n-3\cdot 0)\cdots

Adam Topaz (May 11 2023 at 23:45):

Maybe it’s just n? I was thinking of the fact that Z/0 is Z, so when you take the product of all ints between 1 and n which are congruent mod 0 to n, you get just n. (The gamma function has a shift in the relationship with the factorial, so maybe it does end up being an empty product from that point of view, I don’t know.)

Kyle Miller (May 11 2023 at 23:50):

We could look at (mn)!m=mnn!(mn)!_m = m^nn!, so reparameterizing that's (a)!b=ba/b(a/b)!(a)!_b=b^{a/b}(a/b)! and you can use a gamma function there to extend it. I wonder if the b0b\to 0 limit converges here?

Kyle Miller (May 11 2023 at 23:57):

Oh, that can't be the right formula... According to this, (5)!2=15π/2(5)!_2 = 15\sqrt{\pi/2} rather than 1515 :smile:

Anyway, if it were correct then we'd get (0)!0=1(0)!_0=1, (1)!0=0(1)!_0=0, (2)!0=0(2)!_0=0, and then (a)!0=(a)!_0=\infty for a3a\geq 3.

Jake Levinson (May 12 2023 at 06:23):

#18994

Jake Levinson (May 12 2023 at 06:29):

This has the lemmas suggested by @Adam Topaz and @Kyle Miller, but not multifactorials.

Jake Levinson (May 12 2023 at 06:31):

For what it's worth, many of these other generalizations can be formulated as ∏ i in finset.range n, whatever, if they are ever needed. For now, my intended use case is the odd double factorial (which seems to be the one I've encountered most often).

Kevin Buzzard (May 12 2023 at 07:36):

Yeah from the point of view of the gamma function I think the even and odd double factorials are two different functions which interpolate in two different ways


Last updated: Dec 20 2023 at 11:08 UTC