views:

646

answers:

13

Are there any programming languages designed to define the solution to a given problem instead of defining instructions to solve it? So, one would define what the solution or end result should look like and the language interpreter would determine how to arrive at that result. Looking at the list of programming languages, I'm not sure how to even begin to research this.

The best examples I can currently think of to help illustrate what I'm trying to ask are SQL and MapReduce, although those are both sort of mini-languages designed to retrieve data. But, when writing SQL or MapReduce statements, you're defining the end result, and the DB decides the best course of action to arrive at the end result set.

I could see these types of languages, if they exist, being used in crunching a lot of data or finding solutions to a set of equations. The dream language would be one that could interpret the defined problem, identify which parts are parallelizable, and execute the solution across multiple processes/cores/boxes.

+13  A: 

The closest you can get to something like this is with a logic language such as Prolog. In these languages you model the problem's logic but again it's not magic.

Savvas Dalkitsis
Yeah it's hard to imagine what this would/could look like practically, because of the magic factor. How much magic is too much? Prolog looks like a great example, though.
Jon Smock
This is exactly the example I thought of when I read the question. After using Prolog for a while, you also realize why this paradigm is emulated so infrequently.
Beska
+9  A: 

This sounds like a description of a declarative language (specifically a logic programming language), the most well-known example of which is Prolog. I have no idea whether Prolog is parallelizable, though.

In my experience, Prolog is great for solving constraint-satisfaction problems (ones where there's a set of conditions that must be satisfied) -- you define your input set, define the constraints (e.g., an ordering that must be imposed on the previously unordered inputs) -- but pathological cases are possible, and sometimes the logical deduction process takes a very long time to complete.

If you can define your problem in terms of a Boolean formula you could throw a SAT solver at it, but note that the 3SAT problem (Boolean variable assignment over three-variable clauses) is NP-complete, and its first-order-logic big brother, the Quantified Boolean formula problem (which uses the existential quantifier as well as the universal quantifier), is PSPACE-complete.

There are some very good theorem provers written in Objective Caml and other FP languages; here are a whole bunch of them.

And of course there's always linear programming via the simplex method.

Meredith L. Patterson
Prolog is very parallelisable. The order of evaluation of clauses can happen in any order, and even at the same time.
Matthew Schinckel
Awesome. I've only ever used it on single-processor machines, and even that not very much. Thanks for the data point!
Meredith L. Patterson
+3  A: 

Let me try to answer ... may be Prolog could answer your needs.

nightingale2k1
+23  A: 

What about Declarative Programming? Excerpt from wikipedia article (emphasis added):

In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow. Many languages applying this style attempt to minimize or eliminate side effects by describing what the program should accomplish, rather than describing how to go about accomplishing it. This is in contrast with imperative programming, which requires an explicitly provided algorithm.

Karl Voigtland
Ah, that's the term I need haha. I hate when you don't even know the term to search/ask for. Also "Declarative programming has become of particular interest recently, as it may greatly simplify writing parallel programs" - looks like I'm not alone!
Jon Smock
+1 - Exactly what I was going to suggest
Draemon
+3  A: 

These languages are commonly referred to as 5th generation programming languages. There are a few examples on the Wikipedia entry I have linked to.

Ionuț G. Stan
How common is "commonly" when I have never heard of programming languages categorized in this meaning of "generation"?
erjiang
A: 

There are various Java-based rules engines which allow declarative programming - Drools is one that I've played with and it seems pretty interesting.

A: 

I would say Objective Caml too...

peroumal1
A: 

A lot of languages define more problems than solutions (don't take this one seriously).

On a serious note: one more vote for Prolog and different kinds of DSLs designed to be declarative.

Ray
A: 

I remember reading something about computation using DNA back when I was in college. You would put segments of DNA in a solution that represented segments of the problem, and define it in such a way that if the DNA fits together, it's a valid solution. Then you let the properties of chemicals solve the problem for you and look for finished strands that represent a solution. It sounds sort of like what you are refering to.

I don't recall if it was theoretical or had been done, though.

quillbreaker
If you can find it, that would be incredibly interesting to read about.
Jon Smock
Poking around, I think I may have been hung over before that lecture. I can't find any references to using actual DNA to do calculation.
quillbreaker
Look for "biological computing" or "biocomputers". http://news.nationalgeographic.com/news/2003/02/0224_030224_DNAcomputer.html http://en.wikipedia.org/wiki/Biocomputers
outis
And yes, some domain-specific calculations have been done, but (AFAIK) it's about as advanced as quantum computing.
outis
A: 

This may seem flippant but in a sense that is what stackoverflow is. You declare a problem and or intended result and the community provides the solution, usually in code.

It seems immensely difficult to model dynamic open systems down to a finite number of solutions. I think there is a reason most programming languages are imperative. Not to mention there are massive P = NP problems lurking in the dark that would make such a system difficult to engineer.

Although what would be interesting is if there was a formal framework that could leverage human input to "crunch the numbers" and provide a solution, perhaps imperative code generation. The internet and google search engines are kind of that tool but very primitive.

Large problems and software are basically just a collection of smaller problems solved in code. So any system that generated code would require fairly delimited problem sets that can be mapped to more or less atomic solutions.

Gordon Potter
A: 

LINQ could also be considered another declarative DSL (aschewing the argument that it's too similar to SQL). Again, you declare what your solution looks like, and LINQ decides how to find it.

The beauty of these kinds of languages is that projects like PLINQ (which I just found) can spring up around them. Check out this video with the PLINQ developers (WMV direct link) on how they parallelize solution finding without modifying the LINQ language (much).

Jon Smock
A: 

Lisp. There are so many Lisp systems out there defined in terms of rules not imperative commands. Google ahoy...

David Plumpton
A: 

While mathematical proofs don't constitute a programming language, they do form a formal language where you simply define solutions (as long as you allow nonconstructive proofs). Of course, it's not algorithmic, so "math" might not be an acceptable answer.

outis