Skip to content

Keep Factorial method and add tests to verify precalculated constants#117

Merged
konard merged 4 commits intomainfrom
issue-59-4b426f16
Apr 14, 2026
Merged

Keep Factorial method and add tests to verify precalculated constants#117
konard merged 4 commits intomainfrom
issue-59-4b426f16

Conversation

@konard
Copy link
Copy Markdown
Member

@konard konard commented Sep 13, 2025

Summary

Based on feedback on this PR, the Factorial method should be kept so we can always verify that our precalculated constants are really correct factorials.

This PR adds tests that:

  • Independently compute factorial values using BigInteger arithmetic (no overflow)
  • Verify all precalculated _factorials constants match the computed values
  • Independently compute Catalan numbers using the formula C(n) = (2n)! / ((n+1)! * n!)
  • Verify all precalculated _catalans constants match the computed values
  • For values whose local computation exceeds 10 seconds, make real HTTP requests to OEIS to fetch and verify the expected value:
    • Factorials: OEIS A000142 (https://oeis.org/A000142/b000142.txt)
    • Catalan numbers: OEIS A000108 (https://oeis.org/A000108/b000108.txt)

In practice, all values for n ≤ 36 (the current MaximumCatalanIndex) compute locally in under 1ms — but the OEIS fallback ensures correctness even if the range is extended in future.

Test Plan

  • PrecalculatedFactorialsMatchComputedValues — verifies all 21 factorial constants (0! through 20!) match independently computed BigInteger values; falls back to OEIS A000142 via HTTP if computation exceeds 10s
  • PrecalculatedCatalansMatchComputedFactorials — verifies all 37 Catalan constants (C(0) through C(36)) match independently computed BigInteger values; falls back to OEIS A000108 via HTTP if computation exceeds 10s
  • All existing tests continue to pass
  • Build succeeds with no errors

Fixes #59

🤖 Generated with Claude Code

@konard konard self-assigned this Sep 13, 2025
@konard konard changed the title [WIP] Factorial method is not used anymore in the LinksPlatform, can we delete it? Remove unused Factorial method and related code Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 22:51
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

I thinks we should keep it, at least for all the tests and benches, so we are always sure our pre-calculated constants are really factorials. But also we should not use to much computation if it takes too long, only for parts that will take less than 10 seconds, after that we should use some external trusted resources to verify the big factorial numbers, but only if any of them will be calculated longer than 10 seconds.

@konard konard marked this pull request as draft April 14, 2026 14:16
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-04-14T14:16:29.883Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

Adds two tests that independently compute factorial and Catalan numbers
using BigInteger arithmetic and verify they match the precalculated
constants in Math._factorials and Math._catalans. Computations that
exceed 10 seconds are skipped with a note to use external resources
(OEIS A000142 for factorials, OEIS A000108 for Catalan numbers).

Fixes #59

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard force-pushed the issue-59-4b426f16 branch from 86eefa9 to c7b9418 Compare April 14, 2026 14:20
@konard konard changed the title Remove unused Factorial method and related code Keep Factorial method and add tests to verify precalculated constants Apr 14, 2026
@konard konard marked this pull request as ready for review April 14, 2026 14:20
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

Thanks for the feedback! I've updated this PR to:

  1. Keep the Factorial method — reverted the removal entirely
  2. Add validation tests that use BigInteger arithmetic to independently verify that both the _factorials and _catalans precalculated constants are correct:
    • PrecalculatedFactorialsMatchComputedValues — computes each n! using BigInteger and asserts it matches Math.Factorial(n)
    • PrecalculatedCatalansMatchComputedFactorials — computes each C(n) using the formula C(n) = (2n)! / ((n+1)! × n!) with BigInteger and asserts it matches Math.Catalan(n)
  3. 10-second time limit — computations are bounded by a 10-second timeout. If any exceed it, the test skips that value and notes that an external trusted resource should be used (OEIS A000142 for factorials, OEIS A000108 for Catalan numbers). In practice, all values for the current ranges (n ≤ 20 for factorials, n ≤ 36 for Catalans) complete in under 1ms.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $0.983591

📊 Context and tokens usage:

  • Context window: 60.4K / 1M (6%) input tokens, 11.1K / 64K (17%) output tokens

Total: (49.5K + 2.1M cached) input tokens, 11.1K output tokens, $0.983591 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (1195KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🔄 Auto-restart triggered (iteration 1)

Reason: CI failures detected

Starting new session to address the issues.


Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable.

…add missing newline

Replace XML summary comments on private helper methods with regular line
comments (matching existing code style in BitTests.cs/SystemTests.cs),
and add missing newline at end of file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🔄 Auto-restart-until-mergeable Log (iteration 1)

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $0.683436

📊 Context and tokens usage:

Claude Sonnet 4.6:

  • Context window: 50.5K / 1M (5%) input tokens, 7.5K / 64K (12%) output tokens

Total: (39.8K + 1.3M cached) input tokens, 7.5K output tokens, $0.653584 cost

Claude Haiku 4.5:

Total: 20.4K input tokens, 870 / 64K (1%) output tokens, $0.029852 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Main model: Claude Sonnet 4.6 (claude-sonnet-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (3103KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

Screenshot 2026-04-14 at 7 53 57 PM

See screenshot for Codacy issues.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🔄 Auto-restart triggered (iteration 2)

Reason: CI failures detected

Starting new session to address the issues.


Auto-restart-until-mergeable mode is active. Will continue until PR becomes mergeable.

…talanWithTimeLimit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🔄 Auto-restart-until-mergeable Log (iteration 2)

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $0.371948

📊 Context and tokens usage:

  • Context window: 38.1K / 1M (4%) input tokens, 4.3K / 64K (7%) output tokens

Total: (26.4K + 693.3K cached) input tokens, 4.3K output tokens, $0.371948 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (4766KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

Skip computations that would exceed 10 seconds, noting that those values should be verified via external trusted resources (OEIS A000142 for factorials, OEIS A000108 for Catalan numbers)

We need to actually do it in our tests, using real http requests to OEIS.

@konard konard marked this pull request as draft April 14, 2026 14:52
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-04-14T14:52:44.700Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

… times out

When local BigInteger computation exceeds the 10-second limit, the expected
value is now fetched from the authoritative OEIS b-files via real HTTP requests:
- Factorials: OEIS A000142 (https://oeis.org/A000142/b000142.txt)
- Catalan numbers: OEIS A000108 (https://oeis.org/A000108/b000108.txt)

This replaces the previous behaviour of silently skipping those values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard marked this pull request as ready for review April 14, 2026 14:55
@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $0.590521

📊 Context and tokens usage:

  • Context window: 51.8K / 1M (5%) input tokens, 8.1K / 64K (13%) output tokens

Total: (40.0K + 1.1M cached) input tokens, 8.1K output tokens, $0.590521 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Model: Claude Sonnet 4.6 (claude-sonnet-4-6)

📎 Log file uploaded as Gist (821KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Member Author

konard commented Apr 14, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@konard konard merged commit 6b486ca into main Apr 14, 2026
2 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.

Factorial method is not used anymore in the LinksPlatform, can we delete it?

1 participant