
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
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) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
(FPCore (x y z) :precision binary64 (* (+ 1.0 z) (+ y x)))
double code(double x, double y, double z) {
return (1.0 + z) * (y + x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 + z) * (y + x)
end function
public static double code(double x, double y, double z) {
return (1.0 + z) * (y + x);
}
def code(x, y, z): return (1.0 + z) * (y + x)
function code(x, y, z) return Float64(Float64(1.0 + z) * Float64(y + x)) end
function tmp = code(x, y, z) tmp = (1.0 + z) * (y + x); end
code[x_, y_, z_] := N[(N[(1.0 + z), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + z\right) \cdot \left(y + x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= (+ 1.0 z) -1e+28)
(* z y)
(if (<= (+ 1.0 z) 0.999999)
(fma x z x)
(if (<= (+ 1.0 z) 1.0002) (+ y x) (fma x z x)))))
double code(double x, double y, double z) {
double tmp;
if ((1.0 + z) <= -1e+28) {
tmp = z * y;
} else if ((1.0 + z) <= 0.999999) {
tmp = fma(x, z, x);
} else if ((1.0 + z) <= 1.0002) {
tmp = y + x;
} else {
tmp = fma(x, z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(1.0 + z) <= -1e+28) tmp = Float64(z * y); elseif (Float64(1.0 + z) <= 0.999999) tmp = fma(x, z, x); elseif (Float64(1.0 + z) <= 1.0002) tmp = Float64(y + x); else tmp = fma(x, z, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(1.0 + z), $MachinePrecision], -1e+28], N[(z * y), $MachinePrecision], If[LessEqual[N[(1.0 + z), $MachinePrecision], 0.999999], N[(x * z + x), $MachinePrecision], If[LessEqual[N[(1.0 + z), $MachinePrecision], 1.0002], N[(y + x), $MachinePrecision], N[(x * z + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 + z \leq -1 \cdot 10^{+28}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;1 + z \leq 0.999999:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\mathbf{elif}\;1 + z \leq 1.0002:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, z, x\right)\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -9.99999999999999958e27Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6453.3
Applied rewrites53.3%
Taylor expanded in z around inf
Applied rewrites53.3%
if -9.99999999999999958e27 < (+.f64 z #s(literal 1 binary64)) < 0.999998999999999971 or 1.0002 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6453.5
Applied rewrites53.5%
if 0.999998999999999971 < (+.f64 z #s(literal 1 binary64)) < 1.0002Initial program 100.0%
Taylor expanded in z around 0
lower-+.f6499.0
Applied rewrites99.0%
Final simplification75.5%
herbie shell --seed 2024230
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))