Skip to content
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

Multi factorial #695

Merged
merged 4 commits into from
Feb 24, 2025
Merged

Multi factorial #695

merged 4 commits into from
Feb 24, 2025

Conversation

irevoire
Copy link
Contributor

@irevoire irevoire commented Feb 21, 2025

Hey, currently numbat doesn't handle multifactorial correctly, see the following screenshot:
image

This should in fact returns (5 * 3 * 1): https://en.wikipedia.org/wiki/Double_factorial#Generalizations

This PR adds support for all multifactorial, it's a breaking change though since numbat was already accepting the expression.

@@ -169,6 +169,12 @@ fn test_factorial() {
expect_output("-5!", "-120");
expect_output("-(5!)", "-120");
expect_output("-(5)!", "-120");
expect_output("5!!", "15");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expand at least the double-factorial tests a bit more and include some edge cases, as well as an example for even numbers. And maybe we could write the tests in a way that it's easy to see that we get the desired result. By moving them to a Numbat-source test suite? Something like

assert_eq(7!!, 7 * 5 * 3 * 1)
assert_eq(8!!, 8 * 4 * 2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, that should be done in fb066f0

Could you confirm me that we cannot write an assert in a function in numbat currently?
I wanted to write a more « procedural » test with a recursive function that assert at each step that the function works on all numbers from 0 to 10 with multiple orders but then I didn’t see how to do it 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that it isn't currently possible. I wanted to make a function to encapsulate a repeating pattern in the tests I wrote and learned it wasn't possible yet.
There was some talk about the possibility of numbat having macros for such cases, but that's still just an idea.

Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much, this looks great. I'm not concerned about the breaking change.

@irevoire irevoire requested a review from sharkdp February 23, 2025 22:16
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@sharkdp sharkdp merged commit 5753fde into sharkdp:master Feb 24, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants