%% usm.gl %%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 2-Counter machine %% Example: R1 + R2 -> R1 %% 1: jpz(R2,5,2) %% 2: dec(R2) %% 3: inc(R1) %% 4: goto(1) %% 5: halt %% true => % program instruction(1,jpz,2,5,2), instruction(2,dec,2,3,x), instruction(3,inc,1,4,x), instruction(4,goto,1,x,x), instruction(5,halt,x,x,x), % data inc(0,1), inc(1,2), inc(2,3), inc(3,4), state(1,3,4). // START compute 3 + 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% UNIVERSAL INTERPRETATION OF REGISTER %% INSTRUCTIONS %-- jpz state(PC,0,R2), instruction(PC,jpz,1,PA,PB) => state(PA,0,R2). state(PC,R1,R2), inc(_X,R1), % R1 is NOT zero instruction(PC,jpz,1,PA,PB) => state(PB,R1,R2). state(PC,R1,0), instruction(PC,jpz,2,PA,PB) => state(PA,R1,0). state(PC,R1,R2), inc(_,R2), % R2 is NOT zero instruction(PC,jpz,2,PA,PB) => state(PB,R1,R2). %-- dec state(PC,R1,R2), instruction(PC,dec,1,PB,x), inc(D,R1) => state(PB,D,R2). state(PC,R1,R2), instruction(PC,dec,2,PB,x), inc(D,R2) => state(PB,R1,D). %-- inc state(PC,R1,R2), instruction(PC,inc,1,PB,x), inc(R1,I) => state(PB,I,R2). state(PC,R1,R2), instruction(PC,inc,2,PB,x), inc(R2,I) => state(PB,R1,I). %-- goto state(PC,R1,R2), instruction(PC,goto,PB,x,x) => state(PB,R1,R2). %-- halt state(PC,R1,R2), instruction(PC,halt,x,x,x) => goal. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Natural number generation via inc %% inc(X,Y) => inc(Y,SomeZ).