
(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))) (t_1 (* z (+ 1.0 (/ x (/ z (sin y)))))))
(if (<= z -6e-13)
t_0
(if (<= z -5.8e-146)
t_1
(if (<= z 4.5e-177) (* x (sin y)) (if (<= z 6e+45) 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 / (z / sin(y))));
double tmp;
if (z <= -6e-13) {
tmp = t_0;
} else if (z <= -5.8e-146) {
tmp = t_1;
} else if (z <= 4.5e-177) {
tmp = x * sin(y);
} else if (z <= 6e+45) {
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 / (z / sin(y))))
if (z <= (-6d-13)) then
tmp = t_0
else if (z <= (-5.8d-146)) then
tmp = t_1
else if (z <= 4.5d-177) then
tmp = x * sin(y)
else if (z <= 6d+45) 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 / (z / Math.sin(y))));
double tmp;
if (z <= -6e-13) {
tmp = t_0;
} else if (z <= -5.8e-146) {
tmp = t_1;
} else if (z <= 4.5e-177) {
tmp = x * Math.sin(y);
} else if (z <= 6e+45) {
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 / (z / math.sin(y)))) tmp = 0 if z <= -6e-13: tmp = t_0 elif z <= -5.8e-146: tmp = t_1 elif z <= 4.5e-177: tmp = x * math.sin(y) elif z <= 6e+45: 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(z / sin(y))))) tmp = 0.0 if (z <= -6e-13) tmp = t_0; elseif (z <= -5.8e-146) tmp = t_1; elseif (z <= 4.5e-177) tmp = Float64(x * sin(y)); elseif (z <= 6e+45) 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 / (z / sin(y)))); tmp = 0.0; if (z <= -6e-13) tmp = t_0; elseif (z <= -5.8e-146) tmp = t_1; elseif (z <= 4.5e-177) tmp = x * sin(y); elseif (z <= 6e+45) 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[(z / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6e-13], t$95$0, If[LessEqual[z, -5.8e-146], t$95$1, If[LessEqual[z, 4.5e-177], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 6e+45], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
t_1 := z \cdot \left(1 + \frac{x}{\frac{z}{\sin y}}\right)\\
\mathbf{if}\;z \leq -6 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -5.8 \cdot 10^{-146}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4.5 \cdot 10^{-177}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{elif}\;z \leq 6 \cdot 10^{+45}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.99999999999999968e-13 or 6.00000000000000021e45 < z Initial program 99.8%
Taylor expanded in x around 0 85.4%
if -5.99999999999999968e-13 < z < -5.80000000000000022e-146 or 4.5000000000000003e-177 < z < 6.00000000000000021e45Initial program 99.8%
Taylor expanded in z around inf 96.9%
associate-/l*96.7%
Simplified96.7%
clear-num96.7%
un-div-inv96.8%
Applied egg-rr96.8%
Taylor expanded in y around 0 82.3%
if -5.80000000000000022e-146 < z < 4.5000000000000003e-177Initial program 99.8%
Taylor expanded in x around inf 86.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -6.2e-13)
t_0
(if (<= z -5.8e-146)
(* z (+ 1.0 (* x (/ (sin y) z))))
(if (<= z 4e-114) (* x (sin y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -6.2e-13) {
tmp = t_0;
} else if (z <= -5.8e-146) {
tmp = z * (1.0 + (x * (sin(y) / z)));
} else if (z <= 4e-114) {
tmp = x * 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 <= (-6.2d-13)) then
tmp = t_0
else if (z <= (-5.8d-146)) then
tmp = z * (1.0d0 + (x * (sin(y) / z)))
else if (z <= 4d-114) then
tmp = x * 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 <= -6.2e-13) {
tmp = t_0;
} else if (z <= -5.8e-146) {
tmp = z * (1.0 + (x * (Math.sin(y) / z)));
} else if (z <= 4e-114) {
tmp = x * Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -6.2e-13: tmp = t_0 elif z <= -5.8e-146: tmp = z * (1.0 + (x * (math.sin(y) / z))) elif z <= 4e-114: tmp = x * 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 <= -6.2e-13) tmp = t_0; elseif (z <= -5.8e-146) tmp = Float64(z * Float64(1.0 + Float64(x * Float64(sin(y) / z)))); elseif (z <= 4e-114) tmp = Float64(x * 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 <= -6.2e-13) tmp = t_0; elseif (z <= -5.8e-146) tmp = z * (1.0 + (x * (sin(y) / z))); elseif (z <= 4e-114) tmp = x * 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, -6.2e-13], t$95$0, If[LessEqual[z, -5.8e-146], N[(z * N[(1.0 + N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4e-114], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -6.2 \cdot 10^{-13}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -5.8 \cdot 10^{-146}:\\
\;\;\;\;z \cdot \left(1 + x \cdot \frac{\sin y}{z}\right)\\
\mathbf{elif}\;z \leq 4 \cdot 10^{-114}:\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.1999999999999998e-13 or 4.0000000000000002e-114 < z Initial program 99.8%
Taylor expanded in x around 0 82.7%
if -6.1999999999999998e-13 < z < -5.80000000000000022e-146Initial program 99.7%
Taylor expanded in z around inf 93.2%
associate-/l*93.1%
Simplified93.1%
Taylor expanded in y around 0 85.0%
if -5.80000000000000022e-146 < z < 4.0000000000000002e-114Initial program 99.8%
Taylor expanded in x around inf 83.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.6e-45) (not (<= z 1.7e-115))) (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.6e-45) || !(z <= 1.7e-115)) {
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 <= (-1.6d-45)) .or. (.not. (z <= 1.7d-115))) 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 <= -1.6e-45) || !(z <= 1.7e-115)) {
tmp = z * Math.cos(y);
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.6e-45) or not (z <= 1.7e-115): tmp = z * math.cos(y) else: tmp = x * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.6e-45) || !(z <= 1.7e-115)) 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 <= -1.6e-45) || ~((z <= 1.7e-115))) tmp = z * cos(y); else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.6e-45], N[Not[LessEqual[z, 1.7e-115]], $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 -1.6 \cdot 10^{-45} \lor \neg \left(z \leq 1.7 \cdot 10^{-115}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -1.60000000000000004e-45 or 1.6999999999999999e-115 < z Initial program 99.8%
Taylor expanded in x around 0 82.3%
if -1.60000000000000004e-45 < z < 1.6999999999999999e-115Initial program 99.8%
Taylor expanded in x around inf 78.3%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00162) (not (<= y 750.0))) (* x (sin y)) (+ z (* y (+ x (* -0.5 (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00162) || !(y <= 750.0)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (-0.5 * (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 ((y <= (-0.00162d0)) .or. (.not. (y <= 750.0d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + ((-0.5d0) * (y * z))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00162) || !(y <= 750.0)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (-0.5 * (y * z))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00162) or not (y <= 750.0): tmp = x * math.sin(y) else: tmp = z + (y * (x + (-0.5 * (y * z)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00162) || !(y <= 750.0)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(-0.5 * Float64(y * z))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00162) || ~((y <= 750.0))) tmp = x * sin(y); else tmp = z + (y * (x + (-0.5 * (y * z)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00162], N[Not[LessEqual[y, 750.0]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(-0.5 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00162 \lor \neg \left(y \leq 750\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + -0.5 \cdot \left(y \cdot z\right)\right)\\
\end{array}
\end{array}
if y < -0.0016199999999999999 or 750 < y Initial program 99.6%
Taylor expanded in x around inf 50.3%
if -0.0016199999999999999 < y < 750Initial program 100.0%
Taylor expanded in y around 0 98.6%
*-commutative98.6%
Simplified98.6%
Final simplification73.7%
(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%
Taylor expanded in y around 0 51.1%
*-commutative51.1%
Simplified51.1%
Final simplification51.1%
(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%
Taylor expanded in y around 0 51.1%
*-commutative51.1%
Simplified51.1%
Taylor expanded in z around inf 36.2%
herbie shell --seed 2024116
(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))))