
(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 8 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 -5.6e-33) (not (<= x 530000000000.0))) (fma x (sin y) z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-33) || !(x <= 530000000000.0)) {
tmp = fma(x, sin(y), z);
} else {
tmp = z * cos(y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e-33) || !(x <= 530000000000.0)) tmp = fma(x, sin(y), z); else tmp = Float64(z * cos(y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e-33], N[Not[LessEqual[x, 530000000000.0]], $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 -5.6 \cdot 10^{-33} \lor \neg \left(x \leq 530000000000\right):\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -5.6e-33 or 5.3e11 < x Initial program 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 89.7%
if -5.6e-33 < x < 5.3e11Initial program 99.8%
add-cube-cbrt99.6%
associate-*r*99.7%
fma-def99.7%
pow299.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 86.1%
Final simplification87.9%
(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 -1.06e-32) (not (<= x 530000000000.0))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.06e-32) || !(x <= 530000000000.0)) {
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 <= (-1.06d-32)) .or. (.not. (x <= 530000000000.0d0))) 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 <= -1.06e-32) || !(x <= 530000000000.0)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.06e-32) or not (x <= 530000000000.0): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.06e-32) || !(x <= 530000000000.0)) 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 <= -1.06e-32) || ~((x <= 530000000000.0))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.06e-32], N[Not[LessEqual[x, 530000000000.0]], $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 -1.06 \cdot 10^{-32} \lor \neg \left(x \leq 530000000000\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.05999999999999994e-32 or 5.3e11 < x Initial program 99.8%
Taylor expanded in y around 0 89.7%
if -1.05999999999999994e-32 < x < 5.3e11Initial program 99.8%
add-cube-cbrt99.6%
associate-*r*99.7%
fma-def99.7%
pow299.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 86.1%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1520.0) (not (<= y 0.0052))) (* z (cos y)) (+ (* -0.5 (* y (* y z))) (+ z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1520.0) || !(y <= 0.0052)) {
tmp = z * cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (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 <= (-1520.0d0)) .or. (.not. (y <= 0.0052d0))) then
tmp = z * cos(y)
else
tmp = ((-0.5d0) * (y * (y * z))) + (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1520.0) || !(y <= 0.0052)) {
tmp = z * Math.cos(y);
} else {
tmp = (-0.5 * (y * (y * z))) + (z + (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1520.0) or not (y <= 0.0052): tmp = z * math.cos(y) else: tmp = (-0.5 * (y * (y * z))) + (z + (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1520.0) || !(y <= 0.0052)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(y * Float64(y * z))) + Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1520.0) || ~((y <= 0.0052))) tmp = z * cos(y); else tmp = (-0.5 * (y * (y * z))) + (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1520.0], N[Not[LessEqual[y, 0.0052]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(y * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1520 \lor \neg \left(y \leq 0.0052\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \left(y \cdot z\right)\right) + \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -1520 or 0.0051999999999999998 < y Initial program 99.6%
add-cube-cbrt98.9%
associate-*r*98.9%
fma-def98.9%
pow298.9%
Applied egg-rr98.9%
Taylor expanded in x around 0 49.1%
if -1520 < y < 0.0051999999999999998Initial program 100.0%
Taylor expanded in y around 0 99.3%
expm1-log1p-u95.2%
expm1-udef95.2%
unpow295.2%
associate-*l*95.2%
Applied egg-rr95.2%
expm1-def95.2%
expm1-log1p99.3%
Simplified99.3%
Final simplification73.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-5) (not (<= x 1.08e+77))) (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-5) || !(x <= 1.08e+77)) {
tmp = 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 <= (-3.1d-5)) .or. (.not. (x <= 1.08d+77))) then
tmp = 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 <= -3.1e-5) || !(x <= 1.08e+77)) {
tmp = x * Math.sin(y);
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-5) or not (x <= 1.08e+77): tmp = x * math.sin(y) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-5) || !(x <= 1.08e+77)) tmp = 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 <= -3.1e-5) || ~((x <= 1.08e+77))) tmp = x * sin(y); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-5], N[Not[LessEqual[x, 1.08e+77]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-5} \lor \neg \left(x \leq 1.08 \cdot 10^{+77}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -3.10000000000000014e-5 or 1.07999999999999996e77 < x Initial program 99.8%
add-cube-cbrt98.6%
associate-*r*98.5%
fma-def98.5%
pow298.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 71.2%
pow-base-171.2%
*-lft-identity71.2%
Simplified71.2%
if -3.10000000000000014e-5 < x < 1.07999999999999996e77Initial program 99.8%
add-cube-cbrt99.6%
associate-*r*99.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 83.1%
Final simplification77.8%
(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 51.0%
Final simplification51.0%
(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%
add-cube-cbrt99.1%
associate-*r*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 37.4%
Final simplification37.4%
herbie shell --seed 2023255
(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))))