?

Average Error: 47.0 → 44.5
Time: 27.5s
Precision: binary64
Cost: 74052

?

\[\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{t \cdot \left(\left(1 + 2 \cdot a\right) \cdot b\right)}{16}\right) \leq 2 \cdot 10^{-122}:\\ \;\;\;\;\cos \left(\frac{{\left({\left(\sqrt[3]{\sqrt[3]{t \cdot \mathsf{fma}\left(y, -2, -1\right)}}\right)}^{3}\right)}^{2}}{\frac{-16}{z}} \cdot \sqrt[3]{t \cdot \left(-1 + y \cdot -2\right)}\right) \cdot \left(x \cdot \cos \left(t \cdot \frac{\mathsf{fma}\left(2, a, 1\right)}{\frac{16}{b}}\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 (/ (* t (* (+ 1.0 (* 2.0 a)) b)) 16.0)))
      2e-122)
   (*
    (cos
     (*
      (/ (pow (pow (cbrt (cbrt (* t (fma y -2.0 -1.0)))) 3.0) 2.0) (/ -16.0 z))
      (cbrt (* t (+ -1.0 (* y -2.0))))))
    (* x (cos (* t (/ (fma 2.0 a 1.0) (/ 16.0 b))))))
   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(((t * ((1.0 + (2.0 * a)) * b)) / 16.0))) <= 2e-122) {
		tmp = cos(((pow(pow(cbrt(cbrt((t * fma(y, -2.0, -1.0)))), 3.0), 2.0) / (-16.0 / z)) * cbrt((t * (-1.0 + (y * -2.0)))))) * (x * cos((t * (fma(2.0, a, 1.0) / (16.0 / b)))));
	} 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(t * Float64(Float64(1.0 + Float64(2.0 * a)) * b)) / 16.0))) <= 2e-122)
		tmp = Float64(cos(Float64(Float64(((cbrt(cbrt(Float64(t * fma(y, -2.0, -1.0)))) ^ 3.0) ^ 2.0) / Float64(-16.0 / z)) * cbrt(Float64(t * Float64(-1.0 + Float64(y * -2.0)))))) * Float64(x * cos(Float64(t * Float64(fma(2.0, a, 1.0) / Float64(16.0 / b))))));
	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[(t * N[(N[(1.0 + N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision] / 16.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-122], N[(N[Cos[N[(N[(N[Power[N[Power[N[Power[N[Power[N[(t * N[(y * -2.0 + -1.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision], 2.0], $MachinePrecision] / N[(-16.0 / z), $MachinePrecision]), $MachinePrecision] * N[Power[N[(t * N[(-1.0 + N[(y * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(x * N[Cos[N[(t * N[(N[(2.0 * a + 1.0), $MachinePrecision] / N[(16.0 / b), $MachinePrecision]), $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{t \cdot \left(\left(1 + 2 \cdot a\right) \cdot b\right)}{16}\right) \leq 2 \cdot 10^{-122}:\\
\;\;\;\;\cos \left(\frac{{\left({\left(\sqrt[3]{\sqrt[3]{t \cdot \mathsf{fma}\left(y, -2, -1\right)}}\right)}^{3}\right)}^{2}}{\frac{-16}{z}} \cdot \sqrt[3]{t \cdot \left(-1 + y \cdot -2\right)}\right) \cdot \left(x \cdot \cos \left(t \cdot \frac{\mathsf{fma}\left(2, a, 1\right)}{\frac{16}{b}}\right)\right)\\

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


\end{array}

Error?

Target

Original47.0
Target45.0
Herbie44.5
\[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.00000000000000012e-122

    1. Initial program 34.7

      \[\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. Simplified34.8

      \[\leadsto \color{blue}{\cos \left(t \cdot \frac{\mathsf{fma}\left(y, 2, 1\right)}{\frac{16}{z}}\right) \cdot \left(x \cdot \cos \left(t \cdot \frac{\mathsf{fma}\left(2, a, 1\right)}{\frac{16}{b}}\right)\right)} \]
      Proof

      [Start]34.7

      \[ \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) \]

      *-commutative [=>]34.7

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

      associate-*l* [=>]34.7

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

      *-commutative [=>]34.7

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

      associate-*r/ [<=]34.7

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

      associate-/l* [=>]34.7

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

      fma-def [=>]34.7

      \[ \cos \left(t \cdot \frac{\color{blue}{\mathsf{fma}\left(y, 2, 1\right)}}{\frac{16}{z}}\right) \cdot \left(x \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)\right) \]

      associate-*l/ [<=]34.7

      \[ \cos \left(t \cdot \frac{\mathsf{fma}\left(y, 2, 1\right)}{\frac{16}{z}}\right) \cdot \left(x \cdot \cos \color{blue}{\left(\frac{\left(a \cdot 2 + 1\right) \cdot b}{16} \cdot t\right)}\right) \]

      *-commutative [=>]34.7

      \[ \cos \left(t \cdot \frac{\mathsf{fma}\left(y, 2, 1\right)}{\frac{16}{z}}\right) \cdot \left(x \cdot \cos \color{blue}{\left(t \cdot \frac{\left(a \cdot 2 + 1\right) \cdot b}{16}\right)}\right) \]

      associate-/l* [=>]34.8

      \[ \cos \left(t \cdot \frac{\mathsf{fma}\left(y, 2, 1\right)}{\frac{16}{z}}\right) \cdot \left(x \cdot \cos \left(t \cdot \color{blue}{\frac{a \cdot 2 + 1}{\frac{16}{b}}}\right)\right) \]

      *-commutative [=>]34.8

      \[ \cos \left(t \cdot \frac{\mathsf{fma}\left(y, 2, 1\right)}{\frac{16}{z}}\right) \cdot \left(x \cdot \cos \left(t \cdot \frac{\color{blue}{2 \cdot a} + 1}{\frac{16}{b}}\right)\right) \]

      fma-def [=>]34.8

      \[ \cos \left(t \cdot \frac{\mathsf{fma}\left(y, 2, 1\right)}{\frac{16}{z}}\right) \cdot \left(x \cdot \cos \left(t \cdot \frac{\color{blue}{\mathsf{fma}\left(2, a, 1\right)}}{\frac{16}{b}}\right)\right) \]
    3. Applied egg-rr35.1

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

      \[\leadsto \cos \color{blue}{\left(\frac{{\left(\sqrt[3]{\left(-1 + y \cdot -2\right) \cdot t}\right)}^{2}}{\frac{-16}{z}} \cdot \sqrt[3]{\left(-1 + y \cdot -2\right) \cdot t}\right)} \cdot \left(x \cdot \cos \left(t \cdot \frac{\mathsf{fma}\left(2, a, 1\right)}{\frac{16}{b}}\right)\right) \]
    5. Applied egg-rr35.1

      \[\leadsto \cos \left(\frac{{\color{blue}{\left({\left(\sqrt[3]{\sqrt[3]{\mathsf{fma}\left(y, -2, -1\right) \cdot t}}\right)}^{3}\right)}}^{2}}{\frac{-16}{z}} \cdot \sqrt[3]{\left(-1 + y \cdot -2\right) \cdot t}\right) \cdot \left(x \cdot \cos \left(t \cdot \frac{\mathsf{fma}\left(2, a, 1\right)}{\frac{16}{b}}\right)\right) \]

    if 2.00000000000000012e-122 < (*.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 54.6

      \[\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. Simplified53.6

      \[\leadsto \color{blue}{x \cdot \left(\cos \left(\left(z \cdot t\right) \cdot \left(0.0625 + \frac{y}{8}\right)\right) \cdot \cos \left(\left(t \cdot b\right) \cdot \left(\frac{a}{8} + 0.0625\right)\right)\right)} \]
      Proof

      [Start]54.6

      \[ \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) \]

      associate-*l* [=>]54.6

      \[ \color{blue}{x \cdot \left(\cos \left(\frac{\left(\left(y \cdot 2 + 1\right) \cdot z\right) \cdot t}{16}\right) \cdot \cos \left(\frac{\left(\left(a \cdot 2 + 1\right) \cdot b\right) \cdot t}{16}\right)\right)} \]
    3. Taylor expanded in z around 0 52.3

      \[\leadsto x \cdot \left(\color{blue}{1} \cdot \cos \left(\left(t \cdot b\right) \cdot \left(\frac{a}{8} + 0.0625\right)\right)\right) \]
    4. Taylor expanded in t around 0 50.3

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

    \[\leadsto \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{t \cdot \left(\left(1 + 2 \cdot a\right) \cdot b\right)}{16}\right) \leq 2 \cdot 10^{-122}:\\ \;\;\;\;\cos \left(\frac{{\left({\left(\sqrt[3]{\sqrt[3]{t \cdot \mathsf{fma}\left(y, -2, -1\right)}}\right)}^{3}\right)}^{2}}{\frac{-16}{z}} \cdot \sqrt[3]{t \cdot \left(-1 + y \cdot -2\right)}\right) \cdot \left(x \cdot \cos \left(t \cdot \frac{\mathsf{fma}\left(2, a, 1\right)}{\frac{16}{b}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]

Alternatives

Alternative 1
Error44.0
Cost54532
\[\begin{array}{l} t_1 := \sqrt[3]{t \cdot b}\\ \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{t \cdot \left(\left(1 + 2 \cdot a\right) \cdot b\right)}{16}\right) \leq 2 \cdot 10^{+298}:\\ \;\;\;\;x \cdot \left(\cos \left(\left(z \cdot t\right) \cdot \left(0.0625 + \frac{y}{8}\right)\right) \cdot \cos \left({t_1}^{2} \cdot \frac{t_1}{\frac{1}{\mathsf{fma}\left(a, 0.125, 0.0625\right)}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error44.7
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023057 
(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))))