| Andrew Cooke | Contents | Latest | RSS | Twitter | Previous | Next

C[omp]ute

Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

C-ORM: docs, API.

Last 100 entries

Not The Onion: Google Fireside Chat w Kissinger; Bicycle Wheels, Inertia, and Energy; Another Tax Fraud; Google's Borg; A Verion That Redirects To Local HTTP Server; Spanish Accents For Idiots; Aluminium Cans; Advice on Spray Painting; Female View of Online Chat From a Male; UX Reading List; S4 Subgroups - Geometric Interpretation; Fucking Email; The SQM Affair For Idiots; Using Kolmogorov Complexity; Oblique Strategies in bash; Curses Tools; Markov Chain Monte Carlo Without all the Bullshit; Email Para Matias Godoy Mercado; The Penta Affair For Idiots; Example Code To Create numpy Array in C; Good Article on Bias in Graphic Design (NYTimes); Do You Backup github?; Data Mining Books; SimpleDateFormat should be synchronized; British Words; Chinese Govt Intercepts External Web To DDOS github; Numbering Permutations; Teenage Engineering - Low Price Synths; GCHQ Can Do Whatever It Wants; Dublinesque; A Cryptographic SAT Solver; Security Challenges; Word Lists for Crosswords; 3D Printing and Speaker Design; Searchable Snowden Archive; XCode Backdoored; Derived Apps Have Malware (CIA); Rowhammer - Hacking Software Via Hardware (DRAM) Bugs; Immutable SQL Database (Kinda); Tor GPS Tracker; That PyCon Dongle Mess...; ASCII Fluid Dynamics; Brandalism; Table of Shifter, Cassette and Derailleur Compatability; Lenovo Demonstrates How Bad HTTPS Is; Telegraph Owned by HSBC; Smaptop - Sunrise (Music); Equation Group (NSA); UK Torture in NI; And - A Natural Extension To Regexps; This Is The Future Of Religion; The Shazam (Music Matching) Algorithm; Tributes To Lesbian Community From AIDS Survivors; Nice Rust Summary; List of Good Fiction Books; Constructing JSON From Postgres (Part 2); Constructing JSON From Postgres (Part 1); Postgres in Docker; Why Poor Places Are More Diverse; Smart Writing on Graceland; Satire in France; Free Speech in France; MTB Cornering - Where Should We Point Our Thrusters?; Secure Secure Shell; Java Generics over Primitives; 2014 (Charlie Brooker); How I am 7; Neural Nets Applied to Go; Programming, Business, Social Contracts; Distributed Systems for Fun and Profit; XML and Scheme; Internet Radio Stations (Curated List); Solid Data About Placebos; Half of Americans Think Climate Change Is a Sign of the Apocalypse; Saturday Surf Sessions With Juvenile Delinquents; Ssh, tty, stdout and stderr; Feathers falling in a vacuum; Santiago 30m Bike Route; Mapa de Ciclovias en Santiago; How Unreliable is UDP?; SE Santiago 20m Bike Route; Cameron's Rap; Configuring libxml with Eclipse; Reducing Combinatorial Complexity With Occam - AI; Sentidos Comunes (Chilean Online Magazine); Hilary Mantel: The Assassination of Margaret Thatcher - August 6th 1983; NSA Interceptng Gmail During Delivery; General IIR Filters; What's happening with Scala?; Interesting (But Largely Illegible) Typeface; Retiring Essentialism; Poorest in UK, Poorest in N Europe; I Want To Be A Redneck!; Reverse Racism; The Lost Art Of Nomography; IBM Data Center (Photo); Interesting Account Of Gamma Hack; The Most Interesting Audiophile In The World; How did the first world war actually end?; Ky - Restaurant Santiago; The Black Dork Lives!; The UN Requires Unaninmous Decisions

© 2006-2015 Andrew Cooke (site) / post authors (content).

Datalog, DLV, SQL

From: "andrew cooke" <andrew@...>

Date: Mon, 25 Dec 2006 13:35:17 -0300 (CLST)

I've been experimenting with Datalog to understand the messages in the NSA
(the SOA system at work).

Datalog - http://en.wikipedia.org/wiki/Datalog
DLV - http://www.dbai.tuwien.ac.at/proj/dlv/

At first I had some problems, because I couldn't define the constraints I
wanted (I think it's because, to avoid the inconsistencies you get with
recursive sets, negation is stratified, but I'm not clear on exactly what
was wrong with my particular formulation).  See
http://groups.google.com/group/comp.lang.prolog/browse_thread/thread/7114a8cb8a095aa1
http://groups.google.com/group/comp.databases.theory/browse_thread/thread/7114a8cb8a095aa1

I got round that be putting everything in an SQL database and using
foreign key constraints (and it was worthwhile - I did have a bunch of
errors in my input).

