1

I'm trying to define a prolog predicate numeral(X,Y) which is true if X is the roman numeral for the decimal number Y.

numerals(X,Y) :- X is ('M'), Y>=1000.
numerals(X,Y) :- X is  ('CM'), Y>=900.
numerals(X,Y) :- X is  ('D'), Y>=500.
numerals(X,Y) :- X is  ('CD'), Y>=400.
numerals(X,Y) :- X is  ('C'), Y>=100.
.
.
.
.

When I run my code, I get an error:

?-numerals(M,1001).
ERROR: toplevel: Undefined procedure: numerals/2 (DWIM could not correct goal)
false
  • 10,264
  • 13
  • 101
  • 209

2 Answers2

1

You have not loaded the program. Try listing to see this - and otherwise please refer to my first reply.

Community
  • 1
  • 1
false
  • 10,264
  • 13
  • 101
  • 209
  • numerals(X,Y) :- X is ('M'), Y>=1000. numerals(X,Y) :- X is ('CM'), Y>=900. numerals(X,Y) :- X is ('D'), Y>=500. numerals(X,Y) :- X is ('CD'), Y>=400. numerals(X,Y) :- X is ('C'), Y>=100. numerals(X,Y) :- X is ('L'), Y>=50. numerals(X,Y) :- X is ('XL'), Y>=40. numerals(X,Y) :- X is ('X'), Y>9. numerals(X,Y) :- X is ('IX'), Y>=9. numerals(X,Y) :- X is ('V'), Y>4. numerals(X,Y) :- X is ('IV'), Y>=4. numerals(X,Y) :- X is ('I'), Y>=1. numerals(X,Y) :- X is ('-'), Y>0. – Abdulmajeed Alfahad Nov 08 '12 at 07:30
1

Prolog is based on generating and then testing. The ordering between both part is important. What do you want to test and what do you want to generate?

Moreover, are you sure you want to use "is". This is for arithmetic operations.

Lastly, do you really plan to write rules without dependencies between them? It would probably a good idea to use a recursive algorithm... or you will have to write a rule for any possible number.

Aurélien Bénel
  • 3,775
  • 24
  • 45