
(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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(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 + \left(x + \sin y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -9.5e+77)
t_0
(if (<= z -2.8e-92)
(+ x z)
(if (<= z 1.8e-68) (+ x (sin y)) (if (<= z 5e+163) (+ x z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -9.5e+77) {
tmp = t_0;
} else if (z <= -2.8e-92) {
tmp = x + z;
} else if (z <= 1.8e-68) {
tmp = x + sin(y);
} else if (z <= 5e+163) {
tmp = x + z;
} 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 <= (-9.5d+77)) then
tmp = t_0
else if (z <= (-2.8d-92)) then
tmp = x + z
else if (z <= 1.8d-68) then
tmp = x + sin(y)
else if (z <= 5d+163) then
tmp = x + z
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 <= -9.5e+77) {
tmp = t_0;
} else if (z <= -2.8e-92) {
tmp = x + z;
} else if (z <= 1.8e-68) {
tmp = x + Math.sin(y);
} else if (z <= 5e+163) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -9.5e+77: tmp = t_0 elif z <= -2.8e-92: tmp = x + z elif z <= 1.8e-68: tmp = x + math.sin(y) elif z <= 5e+163: tmp = x + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -9.5e+77) tmp = t_0; elseif (z <= -2.8e-92) tmp = Float64(x + z); elseif (z <= 1.8e-68) tmp = Float64(x + sin(y)); elseif (z <= 5e+163) tmp = Float64(x + z); 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 <= -9.5e+77) tmp = t_0; elseif (z <= -2.8e-92) tmp = x + z; elseif (z <= 1.8e-68) tmp = x + sin(y); elseif (z <= 5e+163) tmp = x + z; 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, -9.5e+77], t$95$0, If[LessEqual[z, -2.8e-92], N[(x + z), $MachinePrecision], If[LessEqual[z, 1.8e-68], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 5e+163], N[(x + z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -9.5 \cdot 10^{+77}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -2.8 \cdot 10^{-92}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{-68}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 5 \cdot 10^{+163}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -9.4999999999999998e77 or 5e163 < z Initial program 99.8%
Taylor expanded in z around inf 82.1%
if -9.4999999999999998e77 < z < -2.8e-92 or 1.80000000000000004e-68 < z < 5e163Initial program 99.9%
Taylor expanded in y around 0 84.7%
+-commutative84.7%
Simplified84.7%
if -2.8e-92 < z < 1.80000000000000004e-68Initial program 100.0%
Taylor expanded in z around 0 94.7%
+-commutative94.7%
Simplified94.7%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e-92) (not (<= z 1e-68))) (+ x (* z (cos y))) (+ x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-92) || !(z <= 1e-68)) {
tmp = x + (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 <= (-2.8d-92)) .or. (.not. (z <= 1d-68))) then
tmp = x + (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 <= -2.8e-92) || !(z <= 1e-68)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e-92) or not (z <= 1e-68): tmp = x + (z * math.cos(y)) else: tmp = x + math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-92) || !(z <= 1e-68)) tmp = Float64(x + 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 <= -2.8e-92) || ~((z <= 1e-68))) tmp = x + (z * cos(y)); else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-92], N[Not[LessEqual[z, 1e-68]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-92} \lor \neg \left(z \leq 10^{-68}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -2.8e-92 or 1.00000000000000007e-68 < z Initial program 99.8%
Taylor expanded in x around inf 98.3%
if -2.8e-92 < z < 1.00000000000000007e-68Initial program 100.0%
Taylor expanded in z around 0 94.7%
+-commutative94.7%
Simplified94.7%
Final simplification97.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -9000.0) (not (<= z 1.8e-68))) (+ x (* z (cos y))) (+ z (+ x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9000.0) || !(z <= 1.8e-68)) {
tmp = x + (z * cos(y));
} 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 <= (-9000.0d0)) .or. (.not. (z <= 1.8d-68))) then
tmp = x + (z * cos(y))
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 <= -9000.0) || !(z <= 1.8e-68)) {
tmp = x + (z * Math.cos(y));
} else {
tmp = z + (x + Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9000.0) or not (z <= 1.8e-68): tmp = x + (z * math.cos(y)) else: tmp = z + (x + math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9000.0) || !(z <= 1.8e-68)) tmp = Float64(x + Float64(z * cos(y))); else tmp = Float64(z + Float64(x + sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9000.0) || ~((z <= 1.8e-68))) tmp = x + (z * cos(y)); else tmp = z + (x + sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9000.0], N[Not[LessEqual[z, 1.8e-68]], $MachinePrecision]], N[(x + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z + N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9000 \lor \neg \left(z \leq 1.8 \cdot 10^{-68}\right):\\
\;\;\;\;x + z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + \sin y\right)\\
\end{array}
\end{array}
if z < -9e3 or 1.80000000000000004e-68 < z Initial program 99.8%
Taylor expanded in x around inf 99.2%
if -9e3 < z < 1.80000000000000004e-68Initial program 100.0%
Taylor expanded in y around 0 99.4%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7e+33) (not (<= x 8.6e-19))) (+ x z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e+33) || !(x <= 8.6e-19)) {
tmp = x + z;
} else {
tmp = z * cos(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 <= (-3.7d+33)) .or. (.not. (x <= 8.6d-19))) then
tmp = x + z
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e+33) || !(x <= 8.6e-19)) {
tmp = x + z;
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7e+33) or not (x <= 8.6e-19): tmp = x + z else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.7e+33) || !(x <= 8.6e-19)) tmp = Float64(x + z); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.7e+33) || ~((x <= 8.6e-19))) tmp = x + z; else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.7e+33], N[Not[LessEqual[x, 8.6e-19]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{+33} \lor \neg \left(x \leq 8.6 \cdot 10^{-19}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -3.6999999999999999e33 or 8.6e-19 < x Initial program 99.9%
Taylor expanded in y around 0 86.3%
+-commutative86.3%
Simplified86.3%
if -3.6999999999999999e33 < x < 8.6e-19Initial program 99.9%
Taylor expanded in z around inf 65.7%
Final simplification77.0%
(FPCore (x y z) :precision binary64 (if (or (<= z 7.2e-225) (not (<= z 1.05e-204))) (+ x z) (sin y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= 7.2e-225) || !(z <= 1.05e-204)) {
tmp = x + z;
} else {
tmp = 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.2d-225) .or. (.not. (z <= 1.05d-204))) then
tmp = x + z
else
tmp = sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= 7.2e-225) || !(z <= 1.05e-204)) {
tmp = x + z;
} else {
tmp = Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= 7.2e-225) or not (z <= 1.05e-204): tmp = x + z else: tmp = math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= 7.2e-225) || !(z <= 1.05e-204)) tmp = Float64(x + z); else tmp = sin(y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= 7.2e-225) || ~((z <= 1.05e-204))) tmp = x + z; else tmp = sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, 7.2e-225], N[Not[LessEqual[z, 1.05e-204]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[Sin[y], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 7.2 \cdot 10^{-225} \lor \neg \left(z \leq 1.05 \cdot 10^{-204}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;\sin y\\
\end{array}
\end{array}
if z < 7.20000000000000018e-225 or 1.05000000000000005e-204 < z Initial program 99.9%
Taylor expanded in y around 0 68.0%
+-commutative68.0%
Simplified68.0%
if 7.20000000000000018e-225 < z < 1.05000000000000005e-204Initial program 99.7%
Taylor expanded in z around 0 99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around 0 96.4%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (<= x -7.5e+40) x (if (<= x 7.5e-26) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e+40) {
tmp = x;
} else if (x <= 7.5e-26) {
tmp = z;
} else {
tmp = 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 (x <= (-7.5d+40)) then
tmp = x
else if (x <= 7.5d-26) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e+40) {
tmp = x;
} else if (x <= 7.5e-26) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.5e+40: tmp = x elif x <= 7.5e-26: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.5e+40) tmp = x; elseif (x <= 7.5e-26) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.5e+40) tmp = x; elseif (x <= 7.5e-26) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.5e+40], x, If[LessEqual[x, 7.5e-26], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+40}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-26}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -7.4999999999999996e40 or 7.4999999999999994e-26 < x Initial program 99.9%
+-commutative99.9%
add-cube-cbrt99.6%
associate-*l*99.6%
fma-def99.6%
pow299.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 76.2%
if -7.4999999999999996e40 < x < 7.4999999999999994e-26Initial program 99.9%
Taylor expanded in z around inf 66.2%
Taylor expanded in y around 0 37.0%
Final simplification58.5%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 66.6%
+-commutative66.6%
Simplified66.6%
Final simplification66.6%
(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.9%
+-commutative99.9%
add-cube-cbrt99.2%
associate-*l*99.1%
fma-def99.2%
pow299.2%
Applied egg-rr99.2%
Taylor expanded in x around inf 45.5%
Final simplification45.5%
herbie shell --seed 2023334
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))