In: Advanced Math
Rule Based System
1. Given the rule following rules from the class notes on production rules to convert an Arabic number less than 40 to a roman numeral. USING LOGIC
Rule 1: if x is null then prompt the user and read x
Rule 2: if x is higher than 999 then print “too Big” and make x null
Rule 3: if x is between 10 and 39 then print “X” and reduce x by 10
Rule 4: if x is equal to 9 then print “IX” and reduce x to 0
Rule 5: if x is between 5 and 8 then print “V” and reduce x by 5
Rule 6: if x is equal to 4 then print “IV” and reduce x to 0
Rule 7: if x is between 1 and 3 then print “I” and reduce x by 1
Rule 8: if x is equal to 0 then print “end-of-line” and STOP
A. What additional rules are needed to convert an Arabic number less than 1000?
* notice rule 2 has already been changed
** hints: 50 is L; 100 is C; 500 is D; 1000 is M
B. Show the rules fired and the working memory to convert 864 into a roman numeral.
SOLUTION A.
RULE 9: if x is between 40 and 49 then print “XL” and reduce x by 40.
RULE 10: if x is between 50 and 89 then print “L” and reduce x by 50.
RULE 11: if x is between 90 and 99 then print “XC” and reduce x by 90.
RULE 12: if x is between 100 and 399 then print “C” and reduce x by 100.
RULE 13: if x is between 400 and 499 then print “CD” and reduce x by 400.
RULE 14: if x is between 500 and 899 then print “D” and reduce x by 500.
RULE 15: if x is between 900 and 999 then print “CM” and reduce x by 900.
SOLUTION B.
x : 864 memory: NULL (initially)
RULE : 1 memory: 864(copy in memory) Output:
RULE : 14 memory: 364 (864-500) Output: D
RULE : 12 memory: 264 (364-100) Output: DC
RULE : 12 memory: 164 (264-100) Output: DCC
RULE : 12 memory: 64 (164-100) Output: DCCC
RULE : 10 memory: 14 (64-50) Output: DCCCL
RULE : 3 memory: 4 (14-10) Output: DCCCLX
RULE : 6 memory: 0 (4-0) Output: DCCCLXIV
RULE : 8 memory: NULL Output: DCCCLXIV end-of-line