
(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), 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%
+-commutative99.8%
*-commutative99.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 -2.4e+70)
(not
(or (<= x -1.85e+44) (and (not (<= x -5.8e-18)) (<= x 2.7e+107)))))
(* x (cos y))
(+ x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.4e+70) || !((x <= -1.85e+44) || (!(x <= -5.8e-18) && (x <= 2.7e+107)))) {
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 <= (-2.4d+70)) .or. (.not. (x <= (-1.85d+44)) .or. (.not. (x <= (-5.8d-18))) .and. (x <= 2.7d+107))) 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 <= -2.4e+70) || !((x <= -1.85e+44) || (!(x <= -5.8e-18) && (x <= 2.7e+107)))) {
tmp = x * Math.cos(y);
} else {
tmp = x + (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.4e+70) or not ((x <= -1.85e+44) or (not (x <= -5.8e-18) and (x <= 2.7e+107))): tmp = x * math.cos(y) else: tmp = x + (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.4e+70) || !((x <= -1.85e+44) || (!(x <= -5.8e-18) && (x <= 2.7e+107)))) 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 <= -2.4e+70) || ~(((x <= -1.85e+44) || (~((x <= -5.8e-18)) && (x <= 2.7e+107))))) tmp = x * cos(y); else tmp = x + (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.4e+70], N[Not[Or[LessEqual[x, -1.85e+44], And[N[Not[LessEqual[x, -5.8e-18]], $MachinePrecision], LessEqual[x, 2.7e+107]]]], $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 -2.4 \cdot 10^{+70} \lor \neg \left(x \leq -1.85 \cdot 10^{+44} \lor \neg \left(x \leq -5.8 \cdot 10^{-18}\right) \land x \leq 2.7 \cdot 10^{+107}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y \cdot z\\
\end{array}
\end{array}
if x < -2.39999999999999987e70 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.39999999999999987e70 < x < -1.85e44 or -5.8e-18 < x < 2.7000000000000001e107Initial program 99.8%
Taylor expanded in y around 0 89.9%
Final simplification91.5%
(FPCore (x y z)
:precision binary64
(if (or (<= x -3.4e-18)
(not (or (<= x -1.25e-53) (and (not (<= x -5.5e-134)) (<= x 4e-82)))))
(* x (cos y))
(* (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.4e-18) || !((x <= -1.25e-53) || (!(x <= -5.5e-134) && (x <= 4e-82)))) {
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 <= (-3.4d-18)) .or. (.not. (x <= (-1.25d-53)) .or. (.not. (x <= (-5.5d-134))) .and. (x <= 4d-82))) 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 <= -3.4e-18) || !((x <= -1.25e-53) || (!(x <= -5.5e-134) && (x <= 4e-82)))) {
tmp = x * Math.cos(y);
} else {
tmp = Math.sin(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.4e-18) or not ((x <= -1.25e-53) or (not (x <= -5.5e-134) and (x <= 4e-82))): tmp = x * math.cos(y) else: tmp = math.sin(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.4e-18) || !((x <= -1.25e-53) || (!(x <= -5.5e-134) && (x <= 4e-82)))) tmp = Float64(x * cos(y)); else tmp = Float64(sin(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.4e-18) || ~(((x <= -1.25e-53) || (~((x <= -5.5e-134)) && (x <= 4e-82))))) tmp = x * cos(y); else tmp = sin(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.4e-18], N[Not[Or[LessEqual[x, -1.25e-53], And[N[Not[LessEqual[x, -5.5e-134]], $MachinePrecision], LessEqual[x, 4e-82]]]], $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 -3.4 \cdot 10^{-18} \lor \neg \left(x \leq -1.25 \cdot 10^{-53} \lor \neg \left(x \leq -5.5 \cdot 10^{-134}\right) \land x \leq 4 \cdot 10^{-82}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot z\\
\end{array}
\end{array}
if x < -3.40000000000000001e-18 or -1.25e-53 < x < -5.5000000000000002e-134 or 4e-82 < x Initial program 99.7%
Taylor expanded in x around inf 82.8%
if -3.40000000000000001e-18 < x < -1.25e-53 or -5.5000000000000002e-134 < x < 4e-82Initial program 99.8%
Taylor expanded in x around 0 76.8%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0058) (not (<= y 0.0055))) (* x (cos y)) (+ x (* y (+ z (* y (* x -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0058) || !(y <= 0.0055)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
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.0058d0)) .or. (.not. (y <= 0.0055d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + (y * (x * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0058) || !(y <= 0.0055)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + (y * (x * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0058) or not (y <= 0.0055): tmp = x * math.cos(y) else: tmp = x + (y * (z + (y * (x * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0058) || !(y <= 0.0055)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(x * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0058) || ~((y <= 0.0055))) tmp = x * cos(y); else tmp = x + (y * (z + (y * (x * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0058], N[Not[LessEqual[y, 0.0055]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0058 \lor \neg \left(y \leq 0.0055\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + y \cdot \left(x \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -0.0058 or 0.0054999999999999997 < y Initial program 99.6%
Taylor expanded in x around inf 52.2%
if -0.0058 < y < 0.0054999999999999997Initial program 100.0%
Taylor expanded in y around 0 99.4%
associate-*r*99.4%
unpow299.4%
associate-*r*99.4%
*-commutative99.4%
distribute-rgt-out99.4%
*-commutative99.4%
Simplified99.4%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (<= x -6.4e-139) x (if (<= x 1.3e-166) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.4e-139) {
tmp = x;
} else if (x <= 1.3e-166) {
tmp = y * z;
} 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.3d-166) then
tmp = y * z
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.3e-166) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.4e-139: tmp = x elif x <= 1.3e-166: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.4e-139) tmp = x; elseif (x <= 1.3e-166) tmp = Float64(y * z); 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.3e-166) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.4e-139], x, If[LessEqual[x, 1.3e-166], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.4 \cdot 10^{-139}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-166}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -6.3999999999999999e-139 or 1.29999999999999995e-166 < x Initial program 99.7%
+-commutative99.7%
*-commutative99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 40.5%
if -6.3999999999999999e-139 < x < 1.29999999999999995e-166Initial program 99.8%
Taylor expanded in y around 0 54.8%
Taylor expanded in x around 0 36.1%
Final simplification39.4%
(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 47.3%
Final simplification47.3%
(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%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 35.8%
Final simplification35.8%
herbie shell --seed 2024041
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))