?

Average Error: 46.3 → 43.8
Time: 2.2min
Precision: binary64
Cost: 41220

?

\[\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \]
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \left(\left(-\mathsf{fma}\left(a, 2, 1\right) \cdot b\right) \cdot \left(t \cdot \sqrt[3]{-0.000244140625}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (*
  (* x (cos (/ (* (* (+ (* y 2.0) 1.0) z) t) 16.0)))
  (cos (/ (* (* (+ (* a 2.0) 1.0) b) t) 16.0))))
(FPCore (x y z t a b)
 :precision binary64
 (if (<=
      (*
       (* x (cos (/ (* (* (+ (* y 2.0) 1.0) z) t) 16.0)))
       (cos (/ (* (* (+ (* a 2.0) 1.0) b) t) 16.0)))
      2e-5)
   (*
    (* x (cos (* 0.0625 (* t z))))
    (cos (* (- (* (fma a 2.0 1.0) b)) (* t (cbrt -0.000244140625)))))
   x))
double code(double x, double y, double z, double t, double a, double b) {
	return (x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos((((((a * 2.0) + 1.0) * b) * t) / 16.0));
}
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos((((((a * 2.0) + 1.0) * b) * t) / 16.0))) <= 2e-5) {
		tmp = (x * cos((0.0625 * (t * z)))) * cos((-(fma(a, 2.0, 1.0) * b) * (t * cbrt(-0.000244140625))));
	} else {
		tmp = x;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(x * cos(Float64(Float64(Float64(Float64(Float64(y * 2.0) + 1.0) * z) * t) / 16.0))) * cos(Float64(Float64(Float64(Float64(Float64(a * 2.0) + 1.0) * b) * t) / 16.0)))
