
(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%
cancel-sign-sub-inv99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Simplified99.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
(let* ((t_0 (* x (cos y))) (t_1 (* (sin y) (- z))))
(if (<= y -2.4e+104)
t_0
(if (<= y -3.9e-6)
t_1
(if (<= y 3600000000000.0)
(+ (- x (* y z)) (* -0.5 (* x (* y y))))
(if (or (<= y 3.6e+79) (not (<= y 8e+257))) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = sin(y) * -z;
double tmp;
if (y <= -2.4e+104) {
tmp = t_0;
} else if (y <= -3.9e-6) {
tmp = t_1;
} else if (y <= 3600000000000.0) {
tmp = (x - (y * z)) + (-0.5 * (x * (y * y)));
} else if ((y <= 3.6e+79) || !(y <= 8e+257)) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x * cos(y)
t_1 = sin(y) * -z
if (y <= (-2.4d+104)) then
tmp = t_0
else if (y <= (-3.9d-6)) then
tmp = t_1
else if (y <= 3600000000000.0d0) then
tmp = (x - (y * z)) + ((-0.5d0) * (x * (y * y)))
else if ((y <= 3.6d+79) .or. (.not. (y <= 8d+257))) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double t_1 = Math.sin(y) * -z;
double tmp;
if (y <= -2.4e+104) {
tmp = t_0;
} else if (y <= -3.9e-6) {
tmp = t_1;
} else if (y <= 3600000000000.0) {
tmp = (x - (y * z)) + (-0.5 * (x * (y * y)));
} else if ((y <= 3.6e+79) || !(y <= 8e+257)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) t_1 = math.sin(y) * -z tmp = 0 if y <= -2.4e+104: tmp = t_0 elif y <= -3.9e-6: tmp = t_1 elif y <= 3600000000000.0: tmp = (x - (y * z)) + (-0.5 * (x * (y * y))) elif (y <= 3.6e+79) or not (y <= 8e+257): tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(sin(y) * Float64(-z)) tmp = 0.0 if (y <= -2.4e+104) tmp = t_0; elseif (y <= -3.9e-6) tmp = t_1; elseif (y <= 3600000000000.0) tmp = Float64(Float64(x - Float64(y * z)) + Float64(-0.5 * Float64(x * Float64(y * y)))); elseif ((y <= 3.6e+79) || !(y <= 8e+257)) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); t_1 = sin(y) * -z; tmp = 0.0; if (y <= -2.4e+104) tmp = t_0; elseif (y <= -3.9e-6) tmp = t_1; elseif (y <= 3600000000000.0) tmp = (x - (y * z)) + (-0.5 * (x * (y * y))); elseif ((y <= 3.6e+79) || ~((y <= 8e+257))) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[y, -2.4e+104], t$95$0, If[LessEqual[y, -3.9e-6], t$95$1, If[LessEqual[y, 3600000000000.0], N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3.6e+79], N[Not[LessEqual[y, 8e+257]], $MachinePrecision]], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -2.4 \cdot 10^{+104}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.9 \cdot 10^{-6}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 3600000000000:\\
\;\;\;\;\left(x - y \cdot z\right) + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{+79} \lor \neg \left(y \leq 8 \cdot 10^{+257}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -2.4e104 or 3.6e12 < y < 3.5999999999999999e79 or 8.00000000000000024e257 < y Initial program 99.5%
Taylor expanded in x around inf 67.2%
if -2.4e104 < y < -3.8999999999999999e-6 or 3.5999999999999999e79 < y < 8.00000000000000024e257Initial program 99.7%
Taylor expanded in x around 0 63.2%
associate-*r*63.2%
neg-mul-163.2%
*-commutative63.2%
Simplified63.2%
if -3.8999999999999999e-6 < y < 3.6e12Initial program 100.0%
flip3--31.2%
clear-num31.2%
clear-num31.2%
flip3--99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 98.2%
associate-+r+98.2%
mul-1-neg98.2%
sub-neg98.2%
*-commutative98.2%
unpow298.2%
Simplified98.2%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.5e-12) (not (<= z 7.3e-34))) (- x (* (sin y) z)) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.5e-12) || !(z <= 7.3e-34)) {
tmp = x - (sin(y) * z);
} 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 <= (-4.5d-12)) .or. (.not. (z <= 7.3d-34))) then
tmp = x - (sin(y) * z)
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 <= -4.5e-12) || !(z <= 7.3e-34)) {
tmp = x - (Math.sin(y) * z);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.5e-12) or not (z <= 7.3e-34): tmp = x - (math.sin(y) * z) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.5e-12) || !(z <= 7.3e-34)) tmp = Float64(x - Float64(sin(y) * z)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.5e-12) || ~((z <= 7.3e-34))) tmp = x - (sin(y) * z); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.5e-12], N[Not[LessEqual[z, 7.3e-34]], $MachinePrecision]], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-12} \lor \neg \left(z \leq 7.3 \cdot 10^{-34}\right):\\
\;\;\;\;x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -4.49999999999999981e-12 or 7.29999999999999996e-34 < z Initial program 99.8%
Taylor expanded in y around 0 88.7%
if -4.49999999999999981e-12 < z < 7.29999999999999996e-34Initial program 99.8%
Taylor expanded in x around inf 89.1%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -6600000.0) (not (<= y 3600000000000.0))) (* x (cos y)) (+ (- x (* y z)) (* -0.5 (* x (* y y))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6600000.0) || !(y <= 3600000000000.0)) {
tmp = x * cos(y);
} else {
tmp = (x - (y * z)) + (-0.5 * (x * (y * 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 ((y <= (-6600000.0d0)) .or. (.not. (y <= 3600000000000.0d0))) then
tmp = x * cos(y)
else
tmp = (x - (y * z)) + ((-0.5d0) * (x * (y * y)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6600000.0) || !(y <= 3600000000000.0)) {
tmp = x * Math.cos(y);
} else {
tmp = (x - (y * z)) + (-0.5 * (x * (y * y)));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6600000.0) or not (y <= 3600000000000.0): tmp = x * math.cos(y) else: tmp = (x - (y * z)) + (-0.5 * (x * (y * y))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6600000.0) || !(y <= 3600000000000.0)) tmp = Float64(x * cos(y)); else tmp = Float64(Float64(x - Float64(y * z)) + Float64(-0.5 * Float64(x * Float64(y * y)))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6600000.0) || ~((y <= 3600000000000.0))) tmp = x * cos(y); else tmp = (x - (y * z)) + (-0.5 * (x * (y * y))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6600000.0], N[Not[LessEqual[y, 3600000000000.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6600000 \lor \neg \left(y \leq 3600000000000\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x - y \cdot z\right) + -0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -6.6e6 or 3.6e12 < y Initial program 99.6%
Taylor expanded in x around inf 54.9%
if -6.6e6 < y < 3.6e12Initial program 99.9%
flip3--32.0%
clear-num32.0%
clear-num32.0%
flip3--99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 96.6%
associate-+r+96.6%
mul-1-neg96.6%
sub-neg96.6%
*-commutative96.6%
unpow296.6%
Simplified96.6%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (<= z 1.2e+218) x (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.2e+218) {
tmp = x;
} 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 (z <= 1.2d+218) then
tmp = x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.2e+218) {
tmp = x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.2e+218: tmp = x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.2e+218) tmp = x; else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.2e+218) tmp = x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.2e+218], x, N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.2 \cdot 10^{+218}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 1.1999999999999999e218Initial program 99.8%
flip3--34.6%
clear-num34.5%
clear-num34.5%
flip3--99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 42.9%
if 1.1999999999999999e218 < z Initial program 99.8%
Taylor expanded in y around 0 64.6%
mul-1-neg64.6%
Simplified64.6%
Taylor expanded in x around 0 54.1%
associate-*r*54.1%
mul-1-neg54.1%
*-commutative54.1%
Simplified54.1%
Final simplification43.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%
flip3--32.8%
clear-num32.8%
clear-num32.8%
flip3--99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 53.1%
mul-1-neg53.1%
sub-neg53.1%
*-commutative53.1%
Simplified53.1%
Final simplification53.1%
(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%
flip3--32.8%
clear-num32.8%
clear-num32.8%
flip3--99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 40.7%
Final simplification40.7%
herbie shell --seed 2023297
(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))))