| Alternative 1 | |
|---|---|
| Error | 44.4 |
| Cost | 64 |
\[x
\]
(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
(let* ((t_1 (* 0.0625 (* t b))) (t_2 (* t (* b (* a 0.125)))))
(if (<=
(*
(* x (cos (/ (* (* (+ (* y 2.0) 1.0) z) t) 16.0)))
(cos (/ (* t (* (+ 1.0 (* 2.0 a)) b)) 16.0)))
4e+206)
(*
x
(*
(cos (* (* z t) (+ 0.0625 (/ y 8.0))))
(- (* (cos t_2) (cos t_1)) (* (sin t_2) (sin t_1)))))
(* x (expm1 (fma -0.0009765625 (* t (* t (* b b))) (log 2.0)))))))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 t_1 = 0.0625 * (t * b);
double t_2 = t * (b * (a * 0.125));
double tmp;
if (((x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos(((t * ((1.0 + (2.0 * a)) * b)) / 16.0))) <= 4e+206) {
tmp = x * (cos(((z * t) * (0.0625 + (y / 8.0)))) * ((cos(t_2) * cos(t_1)) - (sin(t_2) * sin(t_1))));
} else {
tmp = x * expm1(fma(-0.0009765625, (t * (t * (b * b))), log(2.0)));
}
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) t_1 = Float64(0.0625 * Float64(t * b)) t_2 = Float64(t * Float64(b * Float64(a * 0.125))) 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))) <= 4e+206) tmp = Float64(x * Float64(cos(Float64(Float64(z * t) * Float64(0.0625 + Float64(y / 8.0)))) * Float64(Float64(cos(t_2) * cos(t_1)) - Float64(sin(t_2) * sin(t_1))))); else tmp = Float64(x * expm1(fma(-0.0009765625, Float64(t * Float64(t * Float64(b * b))), log(2.0)))); 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_] := Block[{t$95$1 = N[(0.0625 * N[(t * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t * N[(b * N[(a * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, 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], 4e+206], N[(x * N[(N[Cos[N[(N[(z * t), $MachinePrecision] * N[(0.0625 + N[(y / 8.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(N[Cos[t$95$2], $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[t$95$2], $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(Exp[N[(-0.0009765625 * N[(t * N[(t * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]]]]
\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}
t_1 := 0.0625 \cdot \left(t \cdot b\right)\\
t_2 := t \cdot \left(b \cdot \left(a \cdot 0.125\right)\right)\\
\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 4 \cdot 10^{+206}:\\
\;\;\;\;x \cdot \left(\cos \left(\left(z \cdot t\right) \cdot \left(0.0625 + \frac{y}{8}\right)\right) \cdot \left(\cos t_2 \cdot \cos t_1 - \sin t_2 \cdot \sin t_1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{expm1}\left(\mathsf{fma}\left(-0.0009765625, t \cdot \left(t \cdot \left(b \cdot b\right)\right), \log 2\right)\right)\\
\end{array}
| Original | 46.6 |
|---|---|
| Target | 44.7 |
| Herbie | 43.8 |
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))) < 4.0000000000000002e206Initial program 34.1
Simplified34.0
[Start]34.1 | \[ \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* [=>]34.1 | \[ \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)}
\] |
Applied egg-rr34.0
if 4.0000000000000002e206 < (*.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))) Initial program 61.0
Simplified59.8
[Start]61.0 | \[ \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* [=>]61.0 | \[ \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)}
\] |
Taylor expanded in z around 0 57.8
Taylor expanded in a around 0 56.6
Applied egg-rr56.6
Taylor expanded in t around 0 56.1
Simplified55.1
[Start]56.1 | \[ \mathsf{expm1}\left(\log 2 + -0.0009765625 \cdot \left({t}^{2} \cdot {b}^{2}\right)\right) \cdot x
\] |
|---|---|
+-commutative [=>]56.1 | \[ \mathsf{expm1}\left(\color{blue}{-0.0009765625 \cdot \left({t}^{2} \cdot {b}^{2}\right) + \log 2}\right) \cdot x
\] |
fma-def [=>]56.1 | \[ \mathsf{expm1}\left(\color{blue}{\mathsf{fma}\left(-0.0009765625, {t}^{2} \cdot {b}^{2}, \log 2\right)}\right) \cdot x
\] |
unpow2 [=>]56.1 | \[ \mathsf{expm1}\left(\mathsf{fma}\left(-0.0009765625, \color{blue}{\left(t \cdot t\right)} \cdot {b}^{2}, \log 2\right)\right) \cdot x
\] |
associate-*l* [=>]55.1 | \[ \mathsf{expm1}\left(\mathsf{fma}\left(-0.0009765625, \color{blue}{t \cdot \left(t \cdot {b}^{2}\right)}, \log 2\right)\right) \cdot x
\] |
unpow2 [=>]55.1 | \[ \mathsf{expm1}\left(\mathsf{fma}\left(-0.0009765625, t \cdot \left(t \cdot \color{blue}{\left(b \cdot b\right)}\right), \log 2\right)\right) \cdot x
\] |
Final simplification43.8
| Alternative 1 | |
|---|---|
| Error | 44.4 |
| Cost | 64 |
herbie shell --seed 2023018
(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))))