Previous in Forum: SETI Should Rethink its "Point and Listen" Strategy   Next in Forum: PID Controlling a Peltier based cooler
Close
Close
Close
15 comments
Rate Comments: Nested
Anonymous Poster

Prolog predicate

11/26/2008 5:07 PM

Write a Prolog predicate mean/2 to compute the
arithmetic mean of a given list of numbers.
Example: ?- mean([1,2,3,4], X)

Reply
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Anonymous Poster
#1

Re: Prolog predicate

11/26/2008 5:12 PM

hard

Reply
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#2

Re: Prolog predicate

11/27/2008 11:26 PM

Hello Guest,

can you give me any more information? This is just to give you ideas OK?

http://amazingforums.com/forum1/UNDONE/2.html This is a forum which talks about Fibonacci numbers. Is that the kind of thing you want to write a reasoned discourse on? Let me know and I will get back to you. Of course, you could always do your own homework ready for school tomorrow?

I bet you have not even searched the web?

http://www.google.co.uk/search?sourceid=navclient&ie=UTF-8&rlz=1T4GGLJ_enGB294GB294&q=number+strings

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#3

Re: Prolog predicate

11/27/2008 11:28 PM

Here is the Fibonacci site if it means anything to you?

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#4

Re: Prolog predicate

11/28/2008 11:36 PM

I have no idea what "Prolog predicate" is but the arithmetic mean is:

Given a set of numbers, you add up the values of the numbers, then you divide by the quantity of numbers in the set.

For example:

[9,4,7,2,17]

If we add these all up we get 39

There are 5 numbers in the set, so if we divide 39/5, we get 7.8 as the arithmetic mean.

Being lazy, I only used positive integers in the set. There is no reason why the numbers can't be positive, negative, fractions, irrationals (3.14159... for example), or maybe even complex numbers.

Reply
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#5

Re: Prolog predicate

11/28/2008 11:56 PM

Hello Guest,

I now realise what you mean. Check these sites out:

http://scom.hud.ac.uk/scomtlm/cam326/logic/node2.html

=============================================

http://www.inf.ethz.ch/personal/staerk/lptp.html

=============================================

This site has all you would need for your project!!!!!!! Good luck.

http://en.wikibooks.org/wiki/Prolog/Introduction_to_logic

[edit] First Order Logic

First Order Logic (also known as predicate logic) expands on propositional logic, by using predicates, variables and objects. In propositional logic, the atomic sentences (the smallest elements that can take on a true/false value) are terms, symbols represented by letters. In first order logic the atomic sentences are predicates. Predicates have a name (starting with a capital) which is followed by several variables (starting with a lowercase letter). The following are examples of predicates:

  • Predicate(variable1, variable2)
  • BrotherOf(sibling, brother)
  • MotherOf(child, mother)
  • HasWheels(thing)

These variables can be instantiated with objects. Objects are elements represented by words that start with a capital letter. For instance, in the predicate HasWheels(thing) the variable thing can be instantiated with the objects Car, Bike, or Banana. Based on the instantiation of the variables, the predicate is true or false (HasWheels(Car) is true whereas HasWheels(Banana) is false). Note however that these names are for readability only, they do not actually mean anything. HasWheels(Banana) is not functionally different from X(A). Whether HasWheels(Banana)is true or false needs to be defined in some formal way (such as a knowledge base, which is described below).

These predicates can be joined in sentences, just like the terms in propositional logic, using connectives (the connectives are the same as in propositional logic). Usually there is a collection of sentences that are assumed to be true, to create a logical definition of predicates. Such a collection of sentences that are true is called a knowledge base. Such a knowledge base could, for instance contain the following sentences:

HasWheels(Car)
MotherOf(Charles, Elizabeth)

The sentences tell us that the HasWheels predicate is true, if its first element is car; and the MotherOf predicate is true, if Elizabeth is the mother of Charles. To construct this kind of sentences with variables in them we need to state what exactly we mean when we use the variables. If HasWheels(x) is true, do we mean it's true for instantiations of x or that there exists an instantiation of x that makes HasWheels(x) true? To define this we use quantifiers, ie. they determine the quantity of a variable. First order logic has two quantifiers, the universal quantifier and the existential quantifier . These quantifiers are placed before a variable to signify what the variable means in the sentence that follows the quantifier. For instance, the sentence means that for all possible instantiations of x, HasWheels(x) is true, that is, all possible objects have wheels. The sentence means that there exists at least one object x for which HasWheels(x) is true, in other words there is at least one thing that has wheels. To understand the use of the quantifiers, consider the following examples:

  • If x is a land vehicle, then x has wheels. (if x is not a landvehicle, this sentence says nothing about x)

  • If x has a child y and x is a man, x is the father of y.

  • There exists at least one object that has wheels and isn't a car

  • All mothers have a child

[edit] Logic in Prolog

