←back to thread

123 points mtantaoui | 4 comments | | HN request time: 0s | 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 #
1. two_handfuls ◴[] No.42185117[source]
Probably but that would slow down compilation a lot.
replies(3): >>42186409 #>>42186665 #>>42190112 #
2. simlevesque ◴[] No.42186409[source]
Exactly, it's not like the constants are gonna change.
3. blharr ◴[] No.42186665[source]
You wouldn't have to recompile them every time. What if you didn't necessarily use macros but auto-generated it in a file that you keep separate from the other code at the bottom?
4. 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.