
(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 (cos y) x (* z (- (sin y)))))
double code(double x, double y, double z) {
return fma(cos(y), x, (z * -sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(z * Float64(-sin(y)))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, z \cdot \left(-\sin y\right)\right)
\end{array}
Initial program 99.8%
log1p-expm1-u99.7%
Applied egg-rr99.7%
log1p-expm1-u99.8%
+-rgt-identity99.8%
metadata-eval99.8%
associate--l+99.6%
flip--99.6%
metadata-eval99.6%
clear-num99.6%
un-div-inv99.6%
clear-num99.6%
metadata-eval99.6%
flip--99.6%
associate--l+99.7%
metadata-eval99.7%
+-rgt-identity99.7%
Applied egg-rr99.7%
associate-/r/99.8%
fma-neg99.8%
/-rgt-identity99.8%
fma-def99.8%
*-commutative99.8%
fma-def99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* (cos y) x) (* z (sin y))))
double code(double x, double y, double z) {
return (cos(y) * 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 = (cos(y) * x) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (z * Math.sin(y));
}
def code(x, y, z): return (math.cos(y) * x) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - z \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.6e+70) (not (<= x 2.8e+73))) (* (cos y) x) (- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.6e+70) || !(x <= 2.8e+73)) {
tmp = cos(y) * 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 <= (-4.6d+70)) .or. (.not. (x <= 2.8d+73))) then
tmp = cos(y) * 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 <= -4.6e+70) || !(x <= 2.8e+73)) {
tmp = Math.cos(y) * x;
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.6e+70) or not (x <= 2.8e+73): tmp = math.cos(y) * x else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.6e+70) || !(x <= 2.8e+73)) tmp = Float64(cos(y) * 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 <= -4.6e+70) || ~((x <= 2.8e+73))) tmp = cos(y) * x; else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.6e+70], N[Not[LessEqual[x, 2.8e+73]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{+70} \lor \neg \left(x \leq 2.8 \cdot 10^{+73}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -4.59999999999999987e70 or 2.80000000000000008e73 < x Initial program 99.7%
Taylor expanded in x around inf 91.0%
if -4.59999999999999987e70 < x < 2.80000000000000008e73Initial program 99.8%
Taylor expanded in y around 0 89.3%
Final simplification90.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.4e+54) (not (<= x 1.15e-64))) (* (cos y) x) (* z (- (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.4e+54) || !(x <= 1.15e-64)) {
tmp = cos(y) * x;
} 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 <= (-4.4d+54)) .or. (.not. (x <= 1.15d-64))) then
tmp = cos(y) * x
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 <= -4.4e+54) || !(x <= 1.15e-64)) {
tmp = Math.cos(y) * x;
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.4e+54) or not (x <= 1.15e-64): tmp = math.cos(y) * x else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.4e+54) || !(x <= 1.15e-64)) tmp = Float64(cos(y) * x); else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.4e+54) || ~((x <= 1.15e-64))) tmp = cos(y) * x; else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.4e+54], N[Not[LessEqual[x, 1.15e-64]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{+54} \lor \neg \left(x \leq 1.15 \cdot 10^{-64}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if x < -4.3999999999999998e54 or 1.1500000000000001e-64 < x Initial program 99.7%
Taylor expanded in x around inf 84.2%
if -4.3999999999999998e54 < x < 1.1500000000000001e-64Initial program 99.8%
Taylor expanded in x around 0 72.6%
neg-mul-172.6%
*-commutative72.6%
distribute-rgt-neg-in72.6%
Simplified72.6%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.026) (not (<= y 0.0185))) (* (cos y) x) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.026) || !(y <= 0.0185)) {
tmp = cos(y) * x;
} else {
tmp = x - (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 <= (-0.026d0)) .or. (.not. (y <= 0.0185d0))) then
tmp = cos(y) * x
else
tmp = x - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.026) || !(y <= 0.0185)) {
tmp = Math.cos(y) * x;
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.026) or not (y <= 0.0185): tmp = math.cos(y) * x else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.026) || !(y <= 0.0185)) tmp = Float64(cos(y) * x); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.026) || ~((y <= 0.0185))) tmp = cos(y) * x; else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.026], N[Not[LessEqual[y, 0.0185]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.026 \lor \neg \left(y \leq 0.0185\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -0.0259999999999999988 or 0.0184999999999999991 < y Initial program 99.6%
Taylor expanded in x around inf 52.0%
if -0.0259999999999999988 < y < 0.0184999999999999991Initial program 100.0%
Taylor expanded in y around 0 99.6%
mul-1-neg99.6%
unsub-neg99.6%
Simplified99.6%
Final simplification72.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%
sub-neg99.8%
*-commutative99.8%
add-sqr-sqrt55.1%
associate-*r*55.1%
fma-def55.1%
distribute-rgt-neg-in55.1%
add-sqr-sqrt28.3%
sqrt-unprod40.6%
sqr-neg40.6%
sqrt-unprod14.7%
add-sqr-sqrt29.6%
Applied egg-rr29.6%
Taylor expanded in y around 0 31.3%
Final simplification31.3%
(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 46.5%
mul-1-neg46.5%
unsub-neg46.5%
Simplified46.5%
Final simplification46.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 * 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 z
\end{array}
Initial program 99.8%
sub-neg99.8%
*-commutative99.8%
add-sqr-sqrt55.1%
associate-*r*55.1%
fma-def55.1%
distribute-rgt-neg-in55.1%
add-sqr-sqrt28.3%
sqrt-unprod40.6%
sqr-neg40.6%
sqrt-unprod14.7%
add-sqr-sqrt29.6%
Applied egg-rr29.6%
Taylor expanded in y around 0 31.3%
Taylor expanded in x around 0 3.4%
Final simplification3.4%
herbie shell --seed 2023305
(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))))