-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** Special math functions in the Error, Gamma and Beta families | ||
The underlying Rust implementations come from the puruspe crate. | ||
*/ | ||
|
||
:- module(special, [ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dcnorris
Author
Owner
|
||
erf/2 | ||
%,erfc/2 | ||
%,inverf/2 | ||
%,inverfc/2 | ||
%,gamma/2 | ||
%,gammq/3 | ||
%,invgammp/3 | ||
%,ln_gamma/2 | ||
%,beta/3 | ||
%,betai/4 | ||
%,invbetai/4 | ||
]). | ||
|
||
%% erf(+X, -Erf) | ||
% | ||
% Erf is erf(X). | ||
erf(X, Erf) :- '$erf'(X, Erf). | ||
This comment has been minimized.
Sorry, something went wrong.
adri326
|
||
|
||
%% TODO: erfc(+X, -Erfc) | ||
% | ||
% Erfc is erfc(X). | ||
|
||
%% TODO: inverf(+X, -InvErf) | ||
This comment has been minimized.
Sorry, something went wrong.
adri326
|
||
% | ||
% InvErf is erf⁻¹(X). % TODO: Check this; puruspe docs have a mistake. | ||
|
||
%% TODO: inverfc(+X, -InvErfc) | ||
% | ||
% InvErfc is erfc⁻¹(X). % TODO: Check this; puruspe docs have a mistake. | ||
|
||
%% TODO: gamma(+X, -Gamma) | ||
% | ||
% Gamma is Γ(X). | ||
|
||
%% TODO: gammp(+A, +X, -P) | ||
% | ||
% P is P(A,X), the regularized _lower_ incomplete gamma function. | ||
% X ≥ 0 is the upper limit of integration | ||
% A > 0 is the shape parameter | ||
|
||
%% TODO: gammq(+A, +X, -Q) | ||
% | ||
% Q is Q(A,X) := Γ(A,X)/Γ(A), the regularized _upper_ incomplete gamma | ||
% function. | ||
% X ≥ 0 is the lower limit of integration | ||
% A > 0 is the shape parameter | ||
|
||
%% TODO: invgammp(+P, +A, -X) | ||
% | ||
% X is the unique solution of P = P(A,X), where P(-,-) is the | ||
% regularized lower incomplete gamma function. | ||
% P ∈ [0,1] is a probability | ||
% A > 0 is the _shape parameter_ | ||
|
||
%% TODO: ln_gamma(+Z, -LnGamma) | ||
% | ||
% LnGamma is ln(Γ(Z)), the natural logarithm of Γ(Z). | ||
|
||
%% TODO: beta(+Z, +W, -B) | ||
% | ||
% B is B(Z,W) := Γ(Z)*Γ(W)/Γ(Z+W) | ||
|
||
%% TODO: betai(+A, +B, +X, -I) | ||
% | ||
% I is Iₓ(A,B) := B(X;A,B)/B(A,B), the regularized incomplete beta function | ||
% A > 0 and B > 0 are the first and second shape parameters | ||
% X ∈ [0,1] is the upper limit of integration. | ||
|
||
%% TODO: invbetai(+P, +A, +B, -X) | ||
% | ||
% X is the unique solution of P = Iₓ(A,B) := B(X;A,B)/B(A,B) | ||
% P ∈ [0,1] is a probability | ||
% A > 0 and B > 0 are the first and second shape parameters | ||
% X ∈ [0,1] is the upper limit of integration. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,9 @@ use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512}; | |
|
||
use crrl::{ed25519, secp256k1, x25519}; | ||
|
||
#[cfg(feature = "special-math")] | ||
This comment has been minimized.
Sorry, something went wrong.
adri326
|
||
use puruspe::error::erf; | ||
|
||
#[cfg(feature = "tls")] | ||
use native_tls::{Identity, TlsAcceptor, TlsConnector}; | ||
|
||
|
@@ -7748,6 +7751,23 @@ impl Machine { | |
); | ||
} | ||
|
||
#[cfg(feature = "special-math")] | ||
#[inline(always)] | ||
pub(crate) fn erf(&mut self) { | ||
let x = self.deref_register(1); | ||
let x = match Number::try_from(x) { | ||
Ok(Number::Float(n)) => n.into_inner(), | ||
Ok(Number::Fixnum(n)) => n.get_num() as f64, | ||
Ok(Number::Integer(n)) => n.to_f64().value(), | ||
_ => { | ||
unreachable!() | ||
} | ||
}; | ||
let erf_x = float_alloc!(erf(x), self.machine_st.arena); | ||
let return_value = self.deref_register(2); | ||
self.machine_st.unify_f64(erf_x, return_value); | ||
} | ||
|
||
#[inline(always)] | ||
pub(crate) fn crypto_curve_scalar_mult(&mut self) { | ||
let stub_gen = || functor_stub(atom!("crypto_curve_scalar_mult"), 4); | ||
|
4 comments
on commit 157c35c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Darn, Github makes it not visually clear that I've left some comments. Hopefully you can find them above!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, yes, this UI is hard to use!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a severe recent regression of github, it was previously obvious where a comment was placed, now it is almost invisible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I've disabled the feature preview (can be found when you click your profile icon on the top right), I don't know why they felt the need to collapse comments by default with no option to un-collapse them all
I think it would be nice after this to have something like
To warn users when the feature flag isn't enabled (akin to how tools like ripgrep warn you if you use PCRE2 regexes when the feature wasn't enabled).