
(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 8 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 y (+ x z) x))
double code(double x, double y, double z) {
return fma(y, (x + z), x);
}
function code(x, y, z) return fma(y, Float64(x + z), x) end
code[x_, y_, z_] := N[(y * N[(x + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x + z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -3e+15) (not (<= y 0.195))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3e+15) || !(y <= 0.195)) {
tmp = y * (x + z);
} else {
tmp = x + (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 ((y <= (-3d+15)) .or. (.not. (y <= 0.195d0))) then
tmp = y * (x + z)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -3e+15) || !(y <= 0.195)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3e+15) or not (y <= 0.195): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3e+15) || !(y <= 0.195)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3e+15) || ~((y <= 0.195))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3e+15], N[Not[LessEqual[y, 0.195]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+15} \lor \neg \left(y \leq 0.195\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -3e15 or 0.19500000000000001 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 99.5%
if -3e15 < y < 0.19500000000000001Initial program 100.0%
Taylor expanded in z around inf 99.1%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e-69) (not (<= y 4.5e-11))) (* y (+ x z)) (+ x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e-69) || !(y <= 4.5e-11)) {
tmp = y * (x + z);
} else {
tmp = x + (y * 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 <= (-4d-69)) .or. (.not. (y <= 4.5d-11))) then
tmp = y * (x + z)
else
tmp = x + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4e-69) || !(y <= 4.5e-11)) {
tmp = y * (x + z);
} else {
tmp = x + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e-69) or not (y <= 4.5e-11): tmp = y * (x + z) else: tmp = x + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e-69) || !(y <= 4.5e-11)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4e-69) || ~((y <= 4.5e-11))) tmp = y * (x + z); else tmp = x + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e-69], N[Not[LessEqual[y, 4.5e-11]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-69} \lor \neg \left(y \leq 4.5 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot x\\
\end{array}
\end{array}
if y < -3.9999999999999999e-69 or 4.5e-11 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
Taylor expanded in z around inf 95.0%
if -3.9999999999999999e-69 < y < 4.5e-11Initial program 100.0%
Taylor expanded in z around 0 70.5%
*-commutative70.5%
Simplified70.5%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -7e-70) (not (<= y 1.05e-10))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-70) || !(y <= 1.05e-10)) {
tmp = y * (x + z);
} else {
tmp = 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 <= (-7d-70)) .or. (.not. (y <= 1.05d-10))) then
tmp = y * (x + z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-70) || !(y <= 1.05e-10)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7e-70) or not (y <= 1.05e-10): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7e-70) || !(y <= 1.05e-10)) tmp = Float64(y * Float64(x + z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7e-70) || ~((y <= 1.05e-10))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7e-70], N[Not[LessEqual[y, 1.05e-10]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-70} \lor \neg \left(y \leq 1.05 \cdot 10^{-10}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.99999999999999949e-70 or 1.05e-10 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
Taylor expanded in z around inf 95.0%
if -6.99999999999999949e-70 < y < 1.05e-10Initial program 100.0%
distribute-rgt-in100.0%
fma-define100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 70.3%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -7e-72) (not (<= y 1.6e-11))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-72) || !(y <= 1.6e-11)) {
tmp = y * z;
} else {
tmp = 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 <= (-7d-72)) .or. (.not. (y <= 1.6d-11))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7e-72) || !(y <= 1.6e-11)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7e-72) or not (y <= 1.6e-11): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7e-72) || !(y <= 1.6e-11)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7e-72) || ~((y <= 1.6e-11))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7e-72], N[Not[LessEqual[y, 1.6e-11]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-72} \lor \neg \left(y \leq 1.6 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.00000000000000001e-72 or 1.59999999999999997e-11 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
Taylor expanded in z around inf 95.0%
Taylor expanded in x around 0 61.2%
if -7.00000000000000001e-72 < y < 1.59999999999999997e-11Initial program 100.0%
distribute-rgt-in100.0%
fma-define100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 70.3%
Final simplification65.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1800000.0) (not (<= y 2.25e-8))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1800000.0) || !(y <= 2.25e-8)) {
tmp = y * x;
} else {
tmp = 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 <= (-1800000.0d0)) .or. (.not. (y <= 2.25d-8))) then
tmp = y * x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1800000.0) || !(y <= 2.25e-8)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1800000.0) or not (y <= 2.25e-8): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1800000.0) || !(y <= 2.25e-8)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1800000.0) || ~((y <= 2.25e-8))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1800000.0], N[Not[LessEqual[y, 2.25e-8]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1800000 \lor \neg \left(y \leq 2.25 \cdot 10^{-8}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.8e6 or 2.24999999999999996e-8 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 99.0%
Taylor expanded in x around inf 44.5%
*-commutative44.5%
Simplified44.5%
if -1.8e6 < y < 2.24999999999999996e-8Initial program 100.0%
distribute-rgt-in100.0%
fma-define100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 65.9%
Final simplification55.3%
(FPCore (x y z) :precision binary64 (+ x (* y (+ x z))))
double code(double x, double y, double z) {
return x + (y * (x + 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 * (x + z))
end function
public static double code(double x, double y, double z) {
return x + (y * (x + z));
}
def code(x, y, z): return x + (y * (x + z))
function code(x, y, z) return Float64(x + Float64(y * Float64(x + z))) end
function tmp = code(x, y, z) tmp = x + (y * (x + z)); end
code[x_, y_, z_] := N[(x + N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x + z\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(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%
distribute-rgt-in96.5%
fma-define97.3%
*-commutative97.3%
Applied egg-rr97.3%
Taylor expanded in y around 0 34.7%
herbie shell --seed 2024170
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))