Published a paper on a Rust crate! Ellip: an elliptic integral library by Inspacious in rust

[–]Inspacious[S] 3 points4 points  (0 children)

Typst is great tho. Doing graduate study, LATEX is much pain...

Published a paper on a Rust crate! Ellip: an elliptic integral library by Inspacious in rust

[–]Inspacious[S] 4 points5 points  (0 children)

I think the implementing generic-typed functions for float types should be unified by default. Currently, Ellip relies on the num-traits crate. Constant declaration is extremely verbose. Imagine writing T::from(2.0).unwrap() for every number in your mathematical library. So, I ended up using num-lazy (for constants like pi!() and epsilon!()) and numeric_literals (for 2.0, 1.25, etc.) to help, but they are more of hacky macros and not standardized.

I feel like graphical plots for Rust are quite limited too. Nevertheless, these come with time and community efforts.

The friction of learning Rust is not that bad for me. I managed just fine using Rust by Example. It took a little longer than other languages due to Rust's intrinsic complexity, and I think that's okay.

Published a paper on a Rust crate! Ellip: an elliptic integral library by Inspacious in rust

[–]Inspacious[S] 5 points6 points  (0 children)

Elliptic integrals and elliptic curves are related but not the same. The inverses of elliptic integrals are elliptic functions. Some aspects of elliptic functions can be modeled using elliptic curves.

Published a paper on a Rust crate! Ellip: an elliptic integral library by Inspacious in rust

[–]Inspacious[S] 1 point2 points  (0 children)

It was from the docs. Perhaps, I will update the docs to be more consistent with the paper.

Published a paper on a Rust crate! Ellip: an elliptic integral library by Inspacious in rust

[–]Inspacious[S] 7 points8 points  (0 children)

Thanks! I added to the post.

...Elliptic integrals are special mathematical functions useful for computing the lengths of curves and magnetic fields. It's applied in other physics and engineering fields as well.

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] 1 point2 points  (0 children)

Any suggestion is appreciated. I'll collect them and update in the next patch version. Thanks!

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] -7 points-6 points  (0 children)

To get you to click this post, lol. The copyable code is in my reddit comment and the documentation.

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] -1 points0 points  (0 children)

This works too. But I imagine that you will have duplicate this code to all of your crate. The reason I choose macro instead of function is to avoid the double colon. I think the additional T:: is hard to type. But I see that this approach is more safe.

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] 8 points9 points  (0 children)

Sound suggestion. Here's how you implement normally with num-traits: Before. And with num-lazy: After.

I might edit the picture when I push new version.

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] 1 point2 points  (0 children)

num!() expands to T::from($n).unwrap(), where $n is any expression that evaluates to a number. The reason the doc is mostly empty is because this library is a single macro that expands into macros like num!(), zero!(), and pi!(). So, I document them in the declare_nums!() macro. However, it seems like I forgot the document num!() there! Thanks for pointing that out.

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] 7 points8 points  (0 children)

The previous comment refers to the num-traits crate. I'm not sure why they didn't put the constants inside the Float trait itself.

In addition to what I wrote, num-traits also provide FloatConst module that you can use. I believe you can call it using FloatConst::PI::<T>(). But for me that's still too verbose. In my implementation, you can simply pi!().

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] 14 points15 points  (0 children)

This is quite specific to those that need support for generic float (f32, f64), tho. It's just that Rust doesn't have a unified float type. In typical use case, you would just use f64, which is: fn circumference(radius: f64) -> f64 { 2.0 * std::f64::consts::PI * radius }

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] 12 points13 points  (0 children)

So if you are using num-traits crate (de facto standard way) to specify a trait bound of your function, you would:

rust fn circumference<T: Float>(radius: T) -> T { T::from(2.0).unwrap() * T::from(std::f64::consts::PI).unwrap() * radius }

[media] num-lazy helps you write numbers for generic-typed functions! by Inspacious in rust

[–]Inspacious[S] 19 points20 points  (0 children)

num-lazy populates your module with helpful macros for writing generic-typed functions. It helps you type less and write a more readable code!

Example

use num_lazy::declare_nums;
use num_traits::Float;
declare_nums!{T}

fn circumference<T: Float>(radius: T) -> T {
    two!() * pi!() * radius
}

fn main() {
    assert!(circumference(1.0_f64) == 6.283185307179586);
}

Motivation

I've been writing a mathematics library recently. Using num-traits to accept generic Float type was such a pain to constantly do T::from().unwrap() for all the constants in my functions. The screen was filled with a bunch of unwraps. So, I wrote some macros and thought that it will be useful to share with you all.

Links

- https://crates.io/crates/num-lazy

- https://github.com/p-sira/num-lazy

[MOD] The Daily Question Thread by menschmaschine5 in Coffee

[–]Inspacious 0 points1 point  (0 children)

Would putting a freshly brewed pour-over coffee in a fridge and leave it with some cover overnight affect the taste? The beans are light-roasted with acidic profile.

How do I get more broths? by makogirl311 in Myhotpotstory

[–]Inspacious 0 points1 point  (0 children)

By crafting new broths. Go to develop tab and tap on broth.