Then I configured ODBC for Postgres.  This turned out to be very simple:

[msg]
Driver = /usr/lib/psqlodbc.so
Description = NS Message Description
Servername = localhost
Port = 5432
Database = msg

(test this with "isql msg")

Once that was done, I could read the information into DLV as clauses:

#import(msg, "", "", "select name, description from applications",
application, type: CONST, Q_CONST).
#import(msg, "", "", "select service, name, description from methods",
method, type: CONST, CONST, Q_CONST).
#import(msg, "", "", "select name, description from processes", process,
type: CONST, Q_CONST).
#import(msg, "", "", "select process, name, source, destination,
description from calls", call,
type: CONST, CONST, CONST, CONST, Q_CONST).
#import(msg, "", "", "select process, call from returns", return, type:
CONST, CONST).
#import(msg, "", "", "select process, caller, target from nesteds",
nested, type: CONST, CONST, CONST).
#import(msg, "", "", "select process, before, after from follows", follow,
type: CONST, CONST, CONST).

and, finally, define extra rules to analyse the data.  OK, so nothing very
exciting yet (need more data on deployment etc), but this gives the idea:

synch(F, T) :- call(P, C, F, T, _), return(P, C).
asynch(F, T) :- call(P, C, F, T, _), not return(P, C).
mixed(F, T) :- synch(F, T), asynch(F, T).

connected(F1, T1, F2, T2) :- call(P, _, F1, T1, _), call(P, _, F2, T2, _).
ordered(F1, T1, F2, T2) :- call(P, B, F1, T1, _), call(P, A, F2, T2, _),
follow(P, B, A).
ordered(F1, T1, F2, T2) :- call(P, B, F1, T1, _), call(P, A, F2, T2, _),
nested(P, B, A).
ordered(F1, T1, F2, T2) :- ordered(F1, T1, F, T), ordered(F, T, F2, T2).

In particular, note the "ordered" definition, which is horrible to do in
plain old SQL (pre-SQL3) because it's recursive.  A typical fragment of
output is:
  ordered(unp,usr_unreg,usr,mds_persist),...
which means that the UNP calls the User Service before the User service
calls the metadata service.

So I have an "expert system" that "knows" about the messages we send.

Sweet! :o)
Andrew


SQL Input:

-- these are the facts we know about the messages and system we have

-- this used dlv (datalog), but it's essentially the same as sql -
-- think of the declarations below as sql stored procedures that enter
-- the data in suitable tables.


-- applications (services etc)

select application('aud', 'Audit Service');
select application('ath', 'Authorization Service');
select application('cfg', 'Configuration Service');
select application('des', 'Data Entry Service');
select application('dls', 'Data Load Service');
select application('ds',  'Data Service');
select application('fis', 'File Information Service');
select application('mds', 'MetaData Service');
select application('nmg', 'Naming Service');
select application('ptl', 'Portal');
select application('reg', 'Registration Service');
select application('unp', 'User Notification Program');
select application('usr', 'User Service');


-- methods (actions provided by service interfaces)

select method('aud', 'aud_event',    'registerEvent');
select method('aud', 'aud_visit',    'registerVisit');
select method('cfg', 'cfg_getcnf',   'getConfiguration');
select method('dls', 'dls_load',     'load');
select method('ds',  'ds_store',     'store');
select method('fis', 'fis_regfile',  'registerFileInformation');
select method('mds', 'mds_getmo',    'getMetadataObject');
select method('mds', 'mds_getmos',   'getMetadataObjects');
select method('mds', 'mds_persist',  'persistMetadataObjects');
select method('nmg', 'nmg_newname',  'getNewName');
select method('reg', 'reg_invite',   'inviteNewUser');
select method('reg', 'reg_tokinfo',  'getUserInfo');
select method('reg', 'reg_validate', 'validateUser');
select method('usr', 'usr_getinfo',  'getUserInfo');
select method('usr', 'usr_setinfo',  'setUserInfo');
select method('usr', 'usr_unreg',    'getUnregisteredPis');


-- processes (use cases that capture a description of the working system)

