/*
 * Copyright © 2017 <code@io7m.com> http://io7m.com
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

package com.io7m.jtensors.core.parameterized.matrices;

import com.io7m.junreachable.UnreachableCodeException;

final class PMatrixDOps
{
  private PMatrixDOps()
  {
    throw new UnreachableCodeException();
  }

  static double add(
    final double value0,
    final double value1)
  {
    return value0 + value1;
  }

  static double subtract(
    final double value0,
    final double value1)
  {
    return value0 - value1;
  }

  static double multiply(
    final double value0,
    final double value1)
  {
    return value0 * value1;
  }

  static double zero()
  {
    return 0.0;
  }

  static double one()
  {
    return 1.0;
  }

  static double determinant4x4(
    final double r0c0,
    final double r1c0,
    final double r2c0,
    final double r3c0,
    final double r0c1,
    final double r1c1,
    final double r2c1,
    final double r3c1,
    final double r0c2,
    final double r1c2,
    final double r2c2,
    final double r3c2,
    final double r0c3,
    final double r1c3,
    final double r2c3,
    final double r3c3)
  {
    double sum = 0.0;

    sum += r0c0 * r1c1 * r2c2 * r3c3;
    sum -= r0c0 * r1c1 * r2c3 * r3c2;
    sum += r0c0 * r1c2 * r2c3 * r3c1;
    sum -= r0c0 * r1c2 * r2c1 * r3c3;

    sum += r0c0 * r1c3 * r2c1 * r3c2;
    sum -= r0c0 * r1c3 * r2c2 * r3c1;
    sum -= r0c1 * r1c2 * r2c3 * r3c0;
    sum += r0c1 * r1c2 * r2c0 * r3c3;

    sum -= r0c1 * r1c3 * r2c0 * r3c2;
    sum += r0c1 * r1c3 * r2c2 * r3c0;
    sum -= r0c1 * r1c0 * r2c2 * r3c3;
    sum += r0c1 * r1c0 * r2c3 * r3c2;

    sum += r0c2 * r1c3 * r2c0 * r3c1;
    sum -= r0c2 * r1c3 * r2c1 * r3c0;
    sum += r0c2 * r1c0 * r2c1 * r3c3;
    sum -= r0c2 * r1c0 * r2c3 * r3c1;

    sum += r0c2 * r1c1 * r2c3 * r3c0;
    sum -= r0c2 * r1c1 * r2c0 * r3c3;
    sum -= r0c3 * r1c0 * r2c1 * r3c2;
    sum += r0c3 * r1c0 * r2c2 * r3c1;

    sum -= r0c3 * r1c1 * r2c2 * r3c0;
    sum += r0c3 * r1c1 * r2c0 * r3c2;
    sum -= r0c3 * r1c2 * r2c0 * r3c1;
    sum += r0c3 * r1c2 * r2c1 * r3c0;

    return sum;
  }
}

@@ -841,16 +841,73 @@
 rices;%0A%0A
+import com.io7m.junreachable.UnimplementedCodeException;%0A
 import c
@@ -1515,11 +1515,11 @@
 nant
-4x4
+3x3
 (%0A  
@@ -1557,19 +1557,111 @@
 double r
-1c0
+0c1,%0A    final double r0c2,%0A    final double r1c0,%0A    final double r1c1,%0A    final double r1c2
 ,%0A    fi
@@ -1699,13 +1699,121 @@
 le r
-3c0
+2c1
 ,%0A
+    final double r2c2)%0A  %7B%0A    throw new UnimplementedCodeException();%0A  %7D%0A%0A  static double determinant4x4(%0A
     
@@ -1820,33 +1820,33 @@
 final double r0c
-1
+0
 ,%0A    final doub
@@ -1841,33 +1841,33 @@
   final double r
-1
+0
 c1,%0A    final do
@@ -1864,35 +1864,81 @@
   final double r
-2c1
+0c2,%0A    final double r0c3,%0A    final double r1c0
 ,%0A    final doub
@@ -1941,17 +1941,17 @@
 double r
-3
+1
 c1,%0A    
@@ -1956,33 +1956,33 @@
   final double r
-0
+1
 c2,%0A    final do
@@ -1981,33 +1981,33 @@
 final double r1c
-2
+3
 ,%0A    final doub
@@ -2012,17 +2012,40 @@
 uble r2c
-2
+0,%0A    final double r2c1
 ,%0A    fi
@@ -2056,17 +2056,17 @@
 double r
-3
+2
 c2,%0A    
@@ -2071,33 +2071,33 @@
   final double r
-0
+2
 c3,%0A    final do
@@ -2094,35 +2094,35 @@
   final double r
-1c3
+3c0
 ,%0A    final doub
@@ -2117,35 +2117,58 @@
   final double r
-2c3
+3c1,%0A    final double r3c2
 ,%0A    final doub

Reorganize parameters of internal determinant function