· Note: for assignment 4 and 5 you should send me two separate documents which means in assignment 4 there should be 4 files such as, (2_exercises.pl , 3_exercises.pl, 4_exercises.pl ,...

1 answer below »
assignment


· Note: for assignment 4 and 5 you should send me two separate documents which means in assignment 4 there should be 4 files such as, (2_exercises.pl , 3_exercises.pl, 4_exercises.pl , 5_exercises.pl)and for assignment 5 there should be 3 files such as, (6_exercises.pl , 8_exercises.pl , 9_exercises.pl) Assignment 4: Introduction to Prolog Basics Goals for This Assignment By the time you have completed this work, you should be able to: · Define facts and rules in Prolog · Query facts and rules with both simple and complex queries Provided files: · 2_exercises.pl · % Consider the following facts: · % 1.) Apple and Microsoft make operating systems · % 2.) Mac OS X, Windows, and Linux are operating systems · % 3.) Linux is open source · · % Add these facts to the following database at the points · % marked `FILL ME IN`.  Use the atoms 'apple', 'microsoft', · % 'mac_os_x', 'windows', and 'linux' for the respective · % components. · · makesOperatingSystem(google). · % FILL ME IN - apple and microsoft · · operatingSystem(freebsd). · operatingSystem(openbsd). · % FILL ME IN - mac_os_x, windows, and linux · · openSource(freebsd). · openSource(openbsd). · % FILL ME IN - linux · · · 3_exercises.pl · % Below we have some logical facts and some potential queries · % that could be run with those facts.  Your goal is to fill · % in what these queries do.  Ignore any warnings for this file. · % As a hint, you can run this file directly by: · % · % swipl -s 3_exercises.pl · % · % ...and then issuing the queries at the prompt. · · % Consider the following Prolog logicbase: · · easy(1). · easy(2). · easy(3). · · gizmo(a,1). · gizmo(b,3). · gizmo(a,2). · gizmo(d,5). · gizmo(c,3). · gizmo(a,3). · gizmo(c,4). · · % Write out whether or not the following queries are true or · % false, replacing `???` where appropriate. · % If a query is true and involves variable instantiations, then write out · % all possible variable instantiations which make the query · % true.  Some have already been done for you.  If you wish, you may simply · % copy and paste the output of SWI-PL here directly; we will be grading · % this by hand, so the output format isn't important. · · · % QUERY: easy(2). · % ANSWER: true · · % QUERY: gizmo(a,X). · % ANSWER: X = 1, X = 2, X = 3 · · % QUERY: easy(X). · % ANSWER: ??? · · % QUERY: gizmo(X,3). · % ANSWER: ??? · · % QUERY: gizmo(d,Y). · % ANSWER: ??? · · % QUERY: gizmo(X,X). · % ANSWER: ??? · · % Consider this logicbase: · · harder(a,1). · harder(c,X). · harder(b,4). · harder(d,2). · · % Again, replace `???` where appropriate below: · · % QUERY: harder(a,X). · % ANSWER: ??? · · % QUERY: harder(c,X). · % ANSWER: ??? · · % QUERY: harder(X,1). · % ANSWER: ??? · · % QUERY: harder(X,4). · % ANSWER: ??? · · 4_exercises.pl · % Below we have some logical facts and some potential queries · % that could be run with those facts.  Your goal is to fill · % in what these queries do.  Ignore any warnings for this file. · % As a hint, you can run this file directly by: · % · % swipl -s 4_exercises.pl · % · % ...and then issuing the queries at the prompt. · · % Consider the following Prolog logicbase: · · easy(1). · easy(2). · easy(3). · · gizmo(a,1). · gizmo(b,3). · gizmo(a,2). · gizmo(d,5). · gizmo(c,3). · gizmo(a,3). · gizmo(c,4). · · harder(a,1). · harder(c,X). · harder(b,4). · harder(d,2). · · % Write out whether or not the following queries are true or · % false, replacing `???` where appropriate. · % If a query is true and involves variable instantiations, then write out · % all possible variable instantiations which make the query · % true.  Some have already been done for you, to give an · % example of the expected format.  If you wish, you may simply · % copy and paste the output of SWI-PL here directly; we will be grading · % this by hand, so the output format isn't important. · · % QUERY: easy(Y), gizmo(X,Y). · % ANSWER: (X = a, Y = 1), (X = a, Y = 2), (X = b, Y = 3), (X = c, Y = 3), (X = a, Y = 3) · · % QUERY: gizmo(a,X), easy(X). · % ANSWER: ??? · · % QUERY: gizmo(c,X), easy(X). · % ANSWER: ??? · · % QUERY: gizmo(d,Z), easy(Z). · % ANSWER: ??? · · % QUERY: easy(X), harder(Y,X). · % ANSWER: ??? · · % QUERY: harder(Y,X), easy(X). · % ANSWER: ??? · · 5_exercises.pl · % Below we have some logical facts and some potential queries · % that could be run with those facts.  Your goal is to fill · % in what these queries do.  Ignore any warnings for this file. · % As a hint, you can run this file directly by: · % · % swipl -s 5_exercises.pl · % · % ...and then issuing the queries at the prompt. · · % Consider the following Prolog logicbase: · · a(a1,1). · a(A,2). · a(a3,N). · · b(1,b1). · b(2,B). · b(N,b3). · · c(X,Y) :-  ·         a(X,N), ·         b(N,Y). · · d(X,Y) :-  ·         a(X,N), ·         b(Y,N). · · d(X,Y) :-  ·         a(N,X), ·         b(N,Y). · · % Write out whether or not the following queries are true or · % false, replacing `???` where appropriate. · % If a query is true and involves variable instantiations, then write out · % all possible variable instantiations which make the query · % true.  Some have already been done for you, to give an · % example of the expected format.  If you wish, you may simply · % copy and paste the output of SWI-PL here directly; we will be grading · % this by hand, so the output format isn't important. · · % QUERY: a(X, 2). · % ANSWER: true, X = a3 · · % QUERY: c(X,Y). · % ANSWER: (X = a1, Y = b1), (X = a1, Y = b3), true, Y = b3, (X = a3, Y = b1), X = a3, (X = a3, Y = b3) · · % QUERY: b(X,kalamazoo). · % ANSWER: ??? · · % QUERY: c(X,b3). · % ANSWER: ??? · · % QUERY: c(A, B). · % ANSWER: ??? · · % QUERY: c(X, X). · % ANSWER: ??? · · % QUERY: d(X, Y). · % ANSWER: ??? · · % QUERY: d(X, X). · % ANSWER: ??? Step-by-Step Instructions Step 1: Read Chapters 1-5 of the Amzi! Adventure in Prolog Tutorial, and Complete Related Exercises There is only a single big step for this assignment: read chapters 1-5 of the Amzi! Adventure in Prolog Tutorial. This is a relatively short textbook which is freely available online. Links to the individual chapters are on the left side of the screen, below the picture of the flying squirrel (do not ask me why there is a random picture of a flying squirrel there...). Exercises for chapters 2-5 are provided in the following files: · 2_exercises.pl · 3_exercises.pl · 4_exercises.pl · 5_exercises.pl You must complete all of the above exercises. It is recommended to first read a chapter, then complete the exercises for that chapter, as opposed to trying to read in bulk and then complete the exercises in bulk. Step 2- When you done make sure, you send me the following files: · 2_exercises.pl · 3_exercises.pl · 4_exercises.pl · 5_exercises.pl Assignment 5: Recursion and Structures in Prolog Goals for This Assignment By the time you have completed this work, you should be able to: · Use arithmetic in Prolog · Define recursive rules in Prolog · Use structures in Prolog Provided files: · 6_exercises.pl · % Write code below which will convert a temperature in Fahrenheit to · % Celsius.  Note that you cannot simply use the definition of · % `c_to_f` directly from the tutorial, since Prolog in and of itself · % cannot reason about arithmetic in reverse.  Your clause should be · % named `f_to_c`, and it should take two parameters: the Fahrenheit · % and Celsius temperatures, respectively. · · % Recall that the formula conversion is the following: · % · % C = (F - 32) * (5 / 9) · % · % ...where `F` and `C` represent the temperatures in Fahrenheit · % and Celsius, respectively · · % ---REPLACE ME WITH CODE--- · · % With your conversion routine in hand, the following queries should · % all succeed: · · % QUERY 1: f_to_c(0, -17.77777777777778). · % QUERY 2: f_to_c(32, 0.0). · % QUERY 3: f_to_c(212, 100.0). · 8_exercises.pl · % Write a procedure that calculates the sum of the numbers in · % a given range.  The parameters to this procedure should be · % as follows: · % · % 1. The low end of the range · % 2. The high end of the range · % 3. The sum of the values in the range · % · % If the low end equals the high end, then the sum should be · % whatever value is equal to the low/high end (the range is · % inclusive).  If the low end is greater than the high end, · % then failure should occur. · · % ---REPLACE ME WITH CODE--- · · % With your summation procedure in hand,
Answered Same DayAug 27, 2021

Answer To: · Note: for assignment 4 and 5 you should send me two separate documents which means in assignment 4...

Pulkit answered on Aug 28 2021
140 Votes
Assignment 4/2_exercises.pl
% Consider the following facts:
% 1.) Apple and Microsoft make operating systems
% 2.) Mac OS X, Windows, and Linux are operating systems
% 3.) Linux is open source
% Add these facts to the following database at the points
% marked `FILL ME IN`. Use the atoms 'apple', 'microsoft',
% 'mac_os_x', 'windows', and 'linux' for the respective
% components.
makesOperatingSystem(google).
% FILL ME IN - apple and microsoft
makesOperatingSystem(apple).
makesOperatingSystem(microsoft).
operatingSystem(freebsd).
operat
ingSystem(openbsd).
% FILL ME IN - mac_os_x, windows, and linux
operatingSystem(mac_os_x).
operatingSystem(windows).
operatingSystem(linux).
openSource(freebsd).
openSource(openbsd).
% FILL ME IN - linux
openSource(linux).
Assignment 4/3_exercises.pl
% Below we have some logical facts and some potential queries
% that could be run with those facts. Your goal is to fill
% in what these queries do. Ignore any warnings for this file.
% As a hint, you can run this file directly by:
%
% swipl -s 3_exercises.pl
%
% ...and then issuing the queries at the prompt.
% Consider the following Prolog logicbase:
easy(1).
easy(2).
easy(3).
gizmo(a,1).
gizmo(b,3).
gizmo(a,2).
gizmo(d,5).
gizmo(c,3).
gizmo(a,3).
gizmo(c,4).
% Write out whether or not the following queries are true or
% false, replacing `???` where appropriate.
% If a query is true and involves variable instantiations, then write out
% all possible variable instantiations which make the query
% true. Some have already been done for you. If you wish, you may simply
% copy and paste the output of SWI-PL here directly; we will be grading
% this by hand, so the output format isn't important.
% QUERY: easy(2).
% ANSWER: true
% QUERY: gizmo(a,X).
% ANSWER: X = 1, X = 2, X = 3
% QUERY: easy(X).
% ANSWER: X = 1, X = 2, X = 3
% QUERY: gizmo(X,3).
% ANSWER: X = b, X = c, X = a
% QUERY: gizmo(d,Y).
% ANSWER: Y = 5
% QUERY: gizmo(X,X).
% ANSWER: false
% Consider this logicbase:
harder(a,1).
harder(c,X).
harder(b,4).
harder(d,2).
% Again, replace `???` where appropriate below:
% QUERY: harder(a,X).
% ANSWER: X = 1
% QUERY: harder(c,X).
% ANSWER: true
% QUERY: harder(X,1).
% ANSWER: X = a, X = c, false
% QUERY: harder(X,4).
% ANSWER: X = c, X = b, false
Assignment 4/4_exercises.pl
% Below we have some logical facts and some potential queries
% that could be run with those facts. Your goal is to fill
% in what these queries do. Ignore any warnings for this file.
% As a hint, you can run this file directly by:
%
% swipl -s 4_exercises.pl
%
% ...and then issuing the queries at the prompt.
% Consider the following Prolog logicbase:
easy(1).
easy(2).
easy(3).
gizmo(a,1).
gizmo(b,3).
gizmo(a,2).
gizmo(d,5).
gizmo(c,3).
gizmo(a,3).
gizmo(c,4).
harder(a,1).
harder(c,X).
harder(b,4).
harder(d,2).
% Write out whether or not the following queries are true or
% false, replacing `???` where appropriate.
% If a query is true and involves variable instantiations, then write out
% all possible variable instantiations which make the query
% true. Some have already been done for you, to give an
% example of the expected format. If you wish, you may simply
% copy and paste the output of SWI-PL here directly; we will be grading
% this by hand, so the output format isn't important.
% QUERY: easy(Y), gizmo(X,Y).
% ANSWER: (X = a, Y = 1), (X = a, Y = 2), (X = b, Y = 3), (X = c, Y = 3), (X = a, Y = 3)
% QUERY: gizmo(a,X), easy(X).
% ANSWER: X = 1; X = 2; X = 3
% QUERY: gizmo(c,X), easy(X).
% ANSWER: X = 3; false
% QUERY: gizmo(d,Z), easy(Z).
% ANSWER: false
% QUERY: easy(X), harder(Y,X).
% ANSWER: (X = 1, Y = a); (X = 1, Y = c);
         (X = 2, Y = c); (X = 2, Y = d);
         (X = 3, Y = c); false
