#include "libscl.h"

using namespace scl;
using namespace std;

int main(int argc, char** argp, char** envp)
{
  
  const INTEGER n = 5000;
  const INTEGER p = 6;
  const INTEGER lo = 2;

  realmat X(n,p);
  realmat TX(p,n);

  INT_32BIT seed = 2985;

  cout << '\n';

  realmat mean(1,p,0.0);

  for (INTEGER j=1; j<=p; ++j) {
    for (INTEGER i=1; i<=n; ++i) {
      REAL x = unsk(seed);
      REAL sum = 0.0;
      for (INTEGER k=1; k<=j+lo; ++k) {
        REAL z = unsk(seed);
        sum += z*z;
      }
      REAL df = REAL(j+lo-1);
      REAL var = sum/df;
      REAL sdev = sqrt(var);
      REAL t = sqrt(REAL(n))*x/sdev;
      X(i,j) = t;
      TX(j,i) = t;
      mean[j] += t;
    }
  }

  cout << mean/n << '\n';

  realmat S0 = simple(X);
  realmat S1 = simple(T(TX));
  cout << S0 << S1 << S1-S0;

  return 0;
}
