1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
//! # bilby
//!
//! A high-performance numerical quadrature (integration) library for Rust.
//!
//! bilby provides Gaussian quadrature rules, adaptive integration, and
//! multi-dimensional cubature methods with a consistent, generic API.
//!
//! ## Design
//!
//! - **Generic over `F: Float`** via [`num_traits::Float`] — works with `f32`, `f64`,
//! and compatible types (e.g., echidna AD types)
//! - **Precomputed rules** — generate nodes and weights once, integrate many times
//! - **No heap allocation on hot paths** — rule construction allocates, integration does not
//! - **Separate 1D and N-D APIs** — `Fn(F) -> F` for 1D, `Fn(&[F]) -> F` for N-D
//! - **`no_std` compatible** — works without the standard library (with `alloc`)
//!
//! ## Feature Flags
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `std` | Yes | Enables `std::error::Error` impl and [`cache`] module |
//! | `parallel` | No | Enables rayon-based `_par` methods (implies `std`) |
//!
//! ## Quick Start
//!
//! ```
//! use bilby::GaussLegendre;
//!
//! // Create a 10-point Gauss-Legendre rule
//! let gl = GaussLegendre::new(10).unwrap();
//!
//! // Integrate x^2 over [0, 1] (exact result = 1/3)
//! let result = gl.rule().integrate(0.0, 1.0, |x: f64| x * x);
//! assert!((result - 1.0 / 3.0).abs() < 1e-14);
//! ```
//!
//! ## Gauss-Kronrod Error Estimation
//!
//! ```
//! use bilby::{GaussKronrod, GKPair};
//!
//! let gk = GaussKronrod::new(GKPair::G7K15);
//! let (estimate, error) = gk.integrate(0.0, core::f64::consts::PI, f64::sin);
//! assert!((estimate - 2.0).abs() < 1e-14);
//! ```
//!
//! ## Adaptive Integration
//!
//! ```
//! use bilby::adaptive_integrate;
//!
//! let result = adaptive_integrate(|x: f64| x.sin(), 0.0, core::f64::consts::PI, 1e-12).unwrap();
//! assert!((result.value - 2.0).abs() < 1e-12);
//! assert!(result.is_converged());
//! ```
//!
//! ## Infinite Domains
//!
//! ```
//! use bilby::integrate_infinite;
//!
//! // Integral of exp(-x^2) over (-inf, inf) = sqrt(pi)
//! let result = integrate_infinite(|x: f64| (-x * x).exp(), 1e-10).unwrap();
//! assert!((result.value - core::f64::consts::PI.sqrt()).abs() < 1e-8);
//! ```
//!
//! ## Multi-Dimensional Integration
//!
//! ```
//! use bilby::cubature::{TensorProductRule, adaptive_cubature};
//! use bilby::GaussLegendre;
//!
//! // Tensor product: 10-point GL in each of 2 dimensions
//! let gl = GaussLegendre::new(10).unwrap();
//! let tp = TensorProductRule::isotropic(gl.rule(), 2).unwrap();
//! let result = tp.rule().integrate_box(
//! &[0.0, 0.0], &[1.0, 1.0],
//! |x| x[0] * x[1],
//! );
//! assert!((result - 0.25).abs() < 1e-14);
//! ```
//!
//! ## Precomputed Rule Cache
//!
//! Available when the `std` feature is enabled (default):
//!
//! ```
//! # #[cfg(feature = "std")] {
//! use bilby::cache::GL10;
//!
//! let result = GL10.rule().integrate(0.0, 1.0, |x: f64| x * x);
//! assert!((result - 1.0 / 3.0).abs() < 1e-14);
//! # }
//! ```
//!
//! ## Tanh-Sinh (Double Exponential)
//!
//! ```
//! use bilby::tanh_sinh_integrate;
//!
//! // Endpoint singularity: integral of 1/sqrt(x) over [0, 1] = 2
//! let result = tanh_sinh_integrate(|x| 1.0 / x.sqrt(), 0.0, 1.0, 1e-10).unwrap();
//! assert!((result.value - 2.0).abs() < 1e-7);
//! ```
//!
//! ## Cauchy Principal Value
//!
//! ```
//! use bilby::pv_integrate;
//!
//! // PV integral of x^2/(x - 0.3) over [0, 1]
//! let exact = 0.8 + 0.09 * (7.0_f64 / 3.0).ln();
//! let result = pv_integrate(|x| x * x, 0.0, 1.0, 0.3, 1e-10).unwrap();
//! assert!((result.value - exact).abs() < 1e-7);
//! ```
//!
//! ## Oscillatory Integration
//!
//! ```
//! use bilby::integrate_oscillatory_sin;
//!
//! // Integral of sin(100x) over [0, 1]
//! let exact = (1.0 - 100.0_f64.cos()) / 100.0;
//! let result = integrate_oscillatory_sin(|_| 1.0, 0.0, 1.0, 100.0, 1e-10).unwrap();
//! assert!((result.value - exact).abs() < 1e-8);
//! ```
//!
//! ## Weighted Integration
//!
//! ```
//! use bilby::weighted::{weighted_integrate, WeightFunction};
//!
//! // Gauss-Hermite: integral of e^(-x^2) over (-inf, inf) = sqrt(pi)
//! let result = weighted_integrate(|_| 1.0, WeightFunction::Hermite, 20).unwrap();
//! assert!((result - core::f64::consts::PI.sqrt()).abs() < 1e-12);
//! ```
//!
//! ## Sparse Grids
//!
//! ```
//! use bilby::cubature::SparseGrid;
//!
//! let sg = SparseGrid::clenshaw_curtis(3, 3).unwrap();
//! let result = sg.rule().integrate_box(
//! &[0.0, 0.0, 0.0], &[1.0, 1.0, 1.0],
//! |x| x[0] * x[1] * x[2],
//! );
//! assert!((result - 0.125).abs() < 1e-12);
//! ```
extern crate alloc;
/// Implement the standard quadrature rule accessor methods.
///
/// Most 1-D rule types wrap a `QuadratureRule<f64>` in a field called `rule`
/// and expose the same four accessors: `rule()`, `order()`, `nodes()`, and
/// `weights()`. This macro generates all four with the correct attributes
/// and documentation.
///
/// `$nodes_doc` customises the doc comment on `nodes()` to describe the
/// domain (e.g. "\\[-1, 1\\]", "\\[0, ∞)", "(-∞, ∞)").
pub
pub use ;
pub use ;
pub use ClenshawCurtis;
pub use QuadratureError;
pub use ;
pub use GaussHermite;
pub use GaussJacobi;
pub use ;
pub use GaussLaguerre;
pub use GaussLegendre;
pub use GaussLobatto;
pub use GaussRadau;
pub use ;
pub use QuadratureResult;
pub use QuadratureRule;
pub use ;
pub use ;
pub use ;