Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Dec 28, 2016
1 parent d7ae6db commit cccbbc5
Showing 1 changed file with 21 additions and 60 deletions.
81 changes: 21 additions & 60 deletions smop/rules.pl
Original file line number Diff line number Diff line change
@@ -1,68 +1,29 @@
:- discontiguous rank/2.
:- discontiguous shape/2.
:- discontiguous let/2.
:- dynamic let/2.
:- dynamic symtab/2.

:- op(800,xfy,=:).
:- op(800, yfx, =>).
%:- dynamic =>/2.

prog([
% let(solver, matlab_function(ai,af,w)),
% let(nBlocks, matlab_max(matlab_ravel(ai))),
% let([m,n], matlab_size(ai)),
% let(ii, [0, 1, 0,-1]),
% let(jj, [1, 0,-1, 0]),
let(a, ai),
let(mv, [])]).
N => 0 :- number(N).
x => 1.

%while(matlab_neg(matlab_isequal(af,a)),
% []).
N*x => N.

%let(bid, matlab_ceil(matlab_mult(matlab_rand(), nBlocks)))).
%, %[i,j] = find(a==bid);
A+B => C+D :- A => C, B => D.
A-B => C-D :- A => C, B => D.

% resolve/2
% resolve(Expr,Result)
% Expr --> atom ; number
% let(A,B) - store B in symtab with key A
% foo([A,B...] - funcall or arrayref
% [expr1 ... exprN]
%
A => A :- atomic(A),!.

%matlab_eval([],[]).
%matlab_eval([A|B], [C|D]) :- matlab_eval(A,C) , matlab_eval(B,D).
%
%% propagation
%const(A) :- let(A,B), const(B).
%
%shape(A,B) :- length(B,C), rank(A,C).
%shape(matlab_ceil(A),S) :- shape(A,S).
%shape(matlab_isequal(A,B),[]) :- shape(A,[]) ; shape(B,[]) ; shape(A,S), shape(B,S).
%shape(matlab_max(A),S) :- shape(A,[_|S]).
%shape(matlab_mult(A,B),S) :- shape(A,[]) ; shape(B,[]) ; shape(A,S), shape(B,S).
%shape(matlab_not(A),S) :- shape(A,S).
%shape(matlab_ravel(A,S)) :- shape(A,S).
%shape(matlab_zeros(A),A) :- is_list(A).
%
%% nested lists not implemented
%rank(A,0) :- integer(A) ; float(A) ; string(A).
%rank(A,1) :- is_list(A).
%rank(A,R) :- let(A,B), rank(B,R).
%
[A|B] => [C|D] :-
!,
A => C,
B => D.


% %rank(let(A,B),R) :- rank(A,R) ; rank(B,R).
%rank(matlab_size(_),1).
%rank(matlab_max(A),R-1) :- rank(A,R), R > 0.
%rank(matlab_max(A),R1) :- rank(A,R), R1 is R-1, R > 0.
%rank(A,R) :- rank(matlab_ceil(A),R).
%rank(matlab_mult(A,B),max(M,N)) :- rank(A,M), rank(B,N).
%rank(matlab_mult(A,B),R) :- rank(A,M), rank(B,N), R is max(M,N).
%rank(matlab_mult(A,B),R) :- rank(A,M), rank(B,N), R=M*N.
%rank(matlab_rand,0).
% 1. resolve (def/use, funcall/arrayref)
% 2. rank/shape/const
% 3. optimize/resolve
% 4. code gen
A => G :-
compound(A),
!,
compound_name_arguments(A,B,C),
B => D,
C => E,
F =.. [D|E],
F => G.
%G is F.

% vim : syntax=prolog

0 comments on commit cccbbc5

Please sign in to comment.