From cccbbc553c14eb43edaea75d6a825011aed7a7d9 Mon Sep 17 00:00:00 2001 From: Victor Lei Date: Wed, 28 Dec 2016 21:48:07 +0300 Subject: [PATCH] works --- smop/rules.pl | 81 +++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 60 deletions(-) diff --git a/smop/rules.pl b/smop/rules.pl index a804458d..4281784b 100644 --- a/smop/rules.pl +++ b/smop/rules.pl @@ -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