
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + 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 + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + 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 + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma (+ x z) y x))
double code(double x, double y, double z) {
return fma((x + z), y, x);
}
function code(x, y, z) return fma(Float64(x + z), y, x) end
code[x_, y_, z_] := N[(N[(x + z), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + z, y, x\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ x z) y))) (if (<= y -75000000.0) t_0 (if (<= y 1.0) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x + z) * y;
double tmp;
if (y <= -75000000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x + z) * y) tmp = 0.0 if (y <= -75000000.0) tmp = t_0; elseif (y <= 1.0) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -75000000.0], t$95$0, If[LessEqual[y, 1.0], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + z\right) \cdot y\\
\mathbf{if}\;y \leq -75000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.5e7 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.5
Simplified98.5%
if -7.5e7 < y < 1Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.8
Simplified98.8%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.8
Applied egg-rr98.8%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (if (<= z -3.8e-128) (fma z y x) (if (<= z 4.6e-115) (fma y x x) (fma z y x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e-128) {
tmp = fma(z, y, x);
} else if (z <= 4.6e-115) {
tmp = fma(y, x, x);
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -3.8e-128) tmp = fma(z, y, x); elseif (z <= 4.6e-115) tmp = fma(y, x, x); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -3.8e-128], N[(z * y + x), $MachinePrecision], If[LessEqual[z, 4.6e-115], N[(y * x + x), $MachinePrecision], N[(z * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-128}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{-115}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if z < -3.8000000000000002e-128 or 4.59999999999999969e-115 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6491.6
Simplified91.6%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6491.6
Applied egg-rr91.6%
if -3.8000000000000002e-128 < z < 4.59999999999999969e-115Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6497.1
Simplified97.1%
(FPCore (x y z) :precision binary64 (if (<= z -7.6e+115) (* z y) (if (<= z 31500000000000.0) (fma y x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -7.6e+115) {
tmp = z * y;
} else if (z <= 31500000000000.0) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -7.6e+115) tmp = Float64(z * y); elseif (z <= 31500000000000.0) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -7.6e+115], N[(z * y), $MachinePrecision], If[LessEqual[z, 31500000000000.0], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{+115}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 31500000000000:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -7.6000000000000001e115 or 3.15e13 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6476.7
Simplified76.7%
if -7.6000000000000001e115 < z < 3.15e13Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6479.1
Simplified79.1%
Final simplification78.1%
(FPCore (x y z) :precision binary64 (if (<= z -3.1e-128) (* z y) (if (<= z 4.6e-115) (* x y) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e-128) {
tmp = z * y;
} else if (z <= 4.6e-115) {
tmp = x * y;
} else {
tmp = z * 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 <= (-3.1d-128)) then
tmp = z * y
else if (z <= 4.6d-115) then
tmp = x * y
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.1e-128) {
tmp = z * y;
} else if (z <= 4.6e-115) {
tmp = x * y;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.1e-128: tmp = z * y elif z <= 4.6e-115: tmp = x * y else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.1e-128) tmp = Float64(z * y); elseif (z <= 4.6e-115) tmp = Float64(x * y); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.1e-128) tmp = z * y; elseif (z <= 4.6e-115) tmp = x * y; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.1e-128], N[(z * y), $MachinePrecision], If[LessEqual[z, 4.6e-115], N[(x * y), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{-128}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{-115}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -3.10000000000000003e-128 or 4.59999999999999969e-115 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6460.2
Simplified60.2%
if -3.10000000000000003e-128 < z < 4.59999999999999969e-115Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6497.1
Simplified97.1%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6446.4
Simplified46.4%
Final simplification56.6%
(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 \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6457.5
Simplified57.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6422.2
Simplified22.2%
Final simplification22.2%
herbie shell --seed 2024207
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))