
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) z (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), z, Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * z + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (fma x (cos y) (* (sin y) z)))
double code(double x, double y, double z) {
return fma(x, cos(y), (sin(y) * z));
}
function code(x, y, z) return fma(x, cos(y), Float64(sin(y) * z)) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, \sin y \cdot z\right)
\end{array}
Initial program 99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (* (sin y) z) (* x (cos y))))
double code(double x, double y, double z) {
return (sin(y) * z) + (x * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (sin(y) * z) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (Math.sin(y) * z) + (x * Math.cos(y));
}
def code(x, y, z): return (math.sin(y) * z) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(sin(y) * z) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (sin(y) * z) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin y \cdot z + x \cdot \cos y
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -4.6e+113)
t_0
(if (<= y -2.7e+56)
(* (sin y) z)
(if (or (<= y -2.3e-6) (not (<= y 1e-15))) t_0 (+ x (* y z)))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -4.6e+113) {
tmp = t_0;
} else if (y <= -2.7e+56) {
tmp = sin(y) * z;
} else if ((y <= -2.3e-6) || !(y <= 1e-15)) {
tmp = t_0;
} else {
tmp = x + (y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (y <= (-4.6d+113)) then
tmp = t_0
else if (y <= (-2.7d+56)) then
tmp = sin(y) * z
else if ((y <= (-2.3d-6)) .or. (.not. (y <= 1d-15))) then
tmp = t_0
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (y <= -4.6e+113) {
tmp = t_0;
} else if (y <= -2.7e+56) {
tmp = Math.sin(y) * z;
} else if ((y <= -2.3e-6) || !(y <= 1e-15)) {
tmp = t_0;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -4.6e+113: tmp = t_0 elif y <= -2.7e+56: tmp = math.sin(y) * z elif (y <= -2.3e-6) or not (y <= 1e-15): tmp = t_0 else: tmp = x + (y * z) return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -4.6e+113) tmp = t_0; elseif (y <= -2.7e+56) tmp = Float64(sin(y) * z); elseif ((y <= -2.3e-6) || !(y <= 1e-15)) tmp = t_0; else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -4.6e+113) tmp = t_0; elseif (y <= -2.7e+56) tmp = sin(y) * z; elseif ((y <= -2.3e-6) || ~((y <= 1e-15))) tmp = t_0; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.6e+113], t$95$0, If[LessEqual[y, -2.7e+56], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], If[Or[LessEqual[y, -2.3e-6], N[Not[LessEqual[y, 1e-15]], $MachinePrecision]], t$95$0, N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -4.6 \cdot 10^{+113}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{+56}:\\
\;\;\;\;\sin y \cdot z\\
\mathbf{elif}\;y \leq -2.3 \cdot 10^{-6} \lor \neg \left(y \leq 10^{-15}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -4.59999999999999993e113 or -2.7000000000000001e56 < y < -2.3e-6 or 1.0000000000000001e-15 < y Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 65.2%
if -4.59999999999999993e113 < y < -2.7000000000000001e56Initial program 99.7%
Taylor expanded in x around 0 75.9%
if -2.3e-6 < y < 1.0000000000000001e-15Initial program 100.0%
Taylor expanded in y around 0 99.8%
Final simplification83.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -1e+113)
t_0
(if (<= y -8e+55)
(* (sin y) z)
(if (or (<= y -2.3e-6) (not (<= y 1e-15))) t_0 (fma y z x))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -1e+113) {
tmp = t_0;
} else if (y <= -8e+55) {
tmp = sin(y) * z;
} else if ((y <= -2.3e-6) || !(y <= 1e-15)) {
tmp = t_0;
} else {
tmp = fma(y, z, x);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1e+113) tmp = t_0; elseif (y <= -8e+55) tmp = Float64(sin(y) * z); elseif ((y <= -2.3e-6) || !(y <= 1e-15)) tmp = t_0; else tmp = fma(y, z, x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1e+113], t$95$0, If[LessEqual[y, -8e+55], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], If[Or[LessEqual[y, -2.3e-6], N[Not[LessEqual[y, 1e-15]], $MachinePrecision]], t$95$0, N[(y * z + x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1 \cdot 10^{+113}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -8 \cdot 10^{+55}:\\
\;\;\;\;\sin y \cdot z\\
\mathbf{elif}\;y \leq -2.3 \cdot 10^{-6} \lor \neg \left(y \leq 10^{-15}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\end{array}
\end{array}
if y < -1e113 or -8.00000000000000008e55 < y < -2.3e-6 or 1.0000000000000001e-15 < y Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 65.2%
if -1e113 < y < -8.00000000000000008e55Initial program 99.7%
Taylor expanded in x around 0 75.9%
if -2.3e-6 < y < 1.0000000000000001e-15Initial program 100.0%
Taylor expanded in y around 0 99.8%
fma-def99.9%
Simplified99.9%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e+16) (not (<= x 4.8e+53))) (* x (cos y)) (+ x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e+16) || !(x <= 4.8e+53)) {
tmp = x * cos(y);
} else {
tmp = x + (sin(y) * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-2.4d+16)) .or. (.not. (x <= 4.8d+53))) then
tmp = x * cos(y)
else
tmp = x + (sin(y) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e+16) || !(x <= 4.8e+53)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e+16) or not (x <= 4.8e+53): tmp = x * math.cos(y) else: tmp = x + (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e+16) || !(x <= 4.8e+53)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(sin(y) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.4e+16) || ~((x <= 4.8e+53))) tmp = x * cos(y); else tmp = x + (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e+16], N[Not[LessEqual[x, 4.8e+53]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+16} \lor \neg \left(x \leq 4.8 \cdot 10^{+53}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y \cdot z\\
\end{array}
\end{array}
if x < -2.4e16 or 4.8e53 < x Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in z around 0 90.5%
if -2.4e16 < x < 4.8e53Initial program 99.9%
Taylor expanded in y around 0 89.6%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00125) (not (<= y 0.0017))) (* (sin y) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00125) || !(y <= 0.0017)) {
tmp = sin(y) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-0.00125d0)) .or. (.not. (y <= 0.0017d0))) then
tmp = sin(y) * z
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00125) || !(y <= 0.0017)) {
tmp = Math.sin(y) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00125) or not (y <= 0.0017): tmp = math.sin(y) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00125) || !(y <= 0.0017)) tmp = Float64(sin(y) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00125) || ~((y <= 0.0017))) tmp = sin(y) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00125], N[Not[LessEqual[y, 0.0017]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00125 \lor \neg \left(y \leq 0.0017\right):\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -0.00125000000000000003 or 0.00169999999999999991 < y Initial program 99.7%
Taylor expanded in x around 0 41.3%
if -0.00125000000000000003 < y < 0.00169999999999999991Initial program 100.0%
Taylor expanded in y around 0 99.3%
Final simplification73.1%
(FPCore (x y z)
:precision binary64
(if (<= x -1.22e-197)
x
(if (<= x 2.75e-247)
(* y z)
(if (<= x 2.8e-108) x (if (<= x 1.7e-52) (* y z) x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.22e-197) {
tmp = x;
} else if (x <= 2.75e-247) {
tmp = y * z;
} else if (x <= 2.8e-108) {
tmp = x;
} else if (x <= 1.7e-52) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-1.22d-197)) then
tmp = x
else if (x <= 2.75d-247) then
tmp = y * z
else if (x <= 2.8d-108) then
tmp = x
else if (x <= 1.7d-52) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.22e-197) {
tmp = x;
} else if (x <= 2.75e-247) {
tmp = y * z;
} else if (x <= 2.8e-108) {
tmp = x;
} else if (x <= 1.7e-52) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.22e-197: tmp = x elif x <= 2.75e-247: tmp = y * z elif x <= 2.8e-108: tmp = x elif x <= 1.7e-52: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.22e-197) tmp = x; elseif (x <= 2.75e-247) tmp = Float64(y * z); elseif (x <= 2.8e-108) tmp = x; elseif (x <= 1.7e-52) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.22e-197) tmp = x; elseif (x <= 2.75e-247) tmp = y * z; elseif (x <= 2.8e-108) tmp = x; elseif (x <= 1.7e-52) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.22e-197], x, If[LessEqual[x, 2.75e-247], N[(y * z), $MachinePrecision], If[LessEqual[x, 2.8e-108], x, If[LessEqual[x, 1.7e-52], N[(y * z), $MachinePrecision], x]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.22 \cdot 10^{-197}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.75 \cdot 10^{-247}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-108}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-52}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.22e-197 or 2.74999999999999997e-247 < x < 2.8e-108 or 1.70000000000000009e-52 < x Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 47.6%
if -1.22e-197 < x < 2.74999999999999997e-247 or 2.8e-108 < x < 1.70000000000000009e-52Initial program 100.0%
Taylor expanded in y around 0 75.7%
Taylor expanded in y around inf 57.4%
Final simplification49.2%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return x + (y * z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 57.6%
Final simplification57.6%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 43.6%
Final simplification43.6%
herbie shell --seed 2023238
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))