Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23

Percentage Accurate: 99.9% → 99.9%
Time: 4.1s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot y + z\right) \cdot y + t \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
def code(x, y, z, t):
	return (((x * y) + z) * y) + t
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x * y) + z) * y) + t)
end
function tmp = code(x, y, z, t)
	tmp = (((x * y) + z) * y) + t;
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot y + z\right) \cdot y + t \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (+ (* x y) z) y) t))
double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (((x * y) + z) * y) + t
end function
public static double code(double x, double y, double z, double t) {
	return (((x * y) + z) * y) + t;
}
def code(x, y, z, t):
	return (((x * y) + z) * y) + t
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(x * y) + z) * y) + t)
end
function tmp = code(x, y, z, t)
	tmp = (((x * y) + z) * y) + t;
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision] + t), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot y + z\right) \cdot y + t
\end{array}

Alternative 1: 99.9% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (fma (fma x y z) y t))
double code(double x, double y, double z, double t) {
	return fma(fma(x, y, z), y, t);
}
function code(x, y, z, t)
	return fma(fma(x, y, z), y, t)
end
code[x_, y_, z_, t_] := N[(N[(x * y + z), $MachinePrecision] * y + t), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y + z\right) \cdot y + t \]
  2. Step-by-step derivation
    1. fma-def100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot y + z, y, t\right)} \]
    2. fma-def100.0%

      \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(x, y, z\right)}, y, t\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right)} \]
  4. Final simplification100.0%

    \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, y, z\right), y, t\right) \]

Alternative 2: 62.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := y \cdot \left(x \cdot y\right)\\ \mathbf{if}\;y \leq -9.2 \cdot 10^{+135}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{+89}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -1.24 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{-126}:\\ \;\;\;\;t\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+99}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* y (* x y))))
   (if (<= y -9.2e+135)
     t_1
     (if (<= y -1.6e+89)
       (* y z)
       (if (<= y -1.24e-42)
         t_1
         (if (<= y 5.6e-126) t (if (<= y 1.8e+99) (* y z) t_1)))))))
