
(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 7 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 (+ (* 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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.9e+102)
(not (or (<= z -7.8e+62) (and (not (<= z -0.44)) (<= z 3.9e+83)))))
(* z (cos y))
(+ (* x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+102) || !((z <= -7.8e+62) || (!(z <= -0.44) && (z <= 3.9e+83)))) {
tmp = z * cos(y);
} else {
tmp = (x * sin(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 <= (-1.9d+102)) .or. (.not. (z <= (-7.8d+62)) .or. (.not. (z <= (-0.44d0))) .and. (z <= 3.9d+83))) then
tmp = z * cos(y)
else
tmp = (x * sin(y)) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.9e+102) || !((z <= -7.8e+62) || (!(z <= -0.44) && (z <= 3.9e+83)))) {
tmp = z * Math.cos(y);
} else {
tmp = (x * Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.9e+102) or not ((z <= -7.8e+62) or (not (z <= -0.44) and (z <= 3.9e+83))): tmp = z * math.cos(y) else: tmp = (x * math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.9e+102) || !((z <= -7.8e+62) || (!(z <= -0.44) && (z <= 3.9e+83)))) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(x * sin(y)) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.9e+102) || ~(((z <= -7.8e+62) || (~((z <= -0.44)) && (z <= 3.9e+83))))) tmp = z * cos(y); else tmp = (x * sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.9e+102], N[Not[Or[LessEqual[z, -7.8e+62], And[N[Not[LessEqual[z, -0.44]], $MachinePrecision], LessEqual[z, 3.9e+83]]]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{+102} \lor \neg \left(z \leq -7.8 \cdot 10^{+62} \lor \neg \left(z \leq -0.44\right) \land z \leq 3.9 \cdot 10^{+83}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z\\
\end{array}
\end{array}
if z < -1.89999999999999989e102 or -7.8e62 < z < -0.440000000000000002 or 3.9000000000000002e83 < z Initial program 99.8%
add-cube-cbrt99.7%
associate-*l*99.7%
fma-def99.7%
pow299.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 92.4%
if -1.89999999999999989e102 < z < -7.8e62 or -0.440000000000000002 < z < 3.9000000000000002e83Initial program 99.9%
Taylor expanded in y around 0 89.5%
Final simplification90.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= y -0.019)
t_0
(if (<= y 8.8e-13)
(+ z (* x y))
(if (or (<= y 1.15e+87) (not (<= y 2.05e+114))) t_0 (* x (sin y)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (y <= -0.019) {
tmp = t_0;
} else if (y <= 8.8e-13) {
tmp = z + (x * y);
} else if ((y <= 1.15e+87) || !(y <= 2.05e+114)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (y <= (-0.019d0)) then
tmp = t_0
else if (y <= 8.8d-13) then
tmp = z + (x * y)
else if ((y <= 1.15d+87) .or. (.not. (y <= 2.05d+114))) then
tmp = t_0
else
tmp = x * sin(y)
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 (y <= -0.019) {
tmp = t_0;
} else if (y <= 8.8e-13) {
tmp = z + (x * y);
} else if ((y <= 1.15e+87) || !(y <= 2.05e+114)) {
tmp = t_0;
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if y <= -0.019: tmp = t_0 elif y <= 8.8e-13: tmp = z + (x * y) elif (y <= 1.15e+87) or not (y <= 2.05e+114): tmp = t_0 else: tmp = x * math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (y <= -0.019) tmp = t_0; elseif (y <= 8.8e-13) tmp = Float64(z + Float64(x * y)); elseif ((y <= 1.15e+87) || !(y <= 2.05e+114)) tmp = t_0; else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (y <= -0.019) tmp = t_0; elseif (y <= 8.8e-13) tmp = z + (x * y); elseif ((y <= 1.15e+87) || ~((y <= 2.05e+114))) tmp = t_0; else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.019], t$95$0, If[LessEqual[y, 8.8e-13], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.15e+87], N[Not[LessEqual[y, 2.05e+114]], $MachinePrecision]], t$95$0, N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -0.019:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{-13}:\\
\;\;\;\;z + x \cdot y\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+87} \lor \neg \left(y \leq 2.05 \cdot 10^{+114}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if y < -0.0189999999999999995 or 8.79999999999999986e-13 < y < 1.1500000000000001e87 or 2.05e114 < y Initial program 99.6%
add-cube-cbrt98.9%
associate-*l*98.9%
fma-def98.9%
pow298.9%
Applied egg-rr98.9%
Taylor expanded in x around 0 61.1%
if -0.0189999999999999995 < y < 8.79999999999999986e-13Initial program 100.0%
Taylor expanded in y around 0 99.3%
if 1.1500000000000001e87 < y < 2.05e114Initial program 99.7%
add-cube-cbrt98.4%
associate-*l*98.4%
fma-def98.4%
pow298.4%
Applied egg-rr98.4%
Taylor expanded in z around 0 99.7%
pow-base-199.7%
*-lft-identity99.7%
*-commutative99.7%
Simplified99.7%
Final simplification82.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0105) (not (<= y 0.0037))) (* x (sin y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0105) || !(y <= 0.0037)) {
tmp = x * sin(y);
} else {
tmp = z + (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.0105d0)) .or. (.not. (y <= 0.0037d0))) then
tmp = x * sin(y)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0105) || !(y <= 0.0037)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0105) or not (y <= 0.0037): tmp = x * math.sin(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0105) || !(y <= 0.0037)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0105) || ~((y <= 0.0037))) tmp = x * sin(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0105], N[Not[LessEqual[y, 0.0037]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0105 \lor \neg \left(y \leq 0.0037\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -0.0105000000000000007 or 0.0037000000000000002 < y Initial program 99.6%
add-cube-cbrt98.9%
associate-*l*98.9%
fma-def98.9%
pow298.9%
Applied egg-rr98.9%
Taylor expanded in z around 0 44.3%
pow-base-144.3%
*-lft-identity44.3%
*-commutative44.3%
Simplified44.3%
if -0.0105000000000000007 < y < 0.0037000000000000002Initial program 100.0%
Taylor expanded in y around 0 99.6%
Final simplification73.9%
(FPCore (x y z)
:precision binary64
(if (<= z -2.1e-102)
z
(if (<= z 3e-226)
(* x y)
(if (<= z 8e-68) z (if (<= z 6.6e-49) (* x y) z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e-102) {
tmp = z;
} else if (z <= 3e-226) {
tmp = x * y;
} else if (z <= 8e-68) {
tmp = z;
} else if (z <= 6.6e-49) {
tmp = x * y;
} 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 <= (-2.1d-102)) then
tmp = z
else if (z <= 3d-226) then
tmp = x * y
else if (z <= 8d-68) then
tmp = z
else if (z <= 6.6d-49) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e-102) {
tmp = z;
} else if (z <= 3e-226) {
tmp = x * y;
} else if (z <= 8e-68) {
tmp = z;
} else if (z <= 6.6e-49) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -2.1e-102: tmp = z elif z <= 3e-226: tmp = x * y elif z <= 8e-68: tmp = z elif z <= 6.6e-49: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -2.1e-102) tmp = z; elseif (z <= 3e-226) tmp = Float64(x * y); elseif (z <= 8e-68) tmp = z; elseif (z <= 6.6e-49) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -2.1e-102) tmp = z; elseif (z <= 3e-226) tmp = x * y; elseif (z <= 8e-68) tmp = z; elseif (z <= 6.6e-49) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -2.1e-102], z, If[LessEqual[z, 3e-226], N[(x * y), $MachinePrecision], If[LessEqual[z, 8e-68], z, If[LessEqual[z, 6.6e-49], N[(x * y), $MachinePrecision], z]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{-102}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 3 \cdot 10^{-226}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;z \leq 8 \cdot 10^{-68}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 6.6 \cdot 10^{-49}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -2.1e-102 or 2.99999999999999995e-226 < z < 8.00000000000000053e-68 or 6.6e-49 < z Initial program 99.8%
add-cube-cbrt99.5%
associate-*l*99.5%
fma-def99.5%
pow299.5%
Applied egg-rr99.5%
Taylor expanded in y around 0 49.5%
if -2.1e-102 < z < 2.99999999999999995e-226 or 8.00000000000000053e-68 < z < 6.6e-49Initial program 99.8%
add-cube-cbrt98.1%
associate-*l*98.1%
fma-def98.1%
pow298.1%
Applied egg-rr98.1%
Taylor expanded in z around 0 85.2%
pow-base-185.2%
*-lft-identity85.2%
*-commutative85.2%
Simplified85.2%
Taylor expanded in y around 0 44.8%
Final simplification48.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%
Taylor expanded in y around 0 56.2%
Final simplification56.2%
(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%
add-cube-cbrt99.2%
associate-*l*99.1%
fma-def99.1%
pow299.1%
Applied egg-rr99.1%
Taylor expanded in y around 0 40.3%
Final simplification40.3%
herbie shell --seed 2023244
(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))))