
(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 9 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) -1e-269) (fma (- 0.0 z) x x) (fma (- 0.0 z) y y)))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-269) {
tmp = fma((0.0 - z), x, x);
} else {
tmp = fma((0.0 - z), y, y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -1e-269) tmp = fma(Float64(0.0 - z), x, x); else tmp = fma(Float64(0.0 - z), y, y); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -1e-269], N[(N[(0.0 - z), $MachinePrecision] * x + x), $MachinePrecision], N[(N[(0.0 - z), $MachinePrecision] * y + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -1 \cdot 10^{-269}:\\
\;\;\;\;\mathsf{fma}\left(0 - z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0 - z, y, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -9.9999999999999996e-270Initial 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
Simplified70.9%
Taylor expanded in x around inf
Simplified53.3%
sub0-negN/A
neg-lowering-neg.f6453.3
Applied egg-rr53.3%
if -9.9999999999999996e-270 < (+.f64 x y) 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%
Taylor expanded in x around 0
Simplified68.1%
Taylor expanded in x around 0
Simplified42.2%
sub0-negN/A
neg-lowering-neg.f6442.2
Applied egg-rr42.2%
Final simplification48.0%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-269) (fma (- 0.0 z) x x) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-269) {
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) <= -1e-269) 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], -1e-269], 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 -1 \cdot 10^{-269}:\\
\;\;\;\;\mathsf{fma}\left(0 - z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -9.9999999999999996e-270Initial 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
Simplified70.9%
Taylor expanded in x around inf
Simplified53.3%
sub0-negN/A
neg-lowering-neg.f6453.3
Applied egg-rr53.3%
if -9.9999999999999996e-270 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Simplified42.2%
Final simplification48.0%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-269) (* x (- 1.0 z)) (* y (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-269) {
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) <= (-1d-269)) 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) <= -1e-269) {
tmp = x * (1.0 - z);
} else {
tmp = y * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= -1e-269: 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) <= -1e-269) 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) <= -1e-269) 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], -1e-269], 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 -1 \cdot 10^{-269}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -9.9999999999999996e-270Initial program 100.0%
Taylor expanded in x around inf
Simplified53.3%
if -9.9999999999999996e-270 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
Simplified42.2%
(FPCore (x y z) :precision binary64 (if (<= (+ x y) 5e-290) (* x (- 1.0 z)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= 5e-290) {
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) <= 5d-290) 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) <= 5e-290) {
tmp = x * (1.0 - z);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x + y) <= 5e-290: tmp = x * (1.0 - z) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= 5e-290) 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) <= 5e-290) tmp = x * (1.0 - z); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], 5e-290], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq 5 \cdot 10^{-290}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if (+.f64 x y) < 5.0000000000000001e-290Initial program 100.0%
Taylor expanded in x around inf
Simplified53.0%
if 5.0000000000000001e-290 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6451.0
Simplified51.0%
Final simplification52.0%
(FPCore (x y z) :precision binary64 (if (<= (* (+ x y) (- 1.0 z)) -1e-269) x y))
double code(double x, double y, double z) {
double tmp;
if (((x + y) * (1.0 - z)) <= -1e-269) {
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-269)) 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-269) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((x + y) * (1.0 - z)) <= -1e-269: 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-269) 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-269) 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-269], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x + y\right) \cdot \left(1 - z\right) \leq -1 \cdot 10^{-269}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) < -9.9999999999999996e-270Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6457.5
Simplified57.5%
Taylor expanded in y around 0
Simplified27.9%
if -9.9999999999999996e-270 < (*.f64 (+.f64 x y) (-.f64 #s(literal 1 binary64) z)) Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
+-lowering-+.f6449.3
Simplified49.3%
Taylor expanded in y around inf
Simplified19.3%
(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.5
Simplified53.5%
Final simplification53.5%
(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 z around 0
+-commutativeN/A
+-lowering-+.f6453.5
Simplified53.5%
Taylor expanded in y around 0
Simplified30.2%
herbie shell --seed 2024195
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, H"
:precision binary64
(* (+ x y) (- 1.0 z)))