% QUERY: harder(Y,X), easy(X).
% ANSWER: (X = 1, Y = a); (X = 1, Y = c);
         (X = 2, Y = c); (X = 2, Y = d);
         (X = 3, Y = c);
Assignment 4/5_exercises.pl
% Below we have some logical facts and some potential queries
% that could be run with those facts. Your goal is to fill
% in what these queries do. Ignore any warnings for this file.
% As a hint, you can run this file directly by:
%
% swipl -s 5_exercises.pl
%
% ...and then issuing the queries at the prompt.
% Consider the following Prolog logicbase:
a(a1,1).
a(A,2).
a(a3,N).
b(1,b1).
b(2,B).
b(N,b3).
c(X,Y) :-
a(X,N),
b(N,Y).
d(X,Y) :-
a(X,N),
b(Y,N).
d(X,Y) :-
a(N,X),
b(N,Y).
% Write out whether or not the following queries are true or
% false, replacing `???` where appropriate.
% If a query is true and involves variable instantiations, then write out
% all possible variable instantiations which make the query
% true. Some have already been done for you, to give an
% example of the expected format. If you wish, you may simply
% copy and paste the output of SWI-PL here directly; we will be grading
% this by hand, so the output format isn't important.
% QUERY: a(X, 2).
% ANSWER: true, X = a3
% QUERY: c(X,Y).
% ANSWER: (X = a1, Y = b1), (X = a1, Y = b3), true, Y = b3, (X = a3, Y = b1), X = a3, (X = a3, Y = b3)
% QUERY: b(X,kalamazoo).
% ANSWER: X = 2; false
% QUERY: c(X,b3).
% ANSWER: X = a3, true
% QUERY: c(A, B).
% ANSWER: X = a3, Y= b3
% QUERY: c(X, X).
% ANSWER: false
% QUERY: d(X, Y).
% ANSWER: false
% QUERY: d(X, X).
% ANSWER: true
Assignment 4/comp-333-assignment-4-and-5-cfkatxud.docx
· Note: for assignment 4 and 5 you...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here