
(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-def100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -2.1e+56)
(* y z)
(if (<= y -9.0)
(* y x)
(if (<= y -8.8e-57)
(* y z)
(if (<= y 6.6e-22)
x
(if (<= y 1000000000.0)
(* y z)
(if (<= y 3.65e+34) (* y x) (* y z))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.1e+56) {
tmp = y * z;
} else if (y <= -9.0) {
tmp = y * x;
} else if (y <= -8.8e-57) {
tmp = y * z;
} else if (y <= 6.6e-22) {
tmp = x;
} else if (y <= 1000000000.0) {
tmp = y * z;
} else if (y <= 3.65e+34) {
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 (y <= (-2.1d+56)) then
tmp = y * z
else if (y <= (-9.0d0)) then
tmp = y * x
else if (y <= (-8.8d-57)) then
tmp = y * z
else if (y <= 6.6d-22) then
tmp = x
else if (y <= 1000000000.0d0) then
tmp = y * z
else if (y <= 3.65d+34) 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 (y <= -2.1e+56) {
tmp = y * z;
} else if (y <= -9.0) {
tmp = y * x;
} else if (y <= -8.8e-57) {
tmp = y * z;
} else if (y <= 6.6e-22) {
tmp = x;
} else if (y <= 1000000000.0) {
tmp = y * z;
} else if (y <= 3.65e+34) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.1e+56: tmp = y * z elif y <= -9.0: tmp = y * x elif y <= -8.8e-57: tmp = y * z elif y <= 6.6e-22: tmp = x elif y <= 1000000000.0: tmp = y * z elif y <= 3.65e+34: tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.1e+56) tmp = Float64(y * z); elseif (y <= -9.0) tmp = Float64(y * x); elseif (y <= -8.8e-57) tmp = Float64(y * z); elseif (y <= 6.6e-22) tmp = x; elseif (y <= 1000000000.0) tmp = Float64(y * z); elseif (y <= 3.65e+34) tmp = Float64(y * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.1e+56) tmp = y * z; elseif (y <= -9.0) tmp = y * x; elseif (y <= -8.8e-57) tmp = y * z; elseif (y <= 6.6e-22) tmp = x; elseif (y <= 1000000000.0) tmp = y * z; elseif (y <= 3.65e+34) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.1e+56], N[(y * z), $MachinePrecision], If[LessEqual[y, -9.0], N[(y * x), $MachinePrecision], If[LessEqual[y, -8.8e-57], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.6e-22], x, If[LessEqual[y, 1000000000.0], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.65e+34], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+56}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -9:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -8.8 \cdot 10^{-57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{-22}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1000000000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.65 \cdot 10^{+34}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -2.10000000000000017e56 or -9 < y < -8.79999999999999994e-57 or 6.6000000000000002e-22 < y < 1e9 or 3.6499999999999998e34 < y Initial program 100.0%
Taylor expanded in x around -inf 93.5%
mul-1-neg93.5%
unsub-neg93.5%
*-commutative93.5%
sub-neg93.5%
metadata-eval93.5%
+-commutative93.5%
mul-1-neg93.5%
unsub-neg93.5%
Simplified93.5%
Taylor expanded in z around inf 69.6%
if -2.10000000000000017e56 < y < -9 or 1e9 < y < 3.6499999999999998e34Initial program 99.9%
Taylor expanded in x around inf 80.3%
Taylor expanded in y around inf 72.6%
if -8.79999999999999994e-57 < y < 6.6000000000000002e-22Initial program 100.0%
Taylor expanded in y around 0 83.2%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.45e-44) (not (<= y 9e-24))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.45e-44) || !(y <= 9e-24)) {
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.45d-44)) .or. (.not. (y <= 9d-24))) 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.45e-44) || !(y <= 9e-24)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.45e-44) or not (y <= 9e-24): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.45e-44) || !(y <= 9e-24)) 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.45e-44) || ~((y <= 9e-24))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.45e-44], N[Not[LessEqual[y, 9e-24]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-44} \lor \neg \left(y \leq 9 \cdot 10^{-24}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.4500000000000001e-44 or 8.9999999999999995e-24 < y Initial program 100.0%
Taylor expanded in y around inf 95.1%
if -1.4500000000000001e-44 < y < 8.9999999999999995e-24Initial program 100.0%
Taylor expanded in y around 0 82.7%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -8e-47) (not (<= y 1.2e-21))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8e-47) || !(y <= 1.2e-21)) {
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 <= (-8d-47)) .or. (.not. (y <= 1.2d-21))) 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 <= -8e-47) || !(y <= 1.2e-21)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8e-47) or not (y <= 1.2e-21): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8e-47) || !(y <= 1.2e-21)) 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 <= -8e-47) || ~((y <= 1.2e-21))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8e-47], N[Not[LessEqual[y, 1.2e-21]], $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 -8 \cdot 10^{-47} \lor \neg \left(y \leq 1.2 \cdot 10^{-21}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -7.9999999999999998e-47 or 1.2e-21 < y Initial program 100.0%
Taylor expanded in y around inf 95.1%
if -7.9999999999999998e-47 < y < 1.2e-21Initial program 100.0%
Taylor expanded in x around inf 82.7%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.21))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.21)) {
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 <= (-1.0d0)) .or. (.not. (y <= 0.21d0))) 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 <= -1.0) || !(y <= 0.21)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 0.21): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.21)) 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 <= -1.0) || ~((y <= 0.21))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.21]], $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 -1 \lor \neg \left(y \leq 0.21\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 0.209999999999999992 < y Initial program 100.0%
Taylor expanded in y around inf 98.8%
if -1 < y < 0.209999999999999992Initial program 100.0%
Taylor expanded in z around inf 99.7%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (<= y -2.55e-8) (* y x) (if (<= y 26000000.0) x (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.55e-8) {
tmp = y * x;
} else if (y <= 26000000.0) {
tmp = x;
} 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 <= (-2.55d-8)) then
tmp = y * x
else if (y <= 26000000.0d0) then
tmp = x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.55e-8) {
tmp = y * x;
} else if (y <= 26000000.0) {
tmp = x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.55e-8: tmp = y * x elif y <= 26000000.0: tmp = x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.55e-8) tmp = Float64(y * x); elseif (y <= 26000000.0) tmp = x; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.55e-8) tmp = y * x; elseif (y <= 26000000.0) tmp = x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.55e-8], N[(y * x), $MachinePrecision], If[LessEqual[y, 26000000.0], x, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.55 \cdot 10^{-8}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 26000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.55e-8 or 2.6e7 < y Initial program 100.0%
Taylor expanded in x around inf 44.5%
Taylor expanded in y around inf 43.4%
if -2.55e-8 < y < 2.6e7Initial program 100.0%
Taylor expanded in y around 0 75.1%
Final simplification60.2%
(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 41.4%
Final simplification41.4%
herbie shell --seed 2023200
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))