
(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 (sin y) (- z) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) - (sin(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 * cos(y)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -10000000.0) (not (<= x 3.2e-59))) (* x (cos y)) (- x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -10000000.0) || !(x <= 3.2e-59)) {
tmp = x * cos(y);
} else {
tmp = x - (sin(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 ((x <= (-10000000.0d0)) .or. (.not. (x <= 3.2d-59))) then
tmp = x * cos(y)
else
tmp = x - (sin(y) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -10000000.0) || !(x <= 3.2e-59)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -10000000.0) or not (x <= 3.2e-59): tmp = x * math.cos(y) else: tmp = x - (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -10000000.0) || !(x <= 3.2e-59)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(sin(y) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -10000000.0) || ~((x <= 3.2e-59))) tmp = x * cos(y); else tmp = x - (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -10000000.0], N[Not[LessEqual[x, 3.2e-59]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10000000 \lor \neg \left(x \leq 3.2 \cdot 10^{-59}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - \sin y \cdot z\\
\end{array}
\end{array}
if x < -1e7 or 3.1999999999999999e-59 < x Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 87.0%
if -1e7 < x < 3.1999999999999999e-59Initial program 99.8%
Taylor expanded in y around 0 90.0%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-33) (not (<= x 1.3e-122))) (* x (cos y)) (* (sin y) (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-33) || !(x <= 1.3e-122)) {
tmp = x * cos(y);
} else {
tmp = sin(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 ((x <= (-5.8d-33)) .or. (.not. (x <= 1.3d-122))) then
tmp = x * cos(y)
else
tmp = sin(y) * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-33) || !(x <= 1.3e-122)) {
tmp = x * Math.cos(y);
} else {
tmp = Math.sin(y) * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-33) or not (x <= 1.3e-122): tmp = x * math.cos(y) else: tmp = math.sin(y) * -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-33) || !(x <= 1.3e-122)) tmp = Float64(x * cos(y)); else tmp = Float64(sin(y) * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-33) || ~((x <= 1.3e-122))) tmp = x * cos(y); else tmp = sin(y) * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-33], N[Not[LessEqual[x, 1.3e-122]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-33} \lor \neg \left(x \leq 1.3 \cdot 10^{-122}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -5.80000000000000005e-33 or 1.29999999999999988e-122 < x Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 84.0%
if -5.80000000000000005e-33 < x < 1.29999999999999988e-122Initial program 99.8%
Taylor expanded in x around 0 70.4%
mul-1-neg70.4%
*-commutative70.4%
distribute-rgt-neg-in70.4%
Simplified70.4%
Final simplification78.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1400000.0) (not (<= y 0.013))) (* x (cos y)) (+ x (* y (- (* y (* x -0.5)) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1400000.0) || !(y <= 0.013)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * (x * -0.5)) - 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 <= (-1400000.0d0)) .or. (.not. (y <= 0.013d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * (x * (-0.5d0))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1400000.0) || !(y <= 0.013)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * (x * -0.5)) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1400000.0) or not (y <= 0.013): tmp = x * math.cos(y) else: tmp = x + (y * ((y * (x * -0.5)) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1400000.0) || !(y <= 0.013)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(x * -0.5)) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1400000.0) || ~((y <= 0.013))) tmp = x * cos(y); else tmp = x + (y * ((y * (x * -0.5)) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1400000.0], N[Not[LessEqual[y, 0.013]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1400000 \lor \neg \left(y \leq 0.013\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5\right) - z\right)\\
\end{array}
\end{array}
if y < -1.4e6 or 0.0129999999999999994 < y Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 53.7%
if -1.4e6 < y < 0.0129999999999999994Initial program 100.0%
*-commutative100.0%
add-sqr-sqrt53.3%
associate-*r*53.3%
fma-neg53.3%
distribute-rgt-neg-in53.3%
Applied egg-rr53.3%
Taylor expanded in y around 0 53.3%
mul-1-neg53.3%
distribute-rgt-neg-in53.3%
Simplified53.3%
Taylor expanded in y around 0 98.2%
+-commutative98.2%
+-commutative98.2%
associate-+l+98.2%
*-commutative98.2%
associate-*r*98.2%
metadata-eval98.2%
distribute-rgt-out98.2%
mul-1-neg98.2%
unsub-neg98.2%
unpow298.2%
associate-*l*98.2%
distribute-lft-out--98.2%
distribute-rgt-out98.2%
metadata-eval98.2%
Simplified98.2%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (<= z 1.4e+215) x (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.4e+215) {
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.4d+215) 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.4e+215) {
tmp = x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.4e+215: tmp = x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.4e+215) tmp = x; else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.4e+215) tmp = x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.4e+215], x, N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.4 \cdot 10^{+215}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 1.4e215Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 42.1%
if 1.4e215 < z Initial program 99.9%
Taylor expanded in y around 0 64.4%
+-commutative64.4%
mul-1-neg64.4%
unsub-neg64.4%
fma-def64.4%
unpow264.4%
associate-*l*65.0%
Simplified65.0%
Taylor expanded in x around 0 53.6%
neg-mul-153.6%
distribute-lft-neg-in53.6%
Simplified53.6%
Final simplification42.8%
(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.5%
+-commutative50.5%
mul-1-neg50.5%
unsub-neg50.5%
Simplified50.5%
Final simplification50.5%
(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%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 40.1%
Final simplification40.1%
herbie shell --seed 2023258
(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))))