/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8                                :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2020 Justine Alexandra Roberts Tunney                              â
â                                                                              â
â 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.                                                â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "dsp/core/core.h"

/**
 * Computes Î£ð¥áµ¢Î£ð¥â±¼Î£ð¥âÎ£ð¥âÎ£ð¥âÎ£ð¥â(Î´âð¥áµ¢+Î´âð¥â±¼+Î´âð¥â+Î´âð¥â+Î´âð¥â+Î´âð¥â)Â² over ð¿..ð»
 *
 *   âAs soon as an Analytical Engine exists, it will necessarily
 *    guide the future course of the science. Whenever any result
 *    is sought by its aid, the question will then arise â by what
 *    course of calculation can these results be arrived at by the
 *    machine in the shortest time?
 *
 *                    â Charles Babbage (Life of a Philosopher, 1864)
 *
 * @see itu.int/rec/R-REC-BT.601/
 */
double DifferSumSq(const double D[static 6], double L, double H) {
  double T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T2, T20, T21, T22,
      T23, T24, T25, T26, T27, T3, T4, T5, T6, T7, T8, T9;
  T2 = H * H, T3 = (H * H * H), T4 = (H * H * H * H), T5 = (H * H * H * H * H),
  T6 = (H * H * H * H * H * H), T7 = -10 * H, T8 = (H * H * H * H * H * H * H),
  T9 = (L * L * L * L * L * L * L * L), T10 = (L * L * L * L * L * L * L),
  T11 = (L * L * L * L * L * L), T12 = (L * L * L * L * L), T13 = -45 * T2,
  T14 = (L * L * L * L), T15 = 180 * T3, T16 = 120 * T2, T17 = (L * L * L),
  T18 = L * L, T19 = 18 * T2, T20 = (H * H * H * H * H * H * H * H);
  T21 = 45 * T4;
  T22 = 3 * T9 + (-12 * H - 18) * T10 + (12 * T2 + 54 * H + 45) * T11 +
        (12 * T3 - T19 - 90 * H - 60) * T12 +
        (-30 * T4 - 90 * T3 + T13 + 60 * H + 45) * T14 +
        (12 * T5 + 90 * T4 + T15 + T16 - 18) * T17 +
        (12 * T6 + 18 * T5 - T21 - 120 * T3 - 90 * T2 - 18 * H + 3) * T18 +
        (-12 * T8 - 54 * T6 - 90 * T5 - 60 * T4 + T19 + 6 * H) * L + 3 * T20 +
        18 * T8 + 45 * T6 + 60 * T5 + T21 + 18 * T3 + 3 * T2;
  T23 =
      2 * T9 + (T7 - 13) * T10 + (20 * T2 + 55 * H + 36) * T11 +
      (-22 * T3 - 93 * T2 - 126 * H - 55) * T12 +
      (20 * T4 + 95 * T3 + 180 * T2 + 155 * H + 50) * T14 +
      (-22 * T5 - 95 * T4 - T15 - 190 * T2 - 110 * H - 27) * T17 +
      (20 * T6 + 93 * T5 + 180 * T4 + 190 * T3 + T16 + 45 * H + 8) * T18 +
      (-10 * T8 - 55 * T6 - 126 * T5 - 155 * T4 - 110 * T3 + T13 + T7 - 1) * L +
      2 * T20 + 13 * T8 + 36 * T6 + 55 * T5 + 50 * T4 + 27 * T3 + 8 * T2 + H;
  T24 = T22 * D[3], T25 = T22 * D[2], T26 = T22 * D[1], T27 = T22 * D[0];
  return (T23 * D[5] * D[5] + (T22 * D[4] + T24 + T25 + T26 + T27) * D[5] +
          T23 * D[4] * D[4] + (T24 + T25 + T26 + T27) * D[4] +
          T23 * D[3] * D[3] + (T25 + T26 + T27) * D[3] + T23 * D[2] * D[2] +
          (T26 + T27) * D[2] + T23 * D[1] * D[1] + T22 * D[0] * D[1] +
          T23 * D[0] * D[0]) /
         6;
}