end
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(Float64(x * cos(Float64(Float64(Float64(Float64(Float64(y * 2.0) + 1.0) * z) * t) / 16.0))) * cos(Float64(Float64(Float64(Float64(Float64(a * 2.0) + 1.0) * b) * t) / 16.0))) <= 2e-5)
		tmp = Float64(Float64(x * cos(Float64(0.0625 * Float64(t * z)))) * cos(Float64(Float64(-Float64(fma(a, 2.0, 1.0) * b)) * Float64(t * cbrt(-0.000244140625)))));
	else
		tmp = x;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(x * N[Cos[N[(N[(N[(N[(N[(y * 2.0), $MachinePrecision] + 1.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(N[(N[(N[(a * 2.0), $MachinePrecision] + 1.0), $MachinePrecision] * b), $MachinePrecision] * t), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(N[(x * N[Cos[N[(N[(N[(N[(N[(y * 2.0), $MachinePrecision] + 1.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(N[(N[(N[(N[(a * 2.0), $MachinePrecision] + 1.0), $MachinePrecision] * b), $MachinePrecision] * t), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-5], N[(N[(x * N[Cos[N[(0.0625 * N[(t * z), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[N[((-N[(N[(a * 2.0 + 1.0), $MachinePrecision] * b), $MachinePrecision]) * N[(t * N[Power[-0.000244140625, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], x]
\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)
\begin{array}{l}
\mathbf{if}\;\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \leq 2 \cdot 10^{-5}:\\
\;\;\;\;\left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \left(\left(-\mathsf{fma}\left(a, 2, 1\right) \cdot b\right) \cdot \left(t \cdot \sqrt[3]{-0.000244140625}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x\\


\end{array}

Error?

Target

Original46.3
Target44.4
Herbie43.8
\[x \cdot \cos \left(\frac{b}{16} \cdot \frac{t}{\left(1 - a \cdot 2\right) + {\left(a \cdot 2\right)}^{2}}\right) \]

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 x (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 y 2) 1) z) t) 16))) (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 a 2) 1) b) t) 16))) < 2.00000000000000016e-5

    1. Initial program 33.5

      \[\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \]
    2. Simplified33.5

      \[\leadsto \color{blue}{\left(x \cdot \cos \left(\mathsf{fma}\left(y, 2, 1\right) \cdot \left(\left(z \cdot t\right) \cdot 0.0625\right)\right)\right) \cdot \cos \left(\mathsf{fma}\left(a, 2, 1\right) \cdot \left(\left(b \cdot t\right) \cdot 0.0625\right)\right)} \]
      Proof
    3. Taylor expanded in y around 0 33.7

      \[\leadsto \left(x \cdot \color{blue}{\cos \left(0.0625 \cdot \left(t \cdot z\right)\right)}\right) \cdot \cos \left(\mathsf{fma}\left(a, 2, 1\right) \cdot \left(\left(b \cdot t\right) \cdot 0.0625\right)\right) \]
    4. Applied egg-rr39.9

      \[\leadsto \left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \color{blue}{\left({\left({\left(\mathsf{fma}\left(a, 2, 1\right) \cdot \left(\left(b \cdot t\right) \cdot 0.0625\right)\right)}^{3}\right)}^{0.3333333333333333}\right)} \]
    5. Taylor expanded in t around -inf 48.3

      \[\leadsto \left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \color{blue}{\left(-1 \cdot \left({\left({\left(1 + 2 \cdot a\right)}^{2} \cdot \left({b}^{2} \cdot \left(b \cdot \left(1 + 2 \cdot a\right)\right)\right)\right)}^{0.3333333333333333} \cdot \left(t \cdot \sqrt[3]{-0.000244140625}\right)\right)\right)} \]
    6. Simplified33.8

      \[\leadsto \left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \color{blue}{\left(\left(-\mathsf{fma}\left(a, 2, 1\right) \cdot b\right) \cdot \left(t \cdot \sqrt[3]{-0.000244140625}\right)\right)} \]
      Proof

    if 2.00000000000000016e-5 < (*.f64 (*.f64 x (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 y 2) 1) z) t) 16))) (cos.f64 (/.f64 (*.f64 (*.f64 (+.f64 (*.f64 a 2) 1) b) t) 16)))

    1. Initial program 56.3

      \[\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \]
    2. Simplified55.3

      \[\leadsto \color{blue}{\left(x \cdot \cos \left(\mathsf{fma}\left(y, 2, 1\right) \cdot \left(\left(z \cdot t\right) \cdot 0.0625\right)\right)\right) \cdot \cos \left(\mathsf{fma}\left(a, 2, 1\right) \cdot \left(\left(b \cdot t\right) \cdot 0.0625\right)\right)} \]
      Proof
    3. Taylor expanded in y around 0 54.6

      \[\leadsto \left(x \cdot \color{blue}{\cos \left(0.0625 \cdot \left(t \cdot z\right)\right)}\right) \cdot \cos \left(\mathsf{fma}\left(a, 2, 1\right) \cdot \left(\left(b \cdot t\right) \cdot 0.0625\right)\right) \]
    4. Taylor expanded in t around 0 51.6

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error43.8
Cost35400
\[\begin{array}{l} t_1 := \left(b \cdot t\right) \cdot 0.0625\\ t_2 := \left(a + a\right) \cdot t_1\\ \mathbf{if}\;\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \leq 10^{-95}:\\ \;\;\;\;\left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \begin{array}{l} \mathbf{if}\;t_2 \ne 0:\\ \;\;\;\;t_2 \cdot \left(1 + \frac{t_1}{t_2}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, 2, 1\right) \cdot t_1\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error43.8
Cost34756
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \leq 10^{-95}:\\ \;\;\;\;\left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \left(\mathsf{fma}\left(a, 2, 1\right) \cdot \left(\left(b \cdot t\right) \cdot 0.0625\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error44.0
Cost28228
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot \cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right)\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right) \leq 5 \cdot 10^{-115}:\\ \;\;\;\;\left(x \cdot \cos \left(0.0625 \cdot \left(t \cdot z\right)\right)\right) \cdot \cos \left(0.125 \cdot \left(a \cdot \left(t \cdot b\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error44.2
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (x y z t a b)
  :name "Codec.Picture.Jpg.FastDct:referenceDct from JuicyPixels-3.2.6.1"
  :precision binary64

  :herbie-target
  (* x (cos (* (/ b 16.0) (/ t (+ (- 1.0 (* a 2.0)) (pow (* a 2.0) 2.0))))))

  (* (* x (cos (/ (* (* (+ (* y 2.0) 1.0) z) t) 16.0))) (cos (/ (* (* (+ (* a 2.0) 1.0) b) t) 16.0))))