
(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.8%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
(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.8%
fma-define99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) + (sin(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 * cos(y)) + (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) + (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) z)))
(if (<= z -1.9e+164)
t_0
(if (or (<= z -2e-34) (not (<= z 1.4e-11)))
(* x (+ 1.0 (/ t_0 x)))
(* x (cos y))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double tmp;
if (z <= -1.9e+164) {
tmp = t_0;
} else if ((z <= -2e-34) || !(z <= 1.4e-11)) {
tmp = x * (1.0 + (t_0 / x));
} else {
tmp = x * cos(y);
}
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 = sin(y) * z
if (z <= (-1.9d+164)) then
tmp = t_0
else if ((z <= (-2d-34)) .or. (.not. (z <= 1.4d-11))) then
tmp = x * (1.0d0 + (t_0 / x))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) * z;
double tmp;
if (z <= -1.9e+164) {
tmp = t_0;
} else if ((z <= -2e-34) || !(z <= 1.4e-11)) {
tmp = x * (1.0 + (t_0 / x));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * z tmp = 0 if z <= -1.9e+164: tmp = t_0 elif (z <= -2e-34) or not (z <= 1.4e-11): tmp = x * (1.0 + (t_0 / x)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) t_0 = Float64(sin(y) * z) tmp = 0.0 if (z <= -1.9e+164) tmp = t_0; elseif ((z <= -2e-34) || !(z <= 1.4e-11)) tmp = Float64(x * Float64(1.0 + Float64(t_0 / x))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * z; tmp = 0.0; if (z <= -1.9e+164) tmp = t_0; elseif ((z <= -2e-34) || ~((z <= 1.4e-11))) tmp = x * (1.0 + (t_0 / x)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.9e+164], t$95$0, If[Or[LessEqual[z, -2e-34], N[Not[LessEqual[z, 1.4e-11]], $MachinePrecision]], N[(x * N[(1.0 + N[(t$95$0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
\mathbf{if}\;z \leq -1.9 \cdot 10^{+164}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2 \cdot 10^{-34} \lor \neg \left(z \leq 1.4 \cdot 10^{-11}\right):\\
\;\;\;\;x \cdot \left(1 + \frac{t\_0}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.90000000000000011e164Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 81.8%
if -1.90000000000000011e164 < z < -1.99999999999999986e-34 or 1.4e-11 < z Initial program 99.8%
add-cube-cbrt98.7%
pow398.7%
Applied egg-rr98.7%
Taylor expanded in y around 0 90.1%
Taylor expanded in x around inf 82.5%
if -1.99999999999999986e-34 < z < 1.4e-11Initial program 99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 92.3%
Final simplification87.2%
(FPCore (x y z)
:precision binary64
(if (<= z -1.85e+164)
(* (sin y) z)
(if (or (<= z -3.6e-33) (not (<= z 9.5e-12)))
(* x (+ 1.0 (* z (/ (sin y) x))))
(* x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.85e+164) {
tmp = sin(y) * z;
} else if ((z <= -3.6e-33) || !(z <= 9.5e-12)) {
tmp = x * (1.0 + (z * (sin(y) / x)));
} else {
tmp = x * cos(y);
}
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 (z <= (-1.85d+164)) then
tmp = sin(y) * z
else if ((z <= (-3.6d-33)) .or. (.not. (z <= 9.5d-12))) then
tmp = x * (1.0d0 + (z * (sin(y) / x)))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.85e+164) {
tmp = Math.sin(y) * z;
} else if ((z <= -3.6e-33) || !(z <= 9.5e-12)) {
tmp = x * (1.0 + (z * (Math.sin(y) / x)));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.85e+164: tmp = math.sin(y) * z elif (z <= -3.6e-33) or not (z <= 9.5e-12): tmp = x * (1.0 + (z * (math.sin(y) / x))) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.85e+164) tmp = Float64(sin(y) * z); elseif ((z <= -3.6e-33) || !(z <= 9.5e-12)) tmp = Float64(x * Float64(1.0 + Float64(z * Float64(sin(y) / x)))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.85e+164) tmp = sin(y) * z; elseif ((z <= -3.6e-33) || ~((z <= 9.5e-12))) tmp = x * (1.0 + (z * (sin(y) / x))); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.85e+164], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], If[Or[LessEqual[z, -3.6e-33], N[Not[LessEqual[z, 9.5e-12]], $MachinePrecision]], N[(x * N[(1.0 + N[(z * N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+164}:\\
\;\;\;\;\sin y \cdot z\\
\mathbf{elif}\;z \leq -3.6 \cdot 10^{-33} \lor \neg \left(z \leq 9.5 \cdot 10^{-12}\right):\\
\;\;\;\;x \cdot \left(1 + z \cdot \frac{\sin y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.85e164Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 81.8%
if -1.85e164 < z < -3.60000000000000034e-33 or 9.4999999999999995e-12 < z Initial program 99.8%
add-cube-cbrt98.7%
pow398.7%
Applied egg-rr98.7%
Taylor expanded in y around 0 90.1%
Taylor expanded in x around inf 82.5%
associate-/l*82.3%
Simplified82.3%
if -3.60000000000000034e-33 < z < 9.4999999999999995e-12Initial program 99.8%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 92.3%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -94000.0) (not (<= z 3.8e+50))) (* (sin y) z) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -94000.0) || !(z <= 3.8e+50)) {
tmp = sin(y) * z;
} else {
tmp = x * cos(y);
}
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 ((z <= (-94000.0d0)) .or. (.not. (z <= 3.8d+50))) then
tmp = sin(y) * z
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -94000.0) || !(z <= 3.8e+50)) {
tmp = Math.sin(y) * z;
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -94000.0) or not (z <= 3.8e+50): tmp = math.sin(y) * z else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -94000.0) || !(z <= 3.8e+50)) tmp = Float64(sin(y) * z); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -94000.0) || ~((z <= 3.8e+50))) tmp = sin(y) * z; else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -94000.0], N[Not[LessEqual[z, 3.8e+50]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -94000 \lor \neg \left(z \leq 3.8 \cdot 10^{+50}\right):\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -94000 or 3.79999999999999987e50 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 70.0%
if -94000 < z < 3.79999999999999987e50Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 89.3%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.24) (not (<= y 0.00041))) (* x (cos y)) (+ x (* y (+ z (* y (+ (* x -0.5) (* -0.16666666666666666 (* y z)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.24) || !(y <= 0.00041)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (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.24d0)) .or. (.not. (y <= 0.00041d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (y * ((x * (-0.5d0)) + ((-0.16666666666666666d0) * (y * z))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.24) || !(y <= 0.00041)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (y * z))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.24) or not (y <= 0.00041): tmp = x * math.cos(y) else: tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (y * z)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.24) || !(y <= 0.00041)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(Float64(x * -0.5) + Float64(-0.16666666666666666 * Float64(y * z))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.24) || ~((y <= 0.00041))) tmp = x * cos(y); else tmp = x + (y * (z + (y * ((x * -0.5) + (-0.16666666666666666 * (y * z)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.24], N[Not[LessEqual[y, 0.00041]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.24 \lor \neg \left(y \leq 0.00041\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5 + -0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.23999999999999999 or 4.0999999999999999e-4 < y Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 55.0%
if -0.23999999999999999 < y < 4.0999999999999999e-4Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
Final simplification77.7%
(FPCore (x y z) :precision binary64 (if (<= x -5e-207) x (if (<= x 1.8e-210) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -5e-207) {
tmp = x;
} else if (x <= 1.8e-210) {
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 <= (-5d-207)) then
tmp = x
else if (x <= 1.8d-210) 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 <= -5e-207) {
tmp = x;
} else if (x <= 1.8e-210) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5e-207: tmp = x elif x <= 1.8e-210: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5e-207) tmp = x; elseif (x <= 1.8e-210) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5e-207) tmp = x; elseif (x <= 1.8e-210) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5e-207], x, If[LessEqual[x, 1.8e-210], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-207}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-210}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -5.00000000000000014e-207 or 1.7999999999999999e-210 < x Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 43.6%
if -5.00000000000000014e-207 < x < 1.7999999999999999e-210Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 55.0%
Taylor expanded in x around 0 45.3%
(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.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 53.9%
(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.8%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 39.5%
herbie shell --seed 2024148
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))