
(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 7 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 -7e+120)
(* y z)
(if (<= y -7e+30)
(* y x)
(if (<= y -5.8e-19)
(* y z)
(if (<= y 4.1e-18) x (if (<= y 6.2e+64) (* y z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7e+120) {
tmp = y * z;
} else if (y <= -7e+30) {
tmp = y * x;
} else if (y <= -5.8e-19) {
tmp = y * z;
} else if (y <= 4.1e-18) {
tmp = x;
} else if (y <= 6.2e+64) {
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 <= (-7d+120)) then
tmp = y * z
else if (y <= (-7d+30)) then
tmp = y * x
else if (y <= (-5.8d-19)) then
tmp = y * z
else if (y <= 4.1d-18) then
tmp = x
else if (y <= 6.2d+64) 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 <= -7e+120) {
tmp = y * z;
} else if (y <= -7e+30) {
tmp = y * x;
} else if (y <= -5.8e-19) {
tmp = y * z;
} else if (y <= 4.1e-18) {
tmp = x;
} else if (y <= 6.2e+64) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7e+120: tmp = y * z elif y <= -7e+30: tmp = y * x elif y <= -5.8e-19: tmp = y * z elif y <= 4.1e-18: tmp = x elif y <= 6.2e+64: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7e+120) tmp = Float64(y * z); elseif (y <= -7e+30) tmp = Float64(y * x); elseif (y <= -5.8e-19) tmp = Float64(y * z); elseif (y <= 4.1e-18) tmp = x; elseif (y <= 6.2e+64) 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 <= -7e+120) tmp = y * z; elseif (y <= -7e+30) tmp = y * x; elseif (y <= -5.8e-19) tmp = y * z; elseif (y <= 4.1e-18) tmp = x; elseif (y <= 6.2e+64) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7e+120], N[(y * z), $MachinePrecision], If[LessEqual[y, -7e+30], N[(y * x), $MachinePrecision], If[LessEqual[y, -5.8e-19], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.1e-18], x, If[LessEqual[y, 6.2e+64], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{+120}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -7 \cdot 10^{+30}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{-19}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{-18}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+64}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -7.00000000000000015e120 or -7.00000000000000042e30 < y < -5.8e-19 or 4.0999999999999998e-18 < y < 6.1999999999999998e64Initial program 100.0%
Taylor expanded in z around inf 69.8%
Taylor expanded in x around 0 66.2%
if -7.00000000000000015e120 < y < -7.00000000000000042e30 or 6.1999999999999998e64 < y Initial program 100.0%
Taylor expanded in x around inf 66.3%
Taylor expanded in y around inf 66.3%
if -5.8e-19 < y < 4.0999999999999998e-18Initial program 100.0%
Taylor expanded in y around 0 78.0%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.1e-19) (not (<= y 3.4e-18))) (* y (+ x z)) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.1e-19) || !(y <= 3.4e-18)) {
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 <= (-6.1d-19)) .or. (.not. (y <= 3.4d-18))) 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 <= -6.1e-19) || !(y <= 3.4e-18)) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.1e-19) or not (y <= 3.4e-18): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.1e-19) || !(y <= 3.4e-18)) 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 <= -6.1e-19) || ~((y <= 3.4e-18))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.1e-19], N[Not[LessEqual[y, 3.4e-18]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.1 \cdot 10^{-19} \lor \neg \left(y \leq 3.4 \cdot 10^{-18}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.1000000000000003e-19 or 3.40000000000000001e-18 < y Initial program 100.0%
Taylor expanded in y around inf 97.0%
if -6.1000000000000003e-19 < y < 3.40000000000000001e-18Initial program 100.0%
Taylor expanded in y around 0 78.0%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -56.0) (not (<= y 0.0004))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -56.0) || !(y <= 0.0004)) {
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 <= (-56.0d0)) .or. (.not. (y <= 0.0004d0))) 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 <= -56.0) || !(y <= 0.0004)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -56.0) or not (y <= 0.0004): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -56.0) || !(y <= 0.0004)) 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 <= -56.0) || ~((y <= 0.0004))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -56.0], N[Not[LessEqual[y, 0.0004]], $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 -56 \lor \neg \left(y \leq 0.0004\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -56 or 4.00000000000000019e-4 < y Initial program 100.0%
Taylor expanded in y around inf 99.7%
if -56 < y < 4.00000000000000019e-4Initial program 100.0%
Taylor expanded in z around inf 99.2%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (<= y -56.0) (* y x) (if (<= y 0.0004) x (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -56.0) {
tmp = y * x;
} else if (y <= 0.0004) {
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 <= (-56.0d0)) then
tmp = y * x
else if (y <= 0.0004d0) 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 <= -56.0) {
tmp = y * x;
} else if (y <= 0.0004) {
tmp = x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -56.0: tmp = y * x elif y <= 0.0004: tmp = x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -56.0) tmp = Float64(y * x); elseif (y <= 0.0004) tmp = x; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -56.0) tmp = y * x; elseif (y <= 0.0004) tmp = x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -56.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 0.0004], x, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -56:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 0.0004:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -56 or 4.00000000000000019e-4 < y Initial program 100.0%
Taylor expanded in x around inf 52.9%
Taylor expanded in y around inf 52.6%
if -56 < y < 4.00000000000000019e-4Initial program 100.0%
Taylor expanded in y around 0 72.8%
Final simplification63.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 38.9%
Final simplification38.9%
herbie shell --seed 2023275
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))