←back to thread

124 points mtantaoui | 1 comments | | HN request time: 0.212s | source

Integrate is a fast, small, lightweight Rust library for performing numerical integration of real-valued functions. It is designed to integrate functions, providing a simple and efficient way to approximate definite integrals using various numerical methods.

Integrate supports a variety of numerical integration techniques: - Newton-Cotes methods:

  - Rectangle Rule.
  - Trapezoidal Rule.
  - Simpson's Rule.
  - Newton's 3/8 Rule.
- Gauss quadrature methods:

  - Gauss-Legendre.
  - Gauss-Laguerre.
  - Gauss-Hermite.
  - Gauss-Chebyshev First Kind.
  - Gauss-Chebyshev Second Kind.
- Adaptive Methods:

  - Adaptive Simpson's method
- Romberg’s method.
Show context
JanisErdmanis ◴[] No.42183942[source]
It looks a bit sloppy to hardcode so many constants in a single file: `src/gauss_quadrature/legendre.rs`. Isn't it possible to generate them with the help of rust macros in the same way Julia uses metaprogramming?
replies(3): >>42184353 #>>42185117 #>>42185548 #
two_handfuls ◴[] No.42185117[source]
Probably but that would slow down compilation a lot.
replies(3): >>42186409 #>>42186665 #>>42190112 #
1. dataflow ◴[] No.42190112[source]
What I would do in these cases is to define the general computation function, but special-case it to return the hard-coded value for specific common inputs if it's being evaluated at compile time. Then add a test to verify both behaviors.