Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Codex/find and fix a bug (TheAlgorithms#12782)
* Fix enumeration order in FFT string representation

* updating DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update radix2_fft.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: alejandroaldas <alejandroaldas@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
  • Loading branch information
4 people authored Aug 24, 2025
commit 8c1c6c1763e8d4695754dceea072cc1ff58308bb
14 changes: 7 additions & 7 deletions maths/radix2_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class FFT:
>>> x = FFT(A, B)

Print product
>>> x.product # 2x + 3x^2 + 8x^3 + 4x^4 + 6x^5
>>> x.product # 2x + 3x^2 + 8x^3 + 6x^4 + 8x^5
[(-0-0j), (2+0j), (3-0j), (8-0j), (6+0j), (8+0j)]

__str__ test
>>> print(x)
A = 0*x^0 + 1*x^1 + 2*x^0 + 3*x^2
B = 0*x^2 + 1*x^3 + 2*x^4
A*B = 0*x^(-0-0j) + 1*x^(2+0j) + 2*x^(3-0j) + 3*x^(8-0j) + 4*x^(6+0j) + 5*x^(8+0j)
A = 0*x^0 + 1*x^1 + 0*x^2 + 2*x^3
B = 2*x^0 + 3*x^1 + 4*x^2
A*B = (-0-0j)*x^0 + (2+0j)*x^1 + (3-0j)*x^2 + (8-0j)*x^3 + (6+0j)*x^4 + (8+0j)*x^5
"""

def __init__(self, poly_a=None, poly_b=None):
Expand Down Expand Up @@ -159,13 +159,13 @@ def __multiply(self):
# Overwrite __str__ for print(); Shows A, B and A*B
def __str__(self):
a = "A = " + " + ".join(
f"{coef}*x^{i}" for coef, i in enumerate(self.polyA[: self.len_A])
f"{coef}*x^{i}" for i, coef in enumerate(self.polyA[: self.len_A])
)
b = "B = " + " + ".join(
f"{coef}*x^{i}" for coef, i in enumerate(self.polyB[: self.len_B])
f"{coef}*x^{i}" for i, coef in enumerate(self.polyB[: self.len_B])
)
c = "A*B = " + " + ".join(
f"{coef}*x^{i}" for coef, i in enumerate(self.product)
f"{coef}*x^{i}" for i, coef in enumerate(self.product)
)

return f"{a}\n{b}\n{c}"
Expand Down