
(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 2 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)
(FPCore (x y z_m t a b)
:precision binary64
(*
x
(cos
(*
(+
(exp
(*
z_m
(+ 1.0 (+ (* 2.0 y) (* -0.5 (* z_m (pow (+ 1.0 (* 2.0 y)) 2.0)))))))
-1.0)
(/ t 16.0)))))z_m = fabs(z);
double code(double x, double y, double z_m, double t, double a, double b) {
return x * cos(((exp((z_m * (1.0 + ((2.0 * y) + (-0.5 * (z_m * pow((1.0 + (2.0 * y)), 2.0))))))) + -1.0) * (t / 16.0)));
}
z_m = abs(z)
real(8) function code(x, y, z_m, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x * cos(((exp((z_m * (1.0d0 + ((2.0d0 * y) + ((-0.5d0) * (z_m * ((1.0d0 + (2.0d0 * y)) ** 2.0d0))))))) + (-1.0d0)) * (t / 16.0d0)))
end function
z_m = Math.abs(z);
public static double code(double x, double y, double z_m, double t, double a, double b) {
return x * Math.cos(((Math.exp((z_m * (1.0 + ((2.0 * y) + (-0.5 * (z_m * Math.pow((1.0 + (2.0 * y)), 2.0))))))) + -1.0) * (t / 16.0)));
}
z_m = math.fabs(z) def code(x, y, z_m, t, a, b): return x * math.cos(((math.exp((z_m * (1.0 + ((2.0 * y) + (-0.5 * (z_m * math.pow((1.0 + (2.0 * y)), 2.0))))))) + -1.0) * (t / 16.0)))
z_m = abs(z) function code(x, y, z_m, t, a, b) return Float64(x * cos(Float64(Float64(exp(Float64(z_m * Float64(1.0 + Float64(Float64(2.0 * y) + Float64(-0.5 * Float64(z_m * (Float64(1.0 + Float64(2.0 * y)) ^ 2.0))))))) + -1.0) * Float64(t / 16.0)))) end
z_m = abs(z); function tmp = code(x, y, z_m, t, a, b) tmp = x * cos(((exp((z_m * (1.0 + ((2.0 * y) + (-0.5 * (z_m * ((1.0 + (2.0 * y)) ^ 2.0))))))) + -1.0) * (t / 16.0))); end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_, a_, b_] := N[(x * N[Cos[N[(N[(N[Exp[N[(z$95$m * N[(1.0 + N[(N[(2.0 * y), $MachinePrecision] + N[(-0.5 * N[(z$95$m * N[Power[N[(1.0 + N[(2.0 * y), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision] * N[(t / 16.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x \cdot \cos \left(\left(e^{z\_m \cdot \left(1 + \left(2 \cdot y + -0.5 \cdot \left(z\_m \cdot {\left(1 + 2 \cdot y\right)}^{2}\right)\right)\right)} + -1\right) \cdot \frac{t}{16}\right)
\end{array}
Initial program 24.5%
Simplified24.5%
Taylor expanded in b around 0 26.8%
expm1-log1p-u22.1%
expm1-undefine22.1%
Applied egg-rr22.1%
Taylor expanded in z around 0 28.8%
Final simplification28.8%
z_m = (fabs.f64 z) (FPCore (x y z_m t a b) :precision binary64 x)
z_m = fabs(z);
double code(double x, double y, double z_m, double t, double a, double b) {
return x;
}
z_m = abs(z)
real(8) function code(x, y, z_m, t, a, b)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z_m
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
code = x
end function
z_m = Math.abs(z);
public static double code(double x, double y, double z_m, double t, double a, double b) {
return x;
}
z_m = math.fabs(z) def code(x, y, z_m, t, a, b): return x
z_m = abs(z) function code(x, y, z_m, t, a, b) return x end
z_m = abs(z); function tmp = code(x, y, z_m, t, a, b) tmp = x; end
z_m = N[Abs[z], $MachinePrecision] code[x_, y_, z$95$m_, t_, a_, b_] := x
\begin{array}{l}
z_m = \left|z\right|
\\
x
\end{array}
Initial program 24.5%
Simplified24.5%
Taylor expanded in b around 0 26.8%
Taylor expanded in z around 0 28.2%
Final simplification28.2%
(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 2024130
(FPCore (x y z t a b)
:name "Codec.Picture.Jpg.FastDct:referenceDct from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(* 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))))