Skip to content
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

Make floats use CLP(FD) #26

Open
JCumin opened this issue Jul 14, 2016 · 5 comments
Open

Make floats use CLP(FD) #26

JCumin opened this issue Jul 14, 2016 · 5 comments

Comments

@JCumin
Copy link
Owner

JCumin commented Jul 14, 2016

Use something like 'float':Mantissa:Exponent to represent floats in the transpiler and built-ins, so that we can apply constraints on the mantissa and exponent of a floating point number.

This could be used to actually model all numbers but I think that would destroy performance on integer arithmetic if it was like that.

@triska would probably have a better idea about whether this is a good idea or not?

@triska
Copy link
Contributor

triska commented Jul 14, 2016

That's definitely an awesome idea and would certainly be possible with CLP(FD).

I do not expect any problems with this approach. You can have float(M,E) and integer(I) to symbolically distinguish the cases and carry over the information about types so that integer operations remain efficient. SWI does something very similar internally (tags denote the type of the number).

However, how about taking it up a notch and aiming even higher? I see basically two very promising options, both of which could be implemented in Brachylog and would provide a rather unique selling point over many other languages even beyond typical golfing languages:

  1. rational numbers: these are essentially available for free, because they are implemented in SWI-Prolog. Try for example: ?- X is 1 rdiv 2 + 1 rdiv 3.. This would definitely come in handy in Brachylog and would be comparatively easy to implement.
  2. unums: I expect this or a similar format to completely supersede IEEE floating point numbers within our lifetimes. Why not take the lead into this direction?

Especially regarding unums, I will help in every way I can to produce a Prolog implementation. Later, we can even move it to the SWI core. See also the unum page by Ulrich Neumerkel, who may also be interested in these developments.

@JCumin
Copy link
Owner Author

JCumin commented Jul 19, 2016

@triska Rational numbers are available for free, but they present the same problem that low-level arithmetic has as far as I see, e.g. 5 rdiv 6 is X rdiv 2 + 1 rdiv 3. returns an Arguments are not sufficiencly instantiated error.

@JCumin
Copy link
Owner Author

JCumin commented Jul 19, 2016

@triska As for unums, it would indeed be harder to implement, especially considering that the publications on the subject are relatively sparse and not very extensive (excluding the book which I don't have access to)

@triska
Copy link
Contributor

triska commented Jul 19, 2016

For constraint solving over rational numbers, I recommend CLP(Q) constraints, available as library(clpq) in SWI-Prolog. For example:

?- use_module(library(clpq)).
true.
?- { 5/6 = X/2 + 1/3 }.
X = 1.

You are perfectly right to expect more than (is)/2!

CLP(Q) constraints should be your default when using rational numbers.

@JCumin JCumin added grammar and removed grammar labels Jan 31, 2017
@razetime
Copy link

razetime commented Sep 8, 2022

is this still open for addition?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants