views:

356

answers:

5

I know in Prolog you can do something like

someFunction(List) :- 
    someOtherFunction(X, List)
    doSomethingWith(X)
    % and so on

This will not iterate over every element in List; instead, it will branch off into different "machines" (by using multiple threads, backtracking on a single thread, creating parallel universes or whathave you), with a separate execution for every possible value of X that causes someOtherFunction(X, List) to return true!
(I have no idea how it does this, but that's not important to the question)

My question is: What other non-determistic programming languages are out there? It seems like non-determinism is the simplist and most logical way to implement multi-threading in a language with immutable variables, but I've never seen this done before - Why isn't this technique more popular?

+6  A: 
Norman Ramsey
I'm sure you can *achieve* the same thing with `map`, but I'm not so sure it's as trivial as you make it sound. For instance, the code I gave has nothing to do with iterating the elements of `List` - `someOtherFunction()` could be anything at all (ex. the checksum of `List` has `X` bits set)! There is also non-determinism in functions - in Prolog, you can write several definitions of a function, and all of them will be called (if any return true, the result is true). *Why* would it be hard to execute this using separate threads? Since all variables are immutable we don't need locks, right?
BlueRaja - Danny Pflughoeft
A: 

I believe Haskell has the capability to construct and non-deterministic machine. Haskell at first may seem too difficult and abstract for practical use, but it's actually very powerful.

Dan Mantyla
A: 

Java 2K

Note: Before you click the link and being disappointed: This is an esoteric language and has nothing to do with parallelism.

Meinersbur
When I said "non-deterministic," I meant that the program takes every path. This program is not non-deterministic in that sense, even though it is definitely not deterministic.
BlueRaja - Danny Pflughoeft
+2  A: 

The Wikipedia article points to Amb which is a Scheme-derivative with capacities for non-deterministic programming.

As far as I understand, the main reason why programming languages do not do that is because running a non-deterministic program on a deterministic machine (as are all existing computers) is inherently expensive. Basically, a non-deterministic Turing machine can solve complex problems in polynomial time, for which no polynomial algorithm for a deterministic Turing machine is known. In other words, non-deterministic programming fails to capture the essence of algorithmics in the context of existing computers.

The same problem impacts Prolog. Any efficient, or at least not-awfully-inefficient Prolog application must use the "cut" operator to avoid exploring an exponential number of paths. That operator works only as long as the programmer has a good mental view of how the Prolog interpreter will explore the possible paths, in a deterministic and very procedural way. Things which are very procedural do not mix well with functional programming, since the latter is mostly an effort of not thinking procedurally at all.

As a side note, in between deterministic and non-deterministic Turing machines, there is the "quantum computing" model. A quantum computer, assuming that one exists, does not do everything that a non-deterministic Turing machine can do, but it can do more than a deterministic Turing machine. There are people who are currently designing programming languages for the quantum computer (assuming that a quantum computer will ultimately be built). Some of those new languages are functional. You may find a host of useful links on this Wikipedia page. Apparently, designing a quantum programming language, functional or not, and using it, is not easy and certainly not "simple".

Thomas Pornin
A: 

There is a programming language for non-deterministic problems which is called as "control network programming". If you want more information go to "controlnetworkprogramming.com". This site is still in progress but you can read some info about it.

cpxx