double code(double x, double y, double z, double t) {
	double t_1 = y * (x * y);
	double tmp;
	if (y <= -9.2e+135) {
		tmp = t_1;
	} else if (y <= -1.6e+89) {
		tmp = y * z;
	} else if (y <= -1.24e-42) {
		tmp = t_1;
	} else if (y <= 5.6e-126) {
		tmp = t;
	} else if (y <= 1.8e+99) {
		tmp = y * z;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = y * (x * y)
    if (y <= (-9.2d+135)) then
        tmp = t_1
    else if (y <= (-1.6d+89)) then
        tmp = y * z
    else if (y <= (-1.24d-42)) then
        tmp = t_1
    else if (y <= 5.6d-126) then
        tmp = t
    else if (y <= 1.8d+99) then
        tmp = y * z
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double t_1 = y * (x * y);
	double tmp;
	if (y <= -9.2e+135) {
		tmp = t_1;
	} else if (y <= -1.6e+89) {
		tmp = y * z;
	} else if (y <= -1.24e-42) {
		tmp = t_1;
	} else if (y <= 5.6e-126) {
		tmp = t;
	} else if (y <= 1.8e+99) {
		tmp = y * z;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	t_1 = y * (x * y)
	tmp = 0
	if y <= -9.2e+135:
		tmp = t_1
	elif y <= -1.6e+89:
		tmp = y * z
	elif y <= -1.24e-42:
		tmp = t_1
	elif y <= 5.6e-126:
		tmp = t
	elif y <= 1.8e+99:
		tmp = y * z
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t)
	t_1 = Float64(y * Float64(x * y))
	tmp = 0.0
	if (y <= -9.2e+135)
		tmp = t_1;
	elseif (y <= -1.6e+89)
		tmp = Float64(y * z);
	elseif (y <= -1.24e-42)
		tmp = t_1;
	elseif (y <= 5.6e-126)
		tmp = t;
	elseif (y <= 1.8e+99)
		tmp = Float64(y * z);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	t_1 = y * (x * y);
	tmp = 0.0;
	if (y <= -9.2e+135)
		tmp = t_1;
	elseif (y <= -1.6e+89)
		tmp = y * z;
	elseif (y <= -1.24e-42)
		tmp = t_1;
	elseif (y <= 5.6e-126)
		tmp = t;
	elseif (y <= 1.8e+99)
		tmp = y * z;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.2e+135], t$95$1, If[LessEqual[y, -1.6e+89], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.24e-42], t$95$1, If[LessEqual[y, 5.6e-126], t, If[LessEqual[y, 1.8e+99], N[(y * z), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := y \cdot \left(x \cdot y\right)\\
\mathbf{if}\;y \leq -9.2 \cdot 10^{+135}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq -1.6 \cdot 10^{+89}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq -1.24 \cdot 10^{-42}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 5.6 \cdot 10^{-126}:\\
\;\;\;\;t\\

\mathbf{elif}\;y \leq 1.8 \cdot 10^{+99}:\\
\;\;\;\;y \cdot z\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -9.2000000000000005e135 or -1.59999999999999994e89 < y < -1.24e-42 or 1.8000000000000001e99 < y

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in t around 0 92.5%

      \[\leadsto \color{blue}{\left(y \cdot x + z\right) \cdot y} \]
    3. Taylor expanded in y around inf 78.3%

      \[\leadsto \color{blue}{\left(y \cdot x\right)} \cdot y \]

    if -9.2000000000000005e135 < y < -1.59999999999999994e89 or 5.59999999999999983e-126 < y < 1.8000000000000001e99

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in t around 0 81.0%

      \[\leadsto \color{blue}{\left(y \cdot x + z\right) \cdot y} \]
    3. Taylor expanded in y around 0 54.5%

      \[\leadsto \color{blue}{z} \cdot y \]

    if -1.24e-42 < y < 5.59999999999999983e-126

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in y around 0 83.3%

      \[\leadsto \color{blue}{t} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.2 \cdot 10^{+135}:\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq -1.6 \cdot 10^{+89}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -1.24 \cdot 10^{-42}:\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 5.6 \cdot 10^{-126}:\\ \;\;\;\;t\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+99}:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \end{array} \]

Alternative 3: 78.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{+135} \lor \neg \left(y \leq -5.4 \cdot 10^{+83}\right) \land \left(y \leq -1.22 \cdot 10^{+36} \lor \neg \left(y \leq 2.5 \cdot 10^{+98}\right)\right):\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= y -9.5e+135)
         (and (not (<= y -5.4e+83))
              (or (<= y -1.22e+36) (not (<= y 2.5e+98)))))
   (* y (* x y))
   (+ t (* y z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -9.5e+135) || (!(y <= -5.4e+83) && ((y <= -1.22e+36) || !(y <= 2.5e+98)))) {
		tmp = y * (x * y);
	} else {
		tmp = t + (y * z);
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((y <= (-9.5d+135)) .or. (.not. (y <= (-5.4d+83))) .and. (y <= (-1.22d+36)) .or. (.not. (y <= 2.5d+98))) then
        tmp = y * (x * y)
    else
        tmp = t + (y * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -9.5e+135) || (!(y <= -5.4e+83) && ((y <= -1.22e+36) || !(y <= 2.5e+98)))) {
		tmp = y * (x * y);
	} else {
		tmp = t + (y * z);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (y <= -9.5e+135) or (not (y <= -5.4e+83) and ((y <= -1.22e+36) or not (y <= 2.5e+98))):
		tmp = y * (x * y)
	else:
		tmp = t + (y * z)
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((y <= -9.5e+135) || (!(y <= -5.4e+83) && ((y <= -1.22e+36) || !(y <= 2.5e+98))))
		tmp = Float64(y * Float64(x * y));
	else
		tmp = Float64(t + Float64(y * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((y <= -9.5e+135) || (~((y <= -5.4e+83)) && ((y <= -1.22e+36) || ~((y <= 2.5e+98)))))
		tmp = y * (x * y);
	else
		tmp = t + (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -9.5e+135], And[N[Not[LessEqual[y, -5.4e+83]], $MachinePrecision], Or[LessEqual[y, -1.22e+36], N[Not[LessEqual[y, 2.5e+98]], $MachinePrecision]]]], N[(y * N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+135} \lor \neg \left(y \leq -5.4 \cdot 10^{+83}\right) \land \left(y \leq -1.22 \cdot 10^{+36} \lor \neg \left(y \leq 2.5 \cdot 10^{+98}\right)\right):\\
\;\;\;\;y \cdot \left(x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -9.50000000000000036e135 or -5.40000000000000014e83 < y < -1.21999999999999995e36 or 2.4999999999999999e98 < y

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in t around 0 96.5%

      \[\leadsto \color{blue}{\left(y \cdot x + z\right) \cdot y} \]
    3. Taylor expanded in y around inf 84.0%

      \[\leadsto \color{blue}{\left(y \cdot x\right)} \cdot y \]

    if -9.50000000000000036e135 < y < -5.40000000000000014e83 or -1.21999999999999995e36 < y < 2.4999999999999999e98

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in x around 0 85.8%

      \[\leadsto \color{blue}{z} \cdot y + t \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{+135} \lor \neg \left(y \leq -5.4 \cdot 10^{+83}\right) \land \left(y \leq -1.22 \cdot 10^{+36} \lor \neg \left(y \leq 2.5 \cdot 10^{+98}\right)\right):\\ \;\;\;\;y \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \]

Alternative 4: 89.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.15 \cdot 10^{-42} \lor \neg \left(y \leq 8.5 \cdot 10^{-38}\right):\\ \;\;\;\;y \cdot \left(z + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= y -2.15e-42) (not (<= y 8.5e-38)))
   (* y (+ z (* x y)))
   (+ t (* y z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -2.15e-42) || !(y <= 8.5e-38)) {
		tmp = y * (z + (x * y));
	} else {
		tmp = t + (y * z);
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((y <= (-2.15d-42)) .or. (.not. (y <= 8.5d-38))) then
        tmp = y * (z + (x * y))
    else
        tmp = t + (y * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -2.15e-42) || !(y <= 8.5e-38)) {
		tmp = y * (z + (x * y));
	} else {
		tmp = t + (y * z);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (y <= -2.15e-42) or not (y <= 8.5e-38):
		tmp = y * (z + (x * y))
	else:
		tmp = t + (y * z)
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if ((y <= -2.15e-42) || !(y <= 8.5e-38))
		tmp = Float64(y * Float64(z + Float64(x * y)));
	else
		tmp = Float64(t + Float64(y * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((y <= -2.15e-42) || ~((y <= 8.5e-38)))
		tmp = y * (z + (x * y));
	else
		tmp = t + (y * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.15e-42], N[Not[LessEqual[y, 8.5e-38]], $MachinePrecision]], N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{-42} \lor \neg \left(y \leq 8.5 \cdot 10^{-38}\right):\\
\;\;\;\;y \cdot \left(z + x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;t + y \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.1500000000000001e-42 or 8.50000000000000046e-38 < y

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in t around 0 90.7%

      \[\leadsto \color{blue}{\left(y \cdot x + z\right) \cdot y} \]

    if -2.1500000000000001e-42 < y < 8.50000000000000046e-38

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in x around 0 95.3%

      \[\leadsto \color{blue}{z} \cdot y + t \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.15 \cdot 10^{-42} \lor \neg \left(y \leq 8.5 \cdot 10^{-38}\right):\\ \;\;\;\;y \cdot \left(z + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t + y \cdot z\\ \end{array} \]

Alternative 5: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ t + y \cdot \left(z + x \cdot y\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (+ t (* y (+ z (* x y)))))
double code(double x, double y, double z, double t) {
	return t + (y * (z + (x * y)));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = t + (y * (z + (x * y)))
end function
public static double code(double x, double y, double z, double t) {
	return t + (y * (z + (x * y)));
}
def code(x, y, z, t):
	return t + (y * (z + (x * y)))
function code(x, y, z, t)
	return Float64(t + Float64(y * Float64(z + Float64(x * y))))
end
function tmp = code(x, y, z, t)
	tmp = t + (y * (z + (x * y)));
end
code[x_, y_, z_, t_] := N[(t + N[(y * N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
t + y \cdot \left(z + x \cdot y\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y + z\right) \cdot y + t \]
  2. Final simplification99.9%

    \[\leadsto t + y \cdot \left(z + x \cdot y\right) \]

Alternative 6: 46.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{+73}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{-122}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= y -2.8e+73) (* y z) (if (<= y 6.4e-122) t (* y z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -2.8e+73) {
		tmp = y * z;
	} else if (y <= 6.4e-122) {
		tmp = t;
	} else {
		tmp = y * z;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (y <= (-2.8d+73)) then
        tmp = y * z
    else if (y <= 6.4d-122) then
        tmp = t
    else
        tmp = y * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -2.8e+73) {
		tmp = y * z;
	} else if (y <= 6.4e-122) {
		tmp = t;
	} else {
		tmp = y * z;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if y <= -2.8e+73:
		tmp = y * z
	elif y <= 6.4e-122:
		tmp = t
	else:
		tmp = y * z
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (y <= -2.8e+73)
		tmp = Float64(y * z);
	elseif (y <= 6.4e-122)
		tmp = t;
	else
		tmp = Float64(y * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (y <= -2.8e+73)
		tmp = y * z;
	elseif (y <= 6.4e-122)
		tmp = t;
	else
		tmp = y * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[y, -2.8e+73], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.4e-122], t, N[(y * z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+73}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 6.4 \cdot 10^{-122}:\\
\;\;\;\;t\\

\mathbf{else}:\\
\;\;\;\;y \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.80000000000000008e73 or 6.4000000000000004e-122 < y

    1. Initial program 100.0%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in t around 0 91.3%

      \[\leadsto \color{blue}{\left(y \cdot x + z\right) \cdot y} \]
    3. Taylor expanded in y around 0 40.4%

      \[\leadsto \color{blue}{z} \cdot y \]

    if -2.80000000000000008e73 < y < 6.4000000000000004e-122

    1. Initial program 99.9%

      \[\left(x \cdot y + z\right) \cdot y + t \]
    2. Taylor expanded in y around 0 71.3%

      \[\leadsto \color{blue}{t} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification55.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.8 \cdot 10^{+73}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 6.4 \cdot 10^{-122}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \]

Alternative 7: 38.5% accurate, 9.0× speedup?

\[\begin{array}{l} \\ t \end{array} \]
(FPCore (x y z t) :precision binary64 t)
double code(double x, double y, double z, double t) {
	return t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = t
end function
public static double code(double x, double y, double z, double t) {
	return t;
}
def code(x, y, z, t):
	return t
function code(x, y, z, t)
	return t
end
function tmp = code(x, y, z, t)
	tmp = t;
end
code[x_, y_, z_, t_] := t
\begin{array}{l}

\\
t
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot y + z\right) \cdot y + t \]
  2. Taylor expanded in y around 0 40.2%

    \[\leadsto \color{blue}{t} \]
  3. Final simplification40.2%

    \[\leadsto t \]

Reproduce

?
herbie shell --seed 2023196 
(FPCore (x y z t)
  :name "Language.Haskell.HsColour.ColourHighlight:unbase from hscolour-1.23"
  :precision binary64
  (+ (* (+ (* x y) z) y) t))