sparse_ir/basis_trait.rs
1//! Basis trait for IR and DLR representations
2//!
3//! This module provides a common trait for different basis representations
4//! (IR basis, DLR basis, augmented basis, etc.) in imaginary-time/frequency domains.
5
6use crate::freq::MatsubaraFreq;
7use crate::kernel::KernelProperties;
8use crate::traits::StatisticsType;
9
10/// Common trait for basis representations in imaginary-time/frequency domains
11///
12/// This trait abstracts over different basis representations:
13/// - `FiniteTempBasis`: IR (Intermediate Representation) basis
14/// - `DiscreteLehmannRepresentation`: DLR basis
15/// - `AugmentedBasis`: IR basis with additional functions
16///
17/// Each basis provides:
18/// - Physical parameters (β, ωmax, Λ)
19/// - Basis size and accuracy information
20/// - Default sampling points for τ and Matsubara frequencies
21///
22/// # Type Parameters
23/// * `S` - Statistics type (Fermionic or Bosonic)
24pub trait Basis<S: StatisticsType> {
25 /// Associated kernel type
26 type Kernel: KernelProperties;
27
28 /// Get reference to the kernel
29 ///
30 /// # Returns
31 /// Reference to the kernel used to construct this basis
32 fn kernel(&self) -> &Self::Kernel;
33
34 /// Inverse temperature β
35 ///
36 /// # Returns
37 /// The inverse temperature in units where ℏ = kB = 1
38 fn beta(&self) -> f64;
39
40 /// Maximum frequency ωmax
41 ///
42 /// The basis functions are designed to accurately represent
43 /// spectral functions with support in [-ωmax, ωmax].
44 ///
45 /// # Returns
46 /// The maximum frequency cutoff
47 fn wmax(&self) -> f64;
48
49 /// Kernel parameter Λ = β × ωmax
50 ///
51 /// This is the dimensionless parameter that controls the basis.
52 ///
53 /// # Returns
54 /// The dimensionless parameter Λ
55 fn lambda(&self) -> f64 {
56 self.beta() * self.wmax()
57 }
58
59 /// Number of basis functions
60 ///
61 /// # Returns
62 /// The size of the basis (number of basis functions)
63 fn size(&self) -> usize;
64
65 /// Accuracy of the basis
66 ///
67 /// Upper bound to the relative error of representing a propagator
68 /// with the given number of basis functions.
69 ///
70 /// # Returns
71 /// A number between 0 and 1 representing the accuracy
72 fn accuracy(&self) -> f64;
73
74 /// Significance of each basis function
75 ///
76 /// Returns a vector where `σ[i]` (0 ≤ σ[i] ≤ 1) is the significance
77 /// level of the i-th basis function. If ε is the desired accuracy,
78 /// then any basis function where σ[i] < ε can be neglected.
79 ///
80 /// For the IR basis: σ[i] = s[i] / s[0]
81 /// For the DLR basis: σ[i] = 1.0 (all poles equally significant)
82 ///
83 /// # Returns
84 /// Vector of significance values for each basis function
85 fn significance(&self) -> Vec<f64>;
86
87 /// Get singular values (non-normalized)
88 ///
89 /// Returns the singular values s[i] from the SVE decomposition.
90 /// These are the absolute values, not normalized by s[0].
91 ///
92 /// # Returns
93 /// Vector of singular values
94 fn svals(&self) -> Vec<f64>;
95
96 /// Get default tau sampling points
97 ///
98 /// Returns sampling points in imaginary time τ ∈ [-β/2, β/2].
99 /// These are chosen to provide near-optimal conditioning of the
100 /// sampling matrix.
101 ///
102 /// # Returns
103 /// Vector of tau sampling points
104 fn default_tau_sampling_points(&self) -> Vec<f64>;
105
106 /// Get default Matsubara sampling points
107 ///
108 /// Returns sampling points in Matsubara frequency space.
109 /// These are chosen to provide near-optimal conditioning.
110 ///
111 /// # Arguments
112 /// * `positive_only` - If true, only return non-negative frequencies
113 ///
114 /// # Returns
115 /// Vector of Matsubara frequency sampling points
116 fn default_matsubara_sampling_points(&self, positive_only: bool) -> Vec<MatsubaraFreq<S>>
117 where
118 S: 'static;
119
120 /// Evaluate basis functions at imaginary time points
121 ///
122 /// Computes the value of basis functions at given τ points.
123 /// For IR basis: u_l(τ)
124 /// For DLR basis: sum over poles weighted by basis coefficients
125 ///
126 /// # Arguments
127 /// * `tau` - Imaginary time points where τ ∈ [0, β] (or extended range for DLR)
128 ///
129 /// # Returns
130 /// Matrix of shape [tau.len(), self.size()] where result[i, l] = u_l(τ_i)
131 fn evaluate_tau(&self, tau: &[f64]) -> mdarray::DTensor<f64, 2>;
132
133 /// Evaluate basis functions at Matsubara frequencies
134 ///
135 /// Computes the value of basis functions at given Matsubara frequencies.
136 /// For IR basis: û_l(iωn)
137 /// For DLR basis: basis functions in Matsubara space
138 ///
139 /// # Arguments
140 /// * `freqs` - Matsubara frequencies
141 ///
142 /// # Returns
143 /// Matrix of shape [freqs.len(), self.size()] where result[i, l] = û_l(iωn_i)
144 fn evaluate_matsubara(
145 &self,
146 freqs: &[MatsubaraFreq<S>],
147 ) -> mdarray::DTensor<num_complex::Complex<f64>, 2>
148 where
149 S: 'static;
150
151 /// Evaluate spectral basis functions at real frequencies
152 ///
153 /// Computes the value of spectral basis functions at given real frequencies.
154 /// For IR basis: V_l(ω)
155 /// For DLR basis: may return identity or specific representation
156 ///
157 /// # Arguments
158 /// * `omega` - Real frequency points in [-ωmax, ωmax]
159 ///
160 /// # Returns
161 /// Matrix of shape [omega.len(), self.size()] where result[i, l] = V_l(ω_i)
162 fn evaluate_omega(&self, omega: &[f64]) -> mdarray::DTensor<f64, 2>;
163
164 /// Get default omega (real frequency) sampling points
165 ///
166 /// Returns sampling points on the real-frequency axis ω ∈ [-ωmax, ωmax].
167 /// These are used as pole locations for the Discrete Lehmann Representation (DLR).
168 ///
169 /// The sampling points are chosen as the roots/extrema of the L-th basis function
170 /// in the spectral domain, providing near-optimal conditioning.
171 ///
172 /// # Returns
173 /// Vector of real-frequency sampling points in [-ωmax, ωmax]
174 fn default_omega_sampling_points(&self) -> Vec<f64>;
175}
176
177#[cfg(test)]
178#[path = "basis_trait_tests.rs"]
179mod tests;