代写 C Haskell prolog Administration

Administration
Submission
• This assignment is due on Tuesday, April 9th at 2:30PM.
• Please refer to the course Late Policy for information about late submissions and penalties.
• You must submit your assignment in the “Assignment 5” Dropbox area in OnQ.
• Do not email your assignments to the instructor or TAs.
• You must submit one file named Assignment5.pl.
• Failure to not name the file correctly (including case) will result in deductions.
• Your file must include a comment near the top with your name.
• Please do not include your student number.
Important General Requirements
• You are not permitted to use any Prolog components (syntax, predicates, etc.) more advanced than those in the course topics covered thus far, up to and including “Prolog Cuts and Negation”, unless otherwise stated.
• (Updated 31-03-2019) You may only use the predicates specified for each question in your solution as well as is, =, \=, =:=, =\=, <, =<, > and >=.

• You may not use any other predicate, whether built-in or in any library, unless otherwise specified.
• You may not define helper predicates unless otherwise specified.
• Your solutions must not use mutually exclusive conditions within the predicates; you must use cuts instead unless otherwise specified.
• (Updated 31-03-2019) Your solutions must return a single result exactly as shown in the sample output unless otherwise specified.
• Multiple values, even if they’re correct, or a trailing false are not permitted.
• If your answer does not meet these requirements, that answer will be graded as zero even if it works.
Tips
• Before you tackle an assignment, do the assigned readings for the associated topic(s) and the practice problems first.
• Don’t wait until the last minute to work on an assignment – there will be a better chance of getting help if you need it.
• The instructor is able to respond to quick clarification questions about this assignment via e-mail.
• Please refer to the course’s Emailing the Instructor or TAs policy for more information.
Part 1: Recall Information
Overview
Consider the following hypothetical situation:
• several car manufacturers must issue a recall to repair a faulty widget manufactured by a third party;
• a series of Prolog facts with the structure mmyws(Make+Model/Year/WidgetType/NumberSold) contain the following vehicle information, respectively:
• the make;
• the model;
• the year;
• the type of widget used; and
• the number of the vehicles sold.
• 300-type widgets are particularly problematic and will cost $728.63 each to repair (parts & labour);
• 400-type widgets are somewhat less problematic and will cost $439.52 each to repair (parts & labour); and
• 500-type widgets are not faulty and don’t need to be recalled.
Sample Facts (Updated 31-03-2019)
The sample results for this part will use these sample facts. They represent two fictitious car companies, Ium and Cosmos.
Do not limit your testing to these sample facts alone. The TAs will test your work with another set of sample data. It your responsibility to add more facts and test your solution more thoroughly.
mmyws(ium+titan/2010/300/224507).
mmyws(ium+titan/2011/300/262391).
mmyws(ium+titan/2012/400/267041).
mmyws(ium+titan/2013/500/268842).
mmyws(ium+titan/2014/500/263528).

mmyws(ium+pluton/2010/300/99356).
mmyws(ium+pluton/2011/300/76184).
mmyws(ium+pluton/2012/300/65830).

mmyws(ium+zircon/2010/400/326624).
mmyws(ium+zircon/2011/400/337295).
mmyws(ium+zircon/2012/500/332653).
mmyws(ium+zircon/2013/500/330106).
mmyws(ium+zircon/2014/500/335865).

mmyws(cosmos+dyne/2010/400/145522).
mmyws(cosmos+dyne/2011/500/149490).
mmyws(cosmos+dyne/2012/500/151870).
mmyws(cosmos+dyne/2013/500/149911).
mmyws(cosmos+dyne/2014/500/149405).

mmyws(cosmos+flux/2010/300/106221).
mmyws(cosmos+flux/2011/300/105672).
mmyws(cosmos+flux/2012/300/105079).
mmyws(cosmos+flux/2013/300/110415).

mmyws(cosmos+orbit/2010/400/85164).
mmyws(cosmos+orbit/2011/400/82390).
Question 1.1: currency_round
Define a predicate currency_round with two arguments:
• a numeric value, which must be bound; and,
• a numeric value, which may be bound or unbound.
The predicate must round the first argument to two decimal places and bind or compare the value to the second argument.
Requirements
• All restrictions listed in “General Requirements” apply.
• You may use the arithmetic function round.
Sample Results
?- currency_round(87.092843, X).
X = 87.09.

?- currency_round(87.092843, 87.09).
true.

?- currency_round(87.092843, 87.10).
false.

?- currency_round(789243.999, X).
X = 789244.

