
(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 (+ (+ 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -6.5e+146)
t_0
(if (<= z -1.7e-74)
(+ x z)
(if (<= z 1e-100) (+ x (sin y)) (if (<= z 1.55e+145) (+ x z) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -6.5e+146) {
tmp = t_0;
} else if (z <= -1.7e-74) {
tmp = x + z;
} else if (z <= 1e-100) {
tmp = x + sin(y);
} else if (z <= 1.55e+145) {
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 <= (-6.5d+146)) then
tmp = t_0
else if (z <= (-1.7d-74)) then
tmp = x + z
else if (z <= 1d-100) then
tmp = x + sin(y)
else if (z <= 1.55d+145) 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 <= -6.5e+146) {
tmp = t_0;
} else if (z <= -1.7e-74) {
tmp = x + z;
} else if (z <= 1e-100) {
tmp = x + Math.sin(y);
} else if (z <= 1.55e+145) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -6.5e+146: tmp = t_0 elif z <= -1.7e-74: tmp = x + z elif z <= 1e-100: tmp = x + math.sin(y) elif z <= 1.55e+145: 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 <= -6.5e+146) tmp = t_0; elseif (z <= -1.7e-74) tmp = Float64(x + z); elseif (z <= 1e-100) tmp = Float64(x + sin(y)); elseif (z <= 1.55e+145) 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 <= -6.5e+146) tmp = t_0; elseif (z <= -1.7e-74) tmp = x + z; elseif (z <= 1e-100) tmp = x + sin(y); elseif (z <= 1.55e+145) 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, -6.5e+146], t$95$0, If[LessEqual[z, -1.7e-74], N[(x + z), $MachinePrecision], If[LessEqual[z, 1e-100], N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.55e+145], N[(x + z), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -6.5 \cdot 10^{+146}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -1.7 \cdot 10^{-74}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq 10^{-100}:\\
\;\;\;\;x + \sin y\\
\mathbf{elif}\;z \leq 1.55 \cdot 10^{+145}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -6.4999999999999997e146 or 1.54999999999999994e145 < z Initial program 99.8%
associate-+l+99.8%
add-cube-cbrt99.6%
fma-def99.6%
pow299.6%
+-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around inf 91.3%
if -6.4999999999999997e146 < z < -1.7e-74 or 1e-100 < z < 1.54999999999999994e145Initial program 99.9%
Taylor expanded in y around 0 79.9%
if -1.7e-74 < z < 1e-100Initial program 100.0%
Taylor expanded in z around 0 95.6%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.2e+147) (not (<= z 6.5e+145))) (* z (cos y)) (+ (+ x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.2e+147) || !(z <= 6.5e+145)) {
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 <= (-2.2d+147)) .or. (.not. (z <= 6.5d+145))) 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 <= -2.2e+147) || !(z <= 6.5e+145)) {
tmp = z * Math.cos(y);
} else {
tmp = (x + Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.2e+147) or not (z <= 6.5e+145): tmp = z * math.cos(y) else: tmp = (x + math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.2e+147) || !(z <= 6.5e+145)) 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 <= -2.2e+147) || ~((z <= 6.5e+145))) tmp = z * cos(y); else tmp = (x + sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.2e+147], N[Not[LessEqual[z, 6.5e+145]], $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 -2.2 \cdot 10^{+147} \lor \neg \left(z \leq 6.5 \cdot 10^{+145}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\end{array}
\end{array}
if z < -2.2000000000000002e147 or 6.50000000000000034e145 < z Initial program 99.8%
associate-+l+99.8%
add-cube-cbrt99.6%
fma-def99.6%
pow299.6%
+-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around inf 91.3%
if -2.2000000000000002e147 < z < 6.50000000000000034e145Initial program 100.0%
Taylor expanded in y around 0 93.6%
Final simplification92.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.5e+147) (not (<= z 1.56e+147))) (* z (cos y)) (+ x z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e+147) || !(z <= 1.56e+147)) {
tmp = z * cos(y);
} else {
tmp = x + 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.5d+147)) .or. (.not. (z <= 1.56d+147))) then
tmp = z * cos(y)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.5e+147) || !(z <= 1.56e+147)) {
tmp = z * Math.cos(y);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.5e+147) or not (z <= 1.56e+147): tmp = z * math.cos(y) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.5e+147) || !(z <= 1.56e+147)) tmp = Float64(z * cos(y)); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.5e+147) || ~((z <= 1.56e+147))) tmp = z * cos(y); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.5e+147], N[Not[LessEqual[z, 1.56e+147]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.5 \cdot 10^{+147} \lor \neg \left(z \leq 1.56 \cdot 10^{+147}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if z < -1.49999999999999997e147 or 1.56e147 < z Initial program 99.8%
associate-+l+99.8%
add-cube-cbrt99.6%
fma-def99.6%
pow299.6%
+-commutative99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around inf 91.3%
if -1.49999999999999997e147 < z < 1.56e147Initial program 100.0%
Taylor expanded in y around 0 76.9%
Final simplification81.5%
(FPCore (x y z) :precision binary64 (if (<= y -8e+20) (+ x z) (if (<= y 1.36e+17) (+ y (+ x z)) (+ x z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e+20) {
tmp = x + z;
} else if (y <= 1.36e+17) {
tmp = y + (x + z);
} else {
tmp = x + 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 <= (-8d+20)) then
tmp = x + z
else if (y <= 1.36d+17) then
tmp = y + (x + z)
else
tmp = x + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8e+20) {
tmp = x + z;
} else if (y <= 1.36e+17) {
tmp = y + (x + z);
} else {
tmp = x + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e+20: tmp = x + z elif y <= 1.36e+17: tmp = y + (x + z) else: tmp = x + z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e+20) tmp = Float64(x + z); elseif (y <= 1.36e+17) tmp = Float64(y + Float64(x + z)); else tmp = Float64(x + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8e+20) tmp = x + z; elseif (y <= 1.36e+17) tmp = y + (x + z); else tmp = x + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e+20], N[(x + z), $MachinePrecision], If[LessEqual[y, 1.36e+17], N[(y + N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+20}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;y \leq 1.36 \cdot 10^{+17}:\\
\;\;\;\;y + \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + z\\
\end{array}
\end{array}
if y < -8e20 or 1.36e17 < y Initial program 99.8%
Taylor expanded in y around 0 38.3%
if -8e20 < y < 1.36e17Initial program 100.0%
Taylor expanded in y around 0 97.5%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (if (<= x -2.06e-38) x (if (<= x 450000.0) (+ y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.06e-38) {
tmp = x;
} else if (x <= 450000.0) {
tmp = y + 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 <= (-2.06d-38)) then
tmp = x
else if (x <= 450000.0d0) then
tmp = y + z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.06e-38) {
tmp = x;
} else if (x <= 450000.0) {
tmp = y + z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.06e-38: tmp = x elif x <= 450000.0: tmp = y + z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.06e-38) tmp = x; elseif (x <= 450000.0) tmp = Float64(y + z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.06e-38) tmp = x; elseif (x <= 450000.0) tmp = y + z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.06e-38], x, If[LessEqual[x, 450000.0], N[(y + z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.06 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 450000:\\
\;\;\;\;y + z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.06e-38 or 4.5e5 < x Initial program 99.9%
Taylor expanded in x around inf 69.2%
if -2.06e-38 < x < 4.5e5Initial program 99.9%
Taylor expanded in x around 0 92.5%
Taylor expanded in y around 0 49.7%
Final simplification60.9%
(FPCore (x y z) :precision binary64 (if (<= x -2.15e-38) x (if (<= x 4e-7) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.15e-38) {
tmp = x;
} else if (x <= 4e-7) {
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 <= (-2.15d-38)) then
tmp = x
else if (x <= 4d-7) 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 <= -2.15e-38) {
tmp = x;
} else if (x <= 4e-7) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.15e-38: tmp = x elif x <= 4e-7: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.15e-38) tmp = x; elseif (x <= 4e-7) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.15e-38) tmp = x; elseif (x <= 4e-7) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.15e-38], x, If[LessEqual[x, 4e-7], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 4 \cdot 10^{-7}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.1500000000000001e-38 or 3.9999999999999998e-7 < x Initial program 99.9%
Taylor expanded in x around inf 68.6%
if -2.1500000000000001e-38 < x < 3.9999999999999998e-7Initial program 99.9%
associate-+l+99.9%
add-cube-cbrt99.7%
fma-def99.7%
pow299.7%
+-commutative99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in z around inf 67.3%
Taylor expanded in y around 0 43.8%
Final simplification58.3%
(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 69.4%
Final simplification69.4%
(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%
Taylor expanded in x around inf 44.0%
Final simplification44.0%
herbie shell --seed 2023224
(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))))