Skip to content

[fft] Add fused graeffe engine primitive - #87

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1786977962-fused-graeffe
Open

[fft] Add fused graeffe engine primitive#87
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1786977962-fused-graeffe

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds E::graeffe(t, n) -> product to the engine contract: the size-n/2 even half of A(x) * A(-x) (one Graeffe/root-squaring step), semantically downsample(mul(t, negate_arg(t, n), n), n/2, false) but fused so engines can skip materializing the negated transform, the full-size pointwise product, and the separate downsample pass.

The fusion exploits that the product takes the same value A(w) A(-w) at the paired entries 2u, 2u+1 (which hold A at +-w in the bit-reversed convention):

  • ntt: p[u] = t[2u] * t[2u+1] — one mult per output, no halving, no inv_rt twist.
  • real: each A(w) A(-w) is already a plain spectrum value of the halved (real) result, so the pass computes (x + w y)(x - w y) per packed entry and repacks adjacent pairs with one retangle per output (mul's retangle degenerates since p0 == p1).
  • split: inlines the negate shuffle (b[i] = t[i^1]) and the even-half average into mul_impl's conjugate-symmetry unpacking pass.
  • crt delegates per prime; the algebra wrappers (matrix/trunc/*_stable) use the generic composition, which stays correct for the non-commutative case (the fused single-product form assumes commutativity).

Call sites switched: packed_bivariate::advance (the ps_compose Graeffe loop; negate_arg is still computed there since the caller needs the transform of Q(-x, y)) and the Q <- even part of Q(x) Q(-x) update in kth_term_of_rational_function. This saves O(n) work per level/iteration — a constant-factor win on the lower-order pointwise passes, not on the n log^2 n transform term.

New graeffe TEMPLATE_TEST_CASE covers all base engines at n = 2, 16, 64 against the slow product's even coefficients mod x^n - 1 (121 tests pass).

Link to Devin session: https://app.devin.ai/sessions/7d41aa62f31e4620807608a6e6afcc94
Requested by: @ecnerwala


Open in Devin Review (Beta)

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Co-Authored-By: Andrew He <he.andrew.mail@gmail.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1786977962-fused-graeffe branch from c6d77ef to 095004b Compare August 17, 2026 16:47
@github-actions

Copy link
Copy Markdown

GCC Code Coverage Report

📂 Overall coverage

Metric Coverage
Lines 🟡 8211/10013 (82.0%)
Functions 🟢 1122/1227 (91.4%)
Branches 🟡 6418/8290 (77.4%)

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.

0 participants