
(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
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (+ x z)) (+ (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = (y * z) + 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 ((y <= (-1.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + z)
else
tmp = (y * z) + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = (y * z) + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * (x + z) else: tmp = (y * z) + x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(Float64(y * z) + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = y * (x + z); else tmp = (y * z) + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z + x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.8
Applied rewrites98.8%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6498.2
Applied rewrites98.2%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.2e-28) (not (<= y 0.0135))) (* y (+ x z)) (fma y x x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e-28) || !(y <= 0.0135)) {
tmp = y * (x + z);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -2.2e-28) || !(y <= 0.0135)) tmp = Float64(y * Float64(x + z)); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e-28], N[Not[LessEqual[y, 0.0135]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-28} \lor \neg \left(y \leq 0.0135\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if y < -2.19999999999999996e-28 or 0.0134999999999999998 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6497.4
Applied rewrites97.4%
if -2.19999999999999996e-28 < y < 0.0134999999999999998Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6472.2
Applied rewrites72.2%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.1e-61) (not (<= x 5.2e-124))) (fma y x x) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.1e-61) || !(x <= 5.2e-124)) {
tmp = fma(y, x, x);
} else {
tmp = y * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -4.1e-61) || !(x <= 5.2e-124)) tmp = fma(y, x, x); else tmp = Float64(y * z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.1e-61], N[Not[LessEqual[x, 5.2e-124]], $MachinePrecision]], N[(y * x + x), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{-61} \lor \neg \left(x \leq 5.2 \cdot 10^{-124}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.09999999999999999e-61 or 5.1999999999999999e-124 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6482.7
Applied rewrites82.7%
if -4.09999999999999999e-61 < x < 5.1999999999999999e-124Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6470.9
Applied rewrites70.9%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.7e+22) (not (<= x 1.05e+79))) (* y x) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e+22) || !(x <= 1.05e+79)) {
tmp = y * x;
} else {
tmp = 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 ((x <= (-3.7d+22)) .or. (.not. (x <= 1.05d+79))) then
tmp = y * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -3.7e+22) || !(x <= 1.05e+79)) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.7e+22) or not (x <= 1.05e+79): tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.7e+22) || !(x <= 1.05e+79)) tmp = Float64(y * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.7e+22) || ~((x <= 1.05e+79))) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.7e+22], N[Not[LessEqual[x, 1.05e+79]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.7 \cdot 10^{+22} \lor \neg \left(x \leq 1.05 \cdot 10^{+79}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.6999999999999998e22 or 1.05000000000000004e79 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6490.5
Applied rewrites90.5%
Taylor expanded in y around inf
Applied rewrites51.0%
if -3.6999999999999998e22 < x < 1.05000000000000004e79Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6458.7
Applied rewrites58.7%
Final simplification55.4%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return 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 = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6463.1
Applied rewrites63.1%
Taylor expanded in y around inf
Applied rewrites31.0%
herbie shell --seed 2024271
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))