Understanding TML: Prolog -> Datalog -> Tau

in #tauchain6 years ago (edited)

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.

So this example from Ohad:

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:

%facts
man(socrates).
woman(eve).

%%rules
human(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.

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

This says that the string "Socrates is human!" is crypto_data_hash 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.

crypto_n_random_bytes(32, Ks),
crypto_n_random_bytes(32, IV),
crypto_data_encrypt(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 crypto_n_random_bytes is a 32bit key. The how to guide for using this predicate is:

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

References

  1. https://swish.swi-prolog.org/
  2. https://github.com/IDNI/tau
Sort:  

I was a Prolog programmer in an AI lab. It's a powerful language. I used it for Natural Language Processing and Infinite Precision Math. I'm glad to see it used in the Tau project!

Congratulations @dana-edwards! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published a post every day of the week

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Support SteemitBoard's project! Vote for its witness and get one more award!

I have never ever even given any thought whatsoever to understanding code or programming, but coincidentally just last night i finally got around to looking at the tau website and my first realisation was, oh I'd have to learn a new language to utilise this impressive looking tech. I was thinking about bothering some steemians with my totally uninformed enquiries on my morning commute and then I stumbled upon this introduction.

This seems like the vulcan version of code haha, logic based. This is definitely intriguing and I love the idea of consensus from human-machine-human. I guess if I keep saying tech has passed me by I am destined to be a dinosaur,wheras if I confront my tech inferiority the doors begin revolving..

Appreciate this explanation and I'll continue to look into meta and this tau innovation..

Posted using Partiko Android