
(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 (<= y -3.2e+222)
(* y z)
(if (<= y -1.1e+14)
(* y x)
(if (<= y -1.55e-118)
(* y z)
(if (<= y 4.2e-21) x (if (<= y 1.7e+142) (* y z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+222) {
tmp = y * z;
} else if (y <= -1.1e+14) {
tmp = y * x;
} else if (y <= -1.55e-118) {
tmp = y * z;
} else if (y <= 4.2e-21) {
tmp = x;
} else if (y <= 1.7e+142) {
tmp = y * z;
} else {
tmp = 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 <= (-3.2d+222)) then
tmp = y * z
else if (y <= (-1.1d+14)) then
tmp = y * x
else if (y <= (-1.55d-118)) then
tmp = y * z
else if (y <= 4.2d-21) then
tmp = x
else if (y <= 1.7d+142) then
tmp = y * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.2e+222) {
tmp = y * z;
} else if (y <= -1.1e+14) {
tmp = y * x;
} else if (y <= -1.55e-118) {
tmp = y * z;
} else if (y <= 4.2e-21) {
tmp = x;
} else if (y <= 1.7e+142) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.2e+222: tmp = y * z elif y <= -1.1e+14: tmp = y * x elif y <= -1.55e-118: tmp = y * z elif y <= 4.2e-21: tmp = x elif y <= 1.7e+142: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.2e+222) tmp = Float64(y * z); elseif (y <= -1.1e+14) tmp = Float64(y * x); elseif (y <= -1.55e-118) tmp = Float64(y * z); elseif (y <= 4.2e-21) tmp = x; elseif (y <= 1.7e+142) tmp = Float64(y * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.2e+222) tmp = y * z; elseif (y <= -1.1e+14) tmp = y * x; elseif (y <= -1.55e-118) tmp = y * z; elseif (y <= 4.2e-21) tmp = x; elseif (y <= 1.7e+142) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.2e+222], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.1e+14], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.55e-118], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.2e-21], x, If[LessEqual[y, 1.7e+142], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{+222}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.1 \cdot 10^{+14}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{-118}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-21}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+142}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.2000000000000001e222 or -1.1e14 < y < -1.5500000000000001e-118 or 4.20000000000000025e-21 < y < 1.6999999999999999e142Initial program 100.0%
Taylor expanded in y around inf 98.8%
Taylor expanded in x around 0 67.7%
if -3.2000000000000001e222 < y < -1.1e14 or 1.6999999999999999e142 < y Initial program 99.9%
Taylor expanded in x around inf 61.8%
+-commutative61.8%
Simplified61.8%
Taylor expanded in y around inf 61.7%
*-commutative61.7%
Simplified61.7%
if -1.5500000000000001e-118 < y < 4.20000000000000025e-21Initial program 100.0%
Taylor expanded in x around inf 75.0%
+-commutative75.0%
Simplified75.0%
Taylor expanded in y around 0 75.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -160.0) (not (<= y 0.55))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -160.0) || !(y <= 0.55)) {
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 <= (-160.0d0)) .or. (.not. (y <= 0.55d0))) 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 <= -160.0) || !(y <= 0.55)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -160.0) or not (y <= 0.55): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -160.0) || !(y <= 0.55)) 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 <= -160.0) || ~((y <= 0.55))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -160.0], N[Not[LessEqual[y, 0.55]], $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 -160 \lor \neg \left(y \leq 0.55\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -160 or 0.55000000000000004 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in z around inf 99.1%
if -160 < y < 0.55000000000000004Initial program 100.0%
Taylor expanded in z around inf 99.3%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.65e-118) (not (<= y 1.55e-79))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.65e-118) || !(y <= 1.55e-79)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
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.65d-118)) .or. (.not. (y <= 1.55d-79))) then
tmp = y * (x + z)
else
tmp = x * (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.65e-118) || !(y <= 1.55e-79)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.65e-118) or not (y <= 1.55e-79): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.65e-118) || !(y <= 1.55e-79)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.65e-118) || ~((y <= 1.55e-79))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.65e-118], N[Not[LessEqual[y, 1.55e-79]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{-118} \lor \neg \left(y \leq 1.55 \cdot 10^{-79}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -1.65e-118 or 1.55e-79 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
Taylor expanded in z around inf 91.5%
if -1.65e-118 < y < 1.55e-79Initial program 100.0%
Taylor expanded in x around inf 77.3%
+-commutative77.3%
Simplified77.3%
Final simplification87.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.4e+65) (not (<= z 5.8e-14))) (* y z) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e+65) || !(z <= 5.8e-14)) {
tmp = y * z;
} else {
tmp = x * (y + 1.0);
}
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.4d+65)) .or. (.not. (z <= 5.8d-14))) then
tmp = y * z
else
tmp = x * (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.4e+65) || !(z <= 5.8e-14)) {
tmp = y * z;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.4e+65) or not (z <= 5.8e-14): tmp = y * z else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.4e+65) || !(z <= 5.8e-14)) tmp = Float64(y * z); else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.4e+65) || ~((z <= 5.8e-14))) tmp = y * z; else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.4e+65], N[Not[LessEqual[z, 5.8e-14]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.4 \cdot 10^{+65} \lor \neg \left(z \leq 5.8 \cdot 10^{-14}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -3.3999999999999999e65 or 5.8000000000000005e-14 < z Initial program 100.0%
Taylor expanded in y around inf 94.2%
Taylor expanded in x around 0 77.9%
if -3.3999999999999999e65 < z < 5.8000000000000005e-14Initial program 99.9%
Taylor expanded in x around inf 82.4%
+-commutative82.4%
Simplified82.4%
Final simplification80.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -18000000000000.0) (not (<= y 1.8e-20))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -18000000000000.0) || !(y <= 1.8e-20)) {
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 <= (-18000000000000.0d0)) .or. (.not. (y <= 1.8d-20))) 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 <= -18000000000000.0) || !(y <= 1.8e-20)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -18000000000000.0) or not (y <= 1.8e-20): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -18000000000000.0) || !(y <= 1.8e-20)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -18000000000000.0) || ~((y <= 1.8e-20))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -18000000000000.0], N[Not[LessEqual[y, 1.8e-20]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -18000000000000 \lor \neg \left(y \leq 1.8 \cdot 10^{-20}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.8e13 or 1.79999999999999987e-20 < y Initial program 100.0%
Taylor expanded in x around inf 50.3%
+-commutative50.3%
Simplified50.3%
Taylor expanded in y around inf 49.5%
*-commutative49.5%
Simplified49.5%
if -1.8e13 < y < 1.79999999999999987e-20Initial program 100.0%
Taylor expanded in x around inf 66.7%
+-commutative66.7%
Simplified66.7%
Taylor expanded in y around 0 66.0%
Final simplification57.0%
(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%
Taylor expanded in x around inf 57.7%
+-commutative57.7%
Simplified57.7%
Taylor expanded in y around 0 31.6%
herbie shell --seed 2024130
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))