The logic used in prolog is a version of first order logic, with the use of capital letters inverted (predicates and objects start with a lowercase letter, variables start with an uppercase letter). A prolog program consists of a knowledgebase where each sentence is a conjunction of predicates connected to a final predicate with an implication. For instance:

A sentence like this is called a Horn Clause. In prolog the above sentence would look like this:

pred4(A) :- pred1(A, B), pred2(B, C), pred3(C, D).

Note that the implication sign is reversed, commas are used for conjunction, a period is used to end the sentence and all variables are assumed to be universally quantified.

[edit] Examples

[edit] Exercises


(x) Write out a truth table for the following sentences in propositional logic.
a)
b) A
c) A
d) A
e) A

(x) How many connectives are possible, that connect two terms? Why?

(x) Try to find a formula to fit the following truth tables
a)
b)
c)
d)

(x) Truth tables are a great way to prove that a propositional formula is true. Could you do the same thing for first order logic? Explain how, or why not.

(x) Convert the following sentences to first order logic. Try to follow the logical structure of the sentence closely (using objects for individuals, variables for groups of people, connectives for logical constructions and predicates for the rest).
a) All kids are short.
b) Certain kids own shoes.
b) If someone is a kid and a boy, he likes cars.
d) All kids that own shoes, wear them.
e) All kids have a mother.
f) If a woman is a mother, she has a kid.
g) No kid likes a vegetable if it's overcooked.
h) No mother likes a teacher if he punishes her kid.

(x) (advanced)The following questions concern the = symbol. It takes two variables and is true if they are bound to the same thing, in other words x = y is true if x and y represent the same object.
(a) Is the = symbol a function, predicate or a connective? Why?
(b) The = symbol shouldn't be confused with the equality connective. How are the different?
(c) Can you think of a sentence in first order logic that, when added to a knowledge base (and thus considered always true) does the same thing as the = symbol. That is, through it's definition in the knowledge base, this sentence, with 'inputs' x and y, is true if x and y are equal.
(d) The existential quantifier defines that a sentence is true if it's true for at least one possible instantiation of x. Can you think of a way to quantify a variable x for a sentence so that the sentence is true if it's true for only one instantiation of x, but no more? You'll probably need the = symbol for this.

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#6
In reply to #5

Re: Prolog predicate

11/29/2008 4:07 AM

bb

Thanks for the research. This reminds me of something I studied back in the '60s called "Set Theory". All the concepts are there. I suspect that they have updated it (Changed the names to protect the guilty) {and the symbols}. I would not guess what George Boulle might think of it.

Thanks

Bill

Reply
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#10
In reply to #6

Re: Prolog predicate

11/29/2008 5:31 PM

Hello Sciesis2:

The page I found, I had read about it before, maybe 10 years ago. When I first saw the question I thought, and it still may be a homework question? But, after 'grilling' by Markthehandyman, the OP is not giving much away!

My thoughts were the OP wanted to write a thesis on a particular 'number' theory that may or may not have been solved, Like the Fibonacci one.

This seems to be more computer oriented than a number theory, but, I suppose you could still base a code on it.

I was never bright enough to be taught those kinds of things. Though that was mainly down to a teacher who because we were the 'bottom' class thought he could get away with teaching the same subjects for three years! It still makes me angry.

It must have been in the last term I heard about 'set theory' or something like it. Or I could have read it. I bought a set of second hand Encyclopaedia's about then and had my head stuck in there, as well as dirty books, for my bedtime read!.

Was this something you sought out, or did you learn it at school? And did you find any use for it?

I must say I have the same sort of ideas as you. It sort of look familiar, but I have not seen the notation. I don't actually know if the one I read about was by George Boulle. Rings no bells with me................I will research it to see if it is what I read about. I can never recall names of people who perhaps I should live famous theorists and inventor. I know what they did at the time I read about them, and it all turns to dust!

Appreciate your post though Bill, thank you. From the attitude of the OP, I hardly think there is going to be any GA given on this subject?

Take care.........

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply
Guru
Canada - Member - Toronto, Ontario (South Parkdale On The Lakeshore) Engineering Fields - Marine Engineering - Great Lakes School Of Marine Technology (Owen Sound and Port Colbourne) Technical Fields - Architecture - Private Practice 1976-1990 Technical Fields - Education - Toronto Teachers' College 1971 Technical Fields - Marketing/Advertising - Founding Member Hobbies - Hunting - Founding Member Hobbies - Target Shooting - Founding Member

Join Date: Mar 2006
Location: Toronto Ontario Canada
Posts: 1265
Good Answers: 14
#12
In reply to #10

Re: Prolog predicate

11/29/2008 6:20 PM

Hi, babybear!

That you think you are not bright and that you were held back by being in some kind of 'bottom' class --after seeing what you produce in here-- blows my mind.

