
(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 9 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 (+ x (fma z y (* x y))))
double code(double x, double y, double z) {
return x + fma(z, y, (x * y));
}
function code(x, y, z) return Float64(x + fma(z, y, Float64(x * y))) end
code[x_, y_, z_] := N[(x + N[(z * y + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \mathsf{fma}\left(z, y, x \cdot y\right)
\end{array}
Initial program 100.0%
distribute-rgt-in98.4%
fma-def100.0%
*-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(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-def100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.36e+183)
(* z y)
(if (<= y -1.4e+68)
(* x y)
(if (<= y -1.9e-56)
(* z y)
(if (<= y 1.4e-9)
x
(if (<= y 3.7e+243) (* z y) (if (<= y 9e+305) (* x y) (* z y))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.36e+183) {
tmp = z * y;
} else if (y <= -1.4e+68) {
tmp = x * y;
} else if (y <= -1.9e-56) {
tmp = z * y;
} else if (y <= 1.4e-9) {
tmp = x;
} else if (y <= 3.7e+243) {
tmp = z * y;
} else if (y <= 9e+305) {
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 (y <= (-1.36d+183)) then
tmp = z * y
else if (y <= (-1.4d+68)) then
tmp = x * y
else if (y <= (-1.9d-56)) then
tmp = z * y
else if (y <= 1.4d-9) then
tmp = x
else if (y <= 3.7d+243) then
tmp = z * y
else if (y <= 9d+305) 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 (y <= -1.36e+183) {
tmp = z * y;
} else if (y <= -1.4e+68) {
tmp = x * y;
} else if (y <= -1.9e-56) {
tmp = z * y;
} else if (y <= 1.4e-9) {
tmp = x;
} else if (y <= 3.7e+243) {
tmp = z * y;
} else if (y <= 9e+305) {
tmp = x * y;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.36e+183: tmp = z * y elif y <= -1.4e+68: tmp = x * y elif y <= -1.9e-56: tmp = z * y elif y <= 1.4e-9: tmp = x elif y <= 3.7e+243: tmp = z * y elif y <= 9e+305: tmp = x * y else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.36e+183) tmp = Float64(z * y); elseif (y <= -1.4e+68) tmp = Float64(x * y); elseif (y <= -1.9e-56) tmp = Float64(z * y); elseif (y <= 1.4e-9) tmp = x; elseif (y <= 3.7e+243) tmp = Float64(z * y); elseif (y <= 9e+305) tmp = Float64(x * y); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.36e+183) tmp = z * y; elseif (y <= -1.4e+68) tmp = x * y; elseif (y <= -1.9e-56) tmp = z * y; elseif (y <= 1.4e-9) tmp = x; elseif (y <= 3.7e+243) tmp = z * y; elseif (y <= 9e+305) tmp = x * y; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.36e+183], N[(z * y), $MachinePrecision], If[LessEqual[y, -1.4e+68], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.9e-56], N[(z * y), $MachinePrecision], If[LessEqual[y, 1.4e-9], x, If[LessEqual[y, 3.7e+243], N[(z * y), $MachinePrecision], If[LessEqual[y, 9e+305], N[(x * y), $MachinePrecision], N[(z * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.36 \cdot 10^{+183}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{+68}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{-56}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.7 \cdot 10^{+243}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 9 \cdot 10^{+305}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if y < -1.35999999999999995e183 or -1.4e68 < y < -1.9000000000000001e-56 or 1.39999999999999992e-9 < y < 3.7000000000000002e243 or 9.0000000000000006e305 < y Initial program 100.0%
distribute-rgt-in97.0%
fma-def100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 64.4%
if -1.35999999999999995e183 < y < -1.4e68 or 3.7000000000000002e243 < y < 9.0000000000000006e305Initial program 99.9%
Taylor expanded in y around inf 99.9%
Taylor expanded in z around 0 74.9%
if -1.9000000000000001e-56 < y < 1.39999999999999992e-9Initial program 100.0%
Taylor expanded in y around 0 77.7%
Final simplification72.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.35e-57) (not (<= y 1.85e-10))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.35e-57) || !(y <= 1.85e-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 <= (-1.35d-57)) .or. (.not. (y <= 1.85d-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 <= -1.35e-57) || !(y <= 1.85e-10)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.35e-57) or not (y <= 1.85e-10): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.35e-57) || !(y <= 1.85e-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 <= -1.35e-57) || ~((y <= 1.85e-10))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.35e-57], N[Not[LessEqual[y, 1.85e-10]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-57} \lor \neg \left(y \leq 1.85 \cdot 10^{-10}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.3500000000000001e-57 or 1.85000000000000007e-10 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
if -1.3500000000000001e-57 < y < 1.85000000000000007e-10Initial program 100.0%
Taylor expanded in y around 0 77.7%
Final simplification87.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -4.2e-53) (not (<= y 1.7e-10))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.2e-53) || !(y <= 1.7e-10)) {
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 <= (-4.2d-53)) .or. (.not. (y <= 1.7d-10))) 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 <= -4.2e-53) || !(y <= 1.7e-10)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.2e-53) or not (y <= 1.7e-10): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.2e-53) || !(y <= 1.7e-10)) 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 <= -4.2e-53) || ~((y <= 1.7e-10))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.2e-53], N[Not[LessEqual[y, 1.7e-10]], $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 -4.2 \cdot 10^{-53} \lor \neg \left(y \leq 1.7 \cdot 10^{-10}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -4.19999999999999955e-53 or 1.70000000000000007e-10 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
if -4.19999999999999955e-53 < y < 1.70000000000000007e-10Initial program 100.0%
Taylor expanded in x around inf 78.2%
Final simplification87.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -195.0) (not (<= y 1.0))) (* y (+ x z)) (+ x (* z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -195.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (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 ((y <= (-195.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + z)
else
tmp = x + (z * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -195.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (z * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -195.0) or not (y <= 1.0): tmp = y * (x + z) else: tmp = x + (z * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -195.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x + Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -195.0) || ~((y <= 1.0))) tmp = y * (x + z); else tmp = x + (z * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -195.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -195 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot y\\
\end{array}
\end{array}
if y < -195 or 1 < y Initial program 99.9%
Taylor expanded in y around inf 99.3%
if -195 < y < 1Initial program 100.0%
Taylor expanded in z around inf 99.2%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= y -195.0) (* x y) (if (<= y 1.0) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -195.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * 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 (y <= (-195.0d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -195.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -195.0: tmp = x * y elif y <= 1.0: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -195.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -195.0) tmp = x * y; elseif (y <= 1.0) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -195.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -195:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -195 or 1 < y Initial program 99.9%
Taylor expanded in y around inf 99.3%
Taylor expanded in z around 0 49.2%
if -195 < y < 1Initial program 100.0%
Taylor expanded in y around 0 73.2%
Final simplification62.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 y around 0 40.5%
Final simplification40.5%
herbie shell --seed 2023221
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))