MQT Core
The Backbone of the Munich Quantum Toolkit (MQT)
Loading...
Searching...
No Matches
dd::ComplexNumbers Class Reference

A class for managing complex numbers in the DD package. More...

#include <ComplexNumbers.hpp>

Public Member Functions

 ComplexNumbers (RealNumberUniqueTable &table)
 Default constructor.
 ~ComplexNumbers ()=default
 Default destructor.
Complex lookup (const Complex &c)
 Lookup a complex value in the complex table; if not found add it.
Complex lookup (const std::complex< fp > &c)
Complex lookup (const ComplexValue &c)
Complex lookup (fp r)
 Lookup a real value in the complex table; if not found add it.
Complex lookup (fp r, fp i)
 Lookup a complex value in the complex table; if not found add it.
Complex lookupRoot (const ComplexValue &c)
 Preserve matrix root components, including nonzero values below tolerance.
template<class Node>
Edge< Node > lookup (const CachedEdge< Node > &ce)
 Turn a root CachedEdge into Edge via lookup.
std::size_t realCount () const noexcept
 Get the number of stored real numbers.

Static Public Member Functions

static void setTolerance (fp tol)
 Set the numerical tolerance for comparisons of floats.
static fp mag2 (const Complex &a) noexcept
 Compute the squared magnitude of a complex number.
static fp mag (const Complex &a) noexcept
 Compute the magnitude of a complex number.
static fp arg (const Complex &a) noexcept
 Compute the argument of a complex number.
static Complex conj (const Complex &a) noexcept
 Compute the complex conjugate of a complex number.
static Complex neg (const Complex &a) noexcept
 Compute the negation of a complex number.
static constexpr bool isStaticComplex (const Complex &c)
 Check whether a complex number is one of the static ones.

Detailed Description

A class for managing complex numbers in the DD package.

Constructor & Destructor Documentation

◆ ComplexNumbers()

dd::ComplexNumbers::ComplexNumbers ( RealNumberUniqueTable & table)
inlineexplicit

Default constructor.

◆ ~ComplexNumbers()

dd::ComplexNumbers::~ComplexNumbers ( )
default

Default destructor.

Member Function Documentation

◆ setTolerance()

void dd::ComplexNumbers::setTolerance ( fp tol)
static

Set the numerical tolerance for comparisons of floats.

This is global to all packages. Existing DDs are not recanonicalized.

Parameters
tolThe new positive, normal tolerance.
Exceptions
std::invalid_argumentIf the tolerance is not positive and normal.

◆ mag2()

fp dd::ComplexNumbers::mag2 ( const Complex & a)
staticnodiscardnoexcept

Compute the squared magnitude of a complex number.

Parameters
aThe complex number.
Returns
The squared magnitude.

◆ mag()

fp dd::ComplexNumbers::mag ( const Complex & a)
staticnodiscardnoexcept

Compute the magnitude of a complex number.

Parameters
aThe complex number.
Returns
The magnitude.

◆ arg()

fp dd::ComplexNumbers::arg ( const Complex & a)
staticnodiscardnoexcept

Compute the argument of a complex number.

Parameters
aThe complex number.
Returns
The argument.

◆ conj()

Complex dd::ComplexNumbers::conj ( const Complex & a)
staticnodiscardnoexcept

Compute the complex conjugate of a complex number.

Parameters
aThe complex number.
Returns
The complex conjugate.
Note
Conjugation is efficiently handled by just flipping the sign of the imaginary pointer.

◆ neg()

Complex dd::ComplexNumbers::neg ( const Complex & a)
staticnodiscardnoexcept

Compute the negation of a complex number.

Parameters
aThe complex number.
Returns
The negation.
Note
Negation is efficiently handled by just flipping the sign of both pointers.

◆ lookup() [1/6]

Complex dd::ComplexNumbers::lookup ( const Complex & c)
nodiscard

Lookup a complex value in the complex table; if not found add it.

Parameters
cThe complex number.
Returns
The found or added complex number.

◆ lookup() [2/6]

Complex dd::ComplexNumbers::lookup ( const std::complex< fp > & c)
nodiscard

◆ lookup() [3/6]

Complex dd::ComplexNumbers::lookup ( const ComplexValue & c)
nodiscard

◆ lookup() [4/6]

Complex dd::ComplexNumbers::lookup ( fp r)
nodiscard

Lookup a real value in the complex table; if not found add it.

Parameters
rThe real number.
Returns
The found or added complex number with real part r and imaginary part zero.

◆ lookup() [5/6]

Complex dd::ComplexNumbers::lookup ( fp r,
fp i )
nodiscard

Lookup a complex value in the complex table; if not found add it.

Parameters
rThe real part.
iThe imaginary part.
Returns
The found or added complex number.
See also
ComplexTable::lookup

◆ lookupRoot()

Complex dd::ComplexNumbers::lookupRoot ( const ComplexValue & c)
inlinenodiscard

Preserve matrix root components, including nonzero values below tolerance.

Nonzero special constants keep their existing tolerance priority.

◆ lookup() [6/6]

template<class Node>
Edge< Node > dd::ComplexNumbers::lookup ( const CachedEdge< Node > & ce)
inlinenodiscard

Turn a root CachedEdge into Edge via lookup.

Matrix roots preserve range; vector roots retain ordinary lookup.

Template Parameters
NodeThe type of the node.
Parameters
ceThe cached edge.
Returns
The edge with looked-up weight. The zero terminal if the new weight is exactly zero.

◆ isStaticComplex()

constexpr bool dd::ComplexNumbers::isStaticComplex ( const Complex & c)
inlinestaticnodiscardconstexpr

Check whether a complex number is one of the static ones.

Parameters
cThe complex number.
Returns
Whether the complex number is one of the static ones.

◆ realCount()

std::size_t dd::ComplexNumbers::realCount ( ) const
nodiscardnoexcept

Get the number of stored real numbers.

Returns
The number of stored real numbers.