
(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 8 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-def99.8%
Applied egg-rr99.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 (* x (sin y))) (t_1 (* (cos y) z)))
(if (<= y -1.95e+114)
t_0
(if (<= y -3.9e-6)
t_1
(if (<= y 1900000000000.0)
(+ z (* y x))
(if (<= y 3.3e+79) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = cos(y) * z;
double tmp;
if (y <= -1.95e+114) {
tmp = t_0;
} else if (y <= -3.9e-6) {
tmp = t_1;
} else if (y <= 1900000000000.0) {
tmp = z + (y * x);
} else if (y <= 3.3e+79) {
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 * sin(y)
t_1 = cos(y) * z
if (y <= (-1.95d+114)) then
tmp = t_0
else if (y <= (-3.9d-6)) then
tmp = t_1
else if (y <= 1900000000000.0d0) then
tmp = z + (y * x)
else if (y <= 3.3d+79) 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.sin(y);
double t_1 = Math.cos(y) * z;
double tmp;
if (y <= -1.95e+114) {
tmp = t_0;
} else if (y <= -3.9e-6) {
tmp = t_1;
} else if (y <= 1900000000000.0) {
tmp = z + (y * x);
} else if (y <= 3.3e+79) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) t_1 = math.cos(y) * z tmp = 0 if y <= -1.95e+114: tmp = t_0 elif y <= -3.9e-6: tmp = t_1 elif y <= 1900000000000.0: tmp = z + (y * x) elif y <= 3.3e+79: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(cos(y) * z) tmp = 0.0 if (y <= -1.95e+114) tmp = t_0; elseif (y <= -3.9e-6) tmp = t_1; elseif (y <= 1900000000000.0) tmp = Float64(z + Float64(y * x)); elseif (y <= 3.3e+79) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); t_1 = cos(y) * z; tmp = 0.0; if (y <= -1.95e+114) tmp = t_0; elseif (y <= -3.9e-6) tmp = t_1; elseif (y <= 1900000000000.0) tmp = z + (y * x); elseif (y <= 3.3e+79) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -1.95e+114], t$95$0, If[LessEqual[y, -3.9e-6], t$95$1, If[LessEqual[y, 1900000000000.0], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.3e+79], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := \cos y \cdot z\\
\mathbf{if}\;y \leq -1.95 \cdot 10^{+114}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.9 \cdot 10^{-6}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 1900000000000:\\
\;\;\;\;z + y \cdot x\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{+79}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.95e114 or 1.9e12 < y < 3.3000000000000002e79Initial program 99.7%
Taylor expanded in x around inf 65.8%
if -1.95e114 < y < -3.8999999999999999e-6 or 3.3000000000000002e79 < y Initial program 99.5%
Taylor expanded in x around 0 58.2%
if -3.8999999999999999e-6 < y < 1.9e12Initial program 100.0%
Taylor expanded in y around 0 98.7%
*-commutative98.7%
Simplified98.7%
Final simplification80.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -900000000.0) (not (<= z 2.1e+136))) (* (cos y) z) (+ z (* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -900000000.0) || !(z <= 2.1e+136)) {
tmp = cos(y) * z;
} else {
tmp = z + (x * 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 ((z <= (-900000000.0d0)) .or. (.not. (z <= 2.1d+136))) then
tmp = cos(y) * z
else
tmp = z + (x * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -900000000.0) || !(z <= 2.1e+136)) {
tmp = Math.cos(y) * z;
} else {
tmp = z + (x * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -900000000.0) or not (z <= 2.1e+136): tmp = math.cos(y) * z else: tmp = z + (x * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -900000000.0) || !(z <= 2.1e+136)) tmp = Float64(cos(y) * z); else tmp = Float64(z + Float64(x * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -900000000.0) || ~((z <= 2.1e+136))) tmp = cos(y) * z; else tmp = z + (x * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -900000000.0], N[Not[LessEqual[z, 2.1e+136]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -900000000 \lor \neg \left(z \leq 2.1 \cdot 10^{+136}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if z < -9e8 or 2.0999999999999999e136 < z Initial program 99.8%
Taylor expanded in x around 0 87.0%
if -9e8 < z < 2.0999999999999999e136Initial program 99.8%
Taylor expanded in y around 0 88.4%
Final simplification87.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00035) (not (<= y 1900000000000.0))) (* x (sin y)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00035) || !(y <= 1900000000000.0)) {
tmp = x * sin(y);
} else {
tmp = z + (y * 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 ((y <= (-0.00035d0)) .or. (.not. (y <= 1900000000000.0d0))) then
tmp = x * sin(y)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00035) || !(y <= 1900000000000.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00035) or not (y <= 1900000000000.0): tmp = x * math.sin(y) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00035) || !(y <= 1900000000000.0)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00035) || ~((y <= 1900000000000.0))) tmp = x * sin(y); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00035], N[Not[LessEqual[y, 1900000000000.0]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00035 \lor \neg \left(y \leq 1900000000000\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -3.49999999999999996e-4 or 1.9e12 < y Initial program 99.6%
Taylor expanded in x around inf 53.2%
if -3.49999999999999996e-4 < y < 1.9e12Initial program 100.0%
Taylor expanded in y around 0 98.5%
*-commutative98.5%
Simplified98.5%
Final simplification75.9%
(FPCore (x y z) :precision binary64 (if (<= z -5.1e-66) z (if (<= z 2.25e-131) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.1e-66) {
tmp = z;
} else if (z <= 2.25e-131) {
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 (z <= (-5.1d-66)) then
tmp = z
else if (z <= 2.25d-131) 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 (z <= -5.1e-66) {
tmp = z;
} else if (z <= 2.25e-131) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.1e-66: tmp = z elif z <= 2.25e-131: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.1e-66) tmp = z; elseif (z <= 2.25e-131) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.1e-66) tmp = z; elseif (z <= 2.25e-131) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.1e-66], z, If[LessEqual[z, 2.25e-131], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.1 \cdot 10^{-66}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 2.25 \cdot 10^{-131}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -5.10000000000000022e-66 or 2.2500000000000001e-131 < z Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 48.2%
if -5.10000000000000022e-66 < z < 2.2500000000000001e-131Initial program 99.8%
Taylor expanded in x around inf 80.2%
Taylor expanded in y around 0 35.8%
*-commutative35.8%
Simplified35.8%
Final simplification44.2%
(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%
Taylor expanded in y around 0 51.4%
*-commutative51.4%
Simplified51.4%
Final simplification51.4%
(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-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 37.4%
Final simplification37.4%
herbie shell --seed 2023297
(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))))