Last active
March 24, 2022 15:26
-
-
Save egonelbre/1755115 to your computer and use it in GitHub Desktop.
Prolog Explanation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daytime. | |
clear_skies. | |
% I want to have empty tables (facts) `daytime` and `clear_skies` | |
round(earth). | |
round(ball). | |
small(mouse). | |
small(ball). | |
% I want to have tables `round` and `small` | |
% `round` should contain `earth` and `ball` | |
% `small` should contain `mouse` and `ball` | |
time_to_play :- daytime, clear_skies. | |
% I have empty table (fact) `time_to_play` if | |
% there are two other tables (facts) `daytime` and `clear_skies` | |
suitable_for_playing_with(X) :- round(X), small(X). | |
% I want to have a table `suitable_for_playing_with` | |
% such that each value in it must be in tables `round` and `small` | |
does_nick_want_to_play_with(X) :- time_to_play, suitable_for_playing_with(X). | |
% I want to have a table `does_nick_want_to_play_with`, if there is a table `time_to_play` | |
% and there each value is also in table `suitable_for_playing_with` | |
% queries | |
?- daytime. | |
% is there a table `daytime` | |
?- round(cube) | |
% is there a table `round` that contains value `cube` | |
?- round(What). | |
% is there a table `round` and set `What` to it's values | |
?- does_nick_want_to_play_with(ball). | |
% is there a table `does_nick_want_to_play_with` containing `ball` | |
?- does_nick_want_to_play_with(What). | |
% is there a table `does_nick_want_to_play_with` | |
% and give me the values stored in `What` | |
different(1, 2). different(1, 3). | |
different(2, 1). different(2, 3). | |
different(3, 1). different(3, 2). | |
% there is a table `different` with the appropriate values | |
solve_for(A, B, C, D, E) :- | |
different(B, D), different(B, A), | |
different(A, D), different(A, B), | |
different(A, C), different(A, E), | |
different(C, E), different(C, D). | |
% create a table `solve_for` such that each field | |
% `A`, `B`, `C`, `D`, `E` | |
% is in the `different` table appropriately | |
?- solve_for(A, B, C, D, E) | |
% get the values that belong to `solve_for` table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment