
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (- 0.0 z) (+ x y) (+ x y)))
double code(double x, double y, double z) {
return fma((0.0 - z), (x + y), (x + y));
}
function code(x, y, z) return fma(Float64(0.0 - z), Float64(x + y), Float64(x + y)) end
code[x_, y_, z_] := N[(N[(0.0 - z), $MachinePrecision] * N[(x + y), $MachinePrecision] + N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0 - z, x + y, x + y\right)
\end{array}
Initial program 100.0%
sub-negN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-257) (fma (- 0.0 z) x x) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-257) {
tmp = fma((0.0 - z), x, x);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-257) tmp = fma(Float64(0.0 - z), x, x); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-257], N[(N[(0.0 - z), $MachinePrecision] * x + x), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-257}:\\
\;\;\;\;\mathsf{fma}\left(0 - z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -2e-257Initial program 100.0%
sub-negN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
+-lowering-+.f64N/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around inf
Simplified74.3%
Taylor expanded in x around inf
Simplified48.3%
sub0-negN/A
neg-lowering-neg.f6448.3
Applied egg-rr48.3%
if -2e-257 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Simplified47.2%
Final simplification47.7%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-257) (* x (- 1.0 z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-257) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - 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 ((x + y) <= (-2d-257)) then
tmp = x * (1.0d0 - z)
else
tmp = y * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-257) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-257: tmp = x * (1.0 - z) else: tmp = y * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-257) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-257) tmp = x * (1.0 - z); else tmp = y * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-257], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-257}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -2e-257Initial program 100.0%
Taylor expanded in x around inf
Simplified48.3%
if -2e-257 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Simplified47.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-257) (* x (- 1.0 z)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-257) {
tmp = x * (1.0 - z);
} else {
tmp = 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 ((x + y) <= (-2d-257)) then
tmp = x * (1.0d0 - z)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-257) {
tmp = x * (1.0 - z);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -2e-257: tmp = x * (1.0 - z) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-257) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x + y) <= -2e-257) tmp = x * (1.0 - z); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-257], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-257}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (+.f64 x y) < -2e-257Initial program 100.0%
Taylor expanded in x around inf
Simplified48.3%
if -2e-257 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6459.2
Simplified59.2%
Final simplification53.9%
(FPCore (x y z) :precision binary64 (if (<= (* (+ x y) (- 1.0 z)) -1e-209) x y))
double code(double x, double y, double z) {
double tmp;
if (((x + y) * (1.0 - z)) <= -1e-209) {
tmp = x;
} else {
tmp = 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 + y) * (1.0d0 - z)) <= (-1d-209)) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((x + y) * (1.0 - z)) <= -1e-209) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x + y) * (1.0 - z)) <= -1e-209: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(Float64(x + y) * Float64(1.0 - z)) <= -1e-209) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((x + y) * (1.0 - z)) <= -1e-209) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], -1e-209], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) \cdot \left(1 - z\right) \leq -1 \cdot 10^{-209}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -1e-209Initial program 100.0%
Taylor expanded in x around inf
Simplified48.4%
Taylor expanded in z around 0
Simplified22.9%
if -1e-209 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) Initial program 100.0%
Taylor expanded in x around 0
Simplified47.3%
Taylor expanded in z around 0
Simplified27.7%
(FPCore (x y z) :precision binary64 (* (+ x y) (- 1.0 z)))
double code(double x, double y, double z) {
return (x + y) * (1.0 - 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) * (1.0d0 - z)
end function
public static double code(double x, double y, double z) {
return (x + y) * (1.0 - z);
}
def code(x, y, z): return (x + y) * (1.0 - z)
function code(x, y, z) return Float64(Float64(x + y) * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = (x + y) * (1.0 - z); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(1 - z\right)
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (+ x y))
double code(double x, double y, double z) {
return 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 = x + y
end function
public static double code(double x, double y, double z) {
return x + y;
}
def code(x, y, z): return x + y
function code(x, y, z) return Float64(x + y) end
function tmp = code(x, y, z) tmp = x + y; end
code[x_, y_, z_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6453.3
Simplified53.3%
Final simplification53.3%
(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 100.0%
Taylor expanded in x around inf
Simplified51.7%
Taylor expanded in z around 0
Simplified27.5%
herbie shell --seed 2024196
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))