From: timv Date: Thu, 13 Dec 2012 18:46:48 +0000 (-0500) Subject: matrix shape. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=668c5e713dd0e977a30bf8c9c24e5001c227e353;p=dyna2 matrix shape. --- diff --git a/bin/prototype.py b/bin/prototype.py index 4e97c45..bc45fcd 100644 --- a/bin/prototype.py +++ b/bin/prototype.py @@ -299,7 +299,10 @@ function selectline(lineno) { print >> html, '

Update plans

' cmd = """ghc -isrc Dyna.Backend.Python -e 'processFile "%s"' """ % dynafile - assert 0 == os.system(cmd), 'command failed:\n\t' + cmd + if 0 != os.system(cmd): + print 'command failed:\n\t' + cmd + os.system('gnome-open %s 2>/dev/null >/dev/null' % html.name) + return # print >> html, '
'
 
@@ -340,9 +343,6 @@ function selectline(lineno) {
         print >> html, ''
 
 
-    print
-    print 'wrote', html.name
-
     if argv.browser:
         os.system('gnome-open %s 2>/dev/null >/dev/null' % html.name)
 
diff --git a/bin/stdlib.py b/bin/stdlib.py
index 46cb95f..2b4726d 100644
--- a/bin/stdlib.py
+++ b/bin/stdlib.py
@@ -36,7 +36,7 @@ def dump_charts(out=sys.stdout):
         print >> out, x
         print >> out, '====================================='
 
-        rows = [(pretty((x,idx)), idx, row, pretty(row[-1])) for idx, row in chart[x].data.items()]
+        rows = [(pretty((x,idx)), idx, row, pretty(row[-1])) for idx, row in chart[x].data.items() if row[-1] is not None]
         rows.sort()
 
         for p, _, _, v in rows:
diff --git a/examples/matrixops.dyna b/examples/matrixops.dyna
index 9cf7d91..288dd97 100644
--- a/examples/matrixops.dyna
+++ b/examples/matrixops.dyna
@@ -1,11 +1,19 @@
 
 
-% A and B are names of matricies
-times(A, B, I, J)    += m(A, I, K) * m(B, K, J).
-times(A, B, C, I, L) += m(A, I, K) * m(B, K, J) * m(C, J, L).
+% A and B are names of matrices
+times(A, B, I, J) += m(A, I, K) * m(B, K, J) whenever product(A,B).
+
+m(P, I, J) += shape(A, R, C),
+              shape(B, C, D),
+              P is product(A, B),
+              times(A, B, I, J).
+
+shape(P, R, C) :- P is product(A, B), shape(A, R, X), shape(B, X, C).
+
+shape(X, *rows(X), *cols(X)).
+rows(X) max= m(X, R, _), R.
+cols(X) max= m(X, _, C), C.
 
-% matrix "c" is the product of matricies "a" and "b"
-m(c, I, J) += times(a, b, I, J).
 
 % matrix "a" = [ 1 0 ;
 %                0 1 ]
@@ -14,9 +22,14 @@ m(a, 1, 2) += 0 .
 m(a, 2, 1) += 0 .
 m(a, 2, 2) += 1.
 
-% matrix "b" = [ 3 0 ;
-%                0 2 ]
+% matrix "b" = [ 3 0 1 ;
+%                0 2 0 ]
 m(b, 1, 1) += 3.
 m(b, 1, 2) += 0 .
+m(b, 1, 3) += 1 .
 m(b, 2, 1) += 0 .
 m(b, 2, 2) += 2.
+m(b, 2, 3) += 0 .
+
+% matrix "c" is the product of matricies "a" and "b"
+product(a,b) += &c