from complex import ComplexFloat64
# Initialize two complex numbers
a = ComplexFloat64(re=3.0, im=4.0)
b = ComplexFloat64(re=5.0, im=-2.0)
# Perform basic operations
c = a + b # Add two complex numbers
d = a * b # Multiply two complex numbers
e = -a # Negate a complex number
f = a.norm() # Get the magnitude of a complex number
print(f"Addition: {c}, Multiplication: {d}, Negation: {e}, Magnitude: {f}")
The ComplexSIMD
component from the complex
package offers a sophisticated way to represent and manipulate complex numbers leveraging SIMD (Single Instruction, Multiple Data) capabilities. This component is designed to efficiently handle complex mathematical operations, particularly beneficial for high-performance computing tasks.
norm
) and squared magnitude (squared_norm
) of complex numbers.fma
) and squared-add (squared_add
) operations for advanced computational tasks.ComplexFloat32
or ComplexFloat64
) based on the required precision and performance trade-offs.The ComplexSIMD
component is designed to be versatile, but its performance benefits are most pronounced on platforms that support SIMD instructions. The choice between ComplexFloat32
and ComplexFloat64
should be made based on the precision requirements of the application and the underlying hardware capabilities.