POV-Ray : Newsgroups : povray.off-topic : Logic programming : Logic programming Server Time
1 Oct 2024 09:22:11 EDT (-0400)
  Logic programming  
From: Orchid XP v7
Date: 26 Mar 2008 15:02:14
Message: <47eaabc6$1@news.povray.org>
OK, so I realise absolutely nobody here will think this is in any way 
"neat" or "cleaver", but still...

I've managed to construct an interpretter for a kind of primitive logic 
programming language. Currently it's extremely hard to operate, and the 
output isn't very human-readable, but it can do some interesting stuff.

For example, suppose I define a function "join" as follows:

   join(x, y, z) =
     x = [] & y = z   ||   x = (t:ts1) & z = (t:ts2) & join(ts1,y,ts2)

In other words, either x is an empty list and y and z are equal, or the 
first element of x and z is the same and ... well, you can read.

Given this definition, typing join([1,2,3], [4,5,6], z) yields

   z = [1,2,3,4,5,6]

Which is obviously what the answer should be. However, the slightly 
bizare thing is that if I do join(x, [4,5,6], [1,2,3,4,5,6]), I get

   x = [1,2,3]

In other words, it can "un-join" the list. The join operator works 
backwards!

But that's not all. It gets weirder: join([1,2,3], y, [1,2,3,4,5,6] gives

   y = [4,5,6]

But now we come to the really mental part: join(x, y, [1,2,3]) yields

   x = [] & y = [1,2,3]   ||
   x = [1] & y = [2,3]    ||
   x = [1,2] & y = [3]    ||
   x = [1,2,3] & y = []

In other words, all *possible* ways that x and y could be set such that 
their join is [1,2,3]! How neat is that?

OK, I'll sit down now... :-/

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.