(+ (* (cos (* (+ PI PI) z4)) z3) (* (* z2 z1) z0))

Percentage Accurate: 73.1% → 98.0%
Time: 3.3s
Alternatives: 6
Speedup: 0.1×

Specification

?
\[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
(FPCore (z4 z3 z2 z1 z0)
  :precision binary64
  (+ (* (cos (* (+ PI PI) z4)) z3) (* (* z2 z1) z0)))
double code(double z4, double z3, double z2, double z1, double z0) {
	return (cos(((((double) M_PI) + ((double) M_PI)) * z4)) * z3) + ((z2 * z1) * z0);
}
public static double code(double z4, double z3, double z2, double z1, double z0) {
	return (Math.cos(((Math.PI + Math.PI) * z4)) * z3) + ((z2 * z1) * z0);
}
def code(z4, z3, z2, z1, z0):
	return (math.cos(((math.pi + math.pi) * z4)) * z3) + ((z2 * z1) * z0)
function code(z4, z3, z2, z1, z0)
	return Float64(Float64(cos(Float64(Float64(pi + pi) * z4)) * z3) + Float64(Float64(z2 * z1) * z0))
end
function tmp = code(z4, z3, z2, z1, z0)
	tmp = (cos(((pi + pi) * z4)) * z3) + ((z2 * z1) * z0);
end
code[z4_, z3_, z2_, z1_, z0_] := N[(N[(N[Cos[N[(N[(Pi + Pi), $MachinePrecision] * z4), $MachinePrecision]], $MachinePrecision] * z3), $MachinePrecision] + N[(N[(z2 * z1), $MachinePrecision] * z0), $MachinePrecision]), $MachinePrecision]
\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0

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 6 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: 73.1% accurate, 1.0× speedup?

\[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
(FPCore (z4 z3 z2 z1 z0)
  :precision binary64
  (+ (* (cos (* (+ PI PI) z4)) z3) (* (* z2 z1) z0)))
double code(double z4, double z3, double z2, double z1, double z0) {
	return (cos(((((double) M_PI) + ((double) M_PI)) * z4)) * z3) + ((z2 * z1) * z0);
}
public static double code(double z4, double z3, double z2, double z1, double z0) {
	return (Math.cos(((Math.PI + Math.PI) * z4)) * z3) + ((z2 * z1) * z0);
}
def code(z4, z3, z2, z1, z0):
	return (math.cos(((math.pi + math.pi) * z4)) * z3) + ((z2 * z1) * z0)
function code(z4, z3, z2, z1, z0)
	return Float64(Float64(cos(Float64(Float64(pi + pi) * z4)) * z3) + Float64(Float64(z2 * z1) * z0))
end
function tmp = code(z4, z3, z2, z1, z0)
	tmp = (cos(((pi + pi) * z4)) * z3) + ((z2 * z1) * z0);
end
code[z4_, z3_, z2_, z1_, z0_] := N[(N[(N[Cos[N[(N[(Pi + Pi), $MachinePrecision] * z4), $MachinePrecision]], $MachinePrecision] * z3), $MachinePrecision] + N[(N[(z2 * z1), $MachinePrecision] * z0), $MachinePrecision]), $MachinePrecision]
\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0

Alternative 1: 98.0% accurate, 0.1× speedup?

\[\begin{array}{l} t_0 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_1 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_0\right)\\ t_2 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_0\right)\\ t_3 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ \mathbf{if}\;t\_2 \leq 10^{-23}:\\ \;\;\;\;\left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\cos \left(\left(\left(z4 + z4\right) - 0.5\right) \cdot \pi + 0.5 \cdot \pi\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(t\_1 \cdot t\_2\right) \cdot t\_3\\ \mathbf{else}:\\ \;\;\;\;z3 + \left(t\_3 \cdot t\_2\right) \cdot t\_1\\ \end{array} \]
(FPCore (z4 z3 z2 z1 z0)
  :precision binary64
  (let* ((t_0 (fmax (fmin z2 z1) z0))
       (t_1 (fmax (fmax z2 z1) t_0))
       (t_2 (fmin (fmax z2 z1) t_0))
       (t_3 (fmin (fmin z2 z1) z0)))
  (if (<= t_2 1e-23)
    (+
     (*
      (+
       (* (sin (* PI z4)) (sin (+ (* PI z4) PI)))
       (* (- (cos (+ (* (- (+ z4 z4) 0.5) PI) (* 0.5 PI))) -1.0) 0.5))
      z3)
     (* (* t_1 t_2) t_3))
    (+ z3 (* (* t_3 t_2) t_1)))))
double code(double z4, double z3, double z2, double z1, double z0) {
	double t_0 = fmax(fmin(z2, z1), z0);
	double t_1 = fmax(fmax(z2, z1), t_0);
	double t_2 = fmin(fmax(z2, z1), t_0);
	double t_3 = fmin(fmin(z2, z1), z0);
	double tmp;
	if (t_2 <= 1e-23) {
		tmp = (((sin((((double) M_PI) * z4)) * sin(((((double) M_PI) * z4) + ((double) M_PI)))) + ((cos(((((z4 + z4) - 0.5) * ((double) M_PI)) + (0.5 * ((double) M_PI)))) - -1.0) * 0.5)) * z3) + ((t_1 * t_2) * t_3);
	} else {
		tmp = z3 + ((t_3 * t_2) * t_1);
	}
	return tmp;
}
public static double code(double z4, double z3, double z2, double z1, double z0) {
	double t_0 = fmax(fmin(z2, z1), z0);
	double t_1 = fmax(fmax(z2, z1), t_0);
	double t_2 = fmin(fmax(z2, z1), t_0);
	double t_3 = fmin(fmin(z2, z1), z0);
	double tmp;
	if (t_2 <= 1e-23) {
		tmp = (((Math.sin((Math.PI * z4)) * Math.sin(((Math.PI * z4) + Math.PI))) + ((Math.cos(((((z4 + z4) - 0.5) * Math.PI) + (0.5 * Math.PI))) - -1.0) * 0.5)) * z3) + ((t_1 * t_2) * t_3);
	} else {
		tmp = z3 + ((t_3 * t_2) * t_1);
	}
	return tmp;
}
def code(z4, z3, z2, z1, z0):
	t_0 = fmax(fmin(z2, z1), z0)
	t_1 = fmax(fmax(z2, z1), t_0)
	t_2 = fmin(fmax(z2, z1), t_0)
	t_3 = fmin(fmin(z2, z1), z0)
	tmp = 0
	if t_2 <= 1e-23:
		tmp = (((math.sin((math.pi * z4)) * math.sin(((math.pi * z4) + math.pi))) + ((math.cos(((((z4 + z4) - 0.5) * math.pi) + (0.5 * math.pi))) - -1.0) * 0.5)) * z3) + ((t_1 * t_2) * t_3)
	else:
		tmp = z3 + ((t_3 * t_2) * t_1)
	return tmp
function code(z4, z3, z2, z1, z0)
	t_0 = fmax(fmin(z2, z1), z0)
	t_1 = fmax(fmax(z2, z1), t_0)
	t_2 = fmin(fmax(z2, z1), t_0)
	t_3 = fmin(fmin(z2, z1), z0)
	tmp = 0.0
	if (t_2 <= 1e-23)
		tmp = Float64(Float64(Float64(Float64(sin(Float64(pi * z4)) * sin(Float64(Float64(pi * z4) + pi))) + Float64(Float64(cos(Float64(Float64(Float64(Float64(z4 + z4) - 0.5) * pi) + Float64(0.5 * pi))) - -1.0) * 0.5)) * z3) + Float64(Float64(t_1 * t_2) * t_3));
	else
		tmp = Float64(z3 + Float64(Float64(t_3 * t_2) * t_1));
	end
	return tmp
end
function tmp_2 = code(z4, z3, z2, z1, z0)
	t_0 = max(min(z2, z1), z0);
	t_1 = max(max(z2, z1), t_0);
	t_2 = min(max(z2, z1), t_0);
	t_3 = min(min(z2, z1), z0);
	tmp = 0.0;
	if (t_2 <= 1e-23)
		tmp = (((sin((pi * z4)) * sin(((pi * z4) + pi))) + ((cos(((((z4 + z4) - 0.5) * pi) + (0.5 * pi))) - -1.0) * 0.5)) * z3) + ((t_1 * t_2) * t_3);
	else
		tmp = z3 + ((t_3 * t_2) * t_1);
	end
	tmp_2 = tmp;
end
code[z4_, z3_, z2_, z1_, z0_] := Block[{t$95$0 = N[Max[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Max[z2, z1], $MachinePrecision], t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Min[N[Max[z2, z1], $MachinePrecision], t$95$0], $MachinePrecision]}, Block[{t$95$3 = N[Min[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, If[LessEqual[t$95$2, 1e-23], N[(N[(N[(N[(N[Sin[N[(Pi * z4), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(Pi * z4), $MachinePrecision] + Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[N[(N[(N[(N[(z4 + z4), $MachinePrecision] - 0.5), $MachinePrecision] * Pi), $MachinePrecision] + N[(0.5 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * z3), $MachinePrecision] + N[(N[(t$95$1 * t$95$2), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision], N[(z3 + N[(N[(t$95$3 * t$95$2), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
t_1 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_0\right)\\
t_2 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_0\right)\\
t_3 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
\mathbf{if}\;t\_2 \leq 10^{-23}:\\
\;\;\;\;\left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\cos \left(\left(\left(z4 + z4\right) - 0.5\right) \cdot \pi + 0.5 \cdot \pi\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(t\_1 \cdot t\_2\right) \cdot t\_3\\

\mathbf{else}:\\
\;\;\;\;z3 + \left(t\_3 \cdot t\_2\right) \cdot t\_1\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z1 < 9.9999999999999996e-24

    1. Initial program 73.1%

      \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z2 \cdot z1\right) \cdot z0} \]
      2. lift-*.f64N/A

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z2 \cdot z1\right)} \cdot z0 \]
      3. associate-*l*N/A

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{z2 \cdot \left(z1 \cdot z0\right)} \]
      4. *-commutativeN/A

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z1 \cdot z0\right) \cdot z2} \]
      5. lower-*.f64N/A

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z1 \cdot z0\right) \cdot z2} \]
      6. *-commutativeN/A

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z0 \cdot z1\right)} \cdot z2 \]
      7. lower-*.f6473.4%

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z0 \cdot z1\right)} \cdot z2 \]
    3. Applied rewrites73.4%

      \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
    4. Applied rewrites74.5%

      \[\leadsto \color{blue}{\left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot \left(z4 + 0.5\right)\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot 0.5\right)} \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
    5. Step-by-step derivation
      1. lift-cos.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\cos \left(\pi \cdot \left(z4 + \frac{1}{2}\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      2. lift-*.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \color{blue}{\left(\pi \cdot \left(z4 + \frac{1}{2}\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      3. lift-+.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot \color{blue}{\left(z4 + \frac{1}{2}\right)}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      4. distribute-lft-inN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \color{blue}{\left(\pi \cdot z4 + \pi \cdot \frac{1}{2}\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      5. lift-*.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\color{blue}{\pi \cdot z4} + \pi \cdot \frac{1}{2}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      6. metadata-evalN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot z4 + \pi \cdot \color{blue}{\frac{1}{2}}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      7. mult-flipN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot z4 + \color{blue}{\frac{\pi}{2}}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      8. lift-PI.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot z4 + \frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      9. cos-+PI/2-revN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\sin \left(\pi \cdot z4\right)\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      10. sin-+PI-revN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\sin \left(\pi \cdot z4 + \mathsf{PI}\left(\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      11. lower-sin.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\sin \left(\pi \cdot z4 + \mathsf{PI}\left(\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      12. lift-PI.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \color{blue}{\pi}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      13. lower-+.f6494.8%

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \color{blue}{\left(\pi \cdot z4 + \pi\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
    6. Applied rewrites94.8%

      \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\sin \left(\pi \cdot z4 + \pi\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
    7. Step-by-step derivation
      1. lift-cos.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\color{blue}{\cos \left(\left(\pi + \pi\right) \cdot z4\right)} - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      2. cos-neg-revN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\color{blue}{\cos \left(\mathsf{neg}\left(\left(\pi + \pi\right) \cdot z4\right)\right)} - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      3. sin-+PI/2-revN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\color{blue}{\sin \left(\left(\mathsf{neg}\left(\left(\pi + \pi\right) \cdot z4\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      4. lift-*.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\color{blue}{\left(\pi + \pi\right) \cdot z4}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      5. *-commutativeN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\color{blue}{z4 \cdot \left(\pi + \pi\right)}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      6. lift-+.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(z4 \cdot \color{blue}{\left(\pi + \pi\right)}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      7. distribute-lft-inN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\color{blue}{\left(z4 \cdot \pi + z4 \cdot \pi\right)}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      8. distribute-rgt-inN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(z4 + z4\right)}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      9. lift-+.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\pi \cdot \color{blue}{\left(z4 + z4\right)}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      10. *-commutativeN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\color{blue}{\left(z4 + z4\right) \cdot \pi}\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      11. lift-PI.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\left(z4 + z4\right) \cdot \pi\right)\right) + \frac{\color{blue}{\pi}}{2}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      12. mult-flipN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\left(z4 + z4\right) \cdot \pi\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      13. metadata-evalN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\left(z4 + z4\right) \cdot \pi\right)\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      14. *-commutativeN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\left(z4 + z4\right) \cdot \pi\right)\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      15. metadata-evalN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\left(z4 + z4\right) \cdot \pi\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)} \cdot \pi\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      16. distribute-lft-neg-outN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\left(\mathsf{neg}\left(\left(z4 + z4\right) \cdot \pi\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{-1}{2} \cdot \pi\right)\right)}\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      17. distribute-neg-inN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \color{blue}{\left(\mathsf{neg}\left(\left(\left(z4 + z4\right) \cdot \pi + \frac{-1}{2} \cdot \pi\right)\right)\right)} - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      18. distribute-rgt-inN/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(\left(z4 + z4\right) + \frac{-1}{2}\right)}\right)\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      19. lift-+.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\mathsf{neg}\left(\pi \cdot \color{blue}{\left(\left(z4 + z4\right) + \frac{-1}{2}\right)}\right)\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      20. lift-*.f64N/A

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\sin \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(\left(z4 + z4\right) + \frac{-1}{2}\right)}\right)\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
    8. Applied rewrites94.8%

      \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\color{blue}{\cos \left(\left(\left(z4 + z4\right) - 0.5\right) \cdot \pi + 0.5 \cdot \pi\right)} - -1\right) \cdot 0.5\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]

    if 9.9999999999999996e-24 < z1

    1. Initial program 73.1%

      \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
    2. Taylor expanded in z4 around 0

      \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
    3. Step-by-step derivation
      1. Applied rewrites93.5%

        \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 2: 98.0% accurate, 0.1× speedup?

    \[\begin{array}{l} t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ \mathbf{if}\;t\_3 \leq 10^{-23}:\\ \;\;\;\;\left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\cos \left(6.283185307179586 \cdot z4\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;z3 + \left(t\_0 \cdot t\_3\right) \cdot t\_2\\ \end{array} \]
    (FPCore (z4 z3 z2 z1 z0)
      :precision binary64
      (let* ((t_0 (fmin (fmin z2 z1) z0))
           (t_1 (fmax (fmin z2 z1) z0))
           (t_2 (fmax (fmax z2 z1) t_1))
           (t_3 (fmin (fmax z2 z1) t_1)))
      (if (<= t_3 1e-23)
        (+
         (*
          (+
           (* (sin (* PI z4)) (sin (+ (* PI z4) PI)))
           (* (- (cos (* 6.283185307179586 z4)) -1.0) 0.5))
          z3)
         (* (* t_2 t_3) t_0))
        (+ z3 (* (* t_0 t_3) t_2)))))
    double code(double z4, double z3, double z2, double z1, double z0) {
    	double t_0 = fmin(fmin(z2, z1), z0);
    	double t_1 = fmax(fmin(z2, z1), z0);
    	double t_2 = fmax(fmax(z2, z1), t_1);
    	double t_3 = fmin(fmax(z2, z1), t_1);
    	double tmp;
    	if (t_3 <= 1e-23) {
    		tmp = (((sin((((double) M_PI) * z4)) * sin(((((double) M_PI) * z4) + ((double) M_PI)))) + ((cos((6.283185307179586 * z4)) - -1.0) * 0.5)) * z3) + ((t_2 * t_3) * t_0);
    	} else {
    		tmp = z3 + ((t_0 * t_3) * t_2);
    	}
    	return tmp;
    }
    
    public static double code(double z4, double z3, double z2, double z1, double z0) {
    	double t_0 = fmin(fmin(z2, z1), z0);
    	double t_1 = fmax(fmin(z2, z1), z0);
    	double t_2 = fmax(fmax(z2, z1), t_1);
    	double t_3 = fmin(fmax(z2, z1), t_1);
    	double tmp;
    	if (t_3 <= 1e-23) {
    		tmp = (((Math.sin((Math.PI * z4)) * Math.sin(((Math.PI * z4) + Math.PI))) + ((Math.cos((6.283185307179586 * z4)) - -1.0) * 0.5)) * z3) + ((t_2 * t_3) * t_0);
    	} else {
    		tmp = z3 + ((t_0 * t_3) * t_2);
    	}
    	return tmp;
    }
    
    def code(z4, z3, z2, z1, z0):
    	t_0 = fmin(fmin(z2, z1), z0)
    	t_1 = fmax(fmin(z2, z1), z0)
    	t_2 = fmax(fmax(z2, z1), t_1)
    	t_3 = fmin(fmax(z2, z1), t_1)
    	tmp = 0
    	if t_3 <= 1e-23:
    		tmp = (((math.sin((math.pi * z4)) * math.sin(((math.pi * z4) + math.pi))) + ((math.cos((6.283185307179586 * z4)) - -1.0) * 0.5)) * z3) + ((t_2 * t_3) * t_0)
    	else:
    		tmp = z3 + ((t_0 * t_3) * t_2)
    	return tmp
    
    function code(z4, z3, z2, z1, z0)
    	t_0 = fmin(fmin(z2, z1), z0)
    	t_1 = fmax(fmin(z2, z1), z0)
    	t_2 = fmax(fmax(z2, z1), t_1)
    	t_3 = fmin(fmax(z2, z1), t_1)
    	tmp = 0.0
    	if (t_3 <= 1e-23)
    		tmp = Float64(Float64(Float64(Float64(sin(Float64(pi * z4)) * sin(Float64(Float64(pi * z4) + pi))) + Float64(Float64(cos(Float64(6.283185307179586 * z4)) - -1.0) * 0.5)) * z3) + Float64(Float64(t_2 * t_3) * t_0));
    	else
    		tmp = Float64(z3 + Float64(Float64(t_0 * t_3) * t_2));
    	end
    	return tmp
    end
    
    function tmp_2 = code(z4, z3, z2, z1, z0)
    	t_0 = min(min(z2, z1), z0);
    	t_1 = max(min(z2, z1), z0);
    	t_2 = max(max(z2, z1), t_1);
    	t_3 = min(max(z2, z1), t_1);
    	tmp = 0.0;
    	if (t_3 <= 1e-23)
    		tmp = (((sin((pi * z4)) * sin(((pi * z4) + pi))) + ((cos((6.283185307179586 * z4)) - -1.0) * 0.5)) * z3) + ((t_2 * t_3) * t_0);
    	else
    		tmp = z3 + ((t_0 * t_3) * t_2);
    	end
    	tmp_2 = tmp;
    end
    
    code[z4_, z3_, z2_, z1_, z0_] := Block[{t$95$0 = N[Min[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$2 = N[Max[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[Min[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, If[LessEqual[t$95$3, 1e-23], N[(N[(N[(N[(N[Sin[N[(Pi * z4), $MachinePrecision]], $MachinePrecision] * N[Sin[N[(N[(Pi * z4), $MachinePrecision] + Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[N[(6.283185307179586 * z4), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] * z3), $MachinePrecision] + N[(N[(t$95$2 * t$95$3), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(z3 + N[(N[(t$95$0 * t$95$3), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]]]]]]
    
    \begin{array}{l}
    t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
    t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
    t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
    t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
    \mathbf{if}\;t\_3 \leq 10^{-23}:\\
    \;\;\;\;\left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\cos \left(6.283185307179586 \cdot z4\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\
    
    \mathbf{else}:\\
    \;\;\;\;z3 + \left(t\_0 \cdot t\_3\right) \cdot t\_2\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if z1 < 9.9999999999999996e-24

      1. Initial program 73.1%

        \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z2 \cdot z1\right) \cdot z0} \]
        2. lift-*.f64N/A

          \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z2 \cdot z1\right)} \cdot z0 \]
        3. associate-*l*N/A

          \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{z2 \cdot \left(z1 \cdot z0\right)} \]
        4. *-commutativeN/A

          \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z1 \cdot z0\right) \cdot z2} \]
        5. lower-*.f64N/A

          \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z1 \cdot z0\right) \cdot z2} \]
        6. *-commutativeN/A

          \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z0 \cdot z1\right)} \cdot z2 \]
        7. lower-*.f6473.4%

          \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z0 \cdot z1\right)} \cdot z2 \]
      3. Applied rewrites73.4%

        \[\leadsto \cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
      4. Applied rewrites74.5%

        \[\leadsto \color{blue}{\left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot \left(z4 + 0.5\right)\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot 0.5\right)} \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      5. Step-by-step derivation
        1. lift-cos.f64N/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\cos \left(\pi \cdot \left(z4 + \frac{1}{2}\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        2. lift-*.f64N/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \color{blue}{\left(\pi \cdot \left(z4 + \frac{1}{2}\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        3. lift-+.f64N/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot \color{blue}{\left(z4 + \frac{1}{2}\right)}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        4. distribute-lft-inN/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \color{blue}{\left(\pi \cdot z4 + \pi \cdot \frac{1}{2}\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        5. lift-*.f64N/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\color{blue}{\pi \cdot z4} + \pi \cdot \frac{1}{2}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        6. metadata-evalN/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot z4 + \pi \cdot \color{blue}{\frac{1}{2}}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        7. mult-flipN/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot z4 + \color{blue}{\frac{\pi}{2}}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        8. lift-PI.f64N/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \cos \left(\pi \cdot z4 + \frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        9. cos-+PI/2-revN/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\sin \left(\pi \cdot z4\right)\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        10. sin-+PI-revN/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\sin \left(\pi \cdot z4 + \mathsf{PI}\left(\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        11. lower-sin.f64N/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\sin \left(\pi \cdot z4 + \mathsf{PI}\left(\right)\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        12. lift-PI.f64N/A

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \color{blue}{\pi}\right) + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot \frac{1}{2}\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
        13. lower-+.f6494.8%

          \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \color{blue}{\left(\pi \cdot z4 + \pi\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      6. Applied rewrites94.8%

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \color{blue}{\sin \left(\pi \cdot z4 + \pi\right)} + \left(\cos \left(\left(\pi + \pi\right) \cdot z4\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]
      7. Evaluated real constant94.8%

        \[\leadsto \left(\sin \left(\pi \cdot z4\right) \cdot \sin \left(\pi \cdot z4 + \pi\right) + \left(\cos \left(\color{blue}{6.283185307179586} \cdot z4\right) - -1\right) \cdot 0.5\right) \cdot z3 + \left(z0 \cdot z1\right) \cdot z2 \]

      if 9.9999999999999996e-24 < z1

      1. Initial program 73.1%

        \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
      2. Taylor expanded in z4 around 0

        \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
      3. Step-by-step derivation
        1. Applied rewrites93.5%

          \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
      4. Recombined 2 regimes into one program.
      5. Add Preprocessing

      Alternative 3: 97.2% accurate, 0.1× speedup?

      \[\begin{array}{l} t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ \mathbf{if}\;t\_3 \leq 10^{-23}:\\ \;\;\;\;z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;z3 + \left(t\_0 \cdot t\_3\right) \cdot t\_2\\ \end{array} \]
      (FPCore (z4 z3 z2 z1 z0)
        :precision binary64
        (let* ((t_0 (fmin (fmin z2 z1) z0))
             (t_1 (fmax (fmin z2 z1) z0))
             (t_2 (fmax (fmax z2 z1) t_1))
             (t_3 (fmin (fmax z2 z1) t_1)))
        (if (<= t_3 1e-23)
          (+ z3 (* (* t_2 t_3) t_0))
          (+ z3 (* (* t_0 t_3) t_2)))))
      double code(double z4, double z3, double z2, double z1, double z0) {
      	double t_0 = fmin(fmin(z2, z1), z0);
      	double t_1 = fmax(fmin(z2, z1), z0);
      	double t_2 = fmax(fmax(z2, z1), t_1);
      	double t_3 = fmin(fmax(z2, z1), t_1);
      	double tmp;
      	if (t_3 <= 1e-23) {
      		tmp = z3 + ((t_2 * t_3) * t_0);
      	} else {
      		tmp = z3 + ((t_0 * t_3) * t_2);
      	}
      	return tmp;
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(z4, z3, z2, z1, z0)
      use fmin_fmax_functions
          real(8), intent (in) :: z4
          real(8), intent (in) :: z3
          real(8), intent (in) :: z2
          real(8), intent (in) :: z1
          real(8), intent (in) :: z0
          real(8) :: t_0
          real(8) :: t_1
          real(8) :: t_2
          real(8) :: t_3
          real(8) :: tmp
          t_0 = fmin(fmin(z2, z1), z0)
          t_1 = fmax(fmin(z2, z1), z0)
          t_2 = fmax(fmax(z2, z1), t_1)
          t_3 = fmin(fmax(z2, z1), t_1)
          if (t_3 <= 1d-23) then
              tmp = z3 + ((t_2 * t_3) * t_0)
          else
              tmp = z3 + ((t_0 * t_3) * t_2)
          end if
          code = tmp
      end function
      
      public static double code(double z4, double z3, double z2, double z1, double z0) {
      	double t_0 = fmin(fmin(z2, z1), z0);
      	double t_1 = fmax(fmin(z2, z1), z0);
      	double t_2 = fmax(fmax(z2, z1), t_1);
      	double t_3 = fmin(fmax(z2, z1), t_1);
      	double tmp;
      	if (t_3 <= 1e-23) {
      		tmp = z3 + ((t_2 * t_3) * t_0);
      	} else {
      		tmp = z3 + ((t_0 * t_3) * t_2);
      	}
      	return tmp;
      }
      
      def code(z4, z3, z2, z1, z0):
      	t_0 = fmin(fmin(z2, z1), z0)
      	t_1 = fmax(fmin(z2, z1), z0)
      	t_2 = fmax(fmax(z2, z1), t_1)
      	t_3 = fmin(fmax(z2, z1), t_1)
      	tmp = 0
      	if t_3 <= 1e-23:
      		tmp = z3 + ((t_2 * t_3) * t_0)
      	else:
      		tmp = z3 + ((t_0 * t_3) * t_2)
      	return tmp
      
      function code(z4, z3, z2, z1, z0)
      	t_0 = fmin(fmin(z2, z1), z0)
      	t_1 = fmax(fmin(z2, z1), z0)
      	t_2 = fmax(fmax(z2, z1), t_1)
      	t_3 = fmin(fmax(z2, z1), t_1)
      	tmp = 0.0
      	if (t_3 <= 1e-23)
      		tmp = Float64(z3 + Float64(Float64(t_2 * t_3) * t_0));
      	else
      		tmp = Float64(z3 + Float64(Float64(t_0 * t_3) * t_2));
      	end
      	return tmp
      end
      
      function tmp_2 = code(z4, z3, z2, z1, z0)
      	t_0 = min(min(z2, z1), z0);
      	t_1 = max(min(z2, z1), z0);
      	t_2 = max(max(z2, z1), t_1);
      	t_3 = min(max(z2, z1), t_1);
      	tmp = 0.0;
      	if (t_3 <= 1e-23)
      		tmp = z3 + ((t_2 * t_3) * t_0);
      	else
      		tmp = z3 + ((t_0 * t_3) * t_2);
      	end
      	tmp_2 = tmp;
      end
      
      code[z4_, z3_, z2_, z1_, z0_] := Block[{t$95$0 = N[Min[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$2 = N[Max[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[Min[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, If[LessEqual[t$95$3, 1e-23], N[(z3 + N[(N[(t$95$2 * t$95$3), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(z3 + N[(N[(t$95$0 * t$95$3), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]]]]]]
      
      \begin{array}{l}
      t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
      t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
      t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
      t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
      \mathbf{if}\;t\_3 \leq 10^{-23}:\\
      \;\;\;\;z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\
      
      \mathbf{else}:\\
      \;\;\;\;z3 + \left(t\_0 \cdot t\_3\right) \cdot t\_2\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z1 < 9.9999999999999996e-24

        1. Initial program 73.1%

          \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
        2. Taylor expanded in z4 around 0

          \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
        3. Step-by-step derivation
          1. Applied rewrites93.5%

            \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
          2. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right) \cdot z0} \]
            2. lift-*.f64N/A

              \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right)} \cdot z0 \]
            3. associate-*l*N/A

              \[\leadsto z3 + \color{blue}{z2 \cdot \left(z1 \cdot z0\right)} \]
            4. *-commutativeN/A

              \[\leadsto z3 + z2 \cdot \color{blue}{\left(z0 \cdot z1\right)} \]
            5. lift-*.f64N/A

              \[\leadsto z3 + z2 \cdot \color{blue}{\left(z0 \cdot z1\right)} \]
            6. *-commutativeN/A

              \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
            7. lift-*.f6493.9%

              \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
          3. Applied rewrites93.9%

            \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]

          if 9.9999999999999996e-24 < z1

          1. Initial program 73.1%

            \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
          2. Taylor expanded in z4 around 0

            \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
          3. Step-by-step derivation
            1. Applied rewrites93.5%

              \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
          4. Recombined 2 regimes into one program.
          5. Add Preprocessing

          Alternative 4: 97.0% accurate, 0.1× speedup?

          \[\begin{array}{l} t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ \mathbf{if}\;t\_3 \leq 10^{+43}:\\ \;\;\;\;z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;z3 + \left(t\_0 \cdot t\_2\right) \cdot t\_3\\ \end{array} \]
          (FPCore (z4 z3 z2 z1 z0)
            :precision binary64
            (let* ((t_0 (fmin (fmin z2 z1) z0))
                 (t_1 (fmax (fmin z2 z1) z0))
                 (t_2 (fmax (fmax z2 z1) t_1))
                 (t_3 (fmin (fmax z2 z1) t_1)))
            (if (<= t_3 1e+43)
              (+ z3 (* (* t_2 t_3) t_0))
              (+ z3 (* (* t_0 t_2) t_3)))))
          double code(double z4, double z3, double z2, double z1, double z0) {
          	double t_0 = fmin(fmin(z2, z1), z0);
          	double t_1 = fmax(fmin(z2, z1), z0);
          	double t_2 = fmax(fmax(z2, z1), t_1);
          	double t_3 = fmin(fmax(z2, z1), t_1);
          	double tmp;
          	if (t_3 <= 1e+43) {
          		tmp = z3 + ((t_2 * t_3) * t_0);
          	} else {
          		tmp = z3 + ((t_0 * t_2) * t_3);
          	}
          	return tmp;
          }
          
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(z4, z3, z2, z1, z0)
          use fmin_fmax_functions
              real(8), intent (in) :: z4
              real(8), intent (in) :: z3
              real(8), intent (in) :: z2
              real(8), intent (in) :: z1
              real(8), intent (in) :: z0
              real(8) :: t_0
              real(8) :: t_1
              real(8) :: t_2
              real(8) :: t_3
              real(8) :: tmp
              t_0 = fmin(fmin(z2, z1), z0)
              t_1 = fmax(fmin(z2, z1), z0)
              t_2 = fmax(fmax(z2, z1), t_1)
              t_3 = fmin(fmax(z2, z1), t_1)
              if (t_3 <= 1d+43) then
                  tmp = z3 + ((t_2 * t_3) * t_0)
              else
                  tmp = z3 + ((t_0 * t_2) * t_3)
              end if
              code = tmp
          end function
          
          public static double code(double z4, double z3, double z2, double z1, double z0) {
          	double t_0 = fmin(fmin(z2, z1), z0);
          	double t_1 = fmax(fmin(z2, z1), z0);
          	double t_2 = fmax(fmax(z2, z1), t_1);
          	double t_3 = fmin(fmax(z2, z1), t_1);
          	double tmp;
          	if (t_3 <= 1e+43) {
          		tmp = z3 + ((t_2 * t_3) * t_0);
          	} else {
          		tmp = z3 + ((t_0 * t_2) * t_3);
          	}
          	return tmp;
          }
          
          def code(z4, z3, z2, z1, z0):
          	t_0 = fmin(fmin(z2, z1), z0)
          	t_1 = fmax(fmin(z2, z1), z0)
          	t_2 = fmax(fmax(z2, z1), t_1)
          	t_3 = fmin(fmax(z2, z1), t_1)
          	tmp = 0
          	if t_3 <= 1e+43:
          		tmp = z3 + ((t_2 * t_3) * t_0)
          	else:
          		tmp = z3 + ((t_0 * t_2) * t_3)
          	return tmp
          
          function code(z4, z3, z2, z1, z0)
          	t_0 = fmin(fmin(z2, z1), z0)
          	t_1 = fmax(fmin(z2, z1), z0)
          	t_2 = fmax(fmax(z2, z1), t_1)
          	t_3 = fmin(fmax(z2, z1), t_1)
          	tmp = 0.0
          	if (t_3 <= 1e+43)
          		tmp = Float64(z3 + Float64(Float64(t_2 * t_3) * t_0));
          	else
          		tmp = Float64(z3 + Float64(Float64(t_0 * t_2) * t_3));
          	end
          	return tmp
          end
          
          function tmp_2 = code(z4, z3, z2, z1, z0)
          	t_0 = min(min(z2, z1), z0);
          	t_1 = max(min(z2, z1), z0);
          	t_2 = max(max(z2, z1), t_1);
          	t_3 = min(max(z2, z1), t_1);
          	tmp = 0.0;
          	if (t_3 <= 1e+43)
          		tmp = z3 + ((t_2 * t_3) * t_0);
          	else
          		tmp = z3 + ((t_0 * t_2) * t_3);
          	end
          	tmp_2 = tmp;
          end
          
          code[z4_, z3_, z2_, z1_, z0_] := Block[{t$95$0 = N[Min[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$2 = N[Max[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[Min[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, If[LessEqual[t$95$3, 1e+43], N[(z3 + N[(N[(t$95$2 * t$95$3), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(z3 + N[(N[(t$95$0 * t$95$2), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]]]]]]
          
          \begin{array}{l}
          t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
          t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
          t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
          t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
          \mathbf{if}\;t\_3 \leq 10^{+43}:\\
          \;\;\;\;z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\
          
          \mathbf{else}:\\
          \;\;\;\;z3 + \left(t\_0 \cdot t\_2\right) \cdot t\_3\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if z1 < 1e43

            1. Initial program 73.1%

              \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
            2. Taylor expanded in z4 around 0

              \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
            3. Step-by-step derivation
              1. Applied rewrites93.5%

                \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
              2. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right) \cdot z0} \]
                2. lift-*.f64N/A

                  \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right)} \cdot z0 \]
                3. associate-*l*N/A

                  \[\leadsto z3 + \color{blue}{z2 \cdot \left(z1 \cdot z0\right)} \]
                4. *-commutativeN/A

                  \[\leadsto z3 + z2 \cdot \color{blue}{\left(z0 \cdot z1\right)} \]
                5. lift-*.f64N/A

                  \[\leadsto z3 + z2 \cdot \color{blue}{\left(z0 \cdot z1\right)} \]
                6. *-commutativeN/A

                  \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
                7. lift-*.f6493.9%

                  \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
              3. Applied rewrites93.9%

                \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]

              if 1e43 < z1

              1. Initial program 73.1%

                \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
              2. Taylor expanded in z4 around 0

                \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
              3. Step-by-step derivation
                1. Applied rewrites93.5%

                  \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
                2. Step-by-step derivation
                  1. lift-*.f64N/A

                    \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right) \cdot z0} \]
                  2. lift-*.f64N/A

                    \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right)} \cdot z0 \]
                  3. associate-*l*N/A

                    \[\leadsto z3 + \color{blue}{z2 \cdot \left(z1 \cdot z0\right)} \]
                  4. *-commutativeN/A

                    \[\leadsto z3 + z2 \cdot \color{blue}{\left(z0 \cdot z1\right)} \]
                  5. associate-*r*N/A

                    \[\leadsto z3 + \color{blue}{\left(z2 \cdot z0\right) \cdot z1} \]
                  6. lower-*.f64N/A

                    \[\leadsto z3 + \color{blue}{\left(z2 \cdot z0\right) \cdot z1} \]
                  7. lower-*.f6493.8%

                    \[\leadsto z3 + \color{blue}{\left(z2 \cdot z0\right)} \cdot z1 \]
                3. Applied rewrites93.8%

                  \[\leadsto z3 + \color{blue}{\left(z2 \cdot z0\right) \cdot z1} \]
              4. Recombined 2 regimes into one program.
              5. Add Preprocessing

              Alternative 5: 96.0% accurate, 0.1× speedup?

              \[\begin{array}{l} t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\ t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\ \mathbf{if}\;t\_3 \leq 5.6 \cdot 10^{+88}:\\ \;\;\;\;z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_2 \cdot \left(t\_3 \cdot t\_0\right)\\ \end{array} \]
              (FPCore (z4 z3 z2 z1 z0)
                :precision binary64
                (let* ((t_0 (fmin (fmin z2 z1) z0))
                     (t_1 (fmax (fmin z2 z1) z0))
                     (t_2 (fmax (fmax z2 z1) t_1))
                     (t_3 (fmin (fmax z2 z1) t_1)))
                (if (<= t_3 5.6e+88)
                  (+ z3 (* (* t_2 t_3) t_0))
                  (* t_2 (* t_3 t_0)))))
              double code(double z4, double z3, double z2, double z1, double z0) {
              	double t_0 = fmin(fmin(z2, z1), z0);
              	double t_1 = fmax(fmin(z2, z1), z0);
              	double t_2 = fmax(fmax(z2, z1), t_1);
              	double t_3 = fmin(fmax(z2, z1), t_1);
              	double tmp;
              	if (t_3 <= 5.6e+88) {
              		tmp = z3 + ((t_2 * t_3) * t_0);
              	} else {
              		tmp = t_2 * (t_3 * t_0);
              	}
              	return tmp;
              }
              
              module fmin_fmax_functions
                  implicit none
                  private
                  public fmax
                  public fmin
              
                  interface fmax
                      module procedure fmax88
                      module procedure fmax44
                      module procedure fmax84
                      module procedure fmax48
                  end interface
                  interface fmin
                      module procedure fmin88
                      module procedure fmin44
                      module procedure fmin84
                      module procedure fmin48
                  end interface
              contains
                  real(8) function fmax88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmax44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmax84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmax48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                  end function
                  real(8) function fmin88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmin44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmin84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmin48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                  end function
              end module
              
              real(8) function code(z4, z3, z2, z1, z0)
              use fmin_fmax_functions
                  real(8), intent (in) :: z4
                  real(8), intent (in) :: z3
                  real(8), intent (in) :: z2
                  real(8), intent (in) :: z1
                  real(8), intent (in) :: z0
                  real(8) :: t_0
                  real(8) :: t_1
                  real(8) :: t_2
                  real(8) :: t_3
                  real(8) :: tmp
                  t_0 = fmin(fmin(z2, z1), z0)
                  t_1 = fmax(fmin(z2, z1), z0)
                  t_2 = fmax(fmax(z2, z1), t_1)
                  t_3 = fmin(fmax(z2, z1), t_1)
                  if (t_3 <= 5.6d+88) then
                      tmp = z3 + ((t_2 * t_3) * t_0)
                  else
                      tmp = t_2 * (t_3 * t_0)
                  end if
                  code = tmp
              end function
              
              public static double code(double z4, double z3, double z2, double z1, double z0) {
              	double t_0 = fmin(fmin(z2, z1), z0);
              	double t_1 = fmax(fmin(z2, z1), z0);
              	double t_2 = fmax(fmax(z2, z1), t_1);
              	double t_3 = fmin(fmax(z2, z1), t_1);
              	double tmp;
              	if (t_3 <= 5.6e+88) {
              		tmp = z3 + ((t_2 * t_3) * t_0);
              	} else {
              		tmp = t_2 * (t_3 * t_0);
              	}
              	return tmp;
              }
              
              def code(z4, z3, z2, z1, z0):
              	t_0 = fmin(fmin(z2, z1), z0)
              	t_1 = fmax(fmin(z2, z1), z0)
              	t_2 = fmax(fmax(z2, z1), t_1)
              	t_3 = fmin(fmax(z2, z1), t_1)
              	tmp = 0
              	if t_3 <= 5.6e+88:
              		tmp = z3 + ((t_2 * t_3) * t_0)
              	else:
              		tmp = t_2 * (t_3 * t_0)
              	return tmp
              
              function code(z4, z3, z2, z1, z0)
              	t_0 = fmin(fmin(z2, z1), z0)
              	t_1 = fmax(fmin(z2, z1), z0)
              	t_2 = fmax(fmax(z2, z1), t_1)
              	t_3 = fmin(fmax(z2, z1), t_1)
              	tmp = 0.0
              	if (t_3 <= 5.6e+88)
              		tmp = Float64(z3 + Float64(Float64(t_2 * t_3) * t_0));
              	else
              		tmp = Float64(t_2 * Float64(t_3 * t_0));
              	end
              	return tmp
              end
              
              function tmp_2 = code(z4, z3, z2, z1, z0)
              	t_0 = min(min(z2, z1), z0);
              	t_1 = max(min(z2, z1), z0);
              	t_2 = max(max(z2, z1), t_1);
              	t_3 = min(max(z2, z1), t_1);
              	tmp = 0.0;
              	if (t_3 <= 5.6e+88)
              		tmp = z3 + ((t_2 * t_3) * t_0);
              	else
              		tmp = t_2 * (t_3 * t_0);
              	end
              	tmp_2 = tmp;
              end
              
              code[z4_, z3_, z2_, z1_, z0_] := Block[{t$95$0 = N[Min[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Min[z2, z1], $MachinePrecision], z0], $MachinePrecision]}, Block[{t$95$2 = N[Max[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[Min[N[Max[z2, z1], $MachinePrecision], t$95$1], $MachinePrecision]}, If[LessEqual[t$95$3, 5.6e+88], N[(z3 + N[(N[(t$95$2 * t$95$3), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$2 * N[(t$95$3 * t$95$0), $MachinePrecision]), $MachinePrecision]]]]]]
              
              \begin{array}{l}
              t_0 := \mathsf{min}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
              t_1 := \mathsf{max}\left(\mathsf{min}\left(z2, z1\right), z0\right)\\
              t_2 := \mathsf{max}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
              t_3 := \mathsf{min}\left(\mathsf{max}\left(z2, z1\right), t\_1\right)\\
              \mathbf{if}\;t\_3 \leq 5.6 \cdot 10^{+88}:\\
              \;\;\;\;z3 + \left(t\_2 \cdot t\_3\right) \cdot t\_0\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_2 \cdot \left(t\_3 \cdot t\_0\right)\\
              
              
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if z1 < 5.5999999999999998e88

                1. Initial program 73.1%

                  \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
                2. Taylor expanded in z4 around 0

                  \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
                3. Step-by-step derivation
                  1. Applied rewrites93.5%

                    \[\leadsto \color{blue}{z3} + \left(z2 \cdot z1\right) \cdot z0 \]
                  2. Step-by-step derivation
                    1. lift-*.f64N/A

                      \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right) \cdot z0} \]
                    2. lift-*.f64N/A

                      \[\leadsto z3 + \color{blue}{\left(z2 \cdot z1\right)} \cdot z0 \]
                    3. associate-*l*N/A

                      \[\leadsto z3 + \color{blue}{z2 \cdot \left(z1 \cdot z0\right)} \]
                    4. *-commutativeN/A

                      \[\leadsto z3 + z2 \cdot \color{blue}{\left(z0 \cdot z1\right)} \]
                    5. lift-*.f64N/A

                      \[\leadsto z3 + z2 \cdot \color{blue}{\left(z0 \cdot z1\right)} \]
                    6. *-commutativeN/A

                      \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
                    7. lift-*.f6493.9%

                      \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]
                  3. Applied rewrites93.9%

                    \[\leadsto z3 + \color{blue}{\left(z0 \cdot z1\right) \cdot z2} \]

                  if 5.5999999999999998e88 < z1

                  1. Initial program 73.1%

                    \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
                  2. Taylor expanded in z3 around 0

                    \[\leadsto \color{blue}{z0 \cdot \left(z1 \cdot z2\right)} \]
                  3. Step-by-step derivation
                    1. lower-*.f64N/A

                      \[\leadsto z0 \cdot \color{blue}{\left(z1 \cdot z2\right)} \]
                    2. lower-*.f6447.3%

                      \[\leadsto z0 \cdot \left(z1 \cdot \color{blue}{z2}\right) \]
                  4. Applied rewrites47.3%

                    \[\leadsto \color{blue}{z0 \cdot \left(z1 \cdot z2\right)} \]
                4. Recombined 2 regimes into one program.
                5. Add Preprocessing

                Alternative 6: 47.3% accurate, 11.5× speedup?

                \[z0 \cdot \left(z1 \cdot z2\right) \]
                (FPCore (z4 z3 z2 z1 z0)
                  :precision binary64
                  (* z0 (* z1 z2)))
                double code(double z4, double z3, double z2, double z1, double z0) {
                	return z0 * (z1 * z2);
                }
                
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(z4, z3, z2, z1, z0)
                use fmin_fmax_functions
                    real(8), intent (in) :: z4
                    real(8), intent (in) :: z3
                    real(8), intent (in) :: z2
                    real(8), intent (in) :: z1
                    real(8), intent (in) :: z0
                    code = z0 * (z1 * z2)
                end function
                
                public static double code(double z4, double z3, double z2, double z1, double z0) {
                	return z0 * (z1 * z2);
                }
                
                def code(z4, z3, z2, z1, z0):
                	return z0 * (z1 * z2)
                
                function code(z4, z3, z2, z1, z0)
                	return Float64(z0 * Float64(z1 * z2))
                end
                
                function tmp = code(z4, z3, z2, z1, z0)
                	tmp = z0 * (z1 * z2);
                end
                
                code[z4_, z3_, z2_, z1_, z0_] := N[(z0 * N[(z1 * z2), $MachinePrecision]), $MachinePrecision]
                
                z0 \cdot \left(z1 \cdot z2\right)
                
                Derivation
                1. Initial program 73.1%

                  \[\cos \left(\left(\pi + \pi\right) \cdot z4\right) \cdot z3 + \left(z2 \cdot z1\right) \cdot z0 \]
                2. Taylor expanded in z3 around 0

                  \[\leadsto \color{blue}{z0 \cdot \left(z1 \cdot z2\right)} \]
                3. Step-by-step derivation
                  1. lower-*.f64N/A

                    \[\leadsto z0 \cdot \color{blue}{\left(z1 \cdot z2\right)} \]
                  2. lower-*.f6447.3%

                    \[\leadsto z0 \cdot \left(z1 \cdot \color{blue}{z2}\right) \]
                4. Applied rewrites47.3%

                  \[\leadsto \color{blue}{z0 \cdot \left(z1 \cdot z2\right)} \]
                5. Add Preprocessing

                Reproduce

                ?
                herbie shell --seed 2025256 
                (FPCore (z4 z3 z2 z1 z0)
                  :name "(+ (* (cos (* (+ PI PI) z4)) z3) (* (* z2 z1) z0))"
                  :precision binary64
                  (+ (* (cos (* (+ PI PI) z4)) z3) (* (* z2 z1) z0)))