Understanding TML: Prolog -> Datalog -> Tau by dana-edwards

View this thread on steempeak.com
· @dana-edwards · (edited)
$6.48
Understanding TML: Prolog -> Datalog -> Tau
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](http://www.swi-prolog.org/).
Step 2: Watch this [video](https://www.youtube.com/watch?v=gJOZZvYijqk).

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](https://www.metalevel.at/prolog/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)](http://eu.swi-prolog.org/pldoc/doc_for?object=crypto_data_encrypt/6)




References
----
1. https://swish.swi-prolog.org/
2. https://github.com/IDNI/tau
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 62 others
properties (23)
post_id69,054,184
authordana-edwards
permlinkunderstanding-tml-prolog-datalog-tau
categorytauchain
json_metadata{"tags":["tauchain","programming"],"links":["http:\/\/www.swi-prolog.org\/","https:\/\/www.youtube.com\/watch?v=gJOZZvYijqk","https:\/\/www.metalevel.at\/prolog\/cryptography","http:\/\/eu.swi-prolog.org\/pldoc\/doc_for?object=crypto_data_encrypt\/6","https:\/\/swish.swi-prolog.org\/","https:\/\/github.com\/IDNI\/tau"],"app":"steemit\/0.1","format":"markdown"}
created2019-01-20 04:29:51
last_update2019-01-20 04:59:30
depth0
children3
net_rshares11,664,927,206,414
last_payout2019-01-27 04:29:51
cashout_time1969-12-31 23:59:59
total_payout_value4.905 SBD
curator_payout_value1.574 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length4,143
author_reputation348,515,599,824,762
root_title"Understanding TML: Prolog -> Datalog -> Tau"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (126)
@kenny-crane ·
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!
👍  ,
properties (23)
post_id69,062,577
authorkenny-crane
permlinkre-dana-edwards-understanding-tml-prolog-datalog-tau-20190120t095846404z
categorytauchain
json_metadata{"tags":["tauchain"],"app":"steemit\/0.1"}
created2019-01-20 09:58:45
last_update2019-01-20 09:58:45
depth1
children0
net_rshares5,216,160,015
last_payout2019-01-27 09:58:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length183
author_reputation75,277,756,381,416
root_title"Understanding TML: Prolog -> Datalog -> Tau"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (2)
@steemitboard ·
Congratulations @dana-edwards! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

<table><tr><td>https://steemitimages.com/60x60/http://steemitboard.com/notifications/postallweek.png</td><td>You published a post every day of the week</td></tr>
</table>

<sub>_[Click here to view your Board](https://steemitboard.com/@dana-edwards)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


> Support [SteemitBoard's project](https://steemit.com/@steemitboard)! **[Vote for its witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1)** and **get one more award**!
properties (22)
post_id69,095,218
authorsteemitboard
permlinksteemitboard-notify-dana-edwards-20190121t031253000z
categorytauchain
json_metadata{"image":["https:\/\/steemitboard.com\/img\/notify.png"]}
created2019-01-21 03:12:51
last_update2019-01-21 03:12:51
depth1
children0
net_rshares0
last_payout2019-01-28 03:12:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length768
author_reputation38,705,954,145,809
root_title"Understanding TML: Prolog -> Datalog -> Tau"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@skramatters ·
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](https://steemit.com/@partiko-android)
properties (22)
post_id69,138,679
authorskramatters
permlinkskramatters-re-dana-edwards-understanding-tml-prolog-datalog-tau-20190122t022912052z
categorytauchain
json_metadata{"app":"partiko","client":"android"}
created2019-01-22 02:29:12
last_update2019-01-22 02:29:12
depth1
children0
net_rshares0
last_payout2019-01-29 02:29:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length891
author_reputation45,825,911,400,742
root_title"Understanding TML: Prolog -> Datalog -> Tau"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000