
(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 (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 -6.5e-19)
(* y z)
(if (<= y 1.65e-6)
x
(if (or (<= y 1.45e+84) (not (<= y 6.6e+243))) (* y z) (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.5e-19) {
tmp = y * z;
} else if (y <= 1.65e-6) {
tmp = x;
} else if ((y <= 1.45e+84) || !(y <= 6.6e+243)) {
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 <= (-6.5d-19)) then
tmp = y * z
else if (y <= 1.65d-6) then
tmp = x
else if ((y <= 1.45d+84) .or. (.not. (y <= 6.6d+243))) 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 <= -6.5e-19) {
tmp = y * z;
} else if (y <= 1.65e-6) {
tmp = x;
} else if ((y <= 1.45e+84) || !(y <= 6.6e+243)) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.5e-19: tmp = y * z elif y <= 1.65e-6: tmp = x elif (y <= 1.45e+84) or not (y <= 6.6e+243): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.5e-19) tmp = Float64(y * z); elseif (y <= 1.65e-6) tmp = x; elseif ((y <= 1.45e+84) || !(y <= 6.6e+243)) 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 <= -6.5e-19) tmp = y * z; elseif (y <= 1.65e-6) tmp = x; elseif ((y <= 1.45e+84) || ~((y <= 6.6e+243))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.5e-19], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.65e-6], x, If[Or[LessEqual[y, 1.45e+84], N[Not[LessEqual[y, 6.6e+243]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-19}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+84} \lor \neg \left(y \leq 6.6 \cdot 10^{+243}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -6.5000000000000001e-19 or 1.65000000000000008e-6 < y < 1.44999999999999994e84 or 6.59999999999999989e243 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in94.2%
associate-+r+94.2%
Applied egg-rr94.2%
Taylor expanded in x around 0 65.5%
if -6.5000000000000001e-19 < y < 1.65000000000000008e-6Initial program 100.0%
Taylor expanded in y around 0 77.8%
if 1.44999999999999994e84 < y < 6.59999999999999989e243Initial program 100.0%
Taylor expanded in x around inf 71.0%
+-commutative71.0%
Simplified71.0%
Taylor expanded in y around inf 71.0%
Final simplification72.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.000185))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.000185)) {
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.000185d0))) 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.000185)) {
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.000185): 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.000185)) 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.000185))) 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.000185]], $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.000185\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 1.85e-4 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in93.9%
associate-+r+93.9%
Applied egg-rr93.9%
Taylor expanded in y around inf 98.5%
+-commutative98.5%
Simplified98.5%
if -1 < y < 1.85e-4Initial program 100.0%
Taylor expanded in z around inf 99.6%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.6e-17) (not (<= y 5.6e-6))) (* y (+ x z)) (+ x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.6e-17) || !(y <= 5.6e-6)) {
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 <= (-1.6d-17)) .or. (.not. (y <= 5.6d-6))) 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 <= -1.6e-17) || !(y <= 5.6e-6)) {
tmp = y * (x + z);
} else {
tmp = x + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.6e-17) or not (y <= 5.6e-6): tmp = y * (x + z) else: tmp = x + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.6e-17) || !(y <= 5.6e-6)) 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 <= -1.6e-17) || ~((y <= 5.6e-6))) tmp = y * (x + z); else tmp = x + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.6e-17], N[Not[LessEqual[y, 5.6e-6]], $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 -1.6 \cdot 10^{-17} \lor \neg \left(y \leq 5.6 \cdot 10^{-6}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot x\\
\end{array}
\end{array}
if y < -1.6000000000000001e-17 or 5.59999999999999975e-6 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in94.0%
associate-+r+94.0%
Applied egg-rr94.0%
Taylor expanded in y around inf 98.6%
+-commutative98.6%
Simplified98.6%
if -1.6000000000000001e-17 < y < 5.59999999999999975e-6Initial program 100.0%
Taylor expanded in z around 0 78.2%
*-commutative78.2%
Simplified78.2%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e-13) (not (<= y 2.4e-6))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e-13) || !(y <= 2.4e-6)) {
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 <= (-5.5d-13)) .or. (.not. (y <= 2.4d-6))) 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 <= -5.5e-13) || !(y <= 2.4e-6)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e-13) or not (y <= 2.4e-6): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e-13) || !(y <= 2.4e-6)) 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 <= -5.5e-13) || ~((y <= 2.4e-6))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e-13], N[Not[LessEqual[y, 2.4e-6]], $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 -5.5 \cdot 10^{-13} \lor \neg \left(y \leq 2.4 \cdot 10^{-6}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -5.49999999999999979e-13 or 2.3999999999999999e-6 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in94.0%
associate-+r+94.0%
Applied egg-rr94.0%
Taylor expanded in y around inf 98.6%
+-commutative98.6%
Simplified98.6%
if -5.49999999999999979e-13 < y < 2.3999999999999999e-6Initial program 100.0%
Taylor expanded in x around inf 78.2%
+-commutative78.2%
Simplified78.2%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.6e-57) (not (<= x 1120000.0))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e-57) || !(x <= 1120000.0)) {
tmp = x * (y + 1.0);
} 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 ((x <= (-2.6d-57)) .or. (.not. (x <= 1120000.0d0))) then
tmp = x * (y + 1.0d0)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.6e-57) || !(x <= 1120000.0)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.6e-57) or not (x <= 1120000.0): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.6e-57) || !(x <= 1120000.0)) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.6e-57) || ~((x <= 1120000.0))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.6e-57], N[Not[LessEqual[x, 1120000.0]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-57} \lor \neg \left(x \leq 1120000\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.59999999999999985e-57 or 1.12e6 < x Initial program 100.0%
Taylor expanded in x around inf 83.8%
+-commutative83.8%
Simplified83.8%
if -2.59999999999999985e-57 < x < 1.12e6Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
associate-+r+100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 67.2%
Final simplification76.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) 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 <= 1.0))) 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, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 49.4%
+-commutative49.4%
Simplified49.4%
Taylor expanded in y around inf 48.1%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.9%
Final simplification61.4%
(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 38.7%
herbie shell --seed 2024131
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))