
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-29) (not (<= x 4.2e-22))) (fma x (sin y) z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-29) || !(x <= 4.2e-22)) {
tmp = fma(x, sin(y), z);
} else {
tmp = z * cos(y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -9e-29) || !(x <= 4.2e-22)) tmp = fma(x, sin(y), z); else tmp = Float64(z * cos(y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-29], N[Not[LessEqual[x, 4.2e-22]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision] + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-29} \lor \neg \left(x \leq 4.2 \cdot 10^{-22}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -8.9999999999999996e-29 or 4.20000000000000016e-22 < x Initial program 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 86.1%
if -8.9999999999999996e-29 < x < 4.20000000000000016e-22Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.1%
associate-*l*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in z around inf 90.3%
pow-base-190.3%
*-commutative90.3%
*-lft-identity90.3%
Simplified90.3%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * 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 = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.4e-14) (not (<= x 3e-22))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.4e-14) || !(x <= 3e-22)) {
tmp = z + (x * sin(y));
} else {
tmp = z * 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 ((x <= (-4.4d-14)) .or. (.not. (x <= 3d-22))) then
tmp = z + (x * sin(y))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.4e-14) || !(x <= 3e-22)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.4e-14) or not (x <= 3e-22): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.4e-14) || !(x <= 3e-22)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.4e-14) || ~((x <= 3e-22))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.4e-14], N[Not[LessEqual[x, 3e-22]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{-14} \lor \neg \left(x \leq 3 \cdot 10^{-22}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -4.4000000000000002e-14 or 2.9999999999999999e-22 < x Initial program 99.8%
Taylor expanded in y around 0 86.1%
if -4.4000000000000002e-14 < x < 2.9999999999999999e-22Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.1%
associate-*l*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in z around inf 90.3%
pow-base-190.3%
*-commutative90.3%
*-lft-identity90.3%
Simplified90.3%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e-5) (not (<= y 0.00125))) (* z (cos y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e-5) || !(y <= 0.00125)) {
tmp = z * cos(y);
} else {
tmp = z + (x * 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 ((y <= (-7.5d-5)) .or. (.not. (y <= 0.00125d0))) then
tmp = z * cos(y)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e-5) || !(y <= 0.00125)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e-5) or not (y <= 0.00125): tmp = z * math.cos(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e-5) || !(y <= 0.00125)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.5e-5) || ~((y <= 0.00125))) tmp = z * cos(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e-5], N[Not[LessEqual[y, 0.00125]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-5} \lor \neg \left(y \leq 0.00125\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -7.49999999999999934e-5 or 0.00125000000000000003 < y Initial program 99.6%
+-commutative99.6%
*-commutative99.6%
add-cube-cbrt98.8%
associate-*l*98.8%
fma-def98.8%
pow298.8%
Applied egg-rr98.8%
Taylor expanded in z around inf 58.0%
pow-base-158.0%
*-commutative58.0%
*-lft-identity58.0%
Simplified58.0%
if -7.49999999999999934e-5 < y < 0.00125000000000000003Initial program 100.0%
Taylor expanded in y around 0 99.2%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.86e-140) (not (<= z 7.4e-126))) (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.86e-140) || !(z <= 7.4e-126)) {
tmp = z * cos(y);
} else {
tmp = x * sin(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.86d-140)) .or. (.not. (z <= 7.4d-126))) then
tmp = z * cos(y)
else
tmp = x * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.86e-140) || !(z <= 7.4e-126)) {
tmp = z * Math.cos(y);
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.86e-140) or not (z <= 7.4e-126): tmp = z * math.cos(y) else: tmp = x * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.86e-140) || !(z <= 7.4e-126)) tmp = Float64(z * cos(y)); else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.86e-140) || ~((z <= 7.4e-126))) tmp = z * cos(y); else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.86e-140], N[Not[LessEqual[z, 7.4e-126]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.86 \cdot 10^{-140} \lor \neg \left(z \leq 7.4 \cdot 10^{-126}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -1.86e-140 or 7.3999999999999998e-126 < z Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.2%
associate-*l*99.3%
fma-def99.3%
pow299.3%
Applied egg-rr99.3%
Taylor expanded in z around inf 82.2%
pow-base-182.2%
*-commutative82.2%
*-lft-identity82.2%
Simplified82.2%
if -1.86e-140 < z < 7.3999999999999998e-126Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.6%
associate-*l*99.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 72.2%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (<= x -2.8e+154) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e+154) {
tmp = x * y;
} else {
tmp = 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.8d+154)) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e+154) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.8e+154: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.8e+154) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.8e+154) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.8e+154], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{+154}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -2.7999999999999999e154Initial program 99.7%
Taylor expanded in y around 0 33.0%
Taylor expanded in y around inf 25.9%
if -2.7999999999999999e154 < x Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.3%
associate-*l*99.3%
fma-def99.3%
pow299.3%
Applied egg-rr99.3%
Taylor expanded in y around 0 45.9%
Final simplification43.6%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 48.9%
Final simplification48.9%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
add-cube-cbrt99.3%
associate-*l*99.3%
fma-def99.3%
pow299.3%
Applied egg-rr99.3%
Taylor expanded in y around 0 41.9%
Final simplification41.9%
herbie shell --seed 2023215
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))