Welcome to Dream.In.Code
Become an Expert!

Join 149,495 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,344 people online right now. Registration is fast and FREE... Join Now!




Prolog

 
Reply to this topicStart new topic

Prolog, extra credit assignment

mattman059
26 Mar, 2007 - 01:48 PM
Post #1

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 359


Dream Kudos: 175
My Contributions
We've got this assignment and you can write it in any language you want...it's got rules and predicates all ready in it so i was thinking of trying out prolog for it. Anyone know a good prolog compiler as well as a good tutorial on prolog?
User is online!Profile CardPM
+Quote Post

Nova Dragoon
RE: Prolog
26 Mar, 2007 - 01:55 PM
Post #2

The Innocent Shall Suffer, Big Time
Group Icon

Joined: 16 Aug, 2001
Posts: 6,145



Thanked: 8 times
Dream Kudos: 515
Expert In: Python, Linux

My Contributions
I've used SWI-Prolog with no real problems.

The tutorials I found were through a google search.
User is offlineProfile CardPM
+Quote Post

mattman059
RE: Prolog
26 Mar, 2007 - 05:28 PM
Post #3

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 359


Dream Kudos: 175
My Contributions
im a little confused on how to begin...nothing seems to explicitly tell you how to use simple statements like a -> b (though i may be looking it over)
User is online!Profile CardPM
+Quote Post

William_Wilson
RE: Prolog
26 Mar, 2007 - 06:36 PM
Post #4

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
how do you meant a->b?
prolog is programming logic, it is not object oriented and it is not your average language at all. It is a very recursive intense language and you must order your cases correctly as well as including the proper number of variables.

Here is a basic code which compares based on "enjoys", the first line enjoys.robert->baseball could be a meaning of this that it's implied that robert enjoys baseball. The last case of enjoys allows the item to be a list of 2 items, thus both items need to be shared, this can be extended easily with recursion.
I think the common method is straight forward, X and Y are people and Z is an activity. Hope this gives a basic start on teh structure. ! was my favorite thing in prolog.
CODE

enjoys(robert, baseball).
enjoys(robert, swimming).
enjoys(robert, basketball).
enjoys(robert, jogging).

enjoys(margaret, baseball).
enjoys(margaret, gardening).
enjoys(margaret, soccer).

enjoys(ronald, football).
enjoys(ronald, tv).
enjoys(ronald, baseball).

enjoys(X,[Y,Z]) :- enjoys(X,Y), enjoys(X,Z).


common(X, Y, Z) :- enjoys(X, Z), enjoys(Y, Z). /*returns the common activity */


User is offlineProfile CardPM
+Quote Post

mattman059
RE: Prolog
26 Mar, 2007 - 06:41 PM
Post #5

D.I.C Regular
Group Icon

Joined: 23 Oct, 2006
Posts: 359


Dream Kudos: 175
My Contributions
maybe I can elaborate on my question:

For the assignment we were given a set of rules used to derive certain implications

a -> b
b ^ c -> d
b -> e
e ^ f -> g
c ^ e ^ f -> h

Also we were given two facts a and f to be considered true.

you input a statement such as 'g' and it prints out the steps involved in proving that 'g' is true

a is true a->b
b is true b->e
e is true e ^ f -> g

as a counter example
you could not prove statement d to be true because c is not defined as true
User is online!Profile CardPM
+Quote Post

dmallord
RE: Prolog
12 Apr, 2007 - 02:31 PM
Post #6

New D.I.C Head
*

Joined: 30 Oct, 2006
Posts: 4


My Contributions
QUOTE(mattman059 @ 26 Mar, 2007 - 07:41 PM) *

maybe I can elaborate on my question:

For the assignment we were given a set of rules used to derive certain implications

a -> b
b ^ c -> d
b -> e
e ^ f -> g
c ^ e ^ f -> h

Also we were given two facts a and f to be considered true.

you input a statement such as 'g' and it prints out the steps involved in proving that 'g' is true

a is true a->b
b is true b->e
e is true e ^ f -> g

as a counter example
you could not prove statement d to be true because c is not defined as true



hi, prolog is all about facts, rules, and query.

swi prolog is an excellent compiler. the first thing you sre going to notice is a prompt in the way of ?, at that point enter "consult(user)." without the quotes, and press enter. you now should have a prompt in the way of a - , at this point declare a predicate, and give it parameters. this is setting facts. example: "true(a,cool.gif" . again no quotes. this is stating that a is true for b. set up your facts, then declare rules, rules are declared in a similar way to facts give a predicate, followed by parameter, then use the :- symbol followed by your rule. fine so far.

now to compile the program "end_of_file." again no quotes. make sure that you are ending all statements with periods. after the program compiles, you will again have the question mark prompt. at this point enter your query.

you should be able to get started with this much. i am just learning prolog myself, so good luck, and have fun.
User is offlineProfile CardPM
+Quote Post

squirrel1985
RE: Prolog
21 Apr, 2007 - 04:50 AM
Post #7

New D.I.C Head
*

Joined: 21 Apr, 2007
Posts: 1


My Contributions
Hi!

SOS! I need somebody to help in prolog and/or sml. I'm not strong at programming:(
I have a stringlist ts = [t0, t1, ..., tz-1] z>=0 is the length of the list and k>0 is the max superimposition between the words. All words are different.
2 words are in n superposition when the last n letter= first n letter

example:

| ?- max_k_atfedok(2, [asztalos,alma,apu,utas,anyu,satu,malom], L1).
L1 = [alma-[1-anyu,1-apu,1-asztalos,2-malom],anyu-[1-utas],apu-[1-utas],
asztalos-[1-satu],satu-[1-utas],utas-[1-satu,2-asztalos]] ? ;

I have to creat this program in prolog and sml too.

Thx for help!

ps: I have a program about simple n superposition



Attached File(s)
Attached File  prolog.txt ( 1.5k ) Number of downloads: 70
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 05:58PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month