select process('p_dsinit',  'Data Service startup uses the configuration
service');
select process('p_des',     'Data enters the system');
select process('p_unp',     'UNP used to trigger the invitation of new
users');
select process('p_reg',     'User registers via portal');
select process('p_downld',  'User/portal downloads (possibly proprietary)
data');
select process('p_skynode', 'User/portal runs ADQL/SkyNode query');


-- here we describe how applications call each other.
-- for each process, we list the calls and describe the dependencies
-- (nested or follow) and whether the calls return.
-- note that within a process each message name should be unique.


-- messages for p_dsinit

select call('p_dsinit', 'ds_cfg_getcnf', 'ds', 'cfg_getcnf',
'configuration data for ds');
select return('p_dsinit', 'ds_cfg_getcnf');

select call('p_dsinit', 'cfg_ms_getmo', 'cfg', 'mds_getmo', 'configuration
data for ds');
select return('p_dsinit', 'cfg_ms_getmo');
select nested('p_dsinit', 'ds_cfg_getcnf', 'cfg_ms_getmo');


-- messages for p_des

-- probably missing calls' at start (what triggers des?)
select call('p_des', 'des_nmg_newname', 'des', 'nmg_newname', 'new name
for new data');
select return('p_des', 'des_nmg_newname');

select call('p_des', 'des_fis_regfile', 'des', 'fis_regfile', 'register
new data');
select return('p_des', 'des_fis_regfile');
select follow('p_des', 'des_nmg_newname', 'des_fis_regfile');

-- nested 'call 'to MDS here?

select call('p_des', 'des_ds_store', 'des', 'ds_store', 'store new data');
select return('p_des', 'des_ds_store');
select follow('p_des', 'des_fis_regfile', 'des_ds_store');

select call('p_des', 'ds_aud_visit', 'ds', 'aud_visit', 'audit visit to
new data');
select return('p_des', 'ds_aud_visit');
select nested('p_des', 'des_ds_store', 'ds_aud_visit');

select call('p_des', 'des_dls_load', 'des', 'dls_load', 'load new data
into database');
select return('p_des', 'des_dls_load');
select follow('p_des', 'des_ds_store', 'des_dls_load');

select call('p_des', 'des_aud_event', 'des', 'aud_event', 'audit
successful data entry');
select return('p_des', 'des_aud_event');
select follow('p_des', 'des_dls_load', 'des_aud_event');


-- messages for p_unp

select call('p_unp', 'unp_usr_unreg', 'unp', 'usr_unreg', 'list
unregistered pis');
select return('p_unp', 'unp_usr_unreg');

select call('p_unp', 'usr_mds_getmos', 'usr', 'mds_getmos', 'get all pis');
select return('p_unp', 'usr_mds_getmos');
select nested('p_unp', 'unp_usr_unreg', 'usr_mds_getmos');

select call('p_unp', 'unp_reg_invite', 'unp', 'reg_invite', 'invite new pi');
select return('p_unp', 'unp_reg_invite');
select follow('p_unp', 'usr_mds_getmos', 'unp_reg_invite');

select call('p_unp', 'reg_usr_getinfo', 'reg', 'usr_getinfo', 'check pi
uninvited');
select return('p_unp', 'reg_usr_getinfo');
select nested('p_unp', 'unp_reg_invite', 'reg_usr_getinfo');

select call('p_unp', 'reg_usr_setinfo_1', 'reg', 'usr_setinfo', 'set pi
being emailed');
select return('p_unp', 'reg_usr_setinfo_1');
select follow('p_unp', 'reg_usr_getinfo', 'reg_usr_setinfo_1');

select call('p_unp', 'usr_mds_persist_1', 'usr', 'mds_persist', 'set pi
being emailed');
select return('p_unp', 'usr_mds_persist_1');
select nested('p_unp', 'reg_usr_setinfo_1', 'usr_mds_persist_1');

-- mail sent here

select call('p_unp', 'reg_usr_setinfo_2', 'reg', 'usr_setinfo', 'set pi
invited');
select return('p_unp', 'reg_usr_setinfo_2');
select follow('p_unp', 'reg_usr_getinfo', 'reg_usr_setinfo_2');

select call('p_unp', 'usr_mds_persist_2', 'usr', 'mds_persist', 'set pi
invited');
select return('p_unp', 'usr_mds_persist_2');
select nested('p_unp', 'reg_usr_setinfo_2', 'usr_mds_persist_2');


-- messages for p_reg

select call('p_reg', 'ptl_reg_tokinfo', 'ptl', 'reg_tokinfo', 'request
info for token');
select return('p_reg', 'ptl_reg_tokinfo');

select call('p_reg', 'reg_usr_getinfo_1', 'reg', 'usr_getinfo', 'request
info for token');
select return('p_reg', 'reg_usr_getinfo_1');
select nested('p_reg', 'ptl_reg_tokinfo', 'reg_usr_getinfo_1');

select call('p_reg', 'usr_mds_getmos', 'usr', 'mds_getmos', 'get all user
info');
select return('p_reg', 'usr_mds_getmos');
select nested('p_reg', 'reg_usr_getinfo_1', 'usr_mds_getmos');

select call('p_reg', 'ptl_reg_validate', 'ptl', 'reg_validate', 'validate
user, provide dn');
select return('p_reg', 'ptl_reg_validate');
select follow('p_reg', 'ptl_reg_tokinfo', 'ptl_reg_validate');

select call('p_reg', 'reg_usr_getinfo_2', 'reg', 'usr_getinfo', 'request
info for token');
select return('p_reg', 'reg_usr_getinfo_2');
select nested('p_reg', 'ptl_reg_validate', 'reg_usr_getinfo_2');

select call('p_reg', 'reg_usr_setinfo', 'reg', 'usr_setinfo', 'set pi dn,
registered');
select return('p_reg', 'reg_usr_setinfo');
select follow('p_reg', 'reg_usr_getinfo_2', 'reg_usr_setinfo');


-- messages for p_downld

-- missing calls at start
select call('p_downld', 'ath_mds_getmos', 'ath', 'mds_getmos', 'get all
file info');
select return('p_downld', 'ath_mds_getmos');


SQL Schema:


-- applications

create table applications (
  name text unique not null,
  description text not null
);

create function application(nm text, ds text) returns void as $$
begin
  insert into applications (name, description) values (nm, ds);
end;
$$ language plpgsql;


-- methods

create table methods (
  service text not null references applications(name),
  name text unique not null,
  description text not null
);

create function method(ap text, nm text, ds text) returns void as $$
begin
  insert into methods (service, name, description) values (ap, nm, ds);
end;
$$ language plpgsql;


-- processes

create table processes (
  name text unique not null,
  description text not null
);

create function process(nm text, ds text) returns void as $$
begin
  insert into processes (name, description) values (nm, ds);
end;
$$ language plpgsql;



-- calls

create table calls (
  process text not null references processes(name),
  name text not null,
  source text not null references applications(name),
  destination text not null references methods(name),
  description text not null,
  unique (process, name)
);

create function call(pr text, nm text, sr text, de text, ds text) returns
void as $$
begin
  insert into calls (process, name, source, destination, description)
values (pr, nm, sr, de, ds);
end;
$$ language plpgsql;


create table returns (
  process text not null references processes(name),
  call text not null,
  foreign key (process, call) references calls(process, name)
);

create function return(pr text, cl text) returns void as $$
begin
  insert into returns (process, call) values (pr, cl);
end;
$$ language plpgsql;

create table nesteds (
  process text not null references processes(name),
  caller text not null,
  target text not null,
  foreign key (process, caller) references calls(process, name),
  foreign key (process, target) references calls(process, name)
);

create function nested(pr text, cr text, tg text) returns void as $$
begin
  insert into nesteds (process, caller, target) values (pr, cr, tg);
end;
$$ language plpgsql;

create table follows (
  process text not null references processes(name),
  before text not null,
  after text not null,
  foreign key (process, before) references calls(process, name),
  foreign key (process, after) references calls(process, name)
);

create function follow(pr text, bf text, af text) returns void as $$
begin
  insert into follows (process, before, after) values (pr, bf, af);
end;
$$ language plpgsql;

Prolog / XSB book, possible explanation of "unsafe" problem

From: "andrew cooke" <andrew@...>

Date: Mon, 25 Dec 2006 21:34:09 -0300 (CLST)

I just found this draft of a book by Warren -
http://www.cs.sunysb.edu/~warren/xsbbook/book.html - and the introduction
to Prolog chapter is particularly good (I need to look again at Oz,
because I somehoe missed how closely Oz was connected to Prolog; but I
think I also need to look at Prolog, or perhaps XSB, in more detail too).

Anyway, there's a comment here -
http://www.cs.sunysb.edu/~warren/xsbbook/node58.html - that explains the
problem with negating an expression with free terms.  I think that may be
the problem I rant into with DLV.

XSB, incidentally, is at http://xsb.sourceforge.net

Andrew

More on Logic Programming

From: "andrew cooke" <andrew@...>

Date: Tue, 26 Dec 2006 10:51:08 -0300 (CLST)

A nice email from one of the people who developed DLV explained the
problem I had with my constraint
  :- process(P, _), not call(P, _, _, _, _).
which is clearer if written as
  :- process(P, _), not call(P, A, B, C, D).
and none of A-D are grounded (so it's not clear what you are negating).

A better approach is to be explicit:
  process_id(P) :- process(P, _).
  :- call(P, _, _, _, _), not process_id(P).

Also, I did some reading around on Mercury and Oz

Mercury tutorial -
http://www.cs.mu.oz.au/research/mercury/tutorial/book/book.pdf

Logic programming in OZ -
http://www.ps.uni-sb.de/Papers/abstracts/lpinoz99.ps

Andrew

Datalog Jobs

From: "andrew cooke" <andrew@...>

Date: Mon, 25 May 2009 21:10:11 -0400 (CLT)

Wonder if this is going to make a comeback?

http://www.haskell.org/pipermail/haskell/2009-May/021346.html

Andrew

Comment on this post