/********** * making connections between thoughts Forgetting a Thought Antiphoclemone said that when she will die, the world, with its trees, animals and people will be left alone by her. She said, her body will no longer have life in it, so she won't be able to move her jaw, and won't be able to eat nuts. She said, she won't think of tree roots when she is dead. She said that death is like that of a forgotten thought. Antiphoclemone threw the dice, a symbol for her thought. To do this, she put the dice in the cup, then emptied the cup on the table. This helped her concentrate on her life, and meant she lived a successful life. The algorithm delete1/3 deletes thoughts from a tree structure, and links the other thoughts together. delete1([2, 7], [[1, 2], [1, 3], [2, 4], [2, 5], [3, 6], [3, 7]], Items). Items = [[1, 3], [1, 4], [1, 5], [3, 6]] ; delete1(+Items1, +Items2, -Items3) (+ means input, - means output) Items1 - List of items to delete. Items2 - List of pairs of linked items. Items3 - List of pairs of linked items to return after Items1 have been deleted and remaining items have been relinked. **********/ delete1([], Items, Items). delete1(Items1, Items2, Items3) :- Items1 = [Item | Items4], delete2(Item, Items2, [], Items5), delete1(Items4, Items5, Items3). /********** delete2(+Item, +Items1, +Items2, -Items3) Item - Item to delete. Items1 - List of pairs of linked items. Items2 - Initial list of linked items from which Items1 will be deleted and remaining items will have been relinked. Items3 - List of pairs of linked items to return after Items1 have been deleted and remaining items have been relinked. **********/ delete2(_Item, [], Items, Items). delete2(Item1, Items1, Items2, Items3) :- Items1 = [Items4 | Items5], Items4 = [Item2, Item1], change(Item2, Item1, Items5, [], Items6), delete2(Item2, Items6, Items2, Items3), !. delete2(Item1, Items1, Items2, Items3) :- Items1 = [Item2 | Items4], append(Items2, [Item2], Items5), delete2(Item1, Items4, Items5, Items3). /********** change(+Item1, +Item2, +Items1, +Items2, -Items3) Item1 - Item to replace with Item2 in the first position. Item2 - Item that will be replaced in the first position. Items1 - List of pairs of linked items. Items2 - Initial list of linked items from which remaining items will have been relinked. Items3 - List of pairs of linked items to return after the items have been relinked. **********/ change(_Item1, _Item2, [], Items, Items). change(Item1, Item2, Items1, Items2, Items3) :- Items1 = [Items4 | Items5], Items4 = [Item2, Item3], Items6 = [Item1, Item3], append(Items2, [Items6], Items7), change(Item1, Item2, Items5, Items7, Items3). change(Item1, Item2, Items1, Items2, Items3) :- Items1 = [Items4 | Items5], not(Items4 = [Item2, _Item3]), append(Items2, [Items4], Items6), change(Item1, Item2, Items5, Items6, Items3).