
(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 8 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 x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (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 = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.35e-25) (not (<= z 1.55e-25))) (+ x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.35e-25) || !(z <= 1.55e-25)) {
tmp = x + (z * sin(y));
} 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.35d-25)) .or. (.not. (z <= 1.55d-25))) then
tmp = x + (z * sin(y))
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.35e-25) || !(z <= 1.55e-25)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.35e-25) or not (z <= 1.55e-25): tmp = x + (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.35e-25) || !(z <= 1.55e-25)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.35e-25) || ~((z <= 1.55e-25))) tmp = x + (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.35e-25], N[Not[LessEqual[z, 1.55e-25]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{-25} \lor \neg \left(z \leq 1.55 \cdot 10^{-25}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.35000000000000008e-25 or 1.54999999999999997e-25 < z Initial program 99.8%
Taylor expanded in y around 0 94.6%
if -1.35000000000000008e-25 < z < 1.54999999999999997e-25Initial program 99.8%
+-commutative99.8%
add-sqr-sqrt52.4%
associate-*r*52.4%
fma-def52.4%
Applied egg-rr52.4%
Taylor expanded in z around 0 86.1%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.5e-6) (not (<= y 0.0095))) (* z (sin y)) (+ (* y z) (* x (+ (* (* y y) -0.5) 1.0)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-6) || !(y <= 0.0095)) {
tmp = z * sin(y);
} else {
tmp = (y * z) + (x * (((y * y) * -0.5) + 1.0));
}
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 <= (-6.5d-6)) .or. (.not. (y <= 0.0095d0))) then
tmp = z * sin(y)
else
tmp = (y * z) + (x * (((y * y) * (-0.5d0)) + 1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.5e-6) || !(y <= 0.0095)) {
tmp = z * Math.sin(y);
} else {
tmp = (y * z) + (x * (((y * y) * -0.5) + 1.0));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.5e-6) or not (y <= 0.0095): tmp = z * math.sin(y) else: tmp = (y * z) + (x * (((y * y) * -0.5) + 1.0)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.5e-6) || !(y <= 0.0095)) tmp = Float64(z * sin(y)); else tmp = Float64(Float64(y * z) + Float64(x * Float64(Float64(Float64(y * y) * -0.5) + 1.0))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.5e-6) || ~((y <= 0.0095))) tmp = z * sin(y); else tmp = (y * z) + (x * (((y * y) * -0.5) + 1.0)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.5e-6], N[Not[LessEqual[y, 0.0095]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] + N[(x * N[(N[(N[(y * y), $MachinePrecision] * -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-6} \lor \neg \left(y \leq 0.0095\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z + x \cdot \left(\left(y \cdot y\right) \cdot -0.5 + 1\right)\\
\end{array}
\end{array}
if y < -6.4999999999999996e-6 or 0.00949999999999999976 < y Initial program 99.6%
Taylor expanded in x around 0 60.0%
if -6.4999999999999996e-6 < y < 0.00949999999999999976Initial program 100.0%
Taylor expanded in y around 0 99.5%
associate-*r*99.5%
distribute-lft1-in99.5%
*-commutative99.5%
unpow299.5%
Applied egg-rr99.5%
Final simplification80.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.2e+137) (not (<= z 4.8e-5))) (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+137) || !(z <= 4.8e-5)) {
tmp = z * sin(y);
} 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 <= (-2.2d+137)) .or. (.not. (z <= 4.8d-5))) then
tmp = z * sin(y)
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 <= -2.2e+137) || !(z <= 4.8e-5)) {
tmp = z * Math.sin(y);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.2e+137) or not (z <= 4.8e-5): tmp = z * math.sin(y) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+137) || !(z <= 4.8e-5)) tmp = Float64(z * sin(y)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.2e+137) || ~((z <= 4.8e-5))) tmp = z * sin(y); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+137], N[Not[LessEqual[z, 4.8e-5]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.2 \cdot 10^{+137} \lor \neg \left(z \leq 4.8 \cdot 10^{-5}\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -2.20000000000000015e137 or 4.8000000000000001e-5 < z Initial program 99.8%
Taylor expanded in x around 0 79.7%
if -2.20000000000000015e137 < z < 4.8000000000000001e-5Initial program 99.8%
+-commutative99.8%
add-sqr-sqrt54.7%
associate-*r*54.7%
fma-def54.7%
Applied egg-rr54.7%
Taylor expanded in z around 0 82.2%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.15e+189) (* y z) (if (<= z 3.5e+142) x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.15e+189) {
tmp = y * z;
} else if (z <= 3.5e+142) {
tmp = x;
} else {
tmp = 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 (z <= (-1.15d+189)) then
tmp = y * z
else if (z <= 3.5d+142) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.15e+189) {
tmp = y * z;
} else if (z <= 3.5e+142) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.15e+189: tmp = y * z elif z <= 3.5e+142: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.15e+189) tmp = Float64(y * z); elseif (z <= 3.5e+142) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.15e+189) tmp = y * z; elseif (z <= 3.5e+142) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.15e+189], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.5e+142], x, N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+189}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+142}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.15e189 or 3.49999999999999997e142 < z Initial program 99.8%
Taylor expanded in y around 0 57.1%
Taylor expanded in z around inf 45.4%
if -1.15e189 < z < 3.49999999999999997e142Initial program 99.8%
+-commutative99.8%
add-sqr-sqrt54.2%
associate-*r*54.2%
fma-def54.2%
Applied egg-rr54.2%
Taylor expanded in z around 0 72.6%
Taylor expanded in y around 0 47.5%
Final simplification46.9%
(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%
Taylor expanded in y around 0 53.2%
Final simplification53.2%
(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%
add-sqr-sqrt55.6%
associate-*r*55.6%
fma-def55.6%
Applied egg-rr55.6%
Taylor expanded in z around 0 56.4%
Taylor expanded in y around 0 38.4%
Final simplification38.4%
herbie shell --seed 2023195
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))