| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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) |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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). |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.