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

Use a pair instead of a list to represent intervals #9

Closed
pmoura opened this issue Nov 18, 2020 · 5 comments
Closed

Use a pair instead of a list to represent intervals #9

pmoura opened this issue Nov 18, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@pmoura
Copy link
Collaborator

pmoura commented Nov 18, 2020

Representing an interval using a pair, e.g. (X,Y) is more efficient than using a list, [X,Y]. To make it clear:

| ?- write_canonical([1,7]).
'.'(1,'.'(7,[]))

yes
| ?- write_canonical((1,7)).
','(1,7)

yes

I.e. accessing the upper limit in an interval is more costly with a list representation.

@mlliarm mlliarm added the enhancement New feature or request label Nov 18, 2020
@mlliarm
Copy link
Owner

mlliarm commented Nov 18, 2020

Thanks Paulo. This is a nice suggestion actually.

I might be needing some ways to get the first or the second element of the pair in the future. I know how to do this with lists, but I'm not sure how this could be possible with pairs. I'll look it up.

As the interval_arithmetic is I believe it can be changed easily to use pairs instead of lists. So I'll get to it.

@mlliarm mlliarm self-assigned this Nov 18, 2020
mlliarm added a commit that referenced this issue Nov 18, 2020
@mlliarm
Copy link
Owner

mlliarm commented Nov 18, 2020

I found this suggestion regarding my question above.

@pmoura
Copy link
Collaborator Author

pmoura commented Nov 18, 2020

I might be needing some ways to get the first or the second element of the pair in the future. I know how to do this with lists, but I'm not sure how this could be possible with pairs. I'll look it up.

Not sure I understand the problem. You can simply use unification as you're doing with lists. E.g.

    is_in((Xa, Xb), Number) :-
        Xa =< Number,
        Xb >= Number.

@mlliarm
Copy link
Owner

mlliarm commented Nov 18, 2020

I might be needing some ways to get the first or the second element of the pair in the future. I know how to do this with lists, but I'm not sure how this could be possible with pairs. I'll look it up.

Not sure I understand the problem. You can simply use unification as you're doing with lists. E.g.

    is_in((Xa, Xb), Number) :-
        Xa =< Number,
        Xb >= Number.

I wasn't thinking about the predicates from interval_arithmetic, but for predicates to be created (see #10).

But it seems that unification should be enough. I'll have to think things harder, it seems. Thanks !

@mlliarm
Copy link
Owner

mlliarm commented Nov 18, 2020

The interval_arithmetic library has been converted to use pairs (tuples) instead of lists.

So far all the created tests pass with 100%.

For this reason I'll close this issue.

@mlliarm mlliarm closed this as completed Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants