# Understanding TML: Prolog -> Datalog -> Tau

by Dana Edwards

Source:

Understanding TML: Prolog -> Datalog -> Tau - Steemit

This post will explore some concepts behind logic programming. In Ohad's examples on Github he has as inputs his logic programs. For the most part all logic programs work the same way and the initial syntax of Tau is essentially almost an exact copy of Prolog or Datalog. So let's learn a bit of Prolog?

Step 1: Install SWI Prolog.

Step 2: Watch this video.:

The basic concepts to learn to know Prolog/Datalog/Tau:

• We have facts, rules, and queries (clauses).
• We have variables (X, Y, Z). Variables must be in capital letters.
• We have recursion which is a function that can keep calling itself until the goal is complete.
• We have unification.

Facts are statements such as:

Socrates is mortal.Mortals are human.

In Prolog:

human(socrates).mortal(human).

The arity is the number of arguments passed.

uncle(jim, joe)

Has an arity of 2. Why? Because there are two arguments being passed (jim, joe).

When we write our facts we are creating the knowledge base. In Tau these facts would be input via our discussions. So the fact uncle(jim,joe) in plain English is saying Jim and Joe are uncles. The predicate here would be uncle.

Rules are important as well. A rule can be thought of as an extension of a fact but with conditions to be satisfied in order for it to be true. So for example we have the implication symbol " :- " which we use when working with rules.

So for example:

human(X) :- man(X).human(Y) :- woman(Y).

This says in plain English: All man are human. All woman are human. Put another way, man or woman implies being human.

If a predicate contains a goal which refers to itself then we have recursion.

Here is the full logic program I wrote for Socrates is human:

%factsman(socrates).woman(eve).

%%ruleshuman(X) :- man(X).human(Y) :- woman(Y).

To query you simply can ask "is Socrates human?" by typing: human(socrates).The answer can be either true or false. Unification takes place, as socrates unifies with X. Simply type: " man(X). " or " woman(y). " as the queries to confirm unification.

Because we know from the facts that Socrates is a man, and from the rules if human is x then man is x "if it's a man then it's a human", then we know Socrates has to be a human.

We can also ask if eve is human by asking via the same query: human(eve). This should immediately illustrate the potential power of logic programming and also put into context exactly what Tau does with it's binary decision diagram portion of the code. We can see that this kind of logic is:

``````If p then q;
p;
``````

∴ q.

If Socrates is a man then Socrates is human.Socrates is a man.Therefore Socrates is human.

We can do cryptography by using library(crypto).

Remember, it's subject, predicate, object.

To do basic symmetric cryptography you must:

1. Provide the algorithm you want to use.
2. The key used for the encryption.
3. The initiation vector.

It's much much easier than C++. Let's take a look?

use_module(library(crypto)).

This tells Prolog to use the crypto module.

cryptodatahash('Socrates is human!', Hash, [algorithm(sha256)]).

This says that the string "Socrates is human!" is cryptodatahash using sha256.

Before you can do any encryption you typically have to turn a string into a hash value. Our predicate is the part of subject, predicate, object, which tells us what the data does. So the string gets hashed by algorithm sha256.

cryptonrandombytes(32, Ks),cryptonrandombytes(32, IV),cryptodataencrypt(test, 'aes-256-cbc', Ks, IV, CipherText, []).

The structure of the data here are in the form of "bytes". As we can see, we are saying here that the random number generator cryptonrandom_bytes is a 32bit key. The how to guide for using this predicate is:

cryptodataencrypt(+PlainText, +Algorithm, +Key, +IV, -CipherText, +Options)

SWISH -- SWI-Prolog for SHaring

IDNI/TML