
(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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -3.4e+227)
(* y x)
(if (<= y -1.25e+112)
(* y z)
(if (<= y -6e+38)
(* y x)
(if (<= y -2.7e-14)
(* y z)
(if (<= y 3e-184)
x
(if (<= y 9e-156)
(* y z)
(if (<= y 1e-50)
x
(if (or (<= y 9e+109)
(and (not (<= y 3.5e+167)) (<= y 1.2e+214)))
(* y z)
(* y x))))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.4e+227) {
tmp = y * x;
} else if (y <= -1.25e+112) {
tmp = y * z;
} else if (y <= -6e+38) {
tmp = y * x;
} else if (y <= -2.7e-14) {
tmp = y * z;
} else if (y <= 3e-184) {
tmp = x;
} else if (y <= 9e-156) {
tmp = y * z;
} else if (y <= 1e-50) {
tmp = x;
} else if ((y <= 9e+109) || (!(y <= 3.5e+167) && (y <= 1.2e+214))) {
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.4d+227)) then
tmp = y * x
else if (y <= (-1.25d+112)) then
tmp = y * z
else if (y <= (-6d+38)) then
tmp = y * x
else if (y <= (-2.7d-14)) then
tmp = y * z
else if (y <= 3d-184) then
tmp = x
else if (y <= 9d-156) then
tmp = y * z
else if (y <= 1d-50) then
tmp = x
else if ((y <= 9d+109) .or. (.not. (y <= 3.5d+167)) .and. (y <= 1.2d+214)) 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.4e+227) {
tmp = y * x;
} else if (y <= -1.25e+112) {
tmp = y * z;
} else if (y <= -6e+38) {
tmp = y * x;
} else if (y <= -2.7e-14) {
tmp = y * z;
} else if (y <= 3e-184) {
tmp = x;
} else if (y <= 9e-156) {
tmp = y * z;
} else if (y <= 1e-50) {
tmp = x;
} else if ((y <= 9e+109) || (!(y <= 3.5e+167) && (y <= 1.2e+214))) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.4e+227: tmp = y * x elif y <= -1.25e+112: tmp = y * z elif y <= -6e+38: tmp = y * x elif y <= -2.7e-14: tmp = y * z elif y <= 3e-184: tmp = x elif y <= 9e-156: tmp = y * z elif y <= 1e-50: tmp = x elif (y <= 9e+109) or (not (y <= 3.5e+167) and (y <= 1.2e+214)): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.4e+227) tmp = Float64(y * x); elseif (y <= -1.25e+112) tmp = Float64(y * z); elseif (y <= -6e+38) tmp = Float64(y * x); elseif (y <= -2.7e-14) tmp = Float64(y * z); elseif (y <= 3e-184) tmp = x; elseif (y <= 9e-156) tmp = Float64(y * z); elseif (y <= 1e-50) tmp = x; elseif ((y <= 9e+109) || (!(y <= 3.5e+167) && (y <= 1.2e+214))) 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.4e+227) tmp = y * x; elseif (y <= -1.25e+112) tmp = y * z; elseif (y <= -6e+38) tmp = y * x; elseif (y <= -2.7e-14) tmp = y * z; elseif (y <= 3e-184) tmp = x; elseif (y <= 9e-156) tmp = y * z; elseif (y <= 1e-50) tmp = x; elseif ((y <= 9e+109) || (~((y <= 3.5e+167)) && (y <= 1.2e+214))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.4e+227], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.25e+112], N[(y * z), $MachinePrecision], If[LessEqual[y, -6e+38], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.7e-14], N[(y * z), $MachinePrecision], If[LessEqual[y, 3e-184], x, If[LessEqual[y, 9e-156], N[(y * z), $MachinePrecision], If[LessEqual[y, 1e-50], x, If[Or[LessEqual[y, 9e+109], And[N[Not[LessEqual[y, 3.5e+167]], $MachinePrecision], LessEqual[y, 1.2e+214]]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+227}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{+112}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -6 \cdot 10^{+38}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{-14}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-184}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-156}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 10^{-50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+109} \lor \neg \left(y \leq 3.5 \cdot 10^{+167}\right) \land y \leq 1.2 \cdot 10^{+214}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.39999999999999989e227 or -1.25e112 < y < -6.0000000000000002e38 or 8.9999999999999992e109 < y < 3.49999999999999987e167 or 1.2e214 < y Initial program 100.0%
Taylor expanded in x around inf 75.5%
+-commutative75.5%
Simplified75.5%
Taylor expanded in y around inf 75.5%
if -3.39999999999999989e227 < y < -1.25e112 or -6.0000000000000002e38 < y < -2.6999999999999999e-14 or 2.99999999999999991e-184 < y < 8.99999999999999971e-156 or 1.00000000000000001e-50 < y < 8.9999999999999992e109 or 3.49999999999999987e167 < y < 1.2e214Initial program 99.9%
Taylor expanded in x around -inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 67.4%
if -2.6999999999999999e-14 < y < 2.99999999999999991e-184 or 8.99999999999999971e-156 < y < 1.00000000000000001e-50Initial program 100.0%
Taylor expanded in y around 0 80.2%
Final simplification74.4%
(FPCore (x y z)
:precision binary64
(if (or (<= z -1.55e+71)
(not (or (<= z 1.7e+35) (and (not (<= z 3.2e+145)) (<= z 3.2e+185)))))
(* y z)
(* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.55e+71) || !((z <= 1.7e+35) || (!(z <= 3.2e+145) && (z <= 3.2e+185)))) {
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 <= (-1.55d+71)) .or. (.not. (z <= 1.7d+35) .or. (.not. (z <= 3.2d+145)) .and. (z <= 3.2d+185))) 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 <= -1.55e+71) || !((z <= 1.7e+35) || (!(z <= 3.2e+145) && (z <= 3.2e+185)))) {
tmp = y * z;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.55e+71) or not ((z <= 1.7e+35) or (not (z <= 3.2e+145) and (z <= 3.2e+185))): tmp = y * z else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.55e+71) || !((z <= 1.7e+35) || (!(z <= 3.2e+145) && (z <= 3.2e+185)))) 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 <= -1.55e+71) || ~(((z <= 1.7e+35) || (~((z <= 3.2e+145)) && (z <= 3.2e+185))))) tmp = y * z; else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.55e+71], N[Not[Or[LessEqual[z, 1.7e+35], And[N[Not[LessEqual[z, 3.2e+145]], $MachinePrecision], LessEqual[z, 3.2e+185]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{+71} \lor \neg \left(z \leq 1.7 \cdot 10^{+35} \lor \neg \left(z \leq 3.2 \cdot 10^{+145}\right) \land z \leq 3.2 \cdot 10^{+185}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -1.55000000000000009e71 or 1.7000000000000001e35 < z < 3.20000000000000008e145 or 3.20000000000000006e185 < z Initial program 100.0%
Taylor expanded in x around -inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in z around inf 78.8%
if -1.55000000000000009e71 < z < 1.7000000000000001e35 or 3.20000000000000008e145 < z < 3.20000000000000006e185Initial program 99.9%
Taylor expanded in x around inf 85.8%
+-commutative85.8%
Simplified85.8%
Final simplification82.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -2.2e-14)
(not (or (<= y 3e-184) (and (not (<= y 7.8e-140)) (<= y 9e-57)))))
(* y (+ x z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e-14) || !((y <= 3e-184) || (!(y <= 7.8e-140) && (y <= 9e-57)))) {
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 <= (-2.2d-14)) .or. (.not. (y <= 3d-184) .or. (.not. (y <= 7.8d-140)) .and. (y <= 9d-57))) 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 <= -2.2e-14) || !((y <= 3e-184) || (!(y <= 7.8e-140) && (y <= 9e-57)))) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.2e-14) or not ((y <= 3e-184) or (not (y <= 7.8e-140) and (y <= 9e-57))): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.2e-14) || !((y <= 3e-184) || (!(y <= 7.8e-140) && (y <= 9e-57)))) 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 <= -2.2e-14) || ~(((y <= 3e-184) || (~((y <= 7.8e-140)) && (y <= 9e-57))))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.2e-14], N[Not[Or[LessEqual[y, 3e-184], And[N[Not[LessEqual[y, 7.8e-140]], $MachinePrecision], LessEqual[y, 9e-57]]]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-14} \lor \neg \left(y \leq 3 \cdot 10^{-184} \lor \neg \left(y \leq 7.8 \cdot 10^{-140}\right) \land y \leq 9 \cdot 10^{-57}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -2.2000000000000001e-14 or 2.99999999999999991e-184 < y < 7.80000000000000038e-140 or 8.99999999999999945e-57 < y Initial program 99.9%
Taylor expanded in x around -inf 98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
sub-neg98.0%
metadata-eval98.0%
+-commutative98.0%
mul-1-neg98.0%
unsub-neg98.0%
Simplified98.0%
Taylor expanded in y around inf 95.2%
cancel-sign-sub-inv95.2%
metadata-eval95.2%
*-lft-identity95.2%
+-commutative95.2%
Simplified95.2%
if -2.2000000000000001e-14 < y < 2.99999999999999991e-184 or 7.80000000000000038e-140 < y < 8.99999999999999945e-57Initial program 100.0%
Taylor expanded in y around 0 80.8%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -102000.0) (not (<= y 0.00132))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -102000.0) || !(y <= 0.00132)) {
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 <= (-102000.0d0)) .or. (.not. (y <= 0.00132d0))) 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 <= -102000.0) || !(y <= 0.00132)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -102000.0) or not (y <= 0.00132): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -102000.0) || !(y <= 0.00132)) 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 <= -102000.0) || ~((y <= 0.00132))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -102000.0], N[Not[LessEqual[y, 0.00132]], $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 -102000 \lor \neg \left(y \leq 0.00132\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -102000 or 0.00132 < y Initial program 99.9%
Taylor expanded in x around -inf 97.6%
+-commutative97.6%
mul-1-neg97.6%
unsub-neg97.6%
sub-neg97.6%
metadata-eval97.6%
+-commutative97.6%
mul-1-neg97.6%
unsub-neg97.6%
Simplified97.6%
Taylor expanded in y around inf 99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
*-lft-identity99.3%
+-commutative99.3%
Simplified99.3%
if -102000 < y < 0.00132Initial program 100.0%
Taylor expanded in z around inf 99.3%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.00132))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.00132)) {
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 <= (-1.0d0)) .or. (.not. (y <= 0.00132d0))) 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 <= -1.0) || !(y <= 0.00132)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 0.00132): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.00132)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.0) || ~((y <= 0.00132))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.00132]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.00132\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 0.00132 < y Initial program 99.9%
Taylor expanded in x around inf 52.2%
+-commutative52.2%
Simplified52.2%
Taylor expanded in y around inf 51.7%
if -1 < y < 0.00132Initial program 100.0%
Taylor expanded in y around 0 71.5%
Final simplification61.6%
(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 y around 0 37.2%
Final simplification37.2%
herbie shell --seed 2024040
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))