I'm learning PROLOG.

This is a discussion on I'm learning PROLOG. within the PROLOG forums in Programming Languages category; Yesterday i began to learn (or began learning? sorry for my bad english, I'm Austrian) Prolog ( http://www.coli.uni-saarland.de/~kris/ learn-prolog-now/html/index.html). And now my first problem occured ( http://www.coli.uni-saarland.de/ ~kris/learn-prolog-now/html/node30.html#sec.l3.exercises). I can't figure out how to prove if the numeral 0 is greater than the numeral succ(0). (greater_than(0,succ(0))., Exercise 3.2) I also have problems with Exercise 3.3, the Binary trees. I jst don't know how to put leaf(1) and leaf(2) together. (I could write tree(B1,B2) = tree(leaf(1),leaf(2)). but i think this is not what i have to do..) Can anybody help me? Maybe via skype or ICQ? (ICQ: 351186973, Skype: flodili)...

Go Back   Application Development Forum > Programming Languages > PROLOG

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 07-30-2008, 06:51 AM
florian.schindler@aon.at
Guest
 
Default I'm learning PROLOG.

Yesterday i began to learn (or began learning? sorry for my bad
english, I'm Austrian) Prolog (http://www.coli.uni-saarland.de/~kris/
learn-prolog-now/html/index.html).

And now my first problem occured (http://www.coli.uni-saarland.de/
~kris/learn-prolog-now/html/node30.html#sec.l3.exercises).

I can't figure out how to prove if the numeral 0 is greater than the
numeral succ(0). (greater_than(0,succ(0))., Exercise 3.2)

I also have problems with Exercise 3.3, the Binary trees. I jst don't
know how to put leaf(1) and leaf(2) together.
(I could write tree(B1,B2) = tree(leaf(1),leaf(2)). but i think this
is not what i have to do..)


Can anybody help me?
Maybe via skype or ICQ?
(ICQ: 351186973, Skype: flodili)
Reply With Quote
  #2  
Old 07-30-2008, 03:53 PM
Nick Wedd
Guest
 
Default Re: I'm learning PROLOG.

In message
<284bb7f5-8dc5-4852-b758-d4b778fb15a5@t54g2000hsg.googlegroups.com>,
florian.schindler@aon.at writes
>Yesterday i began to learn (or began learning? sorry for my bad
>english, I'm Austrian) Prolog (http://www.coli.uni-saarland.de/~kris/
>learn-prolog-now/html/index.html).
>
>And now my first problem occured (http://www.coli.uni-saarland.de/
>~kris/learn-prolog-now/html/node30.html#sec.l3.exercises).
>
>I can't figure out how to prove if the numeral 0 is greater than the
>numeral succ(0). (greater_than(0,succ(0))., Exercise 3.2)


Figure out how to do it logically. Then figure out how to express that
logic in Prolog.

>I also have problems with Exercise 3.3, the Binary trees. I jst don't
>know how to put leaf(1) and leaf(2) together.
>(I could write tree(B1,B2) = tree(leaf(1),leaf(2)). but i think this
>is not what i have to do..)


There is an example, about half-way through the first paragraph of the
question, showing how to put two leaves together to make a tree.

>Can anybody help me?
>Maybe via skype or ICQ?
>(ICQ: 351186973, Skype: flodili)


Nick
--
Nick Wedd nick@maproom.co.uk
Reply With Quote
  #3  
Old 08-01-2008, 01:28 AM
phi500ac@yahoo.ca
Guest
 
Default Re: I'm learning PROLOG.

On 30 jul, 07:51, florian.schind...@aon.at wrote:
> Yesterday i began to learn (or began learning? sorry for my bad
> english, I'm Austrian) Prolog (http://www.coli.uni-saarland.de/~kris/
> learn-prolog-now/html/index.html).
>
> And now my first problem occured (http://www.coli.uni-saarland.de/
> ~kris/learn-prolog-now/html/node30.html#sec.l3.exercises).
>
> I can't figure out how to prove if the numeral 0 is greater than the
> numeral succ(0). (greater_than(0,succ(0))., Exercise 3.2)
>
> I also have problems with Exercise 3.3, the Binary trees. I jst don't
> know how to put leaf(1) and leaf(2) together.
> (I could write tree(B1,B2) = tree(leaf(1),leaf(2)). but i think this
> is not what i have to do..)
>
> Can anybody help me?
> Maybe via skype or ICQ?
> (ICQ: 351186973, Skype: flodili)


Hi, Florian.
Pratically all Prolog books have a chapter on binary trees. Here is an
example:

/** binary_tree(Tree) :-
Tree is a binary tree. */
binary_tree(void).
binary_tree(tree(Element,Left,Right)) :-
binary_tree(Left), binary_tree(Right).

A predicate that searchs a tree:

tree_member(X,tree(X,Left,Right)).
tree_member(X,tree(Y,Left,Right)) :- tree_member(X,Left).
tree_member(X,tree(Y,Left,Right)) :- tree_member(X,Right).

Preorder traversal:

preorder(tree(X,L,R),Xs) :-
preorder(L,Ls), preorder(R,Rs), append([X|Ls],Rs,Xs).
preorder(void,[]).

Definition of append:

append([],Ys,Ys).
append([X|Xs],Ys,[X|Zs]) :- append(Xs,Ys,Zs).

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 01:11 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.