
(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.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.25e-29) (not (<= z 1.05e-54))) (- x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.25e-29) || !(z <= 1.05e-54)) {
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 <= (-2.25d-29)) .or. (.not. (z <= 1.05d-54))) 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 <= -2.25e-29) || !(z <= 1.05e-54)) {
tmp = x - (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.25e-29) or not (z <= 1.05e-54): tmp = x - (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.25e-29) || !(z <= 1.05e-54)) 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 <= -2.25e-29) || ~((z <= 1.05e-54))) tmp = x - (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.25e-29], N[Not[LessEqual[z, 1.05e-54]], $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 -2.25 \cdot 10^{-29} \lor \neg \left(z \leq 1.05 \cdot 10^{-54}\right):\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -2.2499999999999999e-29 or 1.05e-54 < z Initial program 99.8%
Taylor expanded in y around 0 86.5%
if -2.2499999999999999e-29 < z < 1.05e-54Initial program 99.8%
Taylor expanded in x around inf 91.3%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-115) (not (<= x 2.25e-104))) (* x (cos y)) (* z (- (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-115) || !(x <= 2.25e-104)) {
tmp = x * cos(y);
} else {
tmp = 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 <= (-3.1d-115)) .or. (.not. (x <= 2.25d-104))) then
tmp = x * cos(y)
else
tmp = z * -sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-115) || !(x <= 2.25e-104)) {
tmp = x * Math.cos(y);
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-115) or not (x <= 2.25e-104): tmp = x * math.cos(y) else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-115) || !(x <= 2.25e-104)) tmp = Float64(x * cos(y)); else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.1e-115) || ~((x <= 2.25e-104))) tmp = x * cos(y); else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-115], N[Not[LessEqual[x, 2.25e-104]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-115} \lor \neg \left(x \leq 2.25 \cdot 10^{-104}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if x < -3.10000000000000007e-115 or 2.2499999999999999e-104 < x Initial program 99.8%
Taylor expanded in x around inf 80.9%
if -3.10000000000000007e-115 < x < 2.2499999999999999e-104Initial program 99.8%
Taylor expanded in x around 0 81.4%
associate-*r*81.4%
neg-mul-181.4%
Simplified81.4%
Final simplification81.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.33) (not (<= y 0.185))) (* x (cos y)) (+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* y z)))) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.33) || !(y <= 0.185)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - 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 <= (-0.33d0)) .or. (.not. (y <= 0.185d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (y * z)))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.33) || !(y <= 0.185)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.33) or not (y <= 0.185): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.33) || !(y <= 0.185)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(y * z)))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.33) || ~((y <= 0.185))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.33], N[Not[LessEqual[y, 0.185]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.33 \lor \neg \left(y \leq 0.185\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(y \cdot z\right)\right) - z\right)\\
\end{array}
\end{array}
if y < -0.330000000000000016 or 0.185 < y Initial program 99.6%
Taylor expanded in x around inf 57.3%
if -0.330000000000000016 < y < 0.185Initial program 100.0%
Taylor expanded in y around 0 98.7%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.6e-93) (not (<= x 1.25e-149))) (* z (/ x z)) (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-93) || !(x <= 1.25e-149)) {
tmp = z * (x / z);
} else {
tmp = z * -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.6d-93)) .or. (.not. (x <= 1.25d-149))) then
tmp = z * (x / z)
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.6e-93) || !(x <= 1.25e-149)) {
tmp = z * (x / z);
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.6e-93) or not (x <= 1.25e-149): tmp = z * (x / z) else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.6e-93) || !(x <= 1.25e-149)) tmp = Float64(z * Float64(x / z)); else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.6e-93) || ~((x <= 1.25e-149))) tmp = z * (x / z); else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.6e-93], N[Not[LessEqual[x, 1.25e-149]], $MachinePrecision]], N[(z * N[(x / z), $MachinePrecision]), $MachinePrecision], N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{-93} \lor \neg \left(x \leq 1.25 \cdot 10^{-149}\right):\\
\;\;\;\;z \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -3.6000000000000002e-93 or 1.24999999999999992e-149 < x Initial program 99.8%
Taylor expanded in z around inf 82.9%
associate-/l*82.7%
Simplified82.7%
Taylor expanded in y around 0 44.1%
+-commutative44.1%
mul-1-neg44.1%
unsub-neg44.1%
Simplified44.1%
Taylor expanded in x around inf 36.8%
if -3.6000000000000002e-93 < x < 1.24999999999999992e-149Initial program 99.8%
Taylor expanded in z around inf 99.8%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in y around 0 46.1%
+-commutative46.1%
mul-1-neg46.1%
unsub-neg46.1%
Simplified46.1%
Taylor expanded in z around inf 36.2%
mul-1-neg36.2%
distribute-lft-neg-out36.2%
*-commutative36.2%
Simplified36.2%
Final simplification36.7%
(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 50.7%
mul-1-neg50.7%
unsub-neg50.7%
Simplified50.7%
(FPCore (x y z) :precision binary64 (* z (- y)))
double code(double x, double y, double z) {
return z * -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 * -y
end function
public static double code(double x, double y, double z) {
return z * -y;
}
def code(x, y, z): return z * -y
function code(x, y, z) return Float64(z * Float64(-y)) end
function tmp = code(x, y, z) tmp = z * -y; end
code[x_, y_, z_] := N[(z * (-y)), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \left(-y\right)
\end{array}
Initial program 99.8%
Taylor expanded in z around inf 87.6%
associate-/l*87.5%
Simplified87.5%
Taylor expanded in y around 0 44.7%
+-commutative44.7%
mul-1-neg44.7%
unsub-neg44.7%
Simplified44.7%
Taylor expanded in z around inf 18.2%
mul-1-neg18.2%
distribute-lft-neg-out18.2%
*-commutative18.2%
Simplified18.2%
herbie shell --seed 2024086
(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))))