PROLOG
Exercise 7
Consider the following program.
a(X):- b(X), c(X), d(X).
a(X):- c(X), d(X).
a(X):- d(X).
b(1).
b(a).
b(2).
b(3).
d(10).
d(11).
c(3).
c(4).
Given the query ?- a(X). Write out the variable bindings that the variable X would get when the above query is run.
Exercise 4
Indicate whether the following are syntactically correct Rules.
a :- b, c, d:- e f. % Is this syntactically correct?
happy(X):- a , b. % Is this syntactically correct?
happy(X):- hasmoney(X) & has_friends(X). % Is this syntactically correct?
fun(fish):- blue(betty), bike(yamaha). % Is this syntactically correct?
Exercise 4
Answer
NO
YES
NO
YES
Explanation
a :- b, c, d:- e f.Is this syntactically correct?
NO
first note there is comma missing in between e and f
--
happy(X):- a , b.
YES
rule is syntactically correct
but look at the X
X is not at all used with in the body of rule
--
happy(X):- hasmoney(X) & has_friends(X).
NO
Please note that the & symbol will not recognized by
prolog
You can use comma instead of that
--
fun(fish):- blue(betty), bike(yamaha)
YES
Syntactically correct
even though there is no meaning
--
all the best
PROLOG Exercise 7 Consider the following program. a(X):- b(X), c(X), d(X). a(X):- c(X), d(X). a(X):- d(X)....
CSE 240 Homework 5- Programming with PROLOG Due: Monday, April 22, 11:59 PM A. What This Assignment Is About: Facts, Rules, Goals Prolog execution model Arithmetic operations . Recursive Rules B. Use the following Guidelines Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of...
1. Write a Prolog program that returns the length of a list of numbers. For example: size([1, 2, 3, 4], len). then return len=4. 2. Write a Prolog program that reverses the given list. For example: reverse([a, b, c, d], X). then return X=[d, c, b, a].
Incorrect Question 13 0/5 pts Consider the following PROLOG program: team(diane, nlu). team(mel, nlu). team(suz, nlu). team(tom, num). team(des, num). team(toni, theory). team(rich, ai). teammates (P,Q) :- team(P,x), team(Q,x). What is the first result of the following query? ?- teammates(des,X). (A) X = diane (B) X = des (C) X = tom (D) false (A) (B)
In the following C program, indicate the variable type (global, local, or static local), the lifetime (when the program is run or when the function is called), and the memory allocation (from stack or from heap) for each variable (x, y, z, and w) defined in the program. int w; void fun (int x) { int y; static float z; ... } void main() { fun(w); }
Consider the following Python program: def fun(x, y): return x + y # [2] # [1] a = fun(2, 3) b = fun("2", 3) print a, b What does it evaluate to? Replace the last statement print a, b with print a + b and explain the traceback. What's wrong? Now eliminate the line marked [1] and change line [2] to read return x + y. Run the program and explain the traceback. Consider the following definition: def fun(n, m):...
///Program needs to write in prolog/// 6. A binary tree is either empty or it is composed of a root element and two successors, which are binary trees themselves. In Prolog we represent the empty tree by the atom 'nil' and the non-empty tree by the term t(X,L,R), where X denotes the root node and L and R denote the left and right subtree, respectively. The following Prolog term represents the given binary tree below. T1 = t(a,t(b,t(d,nil,nil),t(e,nil,nil)),t(c,nil,t(f,t(g,nil, nil),nil))) d...
6. Comma between goals means: a. logical conjunction b. logical disjunction c. Exclusive OR d. logical implication 7. Prolog works by: a. Scanning clauses in the program from bottom to top, and by trying to satisfy goals in a question from left to right b. Scanning clauses in the program from top to bottom, and by trying to satisfy goals in a question from left to right c. Scanning clauses in the program from top to bottom, and by trying...
Question #7 12 points Implement the following functions using: X(A,B,C,D) = X (3,7,11,14,15) Y(A, B,C,D) = {(3,4,5,7,11,15) Z(A, B, C,D) = {(1,5, 14, 15) a) a single 16 x 3 ROM (use dot notation to indicate the ROM contents) b) a 4 x 4 x 3 PLA (use dot notation)
Exercise 3.3.1: Unions and intersections of sets. Define the sets A, B, C, and D as follows: A = {-3, 0, 1, 4, 17} B = {-12, -5, 1, 4, 6} C = {x ∈ Z: x is odd} D = {x ∈ Z: x is positive} For each of the following set expressions, if the corresponding set is finite, express the set using roster notation. Otherwise, indicate that the set is infinite. (c) A ∩ C (d) A ∪...
#s 1-5 in prolog Give an example of "or" relationship. Give an example of "and" relationship. Assume the following facts: parent(a,b). man(a). woman(c) 1. 2. 3. State a clause for father(a,b) 4. What would be the English meaning for this o prolog clause. o owner(jack, cat(X)) :- fur(X),spots(X) 5. Do the following terms unify? Why? likes(jax, X), and likes(X, jin). Give an example of "or" relationship. Give an example of "and" relationship. Assume the following facts: parent(a,b). man(a). woman(c) 1....