-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
~~special~~ indispensable math functions #2765
Comments
For Scryer to become a reference system for testing standards conformity of Prolog code, there would have to be a way to turn these extensions off (so-called strictly conforming mode). To avoid weighing down the engine core (i.e., arithmetic evaluation), it would be better to provide such (conforming) extensions in a dedicated library, like the arithmetic functions in |
I'll try that, then. Should be a lot easier than hacking the core! |
Maybe this could be useful as an example of how to make Rust functionality available as a predicate: #2245 |
There's also some info on the wiki (one of the few things currently there): https://github.com/mthom/scryer-prolog/wiki/Flying-Roll-%231:-instructions.rs-and-the-Dispatch-Loop :) You unfortunately have to put the glue code in dispatch.rs, but from there on you can put the rest of the implementation somewhere else — if you want full opt-in/opt-out support, that could be in a module that is only imported if a corresponding feature flag is enabled. |
By slavishly following your commit @triska, I've managed in less than 2 hours to hook up an #[cfg(feature = "special-math")]
#[inline(always)]
pub(crate) fn erf(&mut self) {
let return_value = self.deref_register(2);
let bogus_ans = float_alloc!(0.123f64, self.machine_st.arena);
self.machine_st.unify_f64(bogus_ans, return_value)
} ?- use_module(library(special)).
true.
?- erf(1.0, Erf).
Erf = 0.123. (Any pointers to example code that gets an |
Maybe scryer-prolog/src/machine/system_calls.rs Line 6456 in 2856cc4
You can move type checking to the Prolog side of the implementation, which makes it simpler. |
That did the trick, thanks @triska! ?- use_module(library(special)).
true.
?- erf(1.1, Erf).
Erf = 0.8802050695740817. julia> import SpecialFunctions.erf
julia> erf(1.1)
0.8802050695740817 |
dcnorris@157c35c implements an
?- use_module(library(math/special)).
true.
?- erf(0.5, Erf).
Erf = 0.5204998778130465. |
dcnorris@7b2159e now modularizes the contribution nicely (IMO), thanks to guidance from @adri326. (Quite remarkable how the Rust compiler's suggestions carried me through this refactoring.) |
To clarify one point that I now see was not made sufficiently clear: The point of implementing such extensions in Prolog libraries is that Scryer starts in the strictly conforming mode. Only when the library is loaded do these predicates become available. There is no reason to make the Rust implementation contingent on flags, except for cases where compilation would otherwise fail on some platforms and it may be an advantage to compile Scryer itself without this functionality. |
Scryer would be much more usable for my work if it natively supported so-called 'special' math functions, such as those implemented in Rust crate https://github.com/Axect/puruspe. (They are 'special' really only due to the special effort involved in getting access to them!)
How would people feel about supporting at least the Error, Gamma, and Beta groups of functions from
puruspe
?(I did manage to hack
arithmetic.rs
,machine/arithmetic_ops.rs
andmachine/dispatch.rs
to introduce a newErf
Instruction, albeit mapped tosin
; I got a profusion of compiler errors in my attempts to substituteerf
in place ofsin
. But that was all flying blind, without really understanding the design, and how transcendental functions are fitting in to Instructions. Perhaps it will be best to document that misadventure in a separate Discussion.)The text was updated successfully, but these errors were encountered: