Simple Prolog: Please, find the assignment in the file attached. If possible, write as much comment as you can - I really need to understand this material. Thank you for your time.

PROLOG

Due 7/10

NOTE: For your homework, you are not allowed to use the builtin

predicate

definitions.Â If, for example, you want to use member/2, create you own

version called mymember/2 (or something).Â Same for append, reverse,

sort, and many others.You may use any builtin numeric operators, 'is',

the '[' ']'

brackets for lists, fail, not, and maybe some others

(5) In Prolog, implement the predicate cube/2. Â This predicate will

relate a list of numbers to a list of numbers that, for each number in

the first list, contains the number, the square of the number, and the

cube of the number. Â The only modes for this predicate are: cube(+,-),

and cube(+,+). Â E.g.,

?- cube([2,1,4],A).

A = [2,4,8,1,1,1,4,16,64]

?- cube([],[]).

yes.

?- cube([5],[5,25,125]).

yes.

?- cube([2,3],[2,3,4]).

no.

(5) In Prolog, implement the predicate dotProduct/3. Â This predicate

will relate two vectors (represented as lists) to their dot product.

Â The only modes for this predicate are: dotProduct(+,+,-), and

dotProduct(+,+,+). Â E.g.,

?- dotProduct([1,2,3],[5,5,5],A).

A = 30

?- dotProduct([2],[12],24).

yes.

?- dotProduct([],[0],0).

yes.

?- dotProduct([2,3],[2,3,4],17).

no.

(45) In Prolog, create an ADT for Sets. Â Each Set will be represented

as a list of unique atoms. Â Assume the same semantics as in Hw3.

(5) setAddElt(E,S1,S2).

S2 = S1 Union {E}Â

Assume modes: setAddElt(+,+,-), and SetAddElt(+,+,+).

(5) setDelElt(E,S1,S2).

S2 = S1 - {E}

Assume modes: setDelElt(+,+,-), and SetDelElt(+,+,+).

(5) setMember(E,S).

return E element-of S

Assume any mode.

(10) setEqual(S1,S2).

return S1 == S2 (in Prolog)

Assume modes: setEqual(+,+).

(10) SetUnion(S1,S2,S3).

S3 = S1 Union S2

Assume modes: setUnion(+,+,-), and SetUnion(+,+,+).

(10) Set Intersect(S1,S2,S3).

S3 = S1 Intersection S2

Assume modes: setIntersect(+,+,-), and SetIntersect(+,+,+).

(20) Because Prolog's search engine has the ability to backtrack to find

a solution, Prolog can easily be used to implement a top-down parser.

Assume the following Context-Free-Grammar (CFG) for Boolean Expressions,

with start symbol E.

E --> A or E | A

A --> B and A | B

B --> not B | C

C --> '(' E ')' | true | false

Using Prolog, construct a top-down parser that can be used to parse and

evaluate arbitray Boolean expressions. e.g.,

?- parse(['(',true,and,false,')',or true],V).

V = true.

?- parse([true,or,true,and,false],V).

V = true.

?- parse([true,or,or,true,or,false],V).

No.

Hint: Create a different predicate for each nonterminal in the grammar.

(25) Assume, you only have the numbers 1, 2, 3, and 4. Â Further assume

that you only have the operators '+' and '*'. Â Lastly, assume that you

can only use a number once.

Using Prolog, determine the number of arithmetic expressions that can be

create to equate to the numbers 30, 31, 32, 33, 34, and 35. Â

For example, there are 44 equations that equal 20, e.g.,

?- findExpr(20,E).

E = [1, *, [4, *, [2, +, 3]]] ;

E = [1, *, [4, *, [3, +, 2]]] ;

E = [1, *, [[2, +, 3], *, 4]] ;

E = [1, *, [[3, +, 2], *, 4]] ;

E = [4, *, [2, +, 3]] ;

E = [4, *, [2, +, [1, *, 3]]] ;

E = [4, *, [2, +, [3, *, 1]]] ;

E = [4, *, [3, +, 2]] ;

...

Hint: Use the following as a starting place.

findExpr(N,E):-

Â Â Â generateExpr(...),

Â Â Â computeValue(...).

PROLOG

Due 7/10

NOTE: For your homework, you are not allowed to use the builtin

predicate

definitions.Â If, for example, you want to use member/2, create you own

version called mymember/2 (or something).Â Same for append, reverse,

sort, and many others.You may use any builtin numeric operators, 'is',

the '[' ']'

brackets for lists, fail, not, and maybe some others

(5) In Prolog, implement the predicate cube/2. Â This predicate will

relate a list of numbers to a list of numbers that, for each number in

the first list, contains the number, the square of the number, and the

cube of the number. Â The only modes for this predicate are: cube(+,-),

and cube(+,+). Â E.g.,

?- cube([2,1,4],A).

A = [2,4,8,1,1,1,4,16,64]

?- cube([],[]).

yes.

?- cube([5],[5,25,125]).

yes.

?- cube([2,3],[2,3,4]).

no.

(5) In Prolog, implement the predicate dotProduct/3. Â This predicate

will relate two vectors (represented as lists) to their dot product.

Â The only modes for this predicate are: dotProduct(+,+,-), and

dotProduct(+,+,+). Â E.g.,

?- dotProduct([1,2,3],[5,5,5],A).

A = 30

?- dotProduct([2],[12],24).

yes.

?- dotProduct([],[0],0).

yes.

?- dotProduct([2,3],[2,3,4],17).

no.

(45) In Prolog, create an ADT for Sets. Â Each Set will be represented

as a list of unique atoms. Â Assume the same semantics as in Hw3.

(5) setAddElt(E,S1,S2).

S2 = S1 Union {E}Â

Assume modes: setAddElt(+,+,-), and SetAddElt(+,+,+).

(5) setDelElt(E,S1,S2).

S2 = S1 - {E}

Assume modes: setDelElt(+,+,-), and SetDelElt(+,+,+).

(5) setMember(E,S).

return E element-of S

Assume any mode.

(10) setEqual(S1,S2).

return S1 == S2 (in Prolog)

Assume modes: setEqual(+,+).

(10) SetUnion(S1,S2,S3).

S3 = S1 Union S2

Assume modes: setUnion(+,+,-), and SetUnion(+,+,+).

(10) Set Intersect(S1,S2,S3).

S3 = S1 Intersection S2

Assume modes: setIntersect(+,+,-), and SetIntersect(+,+,+).

(20) Because Prolog's search engine has the ability to backtrack to find

a solution, Prolog can easily be used to implement a top-down parser.

Assume the following Context-Free-Grammar (CFG) for Boolean Expressions,

with start symbol E.

E --> A or E | A

A --> B and A | B

B --> not B | C

C --> '(' E ')' | true | false

Using Prolog, construct a top-down parser that can be used to parse and

evaluate arbitray Boolean expressions. e.g.,

?- parse(['(',true,and,false,')',or true],V).

V = true.

?- parse([true,or,true,and,false],V).

V = true.

?- parse([true,or,or,true,or,false],V).

No.

Hint: Create a different predicate for each nonterminal in the grammar.

(25) Assume, you only have the numbers 1, 2, 3, and 4. Â Further assume

that you only have the operators '+' and '*'. Â Lastly, assume that you

can only use a number once.

Using Prolog, determine the number of arithmetic expressions that can be

create to equate to the numbers 30, 31, 32, 33, 34, and 35. Â

For example, there are 44 equations that equal 20, e.g.,

?- findExpr(20,E).

E = [1, *, [4, *, [2, +, 3]]] ;

E = [1, *, [4, *, [3, +, 2]]] ;

E = [1, *, [[2, +, 3], *, 4]] ;

E = [1, *, [[3, +, 2], *, 4]] ;

E = [4, *, [2, +, 3]] ;

E = [4, *, [2, +, [1, *, 3]]] ;

E = [4, *, [2, +, [3, *, 1]]] ;

E = [4, *, [3, +, 2]] ;

...

Hint: Use the following as a starting place.

findExpr(N,E):-

Â Â Â generateExpr(...),

Â Â Â computeValue(...).

### Recently Asked Questions

- Entrepreneurs view change as ________ .

- Evan Tyson V3 PC -K (Basic DDx) 65 y.o. 6' 0" (183.0 cm) 216 lb (98.0 kg) Evan Tyson Chief complaint: Tired and peeing at night Start Your session will be

- Jan. 1Retired a piece of machinery that was purchased on January 1, 2004. The machine cost $62,350 on that date. It had a useful life of 10 years with no