Društvo LJUDMILA
Rozmanova ulica 12
1000 Ljubljana
Slovenia
Prostori: osmo/za

PostgreSQL Turing Machine

Is it possible to implement Turing machine in PostgreSQL?

create domain symbol name;
comment on domain symbol is 'Symbol on tape';
create domain state name;
comment on domain state is 'Automaton state';
create domain action int check (value in (-1,0,1));
comment on domain action is 'Move the head or NULL to stop';
create table tape (
  pos numeric,
  x   symbol
);
alter table tape add primary key (pos);
create table atransition (
  x0 symbol,
  q0 state,
  x1 symbol,
  q1 state,
  d  action
);
alter table atransition add primary key (x0,q0);
create table astate (
  q  state,
  qx symbol not null,
  qd action
);
update astate set qx=t.x, qd=at.d
from tape t, atransition at, astate
where pos=0 and x0=xq and q0=q;
update tape set x=x1
from tape t, atransition at, astate
where pos=0 and x0=xq and q0=q;
update tape set pos=pos+(select d from astate);