
(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 x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * 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 = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (sin y))) (t_1 (* x (cos y))))
(if (<= y -3.7e+269)
t_0
(if (<= y -7.2e+182)
t_1
(if (<= y -5.1e+23)
t_0
(if (<= y 2.2e+68) (+ t_1 (* y z)) (if (<= y 2e+193) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = z * sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -3.7e+269) {
tmp = t_0;
} else if (y <= -7.2e+182) {
tmp = t_1;
} else if (y <= -5.1e+23) {
tmp = t_0;
} else if (y <= 2.2e+68) {
tmp = t_1 + (y * z);
} else if (y <= 2e+193) {
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 = z * sin(y)
t_1 = x * cos(y)
if (y <= (-3.7d+269)) then
tmp = t_0
else if (y <= (-7.2d+182)) then
tmp = t_1
else if (y <= (-5.1d+23)) then
tmp = t_0
else if (y <= 2.2d+68) then
tmp = t_1 + (y * z)
else if (y <= 2d+193) 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 = z * Math.sin(y);
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -3.7e+269) {
tmp = t_0;
} else if (y <= -7.2e+182) {
tmp = t_1;
} else if (y <= -5.1e+23) {
tmp = t_0;
} else if (y <= 2.2e+68) {
tmp = t_1 + (y * z);
} else if (y <= 2e+193) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.sin(y) t_1 = x * math.cos(y) tmp = 0 if y <= -3.7e+269: tmp = t_0 elif y <= -7.2e+182: tmp = t_1 elif y <= -5.1e+23: tmp = t_0 elif y <= 2.2e+68: tmp = t_1 + (y * z) elif y <= 2e+193: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(z * sin(y)) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -3.7e+269) tmp = t_0; elseif (y <= -7.2e+182) tmp = t_1; elseif (y <= -5.1e+23) tmp = t_0; elseif (y <= 2.2e+68) tmp = Float64(t_1 + Float64(y * z)); elseif (y <= 2e+193) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * sin(y); t_1 = x * cos(y); tmp = 0.0; if (y <= -3.7e+269) tmp = t_0; elseif (y <= -7.2e+182) tmp = t_1; elseif (y <= -5.1e+23) tmp = t_0; elseif (y <= 2.2e+68) tmp = t_1 + (y * z); elseif (y <= 2e+193) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.7e+269], t$95$0, If[LessEqual[y, -7.2e+182], t$95$1, If[LessEqual[y, -5.1e+23], t$95$0, If[LessEqual[y, 2.2e+68], N[(t$95$1 + N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2e+193], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \sin y\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -3.7 \cdot 10^{+269}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -7.2 \cdot 10^{+182}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -5.1 \cdot 10^{+23}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+68}:\\
\;\;\;\;t_1 + y \cdot z\\
\mathbf{elif}\;y \leq 2 \cdot 10^{+193}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -3.6999999999999999e269 or -7.2e182 < y < -5.10000000000000021e23 or 2.19999999999999987e68 < y < 2.00000000000000013e193Initial program 99.5%
Taylor expanded in x around 0 70.0%
if -3.6999999999999999e269 < y < -7.2e182 or 2.00000000000000013e193 < y Initial program 99.4%
Taylor expanded in x around inf 69.7%
if -5.10000000000000021e23 < y < 2.19999999999999987e68Initial program 99.9%
Taylor expanded in y around 0 96.0%
Final simplification85.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.85e-5) (not (<= y 0.00185))) (* x (cos y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.85e-5) || !(y <= 0.00185)) {
tmp = x * cos(y);
} else {
tmp = x + (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 <= (-1.85d-5)) .or. (.not. (y <= 0.00185d0))) then
tmp = x * cos(y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.85e-5) || !(y <= 0.00185)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.85e-5) or not (y <= 0.00185): tmp = x * math.cos(y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.85e-5) || !(y <= 0.00185)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.85e-5) || ~((y <= 0.00185))) tmp = x * cos(y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.85e-5], N[Not[LessEqual[y, 0.00185]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{-5} \lor \neg \left(y \leq 0.00185\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1.84999999999999991e-5 or 0.0018500000000000001 < y Initial program 99.5%
Taylor expanded in x around inf 50.5%
if -1.84999999999999991e-5 < y < 0.0018500000000000001Initial program 100.0%
Taylor expanded in y around 0 99.9%
+-commutative99.9%
Simplified99.9%
Final simplification76.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6e-45) (not (<= x 1.95e-28))) (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-45) || !(x <= 1.95e-28)) {
tmp = x * cos(y);
} else {
tmp = z * 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 ((x <= (-6d-45)) .or. (.not. (x <= 1.95d-28))) then
tmp = x * cos(y)
else
tmp = z * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6e-45) || !(x <= 1.95e-28)) {
tmp = x * Math.cos(y);
} else {
tmp = z * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6e-45) or not (x <= 1.95e-28): tmp = x * math.cos(y) else: tmp = z * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6e-45) || !(x <= 1.95e-28)) tmp = Float64(x * cos(y)); else tmp = Float64(z * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6e-45) || ~((x <= 1.95e-28))) tmp = x * cos(y); else tmp = z * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6e-45], N[Not[LessEqual[x, 1.95e-28]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-45} \lor \neg \left(x \leq 1.95 \cdot 10^{-28}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sin y\\
\end{array}
\end{array}
if x < -6.00000000000000022e-45 or 1.94999999999999999e-28 < x Initial program 99.8%
Taylor expanded in x around inf 86.8%
if -6.00000000000000022e-45 < x < 1.94999999999999999e-28Initial program 99.7%
Taylor expanded in x around 0 69.3%
Final simplification79.3%
(FPCore (x y z) :precision binary64 (if (<= z 4.2e+217) x (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.2e+217) {
tmp = x;
} else {
tmp = 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 (z <= 4.2d+217) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 4.2e+217) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 4.2e+217: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 4.2e+217) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 4.2e+217) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 4.2e+217], x, N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.2 \cdot 10^{+217}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 4.2000000000000002e217Initial program 99.8%
*-commutative99.8%
add-cube-cbrt99.4%
associate-*l*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 46.5%
if 4.2000000000000002e217 < z Initial program 99.8%
Taylor expanded in y around 0 53.6%
+-commutative53.6%
Simplified53.6%
Taylor expanded in y around inf 47.4%
Final simplification46.6%
(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 55.8%
+-commutative55.8%
Simplified55.8%
Final simplification55.8%
(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%
add-cube-cbrt99.4%
associate-*l*99.4%
fma-def99.4%
pow299.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 43.9%
Final simplification43.9%
herbie shell --seed 2024011
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))