That kind of thing just adds more anger and frustration to the natural lack of tolerance I find myself developing for stupidity as I get older. One of the most frustrating parts of living with that intolerance is the difficulty in getting into a position to act as a formal cause against it. However, turning that frustration inward can't do you any good.

They say that it's good for the soul to forgive. I say that's crap. Just hate the son of a B for what he did to you. It feels much better, and for sure it's deserved.

Mark

Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#13
In reply to #12

Re: Prolog predicate

11/29/2008 8:59 PM

Hello Mark,

are you fine? Or did I ask?.......

They say that it's good for the soul to forgive. I say that's crap.

I agree with all you say!........There must be something wrong..............(agrying to everything?)

It has always made me angry that, one part of society can get a proper Education, and the ones, like me, who are really into learning, are not allowed? Excuse my French but, it really pisses me off.

Do you know, I had other Family who were able to get full schooling, though, it was still 'not the done thing' to go to University then, and done nothing with their lives. They learned French and German but, "won't go there as we can't speak the language!". I would have loved one to one tutoring, but, it was never going to happen.

Tell you what, let you and me be the stupid twins?

And, by the way, you have a brain in your head, some of the stuff you post, though I understand it, (just) I just want to know more.

Take care my friend................

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#14
In reply to #12

Re: Prolog predicate

11/29/2008 9:09 PM

By the way........................you aint fick, OK!

Anyone who is a member and, either knows by experience or is prepared to do the 'slog' (because sometimes it is hard just to understand, or guess what the request is?) has respect, you know?

Can't understand why kids ask for answers to homework? They will never learch to check things out for themselves, or, (the posh version) 'research it' and, will know bu-ger-all when they leave school and, what a waste of time going to Uni' with that attitude?

Take care Mark................

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply Off Topic (Score 5)
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#15
In reply to #6

Re: Prolog predicate

11/29/2008 9:47 PM

Hello Sciesis2:

>>I can never recall names of people who perhaps I should live famous theorists and inventor. <<

Sorry about the screwed up English, my native tongue believe it or not!

It should be: I can never recall names of people who, perhaps I should, like famous theorists and inventors.

Sorry.

Take care....................

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply
Guru
Canada - Member - Toronto, Ontario (South Parkdale On The Lakeshore) Engineering Fields - Marine Engineering - Great Lakes School Of Marine Technology (Owen Sound and Port Colbourne) Technical Fields - Architecture - Private Practice 1976-1990 Technical Fields - Education - Toronto Teachers' College 1971 Technical Fields - Marketing/Advertising - Founding Member Hobbies - Hunting - Founding Member Hobbies - Target Shooting - Founding Member

Join Date: Mar 2006
Location: Toronto Ontario Canada
Posts: 1265
Good Answers: 14
#7

Re: Prolog predicate

11/29/2008 4:28 AM

Hi, Guest!

What will you use the response(s) to accomplish?

Mark

Reply
Anonymous Poster
#8
In reply to #7

Re: Prolog predicate

11/29/2008 9:49 AM

i am looking for a simple prolog code

Reply
Guru
Canada - Member - Toronto, Ontario (South Parkdale On The Lakeshore) Engineering Fields - Marine Engineering - Great Lakes School Of Marine Technology (Owen Sound and Port Colbourne) Technical Fields - Architecture - Private Practice 1976-1990 Technical Fields - Education - Toronto Teachers' College 1971 Technical Fields - Marketing/Advertising - Founding Member Hobbies - Hunting - Founding Member Hobbies - Target Shooting - Founding Member

Join Date: Mar 2006
Location: Toronto Ontario Canada
Posts: 1265
Good Answers: 14
#9
In reply to #8

Re: Prolog predicate

11/29/2008 3:48 PM

Hi, Guest!

OK. And..........?

Where/how do you intend to use it?

Just curious.

Mark

Reply
Guru
United Kingdom - Member - Not a new member!

Join Date: Jun 2008
Location: USA/Europe
Posts: 4547
Good Answers: 68
#11
In reply to #9

Re: Prolog predicate

11/29/2008 5:34 PM

Hello Mark,

hope you are fine...............

Doesn't look like the OP is giving much away about how they are going to use this info' does it? Good try at 'grilling', but, you can't get blood from a stone?

Take care............

__________________
Take it easy, bb. >"HEAR & you FORGET<>SEE & you REMEMBER<>DO & you UNDERSTAND"<=$=|O|=$=>"Common Sense is Genius dressed in its Working Clothes"<>[Ralph Waldo Emerson]
Reply
Reply to Forum Thread 15 comments
Copy to Clipboard

Users who posted comments:

Anonymous Poster (2); babybear (8); MarkTheHandyman (3); Sciesis2 (2)

Previous in Forum: SETI Should Rethink its "Point and Listen" Strategy   Next in Forum: PID Controlling a Peltier based cooler

Advertisement