?- currency_round(23437, X).
X = 23437.
Question 1.2: recall_information
Define a predicate recall_information with two arguments:
• an unbound variable which will contain a list of structures of the form Make-Model-Year; and,
• a numeric value, which may be bound or unbound.
The predicate must determine which vehicles are involved in the recall and the total cost of the recall rounded to two decimal places.
Requirements
• All restrictions listed in “General Requirements” apply.
• (Updated 31-03-2019) The order of the elements in the list may be different than those shown in the sample results.
• You may use the built-in predicate findall and/or the currency_round predicate if you choose.
• You may define one helper predicate named recall_information_helper with at most three agruments if you choose.
• You may use two mutually exclusive conditions for the value of the widget type.
• (Updated 2019-04-02) A single condition would be of the form value1 operator value2.
• Joining two such conditions with conjunction or disjunction does not combine them into one condition.
• Due to the structure and length of the resulting list, you may use the following predicate to output its contents for testing purposes only:
• print_list([]).

• print_list([Head|Tail]) :-
• format(‘~w~n’, Head),
• print_list(Tail).
• Hint: you can now use structural and arithmetic operators to calculate and assign values.
Sample Results (Updated 2019-04-02)
?- recall_information(L, C), print_list(L).
ium-titan-2010
ium-titan-2011
ium-titan-2012
ium-pluton-2010
ium-pluton-2011
ium-pluton-2012
ium-zircon-2010
ium-zircon-2011
cosmos-dyne-2010
cosmos-flux-2010
cosmos-flux-2011
cosmos-flux-2012
cosmos-flux-2013
cosmos-orbit-2010
cosmos-orbit-2011
L = [ium-titan-2010, ium-titan-2011, ium-titan-2012, ium-pluton-2010, ium-pluton-2011, ium-pluton-2012, ium-zircon-2010, … – … – 2011, … – …|…],
C = 1388823605.37.

?- recall_information(L, 1388823605.37).
L = [ium-titan-2010, ium-titan-2011, ium-titan-2012, ium-pluton-2010, ium-pluton-2011, ium-pluton-2012, ium-zircon-2010, … – … – 2011, … – …|…].

?- recall_information(L, 1388823605.38).
false.
Part 2: Higher-Order Functions
Question 2.1: foldl1
Define a predicate foldl1 with three arguments:
• a predicate, which must be bound;
• a list of values, which must be bound; and,
• a numeric value, which may be bound or unbound.
The predicate must calculate the result of folding the values in the list in the same manner as foldl1 in Haskell and bind or compare the value to the third argument.
Requirements
• All restrictions listed in “General Requirements” apply.
• You must use the built-in predicate call.
• You may use any of the “Useful Built-In Predicates” listed on slide 17 in Topic 12 if you choose.
• You may define a helper predicate foldl1_helper with at most four arguments if you choose.
• You may use the following predicate to help with your testing as well as define your own for testing purposes:
• subtract(X, Y, Z) :-
• Z is X – Y.
Sample Results
?- foldl1(concat,[‘a’,’b’,’c’],X).
X = abc.

?- foldl1(subtract,[1,2,6,1,8,3],X).
X = -19.

?- foldl1(subtract,[1,2,3,4],X).
X = -8.

?- foldl1(concat,[‘a’,’b’,’c’],’abc’).
true.

?- foldl1(subtract,[1,2,3,4],-9).
false.
Question 2.2: foldr1
Define a predicate foldr1 with three arguments:
• a predicate, which must be bound;
• a list of values, which must be bound; and,
• a numeric value, which may be bound or unbound.
The predicate must calculate the result of folding the values in the list in the same manner as foldr1 in Haskell and bind or compare the value to the third argument.
Requirements
• All restrictions listed in “General Requirements” apply.
• You must use the built-in predicate call.
• You may use the subtract predicate to help with your testing as well as define your own for testing purposes.
Sample Results
?- foldr1(concat,[‘a’,’b’,’c’],X).
X = abc.

?- foldr1(subtract,[1,2,6,1,8,3],X).
X = 9.

?- foldr1(subtract,[1,2,3,4],X).
X = -2.

?- foldr1(concat,[‘a’,’b’,’c’],’abc’).
true.

?- foldr1(subtract,[1,2,3,4],-3).
false.
Grading
The rubric for this assignment is shown following this description. Specific information regarding some aspects is given below.
Style
This includes, but is not limited to: indentation, value names, comments and local declarations using where (or lack thereof).
Deductions
Deductions will be applied for any failure to meet the stated requirements as well as any unanticipated errors or omissions.