(cos (* (+ PI PI) z0))

Percentage Accurate: 57.5% → 98.5%
Time: 1.9s
Alternatives: 4
Speedup: 109.0×

Specification

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

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

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

Alternative 1: 98.5% accurate, 0.3× speedup?

\[\begin{array}{l} \mathbf{if}\;\left|z0\right| \leq 85000:\\ \;\;\;\;\sin \left(\pi \cdot \left|z0\right|\right) \cdot \cos \left(\pi \cdot \left(-0.5 - \left|z0\right|\right)\right) + \left(0.5 + 0.5 \cdot \sin \left(\pi \cdot \left(\left|z0\right| + \left(\left|z0\right| - -0.5\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
(FPCore (z0)
  :precision binary64
  (if (<= (fabs z0) 85000.0)
  (+
   (* (sin (* PI (fabs z0))) (cos (* PI (- -0.5 (fabs z0)))))
   (+ 0.5 (* 0.5 (sin (* PI (+ (fabs z0) (- (fabs z0) -0.5)))))))
  1.0))
double code(double z0) {
	double tmp;
	if (fabs(z0) <= 85000.0) {
		tmp = (sin((((double) M_PI) * fabs(z0))) * cos((((double) M_PI) * (-0.5 - fabs(z0))))) + (0.5 + (0.5 * sin((((double) M_PI) * (fabs(z0) + (fabs(z0) - -0.5))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
public static double code(double z0) {
	double tmp;
	if (Math.abs(z0) <= 85000.0) {
		tmp = (Math.sin((Math.PI * Math.abs(z0))) * Math.cos((Math.PI * (-0.5 - Math.abs(z0))))) + (0.5 + (0.5 * Math.sin((Math.PI * (Math.abs(z0) + (Math.abs(z0) - -0.5))))));
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(z0):
	tmp = 0
	if math.fabs(z0) <= 85000.0:
		tmp = (math.sin((math.pi * math.fabs(z0))) * math.cos((math.pi * (-0.5 - math.fabs(z0))))) + (0.5 + (0.5 * math.sin((math.pi * (math.fabs(z0) + (math.fabs(z0) - -0.5))))))
	else:
		tmp = 1.0
	return tmp
function code(z0)
	tmp = 0.0
	if (abs(z0) <= 85000.0)
		tmp = Float64(Float64(sin(Float64(pi * abs(z0))) * cos(Float64(pi * Float64(-0.5 - abs(z0))))) + Float64(0.5 + Float64(0.5 * sin(Float64(pi * Float64(abs(z0) + Float64(abs(z0) - -0.5)))))));
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(z0)
	tmp = 0.0;
	if (abs(z0) <= 85000.0)
		tmp = (sin((pi * abs(z0))) * cos((pi * (-0.5 - abs(z0))))) + (0.5 + (0.5 * sin((pi * (abs(z0) + (abs(z0) - -0.5))))));
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[z0_] := If[LessEqual[N[Abs[z0], $MachinePrecision], 85000.0], N[(N[(N[Sin[N[(Pi * N[Abs[z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Cos[N[(Pi * N[(-0.5 - N[Abs[z0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(0.5 + N[(0.5 * N[Sin[N[(Pi * N[(N[Abs[z0], $MachinePrecision] + N[(N[Abs[z0], $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\mathbf{if}\;\left|z0\right| \leq 85000:\\
\;\;\;\;\sin \left(\pi \cdot \left|z0\right|\right) \cdot \cos \left(\pi \cdot \left(-0.5 - \left|z0\right|\right)\right) + \left(0.5 + 0.5 \cdot \sin \left(\pi \cdot \left(\left|z0\right| + \left(\left|z0\right| - -0.5\right)\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z0 < 85000

    1. Initial program 57.5%

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

        \[\leadsto \color{blue}{\cos \left(\left(\pi + \pi\right) \cdot z0\right)} \]
      2. sin-+PI/2-revN/A

        \[\leadsto \color{blue}{\sin \left(\left(\pi + \pi\right) \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \sin \left(\color{blue}{\left(\pi + \pi\right) \cdot z0} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      4. *-commutativeN/A

        \[\leadsto \sin \left(\color{blue}{z0 \cdot \left(\pi + \pi\right)} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      5. lift-+.f64N/A

        \[\leadsto \sin \left(z0 \cdot \color{blue}{\left(\pi + \pi\right)} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      6. distribute-rgt-inN/A

        \[\leadsto \sin \left(\color{blue}{\left(\pi \cdot z0 + \pi \cdot z0\right)} + \frac{\mathsf{PI}\left(\right)}{2}\right) \]
      7. associate-+l+N/A

        \[\leadsto \sin \color{blue}{\left(\pi \cdot z0 + \left(\pi \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right)\right)} \]
      8. sin-sumN/A

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

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

        \[\leadsto \color{blue}{\sin \left(\pi \cdot z0\right) \cdot \cos \left(\pi \cdot z0 + \frac{\mathsf{PI}\left(\right)}{2}\right) + \cos \left(\pi \cdot z0\right) \cdot \cos \left(\pi \cdot z0\right)} \]
    3. Applied rewrites59.6%

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

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

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

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

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

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(z0 \cdot \color{blue}{\left(\pi + \pi\right)} + \frac{\mathsf{PI}\left(\right)}{2}\right)\right) \]
      6. distribute-lft-inN/A

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

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

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

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

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

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\left(z0 \cdot \pi + z0 \cdot \pi\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right)\right) \]
      12. *-commutativeN/A

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

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\left(z0 \cdot \pi + z0 \cdot \pi\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right)\right) \]
      14. associate-+l+N/A

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

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\color{blue}{z0 \cdot \pi} + \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right)\right)\right) \]
      16. *-commutativeN/A

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

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

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot z0 + \left(z0 \cdot \pi + \color{blue}{\frac{1}{2} \cdot \pi}\right)\right)\right) \]
      19. distribute-rgt-outN/A

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot z0 + \color{blue}{\pi \cdot \left(z0 + \frac{1}{2}\right)}\right)\right) \]
      20. distribute-lft-outN/A

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \color{blue}{\left(\pi \cdot \left(z0 + \left(z0 + \frac{1}{2}\right)\right)\right)}\right) \]
      21. lower-*.f64N/A

        \[\leadsto \sin \left(z0 \cdot \pi\right) \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \color{blue}{\left(\pi \cdot \left(z0 + \left(z0 + \frac{1}{2}\right)\right)\right)}\right) \]
    5. Applied rewrites58.7%

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

        \[\leadsto \sin \color{blue}{\left(z0 \cdot \pi\right)} \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - \frac{-1}{2}\right)\right)\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \sin \color{blue}{\left(\pi \cdot z0\right)} \cdot \cos \left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - \frac{-1}{2}\right)\right)\right)\right) \]
      3. lower-*.f6458.7%

        \[\leadsto \sin \color{blue}{\left(\pi \cdot z0\right)} \cdot \cos \left(z0 \cdot \pi + 0.5 \cdot \pi\right) + \left(0.5 + 0.5 \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - -0.5\right)\right)\right)\right) \]
      4. lift-cos.f64N/A

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

        \[\leadsto \sin \left(\pi \cdot z0\right) \cdot \color{blue}{\cos \left(\mathsf{neg}\left(\left(z0 \cdot \pi + \frac{1}{2} \cdot \pi\right)\right)\right)} + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - \frac{-1}{2}\right)\right)\right)\right) \]
      6. lower-cos.f64N/A

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

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

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

        \[\leadsto \sin \left(\pi \cdot z0\right) \cdot \cos \left(\mathsf{neg}\left(\left(z0 \cdot \pi + \color{blue}{\frac{1}{2} \cdot \pi}\right)\right)\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - \frac{-1}{2}\right)\right)\right)\right) \]
      10. distribute-rgt-outN/A

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

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

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

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

        \[\leadsto \sin \left(\pi \cdot z0\right) \cdot \cos \color{blue}{\left(\pi \cdot \left(\mathsf{neg}\left(\left(z0 - \frac{-1}{2}\right)\right)\right)\right)} + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - \frac{-1}{2}\right)\right)\right)\right) \]
      15. lower-*.f64N/A

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

        \[\leadsto \sin \left(\pi \cdot z0\right) \cdot \cos \left(\pi \cdot \left(\mathsf{neg}\left(\color{blue}{\left(z0 - \frac{-1}{2}\right)}\right)\right)\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - \frac{-1}{2}\right)\right)\right)\right) \]
      17. sub-negate-revN/A

        \[\leadsto \sin \left(\pi \cdot z0\right) \cdot \cos \left(\pi \cdot \color{blue}{\left(\frac{-1}{2} - z0\right)}\right) + \left(\frac{1}{2} + \frac{1}{2} \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - \frac{-1}{2}\right)\right)\right)\right) \]
      18. lower--.f6458.7%

        \[\leadsto \sin \left(\pi \cdot z0\right) \cdot \cos \left(\pi \cdot \color{blue}{\left(-0.5 - z0\right)}\right) + \left(0.5 + 0.5 \cdot \sin \left(\pi \cdot \left(z0 + \left(z0 - -0.5\right)\right)\right)\right) \]
    7. Applied rewrites58.7%

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

    if 85000 < z0

    1. Initial program 57.5%

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

      \[\leadsto \color{blue}{1} \]
    3. Step-by-step derivation
      1. Applied rewrites97.2%

        \[\leadsto \color{blue}{1} \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 2: 98.5% accurate, 0.9× speedup?

    \[\begin{array}{l} \mathbf{if}\;\left|z0\right| \leq 85000:\\ \;\;\;\;\sin \left(\left(-2 \cdot \pi\right) \cdot \left|z0\right| - -1.5707963267948966\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
    (FPCore (z0)
      :precision binary64
      (if (<= (fabs z0) 85000.0)
      (sin (- (* (* -2.0 PI) (fabs z0)) -1.5707963267948966))
      1.0))
    double code(double z0) {
    	double tmp;
    	if (fabs(z0) <= 85000.0) {
    		tmp = sin((((-2.0 * ((double) M_PI)) * fabs(z0)) - -1.5707963267948966));
    	} else {
    		tmp = 1.0;
    	}
    	return tmp;
    }
    
    public static double code(double z0) {
    	double tmp;
    	if (Math.abs(z0) <= 85000.0) {
    		tmp = Math.sin((((-2.0 * Math.PI) * Math.abs(z0)) - -1.5707963267948966));
    	} else {
    		tmp = 1.0;
    	}
    	return tmp;
    }
    
    def code(z0):
    	tmp = 0
    	if math.fabs(z0) <= 85000.0:
    		tmp = math.sin((((-2.0 * math.pi) * math.fabs(z0)) - -1.5707963267948966))
    	else:
    		tmp = 1.0
    	return tmp
    
    function code(z0)
    	tmp = 0.0
    	if (abs(z0) <= 85000.0)
    		tmp = sin(Float64(Float64(Float64(-2.0 * pi) * abs(z0)) - -1.5707963267948966));
    	else
    		tmp = 1.0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(z0)
    	tmp = 0.0;
    	if (abs(z0) <= 85000.0)
    		tmp = sin((((-2.0 * pi) * abs(z0)) - -1.5707963267948966));
    	else
    		tmp = 1.0;
    	end
    	tmp_2 = tmp;
    end
    
    code[z0_] := If[LessEqual[N[Abs[z0], $MachinePrecision], 85000.0], N[Sin[N[(N[(N[(-2.0 * Pi), $MachinePrecision] * N[Abs[z0], $MachinePrecision]), $MachinePrecision] - -1.5707963267948966), $MachinePrecision]], $MachinePrecision], 1.0]
    
    \begin{array}{l}
    \mathbf{if}\;\left|z0\right| \leq 85000:\\
    \;\;\;\;\sin \left(\left(-2 \cdot \pi\right) \cdot \left|z0\right| - -1.5707963267948966\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;1\\
    
    
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if z0 < 85000

      1. Initial program 57.5%

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

          \[\leadsto \color{blue}{\cos \left(\left(\pi + \pi\right) \cdot z0\right)} \]
        2. cos-neg-revN/A

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

          \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\left(\pi + \pi\right) \cdot z0\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
        4. lower-sin.f64N/A

          \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\left(\pi + \pi\right) \cdot z0\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \]
        5. add-flipN/A

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

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

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

          \[\leadsto \sin \left(\color{blue}{\left(\mathsf{neg}\left(\left(\pi + \pi\right)\right)\right) \cdot z0} - \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right) \]
        9. lower-*.f64N/A

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

          \[\leadsto \sin \left(\left(\mathsf{neg}\left(\color{blue}{\left(\pi + \pi\right)}\right)\right) \cdot z0 - \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right) \]
        11. count-2N/A

          \[\leadsto \sin \left(\left(\mathsf{neg}\left(\color{blue}{2 \cdot \pi}\right)\right) \cdot z0 - \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right) \]
        12. distribute-lft-neg-inN/A

          \[\leadsto \sin \left(\color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot \pi\right)} \cdot z0 - \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right) \]
        13. lower-*.f64N/A

          \[\leadsto \sin \left(\color{blue}{\left(\left(\mathsf{neg}\left(2\right)\right) \cdot \pi\right)} \cdot z0 - \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right) \]
        14. metadata-evalN/A

          \[\leadsto \sin \left(\left(\color{blue}{-2} \cdot \pi\right) \cdot z0 - \left(\mathsf{neg}\left(\frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right) \]
        15. lift-PI.f64N/A

          \[\leadsto \sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \left(\mathsf{neg}\left(\frac{\color{blue}{\pi}}{2}\right)\right)\right) \]
        16. mult-flipN/A

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

          \[\leadsto \sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \color{blue}{\pi \cdot \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right) \]
        18. metadata-evalN/A

          \[\leadsto \sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \pi \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{1}{2}}\right)\right)\right) \]
        19. metadata-evalN/A

          \[\leadsto \sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \pi \cdot \color{blue}{\frac{-1}{2}}\right) \]
        20. metadata-evalN/A

          \[\leadsto \sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \pi \cdot \color{blue}{\frac{1}{-2}}\right) \]
        21. metadata-evalN/A

          \[\leadsto \sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \pi \cdot \frac{1}{\color{blue}{\mathsf{neg}\left(2\right)}}\right) \]
      3. Applied rewrites57.5%

        \[\leadsto \color{blue}{\sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \pi \cdot -0.5\right)} \]
      4. Evaluated real constant57.5%

        \[\leadsto \sin \left(\left(-2 \cdot \pi\right) \cdot z0 - \color{blue}{-1.5707963267948966}\right) \]

      if 85000 < z0

      1. Initial program 57.5%

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

        \[\leadsto \color{blue}{1} \]
      3. Step-by-step derivation
        1. Applied rewrites97.2%

          \[\leadsto \color{blue}{1} \]
      4. Recombined 2 regimes into one program.
      5. Add Preprocessing

      Alternative 3: 98.5% accurate, 0.9× speedup?

      \[\begin{array}{l} \mathbf{if}\;\left|z0\right| \leq 85000:\\ \;\;\;\;\cos \left(6.283185307179586 \cdot \left|z0\right|\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
      (FPCore (z0)
        :precision binary64
        (if (<= (fabs z0) 85000.0) (cos (* 6.283185307179586 (fabs z0))) 1.0))
      double code(double z0) {
      	double tmp;
      	if (fabs(z0) <= 85000.0) {
      		tmp = cos((6.283185307179586 * fabs(z0)));
      	} else {
      		tmp = 1.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(z0)
      use fmin_fmax_functions
          real(8), intent (in) :: z0
          real(8) :: tmp
          if (abs(z0) <= 85000.0d0) then
              tmp = cos((6.283185307179586d0 * abs(z0)))
          else
              tmp = 1.0d0
          end if
          code = tmp
      end function
      
      public static double code(double z0) {
      	double tmp;
      	if (Math.abs(z0) <= 85000.0) {
      		tmp = Math.cos((6.283185307179586 * Math.abs(z0)));
      	} else {
      		tmp = 1.0;
      	}
      	return tmp;
      }
      
      def code(z0):
      	tmp = 0
      	if math.fabs(z0) <= 85000.0:
      		tmp = math.cos((6.283185307179586 * math.fabs(z0)))
      	else:
      		tmp = 1.0
      	return tmp
      
      function code(z0)
      	tmp = 0.0
      	if (abs(z0) <= 85000.0)
      		tmp = cos(Float64(6.283185307179586 * abs(z0)));
      	else
      		tmp = 1.0;
      	end
      	return tmp
      end
      
      function tmp_2 = code(z0)
      	tmp = 0.0;
      	if (abs(z0) <= 85000.0)
      		tmp = cos((6.283185307179586 * abs(z0)));
      	else
      		tmp = 1.0;
      	end
      	tmp_2 = tmp;
      end
      
      code[z0_] := If[LessEqual[N[Abs[z0], $MachinePrecision], 85000.0], N[Cos[N[(6.283185307179586 * N[Abs[z0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1.0]
      
      \begin{array}{l}
      \mathbf{if}\;\left|z0\right| \leq 85000:\\
      \;\;\;\;\cos \left(6.283185307179586 \cdot \left|z0\right|\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;1\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z0 < 85000

        1. Initial program 57.5%

          \[\cos \left(\left(\pi + \pi\right) \cdot z0\right) \]
        2. Evaluated real constant57.5%

          \[\leadsto \cos \left(\color{blue}{6.283185307179586} \cdot z0\right) \]

        if 85000 < z0

        1. Initial program 57.5%

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

          \[\leadsto \color{blue}{1} \]
        3. Step-by-step derivation
          1. Applied rewrites97.2%

            \[\leadsto \color{blue}{1} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 4: 97.2% accurate, 109.0× speedup?

        \[1 \]
        (FPCore (z0)
          :precision binary64
          1.0)
        double code(double z0) {
        	return 1.0;
        }
        
        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(z0)
        use fmin_fmax_functions
            real(8), intent (in) :: z0
            code = 1.0d0
        end function
        
        public static double code(double z0) {
        	return 1.0;
        }
        
        def code(z0):
        	return 1.0
        
        function code(z0)
        	return 1.0
        end
        
        function tmp = code(z0)
        	tmp = 1.0;
        end
        
        code[z0_] := 1.0
        
        1
        
        Derivation
        1. Initial program 57.5%

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

          \[\leadsto \color{blue}{1} \]
        3. Step-by-step derivation
          1. Applied rewrites97.2%

            \[\leadsto \color{blue}{1} \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025250 
          (FPCore (z0)
            :name "(cos (* (+ PI PI) z0))"
            :precision binary64
            (cos (* (+ PI PI) z0)))