
(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 9 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 z (- (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-define99.8%
sin-neg99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= x -3e+70)
t_0
(if (<= x -1.85e+44)
(- x (* z (sin y)))
(if (or (<= x -5.8e-18) (not (<= x 2.7e+107)))
t_0
(fma z (- (sin y)) x))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -3e+70) {
tmp = t_0;
} else if (x <= -1.85e+44) {
tmp = x - (z * sin(y));
} else if ((x <= -5.8e-18) || !(x <= 2.7e+107)) {
tmp = t_0;
} else {
tmp = fma(z, -sin(y), x);
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -3e+70) tmp = t_0; elseif (x <= -1.85e+44) tmp = Float64(x - Float64(z * sin(y))); elseif ((x <= -5.8e-18) || !(x <= 2.7e+107)) tmp = t_0; else tmp = fma(z, Float64(-sin(y)), x); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3e+70], t$95$0, If[LessEqual[x, -1.85e+44], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -5.8e-18], N[Not[LessEqual[x, 2.7e+107]], $MachinePrecision]], t$95$0, N[(z * (-N[Sin[y], $MachinePrecision]) + x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -3 \cdot 10^{+70}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -1.85 \cdot 10^{+44}:\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{elif}\;x \leq -5.8 \cdot 10^{-18} \lor \neg \left(x \leq 2.7 \cdot 10^{+107}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, -\sin y, x\right)\\
\end{array}
\end{array}
if x < -2.99999999999999976e70 or -1.85e44 < x < -5.8e-18 or 2.7000000000000001e107 < x Initial program 99.7%
Taylor expanded in x around inf 93.8%
if -2.99999999999999976e70 < x < -1.85e44Initial program 99.6%
Taylor expanded in y around 0 90.3%
if -5.8e-18 < x < 2.7000000000000001e107Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-define99.8%
sin-neg99.8%
Simplified99.8%
Taylor expanded in y around 0 89.9%
Final simplification91.6%
(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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -2e+70)
(not (or (<= x -4.3e+43) (and (not (<= x -1e-17)) (<= x 2.1e+108)))))
(* x (cos y))
(- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e+70) || !((x <= -4.3e+43) || (!(x <= -1e-17) && (x <= 2.1e+108)))) {
tmp = x * cos(y);
} 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 <= (-2d+70)) .or. (.not. (x <= (-4.3d+43)) .or. (.not. (x <= (-1d-17))) .and. (x <= 2.1d+108))) then
tmp = x * cos(y)
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 <= -2e+70) || !((x <= -4.3e+43) || (!(x <= -1e-17) && (x <= 2.1e+108)))) {
tmp = x * Math.cos(y);
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e+70) or not ((x <= -4.3e+43) or (not (x <= -1e-17) and (x <= 2.1e+108))): tmp = x * math.cos(y) else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e+70) || !((x <= -4.3e+43) || (!(x <= -1e-17) && (x <= 2.1e+108)))) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2e+70) || ~(((x <= -4.3e+43) || (~((x <= -1e-17)) && (x <= 2.1e+108))))) tmp = x * cos(y); else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e+70], N[Not[Or[LessEqual[x, -4.3e+43], And[N[Not[LessEqual[x, -1e-17]], $MachinePrecision], LessEqual[x, 2.1e+108]]]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+70} \lor \neg \left(x \leq -4.3 \cdot 10^{+43} \lor \neg \left(x \leq -1 \cdot 10^{-17}\right) \land x \leq 2.1 \cdot 10^{+108}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -2.00000000000000015e70 or -4.3e43 < x < -1.00000000000000007e-17 or 2.1000000000000001e108 < x Initial program 99.7%
Taylor expanded in x around inf 93.8%
if -2.00000000000000015e70 < x < -4.3e43 or -1.00000000000000007e-17 < x < 2.1000000000000001e108Initial program 99.8%
Taylor expanded in y around 0 89.9%
Final simplification91.6%
(FPCore (x y z)
:precision binary64
(if (or (<= x -2e-18)
(not
(or (<= x -1.75e-56) (and (not (<= x -5.5e-134)) (<= x 6.5e-81)))))
(* x (cos y))
(* (sin y) (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-18) || !((x <= -1.75e-56) || (!(x <= -5.5e-134) && (x <= 6.5e-81)))) {
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 <= (-2d-18)) .or. (.not. (x <= (-1.75d-56)) .or. (.not. (x <= (-5.5d-134))) .and. (x <= 6.5d-81))) 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 <= -2e-18) || !((x <= -1.75e-56) || (!(x <= -5.5e-134) && (x <= 6.5e-81)))) {
tmp = x * Math.cos(y);
} else {
tmp = Math.sin(y) * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-18) or not ((x <= -1.75e-56) or (not (x <= -5.5e-134) and (x <= 6.5e-81))): tmp = x * math.cos(y) else: tmp = math.sin(y) * -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-18) || !((x <= -1.75e-56) || (!(x <= -5.5e-134) && (x <= 6.5e-81)))) 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 <= -2e-18) || ~(((x <= -1.75e-56) || (~((x <= -5.5e-134)) && (x <= 6.5e-81))))) tmp = x * cos(y); else tmp = sin(y) * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-18], N[Not[Or[LessEqual[x, -1.75e-56], And[N[Not[LessEqual[x, -5.5e-134]], $MachinePrecision], LessEqual[x, 6.5e-81]]]], $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 -2 \cdot 10^{-18} \lor \neg \left(x \leq -1.75 \cdot 10^{-56} \lor \neg \left(x \leq -5.5 \cdot 10^{-134}\right) \land x \leq 6.5 \cdot 10^{-81}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -2.0000000000000001e-18 or -1.7499999999999999e-56 < x < -5.5000000000000002e-134 or 6.5000000000000002e-81 < x Initial program 99.7%
Taylor expanded in x around inf 82.5%
if -2.0000000000000001e-18 < x < -1.7499999999999999e-56 or -5.5000000000000002e-134 < x < 6.5000000000000002e-81Initial program 99.8%
Taylor expanded in x around 0 76.8%
neg-mul-176.8%
distribute-rgt-neg-in76.8%
Simplified76.8%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.6e-5) (not (<= y 0.006))) (* x (cos y)) (- x (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6e-5) || !(y <= 0.006)) {
tmp = x * cos(y);
} else {
tmp = x - (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 ((y <= (-6.6d-5)) .or. (.not. (y <= 0.006d0))) then
tmp = x * cos(y)
else
tmp = x - (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6e-5) || !(y <= 0.006)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.6e-5) or not (y <= 0.006): tmp = x * math.cos(y) else: tmp = x - (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.6e-5) || !(y <= 0.006)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -6.6e-5) || ~((y <= 0.006))) tmp = x * cos(y); else tmp = x - (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.6e-5], N[Not[LessEqual[y, 0.006]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.6 \cdot 10^{-5} \lor \neg \left(y \leq 0.006\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot y\\
\end{array}
\end{array}
if y < -6.6000000000000005e-5 or 0.0060000000000000001 < y Initial program 99.6%
Taylor expanded in x around inf 52.0%
if -6.6000000000000005e-5 < y < 0.0060000000000000001Initial program 100.0%
Taylor expanded in y around 0 99.2%
mul-1-neg99.2%
unsub-neg99.2%
Simplified99.2%
Final simplification72.3%
(FPCore (x y z) :precision binary64 (if (<= x -6.4e-139) x (if (<= x 1.18e-166) (* z (- y)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.4e-139) {
tmp = x;
} else if (x <= 1.18e-166) {
tmp = z * -y;
} else {
tmp = x;
}
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 <= (-6.4d-139)) then
tmp = x
else if (x <= 1.18d-166) then
tmp = z * -y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6.4e-139) {
tmp = x;
} else if (x <= 1.18e-166) {
tmp = z * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.4e-139: tmp = x elif x <= 1.18e-166: tmp = z * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.4e-139) tmp = x; elseif (x <= 1.18e-166) tmp = Float64(z * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.4e-139) tmp = x; elseif (x <= 1.18e-166) tmp = z * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.4e-139], x, If[LessEqual[x, 1.18e-166], N[(z * (-y)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-139}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{-166}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -6.3999999999999999e-139 or 1.18000000000000004e-166 < x Initial program 99.8%
Taylor expanded in y around 0 44.3%
mul-1-neg44.3%
unsub-neg44.3%
Simplified44.3%
Taylor expanded in x around inf 40.4%
if -6.3999999999999999e-139 < x < 1.18000000000000004e-166Initial program 99.8%
Taylor expanded in y around 0 54.8%
mul-1-neg54.8%
unsub-neg54.8%
Simplified54.8%
Taylor expanded in x around 0 36.0%
associate-*r*36.0%
neg-mul-136.0%
*-commutative36.0%
Simplified36.0%
Final simplification39.2%
(FPCore (x y z) :precision binary64 (- x (* z y)))
double code(double x, double y, double z) {
return x - (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 = x - (z * y)
end function
public static double code(double x, double y, double z) {
return x - (z * y);
}
def code(x, y, z): return x - (z * y)
function code(x, y, z) return Float64(x - Float64(z * y)) end
function tmp = code(x, y, z) tmp = x - (z * y); end
code[x_, y_, z_] := N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 47.0%
mul-1-neg47.0%
unsub-neg47.0%
Simplified47.0%
Final simplification47.0%
(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%
Taylor expanded in y around 0 47.0%
mul-1-neg47.0%
unsub-neg47.0%
Simplified47.0%
Taylor expanded in x around inf 35.7%
Final simplification35.7%
herbie shell --seed 2024041
(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))))