
(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 (<= x -1.8e+15) x (if (<= x 2.15e+35) (* y z) (if (<= x 2.2e+258) x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.8e+15) {
tmp = x;
} else if (x <= 2.15e+35) {
tmp = y * z;
} else if (x <= 2.2e+258) {
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 (x <= (-1.8d+15)) then
tmp = x
else if (x <= 2.15d+35) then
tmp = y * z
else if (x <= 2.2d+258) 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 (x <= -1.8e+15) {
tmp = x;
} else if (x <= 2.15e+35) {
tmp = y * z;
} else if (x <= 2.2e+258) {
tmp = x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.8e+15: tmp = x elif x <= 2.15e+35: tmp = y * z elif x <= 2.2e+258: tmp = x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.8e+15) tmp = x; elseif (x <= 2.15e+35) tmp = Float64(y * z); elseif (x <= 2.2e+258) tmp = x; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.8e+15) tmp = x; elseif (x <= 2.15e+35) tmp = y * z; elseif (x <= 2.2e+258) tmp = x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.8e+15], x, If[LessEqual[x, 2.15e+35], N[(y * z), $MachinePrecision], If[LessEqual[x, 2.2e+258], x, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.8 \cdot 10^{+15}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.15 \cdot 10^{+35}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+258}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.8e15 or 2.1499999999999999e35 < x < 2.19999999999999983e258Initial program 100.0%
Taylor expanded in y around 0 58.0%
if -1.8e15 < x < 2.1499999999999999e35Initial program 100.0%
Taylor expanded in z around inf 87.8%
Taylor expanded in x around 0 69.9%
if 2.19999999999999983e258 < x Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in81.8%
associate-+r+81.8%
Applied egg-rr81.8%
Taylor expanded in x around 0 55.2%
Taylor expanded in z around 0 73.4%
*-commutative73.4%
Simplified73.4%
Final simplification65.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e-34) (not (<= x 3.6e-19))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e-34) || !(x <= 3.6e-19)) {
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 <= (-7.5d-34)) .or. (.not. (x <= 3.6d-19))) 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 <= -7.5e-34) || !(x <= 3.6e-19)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e-34) or not (x <= 3.6e-19): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e-34) || !(x <= 3.6e-19)) 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 <= -7.5e-34) || ~((x <= 3.6e-19))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e-34], N[Not[LessEqual[x, 3.6e-19]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-34} \lor \neg \left(x \leq 3.6 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -7.5000000000000004e-34 or 3.6000000000000001e-19 < x Initial program 100.0%
Taylor expanded in x around inf 85.0%
+-commutative85.0%
Simplified85.0%
if -7.5000000000000004e-34 < x < 3.6000000000000001e-19Initial program 100.0%
Taylor expanded in z around inf 92.0%
Taylor expanded in x around 0 75.7%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -35000000000000.0) (not (<= x 2.15e+35))) (* x (+ y 1.0)) (* y (+ x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -35000000000000.0) || !(x <= 2.15e+35)) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + 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 <= (-35000000000000.0d0)) .or. (.not. (x <= 2.15d+35))) then
tmp = x * (y + 1.0d0)
else
tmp = y * (x + z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -35000000000000.0) || !(x <= 2.15e+35)) {
tmp = x * (y + 1.0);
} else {
tmp = y * (x + z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -35000000000000.0) or not (x <= 2.15e+35): tmp = x * (y + 1.0) else: tmp = y * (x + z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -35000000000000.0) || !(x <= 2.15e+35)) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * Float64(x + z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -35000000000000.0) || ~((x <= 2.15e+35))) tmp = x * (y + 1.0); else tmp = y * (x + z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -35000000000000.0], N[Not[LessEqual[x, 2.15e+35]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -35000000000000 \lor \neg \left(x \leq 2.15 \cdot 10^{+35}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + z\right)\\
\end{array}
\end{array}
if x < -3.5e13 or 2.1499999999999999e35 < x Initial program 100.0%
Taylor expanded in x around inf 90.5%
+-commutative90.5%
Simplified90.5%
if -3.5e13 < x < 2.1499999999999999e35Initial 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 y around inf 81.1%
+-commutative81.1%
Simplified81.1%
Final simplification85.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.85e+16) (not (<= y 1.2e-22))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.85e+16) || !(y <= 1.2e-22)) {
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 <= (-2.85d+16)) .or. (.not. (y <= 1.2d-22))) 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 <= -2.85e+16) || !(y <= 1.2e-22)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.85e+16) or not (y <= 1.2e-22): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.85e+16) || !(y <= 1.2e-22)) 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 <= -2.85e+16) || ~((y <= 1.2e-22))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.85e+16], N[Not[LessEqual[y, 1.2e-22]], $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 -2.85 \cdot 10^{+16} \lor \neg \left(y \leq 1.2 \cdot 10^{-22}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -2.85e16 or 1.20000000000000001e-22 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in98.3%
associate-+r+98.3%
Applied egg-rr98.3%
Taylor expanded in y around inf 99.9%
+-commutative99.9%
Simplified99.9%
if -2.85e16 < y < 1.20000000000000001e-22Initial program 100.0%
Taylor expanded in z around inf 99.0%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.22e-26))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 1.22e-26)) {
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.22d-26))) 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.22e-26)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.22e-26): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.22e-26)) 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.22e-26))) 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.22e-26]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1.22 \cdot 10^{-26}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 1.22e-26 < y Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
fma-undefine100.0%
+-commutative100.0%
+-commutative100.0%
distribute-lft-in98.4%
associate-+r+98.4%
Applied egg-rr98.4%
Taylor expanded in x around 0 97.8%
Taylor expanded in z around 0 47.0%
*-commutative47.0%
Simplified47.0%
if -1 < y < 1.22e-26Initial program 100.0%
Taylor expanded in y around 0 65.0%
Final simplification56.3%
(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 34.8%
Final simplification34.8%
herbie shell --seed 2024067
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))