
(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 7 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 (+ (* 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 -5.2e-110) (not (<= x 1.6e-92))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e-110) || !(x <= 1.6e-92)) {
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 <= (-5.2d-110)) .or. (.not. (x <= 1.6d-92))) 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 <= -5.2e-110) || !(x <= 1.6e-92)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.2e-110) or not (x <= 1.6e-92): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.2e-110) || !(x <= 1.6e-92)) 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 <= -5.2e-110) || ~((x <= 1.6e-92))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.2e-110], N[Not[LessEqual[x, 1.6e-92]], $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 -5.2 \cdot 10^{-110} \lor \neg \left(x \leq 1.6 \cdot 10^{-92}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -5.19999999999999979e-110 or 1.5999999999999998e-92 < x Initial program 99.8%
Taylor expanded in y around 0 83.5%
if -5.19999999999999979e-110 < x < 1.5999999999999998e-92Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 91.9%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0065) (not (<= y 0.011))) (* z (cos y)) (+ (* -0.5 (* z (* y y))) (+ z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0065) || !(y <= 0.011)) {
tmp = z * cos(y);
} else {
tmp = (-0.5 * (z * (y * y))) + (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 <= (-0.0065d0)) .or. (.not. (y <= 0.011d0))) then
tmp = z * cos(y)
else
tmp = ((-0.5d0) * (z * (y * y))) + (z + (x * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0065) || !(y <= 0.011)) {
tmp = z * Math.cos(y);
} else {
tmp = (-0.5 * (z * (y * y))) + (z + (x * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0065) or not (y <= 0.011): tmp = z * math.cos(y) else: tmp = (-0.5 * (z * (y * y))) + (z + (x * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0065) || !(y <= 0.011)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(z * Float64(y * y))) + Float64(z + Float64(x * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0065) || ~((y <= 0.011))) tmp = z * cos(y); else tmp = (-0.5 * (z * (y * y))) + (z + (x * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0065], N[Not[LessEqual[y, 0.011]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(z * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0065 \lor \neg \left(y \leq 0.011\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(z \cdot \left(y \cdot y\right)\right) + \left(z + x \cdot y\right)\\
\end{array}
\end{array}
if y < -0.0064999999999999997 or 0.010999999999999999 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around inf 54.4%
if -0.0064999999999999997 < y < 0.010999999999999999Initial program 100.0%
Taylor expanded in y around 0 100.0%
expm1-log1p-u89.3%
expm1-udef89.3%
unpow289.3%
associate-*l*89.3%
Applied egg-rr89.3%
expm1-def89.3%
expm1-log1p100.0%
*-commutative100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.9e+141) (not (<= x 1.55e+122))) (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.9e+141) || !(x <= 1.55e+122)) {
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 <= (-5.9d+141)) .or. (.not. (x <= 1.55d+122))) 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 <= -5.9e+141) || !(x <= 1.55e+122)) {
tmp = x * Math.sin(y);
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.9e+141) or not (x <= 1.55e+122): tmp = x * math.sin(y) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.9e+141) || !(x <= 1.55e+122)) 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 <= -5.9e+141) || ~((x <= 1.55e+122))) tmp = x * sin(y); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.9e+141], N[Not[LessEqual[x, 1.55e+122]], $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 -5.9 \cdot 10^{+141} \lor \neg \left(x \leq 1.55 \cdot 10^{+122}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -5.90000000000000029e141 or 1.54999999999999999e122 < x Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around 0 78.5%
if -5.90000000000000029e141 < x < 1.54999999999999999e122Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 78.1%
Final simplification78.2%
(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.8%
Final simplification51.8%
(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%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 39.9%
Final simplification39.9%
herbie shell --seed 2023229
(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))))