Prolog

extra credit assignment

Page 1 of 1

6 Replies - 1748 Views - Last Post: 21 April 2007 - 05:50 AM Rate Topic: -----

#1 mattman059  Icon User is offline

  • Epic Awesomeness
  • member icon

Reputation: 15
  • View blog
  • Posts: 538
  • Joined: 23-October 06

Prolog

Posted 26 March 2007 - 02:48 PM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: Prolog

#2 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: Prolog

Posted 26 March 2007 - 02:55 PM

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

The tutorials I found were through a google search.
Was This Post Helpful? 0
  • +
  • -

#3 mattman059  Icon User is offline

  • Epic Awesomeness
  • member icon

Reputation: 15
  • View blog
  • Posts: 538
  • Joined: 23-October 06

Re: Prolog

Posted 26 March 2007 - 06:28 PM

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)
Was This Post Helpful? 0
  • +
  • -

#4 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: Prolog

Posted 26 March 2007 - 07:36 PM

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.
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 */


Was This Post Helpful? 0
  • +
  • -

#5 mattman059  Icon User is offline

  • Epic Awesomeness
  • member icon

Reputation: 15
  • View blog
  • Posts: 538
  • Joined: 23-October 06

Re: Prolog

Posted 26 March 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
Was This Post Helpful? 0
  • +
  • -

#6 dmallord  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-October 06

Re: Prolog

Posted 12 April 2007 - 03:31 PM

View Postmattman059, on 26 Mar, 2007 - 07:41 PM, said:

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,B)" . 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.
Was This Post Helpful? 0
  • +
  • -

#7 squirrel1985  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-April 07

Re: Prolog

Post icon  Posted 21 April 2007 - 05:50 AM

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)


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1