
(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))))
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));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (x * cos((((((y * 2.0d0) + 1.0d0) * z) * t) / 16.0d0))) * cos((((((a * 2.0d0) + 1.0d0) * b) * t) / 16.0d0))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (x * Math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * Math.cos((((((a * 2.0) + 1.0) * b) * t) / 16.0));
}
def code(x, y, z, t, a, b): return (x * math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * math.cos((((((a * 2.0) + 1.0) * b) * t) / 16.0))
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 tmp = code(x, y, z, t, a, b) tmp = (x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos((((((a * 2.0) + 1.0) * b) * t) / 16.0)); 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]
\begin{array}{l}
\\
\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)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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))))
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));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (x * cos((((((y * 2.0d0) + 1.0d0) * z) * t) / 16.0d0))) * cos((((((a * 2.0d0) + 1.0d0) * b) * t) / 16.0d0))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return (x * Math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * Math.cos((((((a * 2.0) + 1.0) * b) * t) / 16.0));
}
def code(x, y, z, t, a, b): return (x * math.cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * math.cos((((((a * 2.0) + 1.0) * b) * t) / 16.0))
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 tmp = code(x, y, z, t, a, b) tmp = (x * cos((((((y * 2.0) + 1.0) * z) * t) / 16.0))) * cos((((((a * 2.0) + 1.0) * b) * t) / 16.0)); 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]
\begin{array}{l}
\\
\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)
\end{array}
z_m = (fabs.f64 z)
t_m = (fabs.f64 t)
(FPCore (x y z_m t_m a b)
:precision binary64
(let* ((t_1 (log (/ (/ 16.0 z_m) t_m))))
(*
x
(cos
(/ (fma y 2.0 1.0) (exp (fabs (* (cbrt (pow t_1 2.0)) (cbrt t_1)))))))))z_m = fabs(z);
t_m = fabs(t);
double code(double x, double y, double z_m, double t_m, double a, double b) {
double t_1 = log(((16.0 / z_m) / t_m));
return x * cos((fma(y, 2.0, 1.0) / exp(fabs((cbrt(pow(t_1, 2.0)) * cbrt(t_1))))));
}
z_m = abs(z) t_m = abs(t) function code(x, y, z_m, t_m, a, b) t_1 = log(Float64(Float64(16.0 / z_m) / t_m)) return Float64(x * cos(Float64(fma(y, 2.0, 1.0) / exp(abs(Float64(cbrt((t_1 ^ 2.0)) * cbrt(t_1))))))) end
z_m = N[Abs[z], $MachinePrecision]
t_m = N[Abs[t], $MachinePrecision]
code[x_, y_, z$95$m_, t$95$m_, a_, b_] := Block[{t$95$1 = N[Log[N[(N[(16.0 / z$95$m), $MachinePrecision] / t$95$m), $MachinePrecision]], $MachinePrecision]}, N[(x * N[Cos[N[(N[(y * 2.0 + 1.0), $MachinePrecision] / N[Exp[N[Abs[N[(N[Power[N[Power[t$95$1, 2.0], $MachinePrecision], 1/3], $MachinePrecision] * N[Power[t$95$1, 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
z_m = \left|z\right|
\\
t_m = \left|t\right|
\\
\begin{array}{l}
t_1 := \log \left(\frac{\frac{16}{z_m}}{t_m}\right)\\
x \cdot \cos \left(\frac{\mathsf{fma}\left(y, 2, 1\right)}{e^{\left|\sqrt[3]{{t_1}^{2}} \cdot \sqrt[3]{t_1}\right|}}\right)
\end{array}
\end{array}
Initial program 27.8%
Simplified29.0%
Taylor expanded in t around 0 30.6%
add-exp-log14.2%
associate-/l/14.2%
*-commutative14.2%
Applied egg-rr14.2%
add-sqr-sqrt12.8%
sqrt-unprod16.2%
pow216.2%
associate-/r*16.1%
Applied egg-rr16.1%
unpow216.1%
rem-sqrt-square16.1%
Simplified16.1%
diff-log7.0%
add-sqr-sqrt5.7%
fabs-sqr5.7%
add-sqr-sqrt7.0%
add-cbrt-cube7.0%
cbrt-prod7.1%
sqr-abs7.1%
pow27.1%
diff-log7.1%
associate-/r*7.1%
add-sqr-sqrt5.6%
Applied egg-rr16.5%
associate-/l/16.4%
associate-/l/16.4%
Simplified16.4%
Final simplification16.4%
z_m = (fabs.f64 z) t_m = (fabs.f64 t) (FPCore (x y z_m t_m a b) :precision binary64 (* x (cos (/ (* y 2.0) (exp (fabs (log (/ 16.0 (* z_m t_m)))))))))
z_m = fabs(z);
t_m = fabs(t);
double code(double x, double y, double z_m, double t_m, double a, double b) {
return x * cos(((y * 2.0) / exp(fabs(log((16.0 / (z_m * t_m)))))));
}
z_m = abs(z)
t_m = abs(t)
real(8) function code(x, y, z_m, t_m, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t_m
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x * cos(((y * 2.0d0) / exp(abs(log((16.0d0 / (z_m * t_m)))))))
end function
z_m = Math.abs(z);
t_m = Math.abs(t);
public static double code(double x, double y, double z_m, double t_m, double a, double b) {
return x * Math.cos(((y * 2.0) / Math.exp(Math.abs(Math.log((16.0 / (z_m * t_m)))))));
}
z_m = math.fabs(z) t_m = math.fabs(t) def code(x, y, z_m, t_m, a, b): return x * math.cos(((y * 2.0) / math.exp(math.fabs(math.log((16.0 / (z_m * t_m)))))))
z_m = abs(z) t_m = abs(t) function code(x, y, z_m, t_m, a, b) return Float64(x * cos(Float64(Float64(y * 2.0) / exp(abs(log(Float64(16.0 / Float64(z_m * t_m)))))))) end
z_m = abs(z); t_m = abs(t); function tmp = code(x, y, z_m, t_m, a, b) tmp = x * cos(((y * 2.0) / exp(abs(log((16.0 / (z_m * t_m))))))); end
z_m = N[Abs[z], $MachinePrecision] t_m = N[Abs[t], $MachinePrecision] code[x_, y_, z$95$m_, t$95$m_, a_, b_] := N[(x * N[Cos[N[(N[(y * 2.0), $MachinePrecision] / N[Exp[N[Abs[N[Log[N[(16.0 / N[(z$95$m * t$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
t_m = \left|t\right|
\\
x \cdot \cos \left(\frac{y \cdot 2}{e^{\left|\log \left(\frac{16}{z_m \cdot t_m}\right)\right|}}\right)
\end{array}
Initial program 27.8%
Simplified29.0%
Taylor expanded in t around 0 30.6%
add-exp-log14.2%
associate-/l/14.2%
*-commutative14.2%
Applied egg-rr14.2%
add-sqr-sqrt12.8%
sqrt-unprod16.2%
pow216.2%
associate-/r*16.1%
Applied egg-rr16.1%
unpow216.1%
rem-sqrt-square16.1%
Simplified16.1%
Taylor expanded in y around inf 16.2%
associate-*r/16.2%
rem-square-sqrt12.8%
fabs-sqr12.8%
rem-square-sqrt14.3%
associate-/r*14.4%
log-div6.4%
*-commutative6.4%
log-div14.4%
associate-/r*14.3%
rem-square-sqrt12.8%
fabs-sqr12.8%
rem-square-sqrt16.2%
*-commutative16.2%
Simplified16.2%
Final simplification16.2%
z_m = (fabs.f64 z) t_m = (fabs.f64 t) (FPCore (x y z_m t_m a b) :precision binary64 x)
z_m = fabs(z);
t_m = fabs(t);
double code(double x, double y, double z_m, double t_m, double a, double b) {
return x;
}
z_m = abs(z)
t_m = abs(t)
real(8) function code(x, y, z_m, t_m, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t_m
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x
end function
z_m = Math.abs(z);
t_m = Math.abs(t);
public static double code(double x, double y, double z_m, double t_m, double a, double b) {
return x;
}
z_m = math.fabs(z) t_m = math.fabs(t) def code(x, y, z_m, t_m, a, b): return x
z_m = abs(z) t_m = abs(t) function code(x, y, z_m, t_m, a, b) return x end
z_m = abs(z); t_m = abs(t); function tmp = code(x, y, z_m, t_m, a, b) tmp = x; end
z_m = N[Abs[z], $MachinePrecision] t_m = N[Abs[t], $MachinePrecision] code[x_, y_, z$95$m_, t$95$m_, a_, b_] := x
\begin{array}{l}
z_m = \left|z\right|
\\
t_m = \left|t\right|
\\
x
\end{array}
Initial program 27.8%
Taylor expanded in y around 0 27.6%
Taylor expanded in t around 0 31.4%
Final simplification31.4%
(FPCore (x y z t a b) :precision binary64 (* x (cos (* (/ b 16.0) (/ t (+ (- 1.0 (* a 2.0)) (pow (* a 2.0) 2.0)))))))
double code(double x, double y, double z, double t, double a, double b) {
return x * cos(((b / 16.0) * (t / ((1.0 - (a * 2.0)) + pow((a * 2.0), 2.0)))));
}
real(8) function code(x, y, z, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x * cos(((b / 16.0d0) * (t / ((1.0d0 - (a * 2.0d0)) + ((a * 2.0d0) ** 2.0d0)))))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
return x * Math.cos(((b / 16.0) * (t / ((1.0 - (a * 2.0)) + Math.pow((a * 2.0), 2.0)))));
}
def code(x, y, z, t, a, b): return x * math.cos(((b / 16.0) * (t / ((1.0 - (a * 2.0)) + math.pow((a * 2.0), 2.0)))))
function code(x, y, z, t, a, b) return Float64(x * cos(Float64(Float64(b / 16.0) * Float64(t / Float64(Float64(1.0 - Float64(a * 2.0)) + (Float64(a * 2.0) ^ 2.0)))))) end
function tmp = code(x, y, z, t, a, b) tmp = x * cos(((b / 16.0) * (t / ((1.0 - (a * 2.0)) + ((a * 2.0) ^ 2.0))))); end
code[x_, y_, z_, t_, a_, b_] := N[(x * N[Cos[N[(N[(b / 16.0), $MachinePrecision] * N[(t / N[(N[(1.0 - N[(a * 2.0), $MachinePrecision]), $MachinePrecision] + N[Power[N[(a * 2.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos \left(\frac{b}{16} \cdot \frac{t}{\left(1 - a \cdot 2\right) + {\left(a \cdot 2\right)}^{2}}\right)
\end{array}
herbie shell --seed 2024012
(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))))