
(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 x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x * 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 = (z * cos(y)) + (x * sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x * Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x * math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x * sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x * sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + x \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -2.8e-18)
t_0
(if (<= z -3.3e-184)
(* z (+ 1.0 (* x (/ (sin y) z))))
(if (<= z 1.3e-267)
(* x (sin y))
(if (<= z 1.5e+61) (* z (+ 1.0 (/ x (/ z (sin y))))) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -2.8e-18) {
tmp = t_0;
} else if (z <= -3.3e-184) {
tmp = z * (1.0 + (x * (sin(y) / z)));
} else if (z <= 1.3e-267) {
tmp = x * sin(y);
} else if (z <= 1.5e+61) {
tmp = z * (1.0 + (x / (z / sin(y))));
} 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 = z * cos(y)
if (z <= (-2.8d-18)) then
tmp = t_0
else if (z <= (-3.3d-184)) then
tmp = z * (1.0d0 + (x * (sin(y) / z)))
else if (z <= 1.3d-267) then
tmp = x * sin(y)
else if (z <= 1.5d+61) then
tmp = z * (1.0d0 + (x / (z / sin(y))))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -2.8e-18) {
tmp = t_0;
} else if (z <= -3.3e-184) {
tmp = z * (1.0 + (x * (Math.sin(y) / z)));
} else if (z <= 1.3e-267) {
tmp = x * Math.sin(y);
} else if (z <= 1.5e+61) {
tmp = z * (1.0 + (x / (z / Math.sin(y))));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -2.8e-18: tmp = t_0 elif z <= -3.3e-184: tmp = z * (1.0 + (x * (math.sin(y) / z))) elif z <= 1.3e-267: tmp = x * math.sin(y) elif z <= 1.5e+61: tmp = z * (1.0 + (x / (z / math.sin(y)))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -2.8e-18) tmp = t_0; elseif (z <= -3.3e-184) tmp = Float64(z * Float64(1.0 + Float64(x * Float64(sin(y) / z)))); elseif (z <= 1.3e-267) tmp = Float64(x * sin(y)); elseif (z <= 1.5e+61) tmp = Float64(z * Float64(1.0 + Float64(x / Float64(z / sin(y))))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -2.8e-18) tmp = t_0; elseif (z <= -3.3e-184) tmp = z * (1.0 + (x * (sin(y) / z))); elseif (z <= 1.3e-267) tmp = x * sin(y); elseif (z <= 1.5e+61) tmp = z * (1.0 + (x / (z / sin(y)))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.8e-18], t$95$0, If[LessEqual[z, -3.3e-184], N[(z * N[(1.0 + N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.3e-267], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.5e+61], N[(z * N[(1.0 + N[(x / N[(z / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -2.8 \cdot 10^{-18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3.3 \cdot 10^{-184}:\\
\;\;\;\;z \cdot \left(1 + x \cdot \frac{\sin y}{z}\right)\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-267}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+61}:\\
\;\;\;\;z \cdot \left(1 + \frac{x}{\frac{z}{\sin y}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.80000000000000012e-18 or 1.5e61 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 90.5%
if -2.80000000000000012e-18 < z < -3.2999999999999997e-184Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in z around inf 88.6%
associate-/l*88.5%
Simplified88.5%
Taylor expanded in y around 0 80.8%
if -3.2999999999999997e-184 < z < 1.3000000000000001e-267Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 85.6%
if 1.3000000000000001e-267 < z < 1.5e61Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in z around inf 93.5%
associate-/l*93.3%
Simplified93.3%
clear-num93.3%
un-div-inv93.5%
Applied egg-rr93.5%
Taylor expanded in y around 0 90.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))) (t_1 (* z (+ 1.0 (* x (/ (sin y) z))))))
(if (<= z -2.5e-18)
t_0
(if (<= z -6.6e-184)
t_1
(if (<= z 1.8e-268) (* x (sin y)) (if (<= z 1.4e+61) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double t_1 = z * (1.0 + (x * (sin(y) / z)));
double tmp;
if (z <= -2.5e-18) {
tmp = t_0;
} else if (z <= -6.6e-184) {
tmp = t_1;
} else if (z <= 1.8e-268) {
tmp = x * sin(y);
} else if (z <= 1.4e+61) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = z * cos(y)
t_1 = z * (1.0d0 + (x * (sin(y) / z)))
if (z <= (-2.5d-18)) then
tmp = t_0
else if (z <= (-6.6d-184)) then
tmp = t_1
else if (z <= 1.8d-268) then
tmp = x * sin(y)
else if (z <= 1.4d+61) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double t_1 = z * (1.0 + (x * (Math.sin(y) / z)));
double tmp;
if (z <= -2.5e-18) {
tmp = t_0;
} else if (z <= -6.6e-184) {
tmp = t_1;
} else if (z <= 1.8e-268) {
tmp = x * Math.sin(y);
} else if (z <= 1.4e+61) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) t_1 = z * (1.0 + (x * (math.sin(y) / z))) tmp = 0 if z <= -2.5e-18: tmp = t_0 elif z <= -6.6e-184: tmp = t_1 elif z <= 1.8e-268: tmp = x * math.sin(y) elif z <= 1.4e+61: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) t_1 = Float64(z * Float64(1.0 + Float64(x * Float64(sin(y) / z)))) tmp = 0.0 if (z <= -2.5e-18) tmp = t_0; elseif (z <= -6.6e-184) tmp = t_1; elseif (z <= 1.8e-268) tmp = Float64(x * sin(y)); elseif (z <= 1.4e+61) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); t_1 = z * (1.0 + (x * (sin(y) / z))); tmp = 0.0; if (z <= -2.5e-18) tmp = t_0; elseif (z <= -6.6e-184) tmp = t_1; elseif (z <= 1.8e-268) tmp = x * sin(y); elseif (z <= 1.4e+61) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[(1.0 + N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.5e-18], t$95$0, If[LessEqual[z, -6.6e-184], t$95$1, If[LessEqual[z, 1.8e-268], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.4e+61], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := z \cdot \left(1 + x \cdot \frac{\sin y}{z}\right)\\
\mathbf{if}\;z \leq -2.5 \cdot 10^{-18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -6.6 \cdot 10^{-184}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-268}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+61}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.50000000000000018e-18 or 1.4000000000000001e61 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 90.5%
if -2.50000000000000018e-18 < z < -6.5999999999999995e-184 or 1.8000000000000001e-268 < z < 1.4000000000000001e61Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in z around inf 91.8%
associate-/l*91.6%
Simplified91.6%
Taylor expanded in y around 0 86.8%
if -6.5999999999999995e-184 < z < 1.8000000000000001e-268Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 85.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.8e-81) (not (<= z 2.1e-43))) (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.8e-81) || !(z <= 2.1e-43)) {
tmp = z * cos(y);
} else {
tmp = 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 <= (-7.8d-81)) .or. (.not. (z <= 2.1d-43))) then
tmp = z * cos(y)
else
tmp = x * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7.8e-81) || !(z <= 2.1e-43)) {
tmp = z * Math.cos(y);
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.8e-81) or not (z <= 2.1e-43): tmp = z * math.cos(y) else: tmp = x * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.8e-81) || !(z <= 2.1e-43)) tmp = Float64(z * cos(y)); else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.8e-81) || ~((z <= 2.1e-43))) tmp = z * cos(y); else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.8e-81], N[Not[LessEqual[z, 2.1e-43]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-81} \lor \neg \left(z \leq 2.1 \cdot 10^{-43}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -7.7999999999999997e-81 or 2.1000000000000001e-43 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 82.7%
if -7.7999999999999997e-81 < z < 2.1000000000000001e-43Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 73.5%
Final simplification79.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.04) (not (<= y 0.17))) (* x (sin y)) (+ z (* y (+ x (* y (+ (* z -0.5) (* -0.16666666666666666 (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.04) || !(y <= 0.17)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * 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 <= (-0.04d0)) .or. (.not. (y <= 0.17d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + (y * ((z * (-0.5d0)) + ((-0.16666666666666666d0) * (x * y))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.04) || !(y <= 0.17)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.04) or not (y <= 0.17): tmp = x * math.sin(y) else: tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.04) || !(y <= 0.17)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(Float64(z * -0.5) + Float64(-0.16666666666666666 * Float64(x * y))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.04) || ~((y <= 0.17))) tmp = x * sin(y); else tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.04], N[Not[LessEqual[y, 0.17]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(N[(z * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.04 \lor \neg \left(y \leq 0.17\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5 + -0.16666666666666666 \cdot \left(x \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.0400000000000000008 or 0.170000000000000012 < y Initial program 99.5%
fma-define99.5%
Simplified99.5%
Taylor expanded in x around inf 53.0%
if -0.0400000000000000008 < y < 0.170000000000000012Initial program 100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 99.1%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 52.6%
+-commutative52.6%
Simplified52.6%
Final simplification52.6%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * 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 * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 52.6%
+-commutative52.6%
Simplified52.6%
Taylor expanded in x around inf 14.5%
*-commutative14.5%
Simplified14.5%
Final simplification14.5%
herbie shell --seed 2024123
(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))))