-
-
Notifications
You must be signed in to change notification settings - Fork 601
unify the three implementations of gaussian q-binomial coefficients #14496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
comment:1
Here is already a seemingly faster function. There remains to deprecate the two others. The most annoying one is q_bin, with a different syntax and with a global variable inside. |
comment:3
This looks good. It's certainly nice to have integer parameters giving integer results. But I also don't like the way (inherited from the existing code) that
is particularly bad style. It would make the code more readable to call them " |
comment:4
Here is a new version of the patch. I have modified the names d and n and introduced a try statement. I am not sure what kind of exceptions I need to catch. Still it remains to choose if one keeps the gaussian_binomial or rather the q_binomial function. |
Author: Frédéric Chapoton |
comment:6
So it's nearly ready for a positive review. |
comment:7
Here is a new patch. Point 1 is indeed a problem. I do not understand either what is computed in the weight function. The procedure q_bin was returning 1 for any negative values of n and any k. This is not a very natural behaviour. Point 4 : I have chosen that the name to be kept would be q_binomial. There is another problem remaining. The existing algorithm in sage.combinat.q_analogues uses cyclotomic polynomials and become faster than the naive one when the arguments are big (and of similar size ?), but is much slower in some cases (when n is small or k is small ?).
So one needs to keep both and find a strategy of choice.. |
comment:8
I'll take a look at why the weight function in SF fails; but the best way to fix it is in the weight, have a check for negative As for the speed of the naive vs. cyclotomic polys, I would pick a cutoff value which you think is about the breakeven point(s) for the two, and call which ever function is faster based on that. Also, have you tried implementing it by computing the q-binomial, then substituting in a user defined Thanks for noticing this and working on it, Travis |
comment:9
Good idea, I have done just that in the new patch, so there is no doctest failure now. There remains to choose a strategy.. |
comment:10
Some timings were given in the ticket #13166 According to my own timings, it seems that for n <= ~ 78 the naive algorithm is faster than the cyclotomic algorithm for computing the gaussian polynomial. |
comment:11
Replying to @fchapoton:
I get much the same. For One point about the naive method:
Since the code contains two loops of length |
comment:12
Here is a new patch
if n <= 70 or k <= N/4 or q is not a polynomial, use the naive algo otherwise use the cyclotomic algo I have found this strategy using some timings (I only timed the polynomial case). |
Reviewer: Francis Clarke, Travis Scrimshaw |
comment:15
Two points remain, I think:
|
comment:18
Hey Frederic and Francis, I've uploaded a review patch which does two things I wanted, an input for the algorithm and handling objects which may not have division (by computing it using a formal variable and then substituting in Best, Travis |
comment:19
hello, it seems to me that at the end you can write simply
because then the polygen import will be done inside the function |
comment:20
Attachment: trac_14496-qbinomial-review-ts.patch.gz Yep, that works. I've uploaded the updated patch. |
comment:21
I was about to say positive review, when I noticed two things:
|
comment:22
Point 2 is done. I vote to ignore point 1 (anyway, who cares about that ?) |
comment:23
Replying to @fchapoton:
Agreed. Positive review. |
comment:24
|
comment:25
ah, well, sorry. This is because I defined an alias in an incorrect way, using But what is the correct way ? |
comment:26
Hum, it seems that I have used the correct way to create an alias. But as the doc is duplicated (instead of saying that one function is an alias for the other), it will necessarily create a conflict any time it contains a reference. I am surprised that this problem has never been met before ! One can compare the situation to the definition of charpoly and characteristic_polynomial in sage.misc.functional, which does not contain a reference, hence dos not raise this problem. |
comment:27
There are two workarounds I can see:
Option 2 is more work and less clean IMO. Option 1 isn't perfect to me either but is the lesser of 2 evils. Up to you; either way would be okay with me. |
comment:29
ok, this should be good now. Back to positive review |
comment:30
Hey Frederic, Two minor things on the doc for
Otherwise I'm also happy with the patch. Thanks. |
Attachment: trac_14496-qbinomial-rev-rev-fc.patch.gz |
comment:31
Done, and thanks for the review |
Merged: sage-5.10.beta2 |
In sage 5.8, one can find the gaussian q-binomial coefficients in (at least) three places :
The syntax is not quite the same for q_bin as for the two others.
Some timings:
The parents :
The behaviour with an added integer parameter
The behaviour with a polynomial parameter
Maybe it would be better to have a single function ?
CC: @sagetrac-fwclarke @AndrewAtLarge
Component: combinatorics
Keywords: gaussian binomial
Author: Frédéric Chapoton
Reviewer: Francis Clarke, Travis Scrimshaw
Merged: sage-5.10.beta2
Issue created by migration from https://trac.sagemath.org/ticket/14496
The text was updated successfully, but these errors were encountered: