Re:Show HN: A Mathematical Integration rust crate
by JanisErdmanis on Tuesday November 19, 2024 @09:42AM
(#42183942)
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?
[ Parent
| on HN ]
Re:Show HN: A Mathematical Integration rust crate
by ok123456 on Tuesday November 19, 2024 @10:18AM
(#42184353)
Gaussian quadrature points are typically solved numerically. There's a good chance these ultimately came from a table.
Additionally, compile time floating-point evaluation is limited. When I looked around recently, I didn't see a rust equivalent of gcem; any kind of transcendental function evaluation (which finding Gaussian quadrature points absolutely would require) would not allow compile-time evaluation.
Re:Show HN: A Mathematical Integration rust crate
by AlotOfReading on Tuesday November 19, 2024 @11:29AM
(#42185264)
Support for float const fns was merged just a couple months ago and hasn't been officially announced yet.
Re:Show HN: A Mathematical Integration rust crate
by BD103 on Tuesday November 19, 2024 @11:54AM
(#42185528)
Support for constant float operations was released in Rust 1.82! https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html
Re:Show HN: A Mathematical Integration rust crate
by ok123456 on Tuesday November 19, 2024 @11:37AM
(#42185347)
IIRC, that only supports elementary arithmetic operations. Useful but not general.
Re:Show HN: A Mathematical Integration rust crate
by AlotOfReading on Tuesday November 19, 2024 @11:54AM
(#42185534)
It's relatively straightforward to build transcendental functions out of the basic operations and the stdlib support will eventually get there, but rust's float story is still a work in progress. They're trying to do things more properly and document semantics better than C and C++ have.
Re:Show HN: A Mathematical Integration rust crate
by zokier on Tuesday November 19, 2024 @01:44PM
(#42186782)
I was under the impression that macros can execute arbitrary code, surely some FP would not be big problem. And if not macros then build.rs script certainly could do the trick.
Re:Show HN: A Mathematical Integration rust crate
by dhosek on Tuesday November 19, 2024 @02:39PM
(#42187277)
build.rs can definitely execute arbitrary code, which means that a lot of places (including, IIRC crates.io) will forbid crates that rely on build.rs. I ended up refactoring my build.rs into a separate sub-application in finl_unicode that built data tables which are then checked into git and used pre-built. I include the sub-app in the source code so that anyone with access to the repo could continue development if I were to die tomorrow.
Re:Show HN: A Mathematical Integration rust crate
by n_plus_1_acc on Tuesday November 19, 2024 @04:09PM
(#42188113)
There are many crates with build.rs scripts on crates.io, because they host just the source code with the Cargo.{toml,lock}.
Re:Show HN: A Mathematical Integration rust crate
by dhosek on Tuesday November 19, 2024 @05:42PM
(#42188859)
I ran into some issues with crates.io and my build.rs when I first released the crate, although it’s long enough ago, that I don’t remember exactly what the issue was. It might also have been that the build.rs script downloaded raw data files from unicode.org
Re:Show HN: A Mathematical Integration rust crate
by Arnavion on Tuesday November 19, 2024 @09:20PM
(#42190262)
crates.io doesn't care what your build.rs does because it doesn't try to compile your code, neither now or ever in the past. There would be no point in it trying to compile your code; there are lots of crates that are bindings to C libraries that crates.io's builders can't be expected to have, crates that target architectures which crates.io can't be expected to have builders for, etc.
Re:Show HN: A Mathematical Integration rust crate
by mtantaoui on Tuesday November 19, 2024 @11:55AM
(#42185548)
this was mainly to use an Iteration free method in this paper: https://www.cfm.brown.edu/faculty/gk/APMA2560/Handouts/GL_qu...
this method is much faster and simpler.
Re:Show HN: A Mathematical Integration rust crate
by two_handfuls on Tuesday November 19, 2024 @11:19AM
(#42185117)
Probably but that would slow down compilation a lot.
Re:Show HN: A Mathematical Integration rust crate
by simlevesque on Tuesday November 19, 2024 @01:06PM
(#42186409)
Exactly, it's not like the constants are gonna change.
Re:Show HN: A Mathematical Integration rust crate
by blharr on Tuesday November 19, 2024 @01:32PM
(#42186665)
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?
Re:Show HN: A Mathematical Integration rust crate
by dataflow on Tuesday November 19, 2024 @08:52PM
(#42190112)
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.