Logic Programming is Neat

This is gonna be a departure from my normal topic of game design to talk about a closely-related field equally as close to my heart: programming. Specifically, from a completely unscientific point of view, I wanna tapk about how neat logic languages are.

newseventsimages
This picture basically has nothing to do with anything, but I felt like it belonged here.
With normal programming languages, you basically have a file full of code that just executes top to bottom. Occasionally, you’ll prompt for user input, or jump to another section of code, but in general, your code starts at the top, goes down until it hits the bottom, and stops.

Logic languages don’t work like that. Instead, your code forms what’s called a Knowledge Base. This Base contains facts (“Steve and Eric are brothers”, “3 is positive”, “You suck”) and implications, which is the fancy propositional logic of saying “If X then Y” (“If Steve and Eric are brothers, then Steve’s Mom is Eric’s Mom”, “If a number is positive, that number times -1 is negative that number”, “If you suck, then you also blow”).

With this Knowledge Base, you can then query your code to find stuff out. In the case of Prolog (my logic language of choice), every time you query the Base, you get one of three responses. The first two are simple “true” and “false”, for simpler questions, but, if you design your code right, you can leave your queries open ended (like saying “X is the 4th number in this list of numbers”), and Prolog will use the Knowledge base to determine every possible value that could be inserted into that statement to ensure it’s true.

This is neat to me. The idea that you’re giving the computer a series of facts, and a series of rules, and it can use that to develop its own conclusions. It’s powerful for things like developing permutations and combinations, since you only need to provide the rules for what a permutation and combination is, and the initial list, and Prolog will churn away at the rest.

Prolog reminds me kind of like an AI, where you’re teaching your computer about the rules to solving problems the same way that you teach a person, and then that computer/person becomes able to solve those problems, as long as their knowledge is properly comprehensive. It’s just, I dunno, cool.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s