
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (fma x (sin y) (* (cos y) z)))
double code(double x, double y, double z) {
return fma(x, sin(y), (cos(y) * z));
}
function code(x, y, z) return fma(x, sin(y), Float64(cos(y) * z)) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, \cos y \cdot z\right)
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* (cos y) z)))
double code(double x, double y, double z) {
return (x * sin(y)) + (cos(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 * sin(y)) + (cos(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (Math.cos(y) * z);
}
def code(x, y, z): return (x * math.sin(y)) + (math.cos(y) * z)
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(cos(y) * z)) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (cos(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + \cos y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)))
(if (<= y -3.1e+178)
t_0
(if (<= y -0.065)
(* x (sin y))
(if (<= y 4.5e-21) (+ z (* y (+ x (* z (* y -0.5))))) t_0)))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double tmp;
if (y <= -3.1e+178) {
tmp = t_0;
} else if (y <= -0.065) {
tmp = x * sin(y);
} else if (y <= 4.5e-21) {
tmp = z + (y * (x + (z * (y * -0.5))));
} else {
tmp = t_0;
}
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) :: tmp
t_0 = cos(y) * z
if (y <= (-3.1d+178)) then
tmp = t_0
else if (y <= (-0.065d0)) then
tmp = x * sin(y)
else if (y <= 4.5d-21) then
tmp = z + (y * (x + (z * (y * (-0.5d0)))))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.cos(y) * z;
double tmp;
if (y <= -3.1e+178) {
tmp = t_0;
} else if (y <= -0.065) {
tmp = x * Math.sin(y);
} else if (y <= 4.5e-21) {
tmp = z + (y * (x + (z * (y * -0.5))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * z tmp = 0 if y <= -3.1e+178: tmp = t_0 elif y <= -0.065: tmp = x * math.sin(y) elif y <= 4.5e-21: tmp = z + (y * (x + (z * (y * -0.5)))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * z) tmp = 0.0 if (y <= -3.1e+178) tmp = t_0; elseif (y <= -0.065) tmp = Float64(x * sin(y)); elseif (y <= 4.5e-21) tmp = Float64(z + Float64(y * Float64(x + Float64(z * Float64(y * -0.5))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = cos(y) * z; tmp = 0.0; if (y <= -3.1e+178) tmp = t_0; elseif (y <= -0.065) tmp = x * sin(y); elseif (y <= 4.5e-21) tmp = z + (y * (x + (z * (y * -0.5)))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -3.1e+178], t$95$0, If[LessEqual[y, -0.065], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.5e-21], N[(z + N[(y * N[(x + N[(z * N[(y * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
\mathbf{if}\;y \leq -3.1 \cdot 10^{+178}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.065:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{-21}:\\
\;\;\;\;z + y \cdot \left(x + z \cdot \left(y \cdot -0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.09999999999999991e178 or 4.49999999999999968e-21 < y Initial program 99.6%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around 0 67.8%
if -3.09999999999999991e178 < y < -0.065000000000000002Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 64.0%
if -0.065000000000000002 < y < 4.49999999999999968e-21Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.4e-27) (not (<= x 2.8e-48))) (+ z (* x (sin y))) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-27) || !(x <= 2.8e-48)) {
tmp = z + (x * sin(y));
} else {
tmp = cos(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 <= (-1.4d-27)) .or. (.not. (x <= 2.8d-48))) then
tmp = z + (x * sin(y))
else
tmp = cos(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e-27) || !(x <= 2.8e-48)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = Math.cos(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e-27) or not (x <= 2.8e-48): tmp = z + (x * math.sin(y)) else: tmp = math.cos(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e-27) || !(x <= 2.8e-48)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(cos(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.4e-27) || ~((x <= 2.8e-48))) tmp = z + (x * sin(y)); else tmp = cos(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e-27], N[Not[LessEqual[x, 2.8e-48]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{-27} \lor \neg \left(x \leq 2.8 \cdot 10^{-48}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
if x < -1.4e-27 or 2.80000000000000005e-48 < x Initial program 99.8%
Taylor expanded in y around 0 92.3%
if -1.4e-27 < x < 2.80000000000000005e-48Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 91.7%
Final simplification92.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.085) (not (<= y 0.105))) (* x (sin y)) (+ z (* y (+ x (* z (* y -0.5)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.085) || !(y <= 0.105)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (z * (y * -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.085d0)) .or. (.not. (y <= 0.105d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (z * (y * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.085) || !(y <= 0.105)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (z * (y * -0.5))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.085) or not (y <= 0.105): tmp = x * math.sin(y) else: tmp = z + (y * (x + (z * (y * -0.5)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.085) || !(y <= 0.105)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(z * Float64(y * -0.5))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.085) || ~((y <= 0.105))) tmp = x * sin(y); else tmp = z + (y * (x + (z * (y * -0.5)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.085], N[Not[LessEqual[y, 0.105]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(z * N[(y * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.085 \lor \neg \left(y \leq 0.105\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + z \cdot \left(y \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if y < -0.0850000000000000061 or 0.104999999999999996 < y Initial program 99.6%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 44.6%
if -0.0850000000000000061 < y < 0.104999999999999996Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 99.6%
associate-*r*99.6%
Simplified99.6%
Final simplification74.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.25e+216) (not (<= x 5.5e+254))) (* y x) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e+216) || !(x <= 5.5e+254)) {
tmp = y * x;
} else {
tmp = 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 <= (-1.25d+216)) .or. (.not. (x <= 5.5d+254))) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.25e+216) || !(x <= 5.5e+254)) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.25e+216) or not (x <= 5.5e+254): tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.25e+216) || !(x <= 5.5e+254)) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.25e+216) || ~((x <= 5.5e+254))) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e+216], N[Not[LessEqual[x, 5.5e+254]], $MachinePrecision]], N[(y * x), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+216} \lor \neg \left(x \leq 5.5 \cdot 10^{+254}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.24999999999999995e216 or 5.50000000000000004e254 < x Initial program 99.7%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 64.1%
+-commutative64.1%
Simplified64.1%
Taylor expanded in x around inf 49.0%
if -1.24999999999999995e216 < x < 5.50000000000000004e254Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-define99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 47.7%
Final simplification47.9%
(FPCore (x y z) :precision binary64 (+ z (* y x)))
double code(double x, double y, double z) {
return z + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * x)
end function
public static double code(double x, double y, double z) {
return z + (y * x);
}
def code(x, y, z): return z + (y * x)
function code(x, y, z) return Float64(z + Float64(y * x)) end
function tmp = code(x, y, z) tmp = z + (y * x); end
code[x_, y_, z_] := N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot x
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 55.8%
+-commutative55.8%
Simplified55.8%
Final simplification55.8%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-define99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 43.7%
herbie shell --seed 2024147
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))