Skip to content

Add integration test for MatExpr.dft with complex twiddle factors #17

@Oppen

Description

@Oppen

Currently, the DFT integration test (integration_tests/verify_dft4.py) only validates the integer/real specialisation of MatExpr.dft 4, which happens to reduce to the Walsh-Hadamard Transform (all ±1 coefficients). This covers neither the general complex case ω = e^{-2πi/n} nor other sizes.

What needs to be tested:

  • Code generation for MatExpr.dft n where n > 2 and the twiddle factors are genuinely non-trivial (e.g., n=8 with ω = e^{-2πi/8})
  • Verify that generated C code computes the correct DFT output for complex-valued inputs
  • Test roundtrip property: applying DFT twice (with conjugate) should return a scaled input

Current state:

  • evalDFT (AlgebraicSemantics.lean:919) implements the generic formula y[k] = Σ ω^{kj} · x[j] over a parametric field element ω
  • Code generation (FRI/CodeGen.lean:235-243) emits placeholder dft_n() function calls
  • No concrete binding or complex arithmetic in code generation

Testing approach:

  1. Create a reference DFT implementation (NumPy FFT or similar)
  2. Generate test vectors from random complex inputs using the reference implementation
  3. Add differential fuzzing: randomly generate inputs, compute reference output, compare against generated code
  4. Include both hand-crafted vectors (identity, constant, alternating patterns) and fuzzing-generated ones
  5. Verify roundtrip property: DFT(DFT*(x)) ≈ n·x within numerical tolerance

Missing pieces:

  1. Complex number representation in generated C (or using a fixed-point encoding for ℂ)
  2. Actual twiddle factor computation (ω^k for ω = e^{-2πi/n})
  3. Test vectors with complex roots (or appropriate fixed-point approximations)

Note on DFT vs. WHT relationship:

For n=4, the DFT with a primitive 4th root of unity mathematically simplifies to the Walsh-Hadamard Transform (all ±1 coefficients). The current integration test exploits this equivalence by using WHT as a reference. Once complex DFT code generation is implemented, the DFT_4 implementation should be verified to produce WHT_4 outputs, confirming the mathematical identity. This could later enable an optimization rule: when MatExpr.dft n is instantiated over Int or a field where the primitive n-th root reduces to ±1, rewrite to faster integer-only butterfly code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions