
(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 7 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 (- (* 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e+40) (not (<= x 6e+111))) (- (* x (cos y)) (* y z)) (- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+40) || !(x <= 6e+111)) {
tmp = (x * cos(y)) - (y * z);
} else {
tmp = x - (z * 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 ((x <= (-2.6d+40)) .or. (.not. (x <= 6d+111))) then
tmp = (x * cos(y)) - (y * z)
else
tmp = x - (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e+40) || !(x <= 6e+111)) {
tmp = (x * Math.cos(y)) - (y * z);
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e+40) or not (x <= 6e+111): tmp = (x * math.cos(y)) - (y * z) else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e+40) || !(x <= 6e+111)) tmp = Float64(Float64(x * cos(y)) - Float64(y * z)); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.6e+40) || ~((x <= 6e+111))) tmp = (x * cos(y)) - (y * z); else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e+40], N[Not[LessEqual[x, 6e+111]], $MachinePrecision]], N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+40} \lor \neg \left(x \leq 6 \cdot 10^{+111}\right):\\
\;\;\;\;x \cdot \cos y - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -2.6000000000000001e40 or 6e111 < x Initial program 99.9%
Taylor expanded in y around 0 81.2%
if -2.6000000000000001e40 < x < 6e111Initial program 99.9%
Taylor expanded in y around 0 88.4%
Final simplification85.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.4e+16) (not (<= x 4.8e+53))) (- (* x (+ (cos y) 1.0)) x) (- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e+16) || !(x <= 4.8e+53)) {
tmp = (x * (cos(y) + 1.0)) - x;
} else {
tmp = x - (z * 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 ((x <= (-2.4d+16)) .or. (.not. (x <= 4.8d+53))) then
tmp = (x * (cos(y) + 1.0d0)) - x
else
tmp = x - (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e+16) || !(x <= 4.8e+53)) {
tmp = (x * (Math.cos(y) + 1.0)) - x;
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e+16) or not (x <= 4.8e+53): tmp = (x * (math.cos(y) + 1.0)) - x else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e+16) || !(x <= 4.8e+53)) tmp = Float64(Float64(x * Float64(cos(y) + 1.0)) - x); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.4e+16) || ~((x <= 4.8e+53))) tmp = (x * (cos(y) + 1.0)) - x; else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e+16], N[Not[LessEqual[x, 4.8e+53]], $MachinePrecision]], N[(N[(x * N[(N[Cos[y], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+16} \lor \neg \left(x \leq 4.8 \cdot 10^{+53}\right):\\
\;\;\;\;x \cdot \left(\cos y + 1\right) - x\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -2.4e16 or 4.8e53 < x Initial program 99.9%
expm1-log1p-u99.8%
expm1-udef99.7%
log1p-udef99.6%
add-exp-log99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 78.4%
sub-neg78.4%
distribute-rgt-in78.3%
metadata-eval78.3%
Applied egg-rr78.3%
Taylor expanded in z around 0 89.9%
if -2.4e16 < x < 4.8e53Initial program 99.9%
Taylor expanded in y around 0 89.6%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -450.0) (not (<= y 0.0034))) (* z (- (sin y))) (- (* x (+ 1.0 (* -0.5 (* y y)))) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -450.0) || !(y <= 0.0034)) {
tmp = z * -sin(y);
} else {
tmp = (x * (1.0 + (-0.5 * (y * y)))) - (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 <= (-450.0d0)) .or. (.not. (y <= 0.0034d0))) then
tmp = z * -sin(y)
else
tmp = (x * (1.0d0 + ((-0.5d0) * (y * y)))) - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -450.0) || !(y <= 0.0034)) {
tmp = z * -Math.sin(y);
} else {
tmp = (x * (1.0 + (-0.5 * (y * y)))) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -450.0) or not (y <= 0.0034): tmp = z * -math.sin(y) else: tmp = (x * (1.0 + (-0.5 * (y * y)))) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -450.0) || !(y <= 0.0034)) tmp = Float64(z * Float64(-sin(y))); else tmp = Float64(Float64(x * Float64(1.0 + Float64(-0.5 * Float64(y * y)))) - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -450.0) || ~((y <= 0.0034))) tmp = z * -sin(y); else tmp = (x * (1.0 + (-0.5 * (y * y)))) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -450.0], N[Not[LessEqual[y, 0.0034]], $MachinePrecision]], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], N[(N[(x * N[(1.0 + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -450 \lor \neg \left(y \leq 0.0034\right):\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + -0.5 \cdot \left(y \cdot y\right)\right) - y \cdot z\\
\end{array}
\end{array}
if y < -450 or 0.00339999999999999981 < y Initial program 99.8%
Taylor expanded in y around 0 17.9%
unpow217.9%
Simplified17.9%
Taylor expanded in x around 0 41.8%
mul-1-neg41.8%
distribute-rgt-neg-out41.8%
Simplified41.8%
if -450 < y < 0.00339999999999999981Initial program 100.0%
Taylor expanded in y around 0 99.4%
unpow299.4%
Simplified99.4%
Taylor expanded in y around 0 99.3%
Final simplification73.4%
(FPCore (x y z) :precision binary64 (- x (* z (sin y))))
double code(double x, double y, double z) {
return x - (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 - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return x - (z * Math.sin(y));
}
def code(x, y, z): return x - (z * math.sin(y))
function code(x, y, z) return Float64(x - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = x - (z * sin(y)); end
code[x_, y_, z_] := N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot \sin y
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 75.6%
Final simplification75.6%
(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.9%
Taylor expanded in y around 0 75.6%
Taylor expanded in y around 0 57.5%
Final simplification57.5%
(FPCore (x y z) :precision binary64 (* y (- z)))
double code(double x, double y, double z) {
return 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 = y * -z
end function
public static double code(double x, double y, double z) {
return y * -z;
}
def code(x, y, z): return y * -z
function code(x, y, z) return Float64(y * Float64(-z)) end
function tmp = code(x, y, z) tmp = y * -z; end
code[x_, y_, z_] := N[(y * (-z)), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(-z\right)
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 70.8%
Taylor expanded in x around 0 17.7%
associate-*r*17.7%
neg-mul-117.7%
*-commutative17.7%
Simplified17.7%
Final simplification17.7%
herbie shell --seed 2023238
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))