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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
//
// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
//
//! The Legendre Functions and Legendre Polynomials are described in Abramowitz & Stegun, Chapter 8.
pub mod polynomials {
use crate::{types, Value};
use std::mem::MaybeUninit;
/// This function evaluates the Legendre polynomials P_l(x) using explicit representations for l=1, 2, 3.
#[doc(alias = "gsl_sf_legendre_P1")]
pub fn legendre_P1(x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_P1(x) }
}
/// This function evaluates the Legendre polynomials P_l(x) using explicit representations for l=1, 2, 3.
#[doc(alias = "gsl_sf_legendre_P2")]
pub fn legendre_P2(x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_P2(x) }
}
/// This function evaluates the Legendre polynomials P_l(x) using explicit representations for l=1, 2, 3.
#[doc(alias = "gsl_sf_legendre_P3")]
pub fn legendre_P3(x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_P3(x) }
}
/// This function evaluates the Legendre polynomials P_l(x) using explicit representations for l=1, 2, 3.
#[doc(alias = "gsl_sf_legendre_P1_e")]
pub fn legendre_P1_e(x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_P1_e(x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This function evaluates the Legendre polynomials P_l(x) using explicit representations for l=1, 2, 3.
#[doc(alias = "gsl_sf_legendre_P2_e")]
pub fn legendre_P2_e(x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_P2_e(x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This function evaluates the Legendre polynomials P_l(x) using explicit representations for l=1, 2, 3.
#[doc(alias = "gsl_sf_legendre_P3_e")]
pub fn legendre_P3_e(x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_P3_e(x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This function evaluates the Legendre polynomial P_l(x) for a specific value of l, x subject to l >= 0, |x| <= 1
#[doc(alias = "gsl_sf_legendre_Pl")]
pub fn legendre_Pl(l: i32, x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_Pl(l, x) }
}
/// This function evaluates the Legendre polynomial P_l(x) for a specific value of l, x subject to l >= 0, |x| <= 1
#[doc(alias = "gsl_sf_legendre_Pl_e")]
pub fn legendre_Pl_e(l: i32, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_Pl_e(l, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This function computes arrays of Legendre polynomials P_l(x) and derivatives dP_l(x)/dx, for l = 0, \dots, lmax, |x| <= 1
#[doc(alias = "gsl_sf_legendre_Pl_array")]
pub fn legendre_Pl_array(lmax: usize, x: f64, result_array: &mut [f64]) -> Result<(), Value> {
let ret = unsafe { sys::gsl_sf_legendre_Pl_array(lmax as _, x, result_array.as_mut_ptr()) };
result_handler!(ret, ())
}
/// This function computes arrays of Legendre polynomials P_l(x) and derivatives dP_l(x)/dx, for l = 0, \dots, lmax, |x| <= 1
#[doc(alias = "gsl_sf_legendre_Pl_deriv_array")]
pub fn legendre_Pl_deriv_array(
x: f64,
result_array: &mut [f64],
result_deriv_array: &mut [f64],
) -> Result<(), Value> {
let ret = unsafe {
sys::gsl_sf_legendre_Pl_deriv_array(
result_array.len() as _,
x,
result_array.as_mut_ptr(),
result_deriv_array.as_mut_ptr(),
)
};
result_handler!(ret, ())
}
/// This function computes the Legendre function Q_0(x) for x > -1, x != 1
#[doc(alias = "gsl_sf_legendre_Q0")]
pub fn legendre_Q0(x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_Q0(x) }
}
/// This function computes the Legendre function Q_0(x) for x > -1, x != 1
#[doc(alias = "gsl_sf_legendre_Q0_e")]
pub fn legendre_Q0_e(x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_Q0_e(x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This function computes the Legendre function Q_0(x) for x > -1, x != 1.
#[doc(alias = "gsl_sf_legendre_Q1")]
pub fn legendre_Q1(x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_Q1(x) }
}
/// This function computes the Legendre function Q_0(x) for x > -1, x != 1.
#[doc(alias = "gsl_sf_legendre_Q1_e")]
pub fn legendre_Q1_e(x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_Q1_e(x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This function computes the Legendre function Q_l(x) for x > -1, x != 1 and l >= 0.
#[doc(alias = "gsl_sf_legendre_Ql")]
pub fn legendre_Ql(l: i32, x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_Ql(l, x) }
}
/// This function computes the Legendre function Q_l(x) for x > -1, x != 1 and l >= 0.
#[doc(alias = "gsl_sf_legendre_Ql_e")]
pub fn legendre_Ql_e(l: i32, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_Ql_e(l, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
}
/// The following functions compute the associated Legendre Polynomials P_l^m(x).
/// Note that this function grows combinatorially with l and can overflow for l larger than about 150.
/// There is no trouble for small m, but overflow occurs when m and l are both large.
/// Rather than allow overflows, these functions refuse to calculate P_l^m(x) and return [`OvrFlw`](enums/type.Value.html) when they can sense that l and m are too big.
///
/// If you want to calculate a spherical harmonic, then do not use these functions. Instead use [`legendre_sphPlm`](fn.legendre_sphPlm.html) below, which uses a similar recursion, but with the normalized functions.
pub mod associated_polynomials {
use crate::{enums, types, Value};
use std::mem::MaybeUninit;
/// This routine computes the associated Legendre polynomial P_l^m(x) for m >= 0, l >= m, |x| <= 1.
#[doc(alias = "gsl_sf_legendre_Plm")]
pub fn legendre_Plm(l: i32, m: i32, x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_Plm(l, m, x) }
}
/// This routine computes the associated Legendre polynomial P_l^m(x) for m >= 0, l >= m, |x| <= 1.
#[doc(alias = "gsl_sf_legendre_Plm_e")]
pub fn legendre_Plm_e(l: i32, m: i32, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_Plm_e(l, m, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the normalized associated Legendre polynomial \sqrt{(2l+1)/(4\pi)} \sqrt{(l-m)!/(l+m)!} P_l^m(x) suitable for use in spherical harmonics.
/// The parameters must satisfy m >= 0, l >= m, |x| <= 1.
/// This routine avoids the overflows that occur for the standard normalization of P_l^m(x).
#[doc(alias = "gsl_sf_legendre_sphPlm")]
pub fn legendre_sphPlm(l: i32, m: i32, x: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_sphPlm(l, m, x) }
}
/// This routine computes the normalized associated Legendre polynomial \sqrt{(2l+1)/(4\pi)} \sqrt{(l-m)!/(l+m)!} P_l^m(x) suitable for use in spherical harmonics.
/// The parameters must satisfy m >= 0, l >= m, |x| <= 1.
/// This routine avoids the overflows that occur for the standard normalization of P_l^m(x).
#[doc(alias = "gsl_sf_legendre_sphPlm_e")]
pub fn legendre_sphPlm_e(l: i32, m: i32, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_sphPlm_e(l, m, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// Returns the size of the array needed for these functions, including GSL workspace.
#[doc(alias = "gsl_sf_legendre_array_n")]
pub fn legendre_array_n(lmax: usize) -> usize {
unsafe { sys::gsl_sf_legendre_array_n(lmax as _) }
}
#[doc(alias = "gsl_sf_legendre_array_index")]
pub fn legendre_array_index(l: usize, m: usize) -> usize {
unsafe { sys::gsl_sf_legendre_array_index(l as _, m as _) }
}
#[doc(alias = "gsl_sf_legendre_array")]
pub fn legendre_array(
norm: enums::SfLegendreNorm,
lmax: usize,
x: f64,
result: &mut [f64],
) -> Result<(), Value> {
let ret = unsafe { sys::gsl_sf_legendre_array(norm.into(), lmax, x, result.as_mut_ptr()) };
result_handler!(ret, ())
}
#[doc(alias = "gsl_sf_legendre_deriv_array")]
pub fn legendre_deriv_array(
norm: enums::SfLegendreNorm,
lmax: usize,
x: f64,
result: &mut [f64],
deriv: &mut [f64],
) -> Result<(), Value> {
let ret = unsafe {
sys::gsl_sf_legendre_deriv_array(
norm.into(),
lmax,
x,
result.as_mut_ptr(),
deriv.as_mut_ptr(),
)
};
result_handler!(ret, ())
}
}
/// The Conical Functions P^\mu_{-(1/2)+i\lambda}(x) and Q^\mu_{-(1/2)+i\lambda} are described in Abramowitz & Stegun, Section 8.12.
pub mod conical {
use crate::{types, Value};
use std::mem::MaybeUninit;
/// This routine computes the irregular Spherical Conical Function P^{1/2}_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_half")]
pub fn half(lambda: f64, x: f64) -> f64 {
unsafe { sys::gsl_sf_conicalP_half(lambda, x) }
}
/// This routine computes the irregular Spherical Conical Function P^{1/2}_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_half_e")]
pub fn half_e(lambda: f64, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_conicalP_half_e(lambda, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the regular Spherical Conical Function P^{-1/2}_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_mhalf")]
pub fn mhalf(lambda: f64, x: f64) -> f64 {
unsafe { sys::gsl_sf_conicalP_mhalf(lambda, x) }
}
/// This routine computes the regular Spherical Conical Function P^{-1/2}_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_mhalf_e")]
pub fn mhalf_e(lambda: f64, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_conicalP_mhalf_e(lambda, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the conical function P^0_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_0")]
pub fn _0(lambda: f64, x: f64) -> f64 {
unsafe { sys::gsl_sf_conicalP_0(lambda, x) }
}
/// This routine computes the conical function P^0_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_0_e")]
pub fn _0_e(lambda: f64, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_conicalP_0_e(lambda, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the conical function P^1_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_1")]
pub fn _1(lambda: f64, x: f64) -> f64 {
unsafe { sys::gsl_sf_conicalP_1(lambda, x) }
}
/// This routine computes the conical function P^1_{-1/2 + i \lambda}(x) for x > -1.
#[doc(alias = "gsl_sf_conicalP_1_e")]
pub fn _1_e(lambda: f64, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_conicalP_1_e(lambda, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the Regular Spherical Conical Function P^{-1/2-l}_{-1/2 + i \lambda}(x) for x > -1, l >= -1.
#[doc(alias = "gsl_sf_conicalP_sph_reg")]
pub fn sph_reg(l: i32, lambda: f64, x: f64) -> f64 {
unsafe { sys::gsl_sf_conicalP_sph_reg(l, lambda, x) }
}
/// This routine computes the Regular Spherical Conical Function P^{-1/2-l}_{-1/2 + i \lambda}(x) for x > -1, l >= -1.
#[doc(alias = "gsl_sf_conicalP_sph_reg_e")]
pub fn sph_reg_e(l: i32, lambda: f64, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_conicalP_sph_reg_e(l, lambda, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the Regular Cylindrical Conical Function P^{-m}_{-1/2 + i \lambda}(x) for x > -1, m >= -1.
#[doc(alias = "gsl_sf_conicalP_cyl_reg")]
pub fn cyl_reg(m: i32, lambda: f64, x: f64) -> f64 {
unsafe { sys::gsl_sf_conicalP_cyl_reg(m, lambda, x) }
}
/// This routine computes the Regular Cylindrical Conical Function P^{-m}_{-1/2 + i \lambda}(x) for x > -1, m >= -1.
#[doc(alias = "gsl_sf_conicalP_cyl_reg_e")]
pub fn cyl_reg_e(m: i32, lambda: f64, x: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_conicalP_cyl_reg_e(m, lambda, x, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
}
/// The following spherical functions are specializations of Legendre functions which give the regular eigenfunctions of the Laplacian on a 3-dimensional hyperbolic space H3d.
/// Of particular interest is the flat limit, \lambda \to \infty, \eta \to 0, \lambda\eta fixed.
pub mod radial {
use crate::{types, Value};
use std::mem::MaybeUninit;
/// This routine computes the zeroth radial eigenfunction of the Laplacian on the 3-dimensional hyperbolic space, L^{H3d}_0(\lambda,\eta) := \sin(\lambda\eta)/(\lambda\sinh(\eta)) for \eta >= 0.
/// In the flat limit this takes the form L^{H3d}_0(\lambda,\eta) = j_0(\lambda\eta).
#[doc(alias = "gsl_sf_legendre_H3d_0")]
pub fn legendre_H3d_0(lambda: f64, eta: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_H3d_0(lambda, eta) }
}
/// This routine computes the zeroth radial eigenfunction of the Laplacian on the 3-dimensional hyperbolic space, L^{H3d}_0(\lambda,\eta) := \sin(\lambda\eta)/(\lambda\sinh(\eta)) for \eta >= 0.
/// In the flat limit this takes the form L^{H3d}_0(\lambda,\eta) = j_0(\lambda\eta).
#[doc(alias = "gsl_sf_legendre_H3d_0_e")]
pub fn legendre_H3d_0_e(lambda: f64, eta: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_H3d_0_e(lambda, eta, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the first radial eigenfunction of the Laplacian on the 3-dimensional hyperbolic space, L^{H3d}_1(\lambda,\eta) := 1/\sqrt{\lambda^2 + 1} \sin(\lambda \eta)/(\lambda \sinh(\eta))
/// (\coth(\eta) - \lambda \cot(\lambda\eta)) for \eta >= 0.
/// In the flat limit this takes the form L^{H3d}_1(\lambda,\eta) = j_1(\lambda\eta).
#[doc(alias = "gsl_sf_legendre_H3d_1")]
pub fn legendre_H3d_1(lambda: f64, eta: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_H3d_1(lambda, eta) }
}
/// This routine computes the first radial eigenfunction of the Laplacian on the 3-dimensional hyperbolic space, L^{H3d}_1(\lambda,\eta) := 1/\sqrt{\lambda^2 + 1} \sin(\lambda \eta)/(\lambda \sinh(\eta))
/// (\coth(\eta) - \lambda \cot(\lambda\eta)) for \eta >= 0.
/// In the flat limit this takes the form L^{H3d}_1(\lambda,\eta) = j_1(\lambda\eta).
#[doc(alias = "gsl_sf_legendre_H3d_1_e")]
pub fn legendre_H3d_1_e(lambda: f64, eta: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_H3d_1_e(lambda, eta, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This routine computes the l-th radial eigenfunction of the Laplacian on the 3-dimensional hyperbolic space \eta >= 0, l >= 0. In the flat limit this takes the form L^{H3d}_l(\lambda,\eta) = j_l(\lambda\eta).
#[doc(alias = "gsl_sf_legendre_H3d")]
pub fn legendre_H3d(l: i32, lambda: f64, eta: f64) -> f64 {
unsafe { sys::gsl_sf_legendre_H3d(l, lambda, eta) }
}
/// This routine computes the l-th radial eigenfunction of the Laplacian on the 3-dimensional hyperbolic space \eta >= 0, l >= 0. In the flat limit this takes the form L^{H3d}_l(\lambda,\eta) = j_l(\lambda\eta).
#[doc(alias = "gsl_sf_legendre_H3d_e")]
pub fn legendre_H3d_e(l: i32, lambda: f64, eta: f64) -> Result<types::Result, Value> {
let mut result = MaybeUninit::<sys::gsl_sf_result>::uninit();
let ret = unsafe { sys::gsl_sf_legendre_H3d_e(l, lambda, eta, result.as_mut_ptr()) };
result_handler!(ret, unsafe { result.assume_init() }.into())
}
/// This function computes an array of radial eigenfunctions L^{H3d}_l(\lambda, \eta) for 0 <= l <= lmax.
#[doc(alias = "gsl_sf_legendre_H3d_array")]
pub fn legendre_H3d_array(
lambda: f64,
eta: f64,
result_array: &mut [f64],
) -> Result<(), Value> {
let ret = unsafe {
sys::gsl_sf_legendre_H3d_array(
result_array.len() as _,
lambda,
eta,
result_array.as_mut_ptr(),
)
};
result_handler!(ret, ())
}
}