Index: doc/theses/mike_brooks_MMath/programs/ar-bchk/Makefile
===================================================================
--- doc/theses/mike_brooks_MMath/programs/ar-bchk/Makefile	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
+++ doc/theses/mike_brooks_MMath/programs/ar-bchk/Makefile	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
@@ -0,0 +1,52 @@
+CFA?=cfa
+
+DEMOS?=control treatment
+LANGS?=cfa c cc
+
+CFLAGS=-O3 #-DNDEBUG
+
+SOURCES=$(foreach demo,$(DEMOS),$(foreach lang,$(LANGS),$(demo).$(lang)))
+TGT_SLUGS=$(call BOUND_ALTS,$(SOURCES))
+EXES=$(addsuffix .runme,$(TGT_SLUGS))
+ASMS=$(addsuffix .s,$(TGT_SLUGS))
+TGTS=$(EXES) $(ASMS)
+define BOUND_ALTS
+$(1) $(addsuffix .unsound,$(1))
+endef
+define COMPILER_FOR
+$(strip
+	$(if $(findstring .cfa,$(1)),$(CFA),
+	$(if $(findstring .cc,$(1)),$(CXX),
+	$(if $(findstring .c,$(1)),$(CC),
+	unknown$(1)))))
+endef
+
+
+.SUFFIXES:  # disable make built-in rules, notably `% : %.s`, which introduces circularity
+.SECONDEXPANSION:  # evaluate prereq dynamically
+
+all: $(TGTS)
+exes: $(EXES)
+asms: $(ASMS)
+
+.PHONY: all exes asms echo_% clean
+
+$(TGTS): tgt_slug=$(basename $@)
+$(TGTS): unsound_flag=$(if $(findstring .unsound,$(tgt_slug)),-DUNSOUND_BOUND)
+$(TGTS): source=$(subst .unsound,,$(tgt_slug))
+$(TGTS): compiler=$(call COMPILER_FOR,$(suffix $(source)))
+
+$(EXES): out_type_flag=-DRUNIT
+$(ASMS): out_type_flag=-S
+
+$(TGTS): Makefile
+$(TGTS): $$(source)
+	$(compiler) $< $(unsound_flag) $(out_type_flag) $(CFLAGS) -MMD -MF $@.d -o $@
+
+echo_%:
+	@echo '$($(@:echo_%=%))'
+
+clean:
+	rm -f *.s *.runme *.d
+
+-include *.d
Index: doc/theses/mike_brooks_MMath/programs/ar-bchk/control.c
===================================================================
--- doc/theses/mike_brooks_MMath/programs/ar-bchk/control.c	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
+++ doc/theses/mike_brooks_MMath/programs/ar-bchk/control.c	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
@@ -0,0 +1,53 @@
+#include <stddef.h>
+#include <stdio.h>
+
+
+
+#ifdef UNSOUND_BOUND
+	#define BND( correct_limit ) 100
+#else
+	#define BND( correct_limit ) correct_limit
+#endif
+
+
+
+
+
+
+
+
+
+
+double sum(
+        size_t n, float x[] ) {
+	double sum = 0;
+	for( size_t i = 0;
+            i < BND( n ); i++ )
+        sum += x[i];
+	return sum;
+}
+
+
+
+
+
+
+#ifdef RUNIT
+
+#define EXPSZ 7
+
+
+
+
+
+int main() {
+	float x[EXPSZ];
+	for( size_t i = 0; i < EXPSZ; i++ ) x[i] = 0.1 * (i + 1);
+	for( size_t i = 0; i < EXPSZ; i++ ) printf("elm %zd %g\n", i, x[i]);
+	double sum_ret = sum( EXPSZ, x );
+	printf( "sum   %2g\n", sum_ret );
+}
+
+
+
+#endif
Index: doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cc
===================================================================
--- doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cc	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
+++ doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cc	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
@@ -0,0 +1,53 @@
+#include <cstddef>
+#include <iostream>
+#include <vector>
+using namespace std;
+
+#ifdef UNSOUND_BOUND
+	#define BND( correct_limit ) 100
+#else
+	#define BND( correct_limit ) correct_limit
+#endif
+
+
+
+
+
+
+
+
+
+
+double sum(
+        vector<float> & x ) {
+	double sum = 0;
+	for( size_t i = 0;
+            i < BND( x.size() ); i++ )
+        sum += x.at(i);
+	return sum;
+}
+
+
+
+
+
+
+#ifdef RUNIT
+
+#define EXPSZ 7
+
+
+
+
+
+int main() {
+	vector<float> x( EXPSZ );
+	for( size_t i = 0; i < EXPSZ; i++ ) x.at(i) = 0.1 * (i + 1);
+	for( size_t i = 0; i < EXPSZ; i++ ) cout << "elm " << i << " " <<  x[i] << endl;
+	double sum_ret = sum( x );
+	cout << "sum   " << sum_ret << endl;
+}
+
+
+
+#endif
Index: doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cfa
===================================================================
--- doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cfa	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
+++ doc/theses/mike_brooks_MMath/programs/ar-bchk/control.cfa	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
@@ -0,0 +1,53 @@
+#include <fstream.hfa>
+#include <array.hfa>
+
+//extern "C" { // don't mangle the function name `sum`
+
+#ifdef UNSOUND_BOUND
+	#define BND( correct_limit ) 100
+#else
+	#define BND( correct_limit ) correct_limit
+#endif
+
+
+
+
+
+
+
+
+
+forall( [N] )
+double sum(
+		array(float, N) & x ) {
+	double sum = 0;
+	for( i;
+			BND( N ) )
+		sum += x[i];
+	return sum;
+}
+
+
+
+
+//} // extern "C"
+
+#ifdef RUNIT
+
+#define EXPSZ 7
+
+
+
+
+
+int main() {
+	array( float, EXPSZ ) x;
+	for ( i; EXPSZ ) x[i] = 0.1 * (i + 1);
+	for ( i; EXPSZ ) sout | "elm" | i | x[i];
+	double sum = sum( x );
+	sout | "sum   " | wd( 2, sum );
+}
+
+
+
+#endif
Index: doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.c
===================================================================
--- doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.c	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
+++ doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.c	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
@@ -0,0 +1,91 @@
+#include <stdio.h>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void mul( size_t m,
+        size_t n, size_t p,
+        float res[m][n],
+        float lhs[m][p],
+        float rhs[p][n] ) {
+    for( size_t i = 0;
+            i < m; i++ )
+        for( size_t j = 0;
+                j < n; j++ ) {
+            res[i][j] = 0.0;
+            for( size_t k = 0;
+                    k < p; k++ )
+                res[i][j] +=
+                    lhs[i][k] *
+                    rhs[k][j];
+        }
+}
+
+
+
+
+
+
+
+
+
+#ifdef RUNIT
+
+
+static void zero( size_t r, size_t c, float mat[r][c] ) {
+    for( size_t i = 0; i < r; i++ )
+        for( size_t j = 0; j < c; j++ )
+            mat[i][j] = 0.0;
+}
+
+
+static void fill( size_t r, size_t c, float mat[r][c] ) {
+    for( size_t i = 0; i < r; i++ )
+        for( size_t j = 0; j < c; j++ )
+            mat[i][j] = 1.0 * (i + 1) + 0.1 * (j+1);
+}
+
+
+static void print( size_t r, size_t c, float mat[r][c] ) {
+    for( size_t i = 0; i < r; i++ ) {
+        for( size_t j = 0; j < c; j++ )
+            printf("%2g ", mat[i][j]);
+        printf("\n");
+    }
+}
+
+#define EXPSZ_M 2
+#define EXPSZ_N 3
+#define EXPSZ_P 4
+
+
+int main() {
+    float res[ EXPSZ_M ][ EXPSZ_N ];  zero( EXPSZ_M, EXPSZ_N, res );
+    float lhs[ EXPSZ_M ][ EXPSZ_P ];  fill( EXPSZ_M, EXPSZ_P, lhs );
+    float rhs[ EXPSZ_P ][ EXPSZ_N ];  fill( EXPSZ_P, EXPSZ_N, rhs );
+    mul( EXPSZ_M, EXPSZ_N, EXPSZ_P, res, lhs, rhs );
+    print(EXPSZ_M, EXPSZ_P, lhs);
+    printf("*\n");
+    print(EXPSZ_P, EXPSZ_N, rhs);
+    printf("=\n");
+    print(EXPSZ_M, EXPSZ_N, res);
+}
+
+
+
+#endif
Index: doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.cc
===================================================================
--- doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.cc	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
+++ doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.cc	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
@@ -0,0 +1,91 @@
+#include <iostream>
+#include <vector>
+using namespace std;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+void mul(
+    
+        vector<vector<float>> & res,
+        vector<vector<float>> & lhs,
+        vector<vector<float>> & rhs ) {
+    for( size_t i = 0;
+            i < res.size(); i++ )
+        for( size_t j = 0;
+                j < res.at(i).size(); j++ ) {
+            res.at(i).at(j) = 0.0;
+            for( size_t k = 0;
+                    k < rhs.size(); k++ )
+                res.at(i).at(j) +=
+                    lhs.at(i).at(k) *
+                    rhs.at(k).at(j);
+        }
+}
+
+
+
+
+
+
+
+
+
+#ifdef RUNIT
+
+
+static void zero( vector<vector<float>> & mat ) {
+    for( size_t i = 0; i < mat.size(); i++ )
+        for( size_t j = 0; j < mat.at(i).size(); j++ )
+            mat.at(i).at(j) = 0.0;
+}
+
+
+static void fill( vector<vector<float>> & mat ) {
+    for( size_t i = 0; i < mat.size(); i++ )
+        for( size_t j = 0; j < mat.at(i).size(); j++ )
+            mat.at(i).at(j) = 1.0 * (i + 1) + 0.1 * (j+1);
+}
+
+
+static void print( vector<vector<float>> & mat ) {
+    for( size_t i = 0; i < mat.size(); i++ ) {
+        for( size_t j = 0; j < mat.at(i).size(); j++ )
+            cout << mat.at(i).at(j) << " ";
+        cout << endl;
+    }
+}
+
+#define EXPSZ_M 2
+#define EXPSZ_N 3
+#define EXPSZ_P 4
+
+
+int main() {
+    vector<vector<float>> res( EXPSZ_M, vector<float>( EXPSZ_N ) );  zero( res );
+    vector<vector<float>> lhs( EXPSZ_M, vector<float>( EXPSZ_P ) );  fill( lhs );
+    vector<vector<float>> rhs( EXPSZ_P, vector<float>( EXPSZ_N ) );  fill( rhs );
+    mul( res, lhs, rhs );
+    print(lhs);
+    printf("*\n");
+    print(rhs);
+    printf("=\n");
+    print(res);
+}
+
+
+
+#endif
Index: doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.cfa
===================================================================
--- doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.cfa	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
+++ doc/theses/mike_brooks_MMath/programs/ar-bchk/treatment.cfa	(revision eb0d9b7d937213cd3bc39235c18121a496cbb52f)
@@ -0,0 +1,88 @@
+#include <fstream.hfa>
+#include <array.hfa>
+
+extern "C" { // don't mangle the function name `sum`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+forall( [M], [N], [P] )
+void mul(
+    
+        array(float, M, N) & res,
+        array(float, M, P) & lhs,
+        array(float, P, N) & rhs ) {
+    for( i; M )
+
+        for( j; N ) {
+
+            res[i, j] = 0.0;
+            for( k; P )
+
+                res[i, j] +=
+                    lhs[i, k] *
+                    rhs[k, j];
+        }
+}
+
+
+
+
+
+
+
+} // extern "C"
+
+#ifdef RUNIT
+
+forall( [R], [C] )
+static void zero( array(float, R, C) & mat ) {
+    for ( i; R ) for ( j; C )
+        mat[i,j] = 0.0;
+}
+
+forall( [R], [C] )
+static void fill( array(float, R, C) & mat ) {
+    for ( i; R ) for ( j; C )
+        mat[i,j] = 1.0 * (i + 1) + 0.1 * (j+1);
+}
+
+forall( [R], [C] )
+static void print( array(float, R, C) & mat ) {
+    for ( i; R ) {
+        for ( j; C ) sout | wd(2, mat[i, j]) | sep | nonl;
+        sout | nl;
+    }
+}
+
+#define EXPSZ_M 2
+#define EXPSZ_N 3
+#define EXPSZ_P 4
+
+
+int main() {
+    array( float, EXPSZ_M, EXPSZ_N ) res;  zero( res );
+    array( float, EXPSZ_M, EXPSZ_P ) lhs;  fill( lhs );
+    array( float, EXPSZ_P, EXPSZ_N ) rhs;  fill( rhs );
+    mul( res, lhs, rhs );
+    print(lhs);
+    sout | "*";
+    print(rhs);
+    sout | "=";
+    print(res);
+}
+
+
+
+#endif
Index: doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal-matmul.cfa
===================================================================
--- doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal-matmul.cfa	(revision 5d300ba784b5d5ea7e8ee28df45bf31e6d789d86)
+++ 	(revision )
@@ -1,13 +1,0 @@
-#include <array.hfa>
-
-// traditional "naiive" loops
-forall( [M], [N], [P] )
-void matmul( array(float, M, P) & src1,
-			 array(float, P, N) & src2, 
-			 array(float, M, N) & tgt ) {
-	for (i; M) for (j; N) {
-		tgt[i][j] = 0;
-		for (k; P)
-			tgt[i][j] += src1[i][k] * src2[k][j];
-	}
-}
Index: doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal-stdvec.cpp
===================================================================
--- doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal-stdvec.cpp	(revision 5d300ba784b5d5ea7e8ee28df45bf31e6d789d86)
+++ 	(revision )
@@ -1,121 +1,0 @@
-/*
-// traditional "naiive" loops
-forall( [M], [N], [P] )
-void matmul( array(float, M, P) & src1,
-			 array(float, P, N) & src2, 
-			 array(float, M, N) & tgt ) {
-	for (i; M) for (j; N) {
-		tgt[i][j] = 0;
-		for (k; P)
-			tgt[i][j] += src1[i][k] * src2[k][j];
-	}
-}
-*/
-
-#if defined BADBOUNDS
-#define BOUND(X) 17
-#else
-#define BOUND(X) X
-#endif
-
-#include <vector>
-using namespace std;
-
-
-#ifndef TESTCASE
-#define TESTCASE 1
-#endif
-
-#if TESTCASE==1
-
-float f( vector<float> & a ) {
-	float result = 0;
-	for( int i = 0; i < BOUND(a.size()); i++ ) {
-		result += a.at(i);
-		// hillarious that, while writing THIS VERY DEMO, on first go, I actaully wrote it a[i]
-	}
-	return result;
-}
-
-#ifdef WITHHARNESS
-#include <iostream>
-int main( int argc, char ** argv ) {
-	vector<float> v(5);
-	v.at(0) = 3.14;
-	v.at(1) = 3.14;
-	v.at(2) = 3.14;
-	v.at(3) = 3.14;
-	v.at(4) = 3.14;
-
-	float answer = f(v);
-
-	cout << "answer: " << answer << endl;
-
-}
-#endif 
-
-// g++ array-boundcheck-removal-stdvec.cpp -DWITHHARNESS -DBADBOUNDS
-// ./a.out
-// Aborted: terminate called after throwing an instance of 'std::out_of_range'
-
-
-// g++ array-boundcheck-removal-stdvec.cpp -DWITHHARNESS
-// ./a.out
-// answer: 15.7
-
-// g++ array-boundcheck-removal-stdvec.cpp -S -O2 -DBADBOUNDS
-// loop has cmp-jmp
-// jmp target has call _ZSt24__throw_out_of_range_fmtPKcz@PLT
-
-// g++ array-boundcheck-removal-stdvec.cpp -S -O2
-// loop is clean
-
-
-#elif TESTCASE==2
-
-//#include <cassert>
-#define assert(prop) if (!prop) return
-
-typedef vector<vector<float> > mat;
-
-void matmul( mat & a, mat & b, mat & rslt ) {
-	size_t m = rslt.size();
-	assert( m == a.size() );
-	size_t p = b.size();
-	for ( int i = 0; i < BOUND(m); i++ ) {
-		assert( p == a.at(i).size() );
-		size_t n = rslt.at(i).size();
-		for ( int j = 0; j < BOUND(n); j++ ) {
-			rslt.at(i).at(j) = 0.0;
-			for ( int k = 0; k < BOUND(p); k++ ) {
-				assert(b.at(k).size() == n); // asking to check it too often
-				rslt.at(i).at(j) += a.at(i).at(k) * b.at(k).at(j);
-			}
-		}
-	}
-}
-
-#ifdef WITHHARNESS
-#include <iostream>
-int main( int argc, char ** argv ) {
-	mat a(5, vector<float>(6));
-	mat b(6, vector<float>(7));
-	mat r(5, vector<float>(7));
-	matmul(a, b, r);
-}
-#endif 
-
-// (modify the declarations in main to be off by one, each of the 6 values at a time)
-// g++ array-boundcheck-removal-stdvec.cpp -DWITHHARNESS -DTESTCASE=2
-// ./a.out
-// (see an assertion failure)
-
-// g++ array-boundcheck-removal-stdvec.cpp -DWITHHARNESS -DTESTCASE=2
-// ./a.out
-// (runs fine)
-
-// g++ array-boundcheck-removal-stdvec.cpp -S -O2 -DTESTCASE=2
-// hypothesis: loop bound checks are clean because the assertions took care of it
-// actual so far:  both assertions and bound checks survived
-
-#endif
Index: doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal.cfa
===================================================================
--- doc/theses/mike_brooks_MMath/programs/array-boundcheck-removal.cfa	(revision 5d300ba784b5d5ea7e8ee28df45bf31e6d789d86)
+++ 	(revision )
@@ -1,55 +1,0 @@
-#include <array.hfa>
-
-#ifndef DIMSVERSION
-#define DIMSVERSION 1
-#endif
-
-#if DIMSVERSION == 1
-
-forall( [N] )
-size_t foo( array( size_t, N ) & a ) {
-	size_t retval = 0;
-	for( i; N ) {
-		retval += a[i];
-	}
-	return retval;
-}
-
-#elif DIMSVERSION == 2 
-
-forall( [N], [M] )
-size_t foo( array( size_t, N, M ) & a ) {
-	size_t retval = 0;
-	for( i; N ) for( j; M ) {
-		retval += a[i][j];
-	}
-	return retval;
-}
-
-#elif DIMSVERSION == 3
-
-forall( [N] )
-size_t foo( array( size_t, N ) & a, array( size_t, N ) & b ) {
-	size_t retval = 0;
-	for( i; N ) {
-		retval += a[i] - b[i];
-	}
-	return retval;
-}
-
-#elif DIMSVERSION == 4
-
-forall( [M], [N], [P] )
-void foo   ( array(size_t, M, P) & src1,
-			 array(size_t, P, N) & src2, 
-			 array(size_t, M, N) & tgt ) {
-	for (i; M) for (j; N) {
-		tgt[i][j] = 0;
-		for (k; P)
-			tgt[i][j] += src1[i][k] * src2[k][j];
-	}
-}
-
-#else
-#error Bad Version 
-#endif
