
(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 (<= y -6.2e+268)
(* y z)
(if (<= y -1.15e+118)
(* y x)
(if (or (<= y -2.55e-16)
(and (not (<= y -9.5e-56))
(or (<= y -1.3e-77) (not (<= y 1.32e-45)))))
(* y z)
x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -6.2e+268) {
tmp = y * z;
} else if (y <= -1.15e+118) {
tmp = y * x;
} else if ((y <= -2.55e-16) || (!(y <= -9.5e-56) && ((y <= -1.3e-77) || !(y <= 1.32e-45)))) {
tmp = y * 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.2d+268)) then
tmp = y * z
else if (y <= (-1.15d+118)) then
tmp = y * x
else if ((y <= (-2.55d-16)) .or. (.not. (y <= (-9.5d-56))) .and. (y <= (-1.3d-77)) .or. (.not. (y <= 1.32d-45))) then
tmp = y * 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.2e+268) {
tmp = y * z;
} else if (y <= -1.15e+118) {
tmp = y * x;
} else if ((y <= -2.55e-16) || (!(y <= -9.5e-56) && ((y <= -1.3e-77) || !(y <= 1.32e-45)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -6.2e+268: tmp = y * z elif y <= -1.15e+118: tmp = y * x elif (y <= -2.55e-16) or (not (y <= -9.5e-56) and ((y <= -1.3e-77) or not (y <= 1.32e-45))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -6.2e+268) tmp = Float64(y * z); elseif (y <= -1.15e+118) tmp = Float64(y * x); elseif ((y <= -2.55e-16) || (!(y <= -9.5e-56) && ((y <= -1.3e-77) || !(y <= 1.32e-45)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -6.2e+268) tmp = y * z; elseif (y <= -1.15e+118) tmp = y * x; elseif ((y <= -2.55e-16) || (~((y <= -9.5e-56)) && ((y <= -1.3e-77) || ~((y <= 1.32e-45))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -6.2e+268], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.15e+118], N[(y * x), $MachinePrecision], If[Or[LessEqual[y, -2.55e-16], And[N[Not[LessEqual[y, -9.5e-56]], $MachinePrecision], Or[LessEqual[y, -1.3e-77], N[Not[LessEqual[y, 1.32e-45]], $MachinePrecision]]]], N[(y * z), $MachinePrecision], x]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.2 \cdot 10^{+268}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.15 \cdot 10^{+118}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.55 \cdot 10^{-16} \lor \neg \left(y \leq -9.5 \cdot 10^{-56}\right) \land \left(y \leq -1.3 \cdot 10^{-77} \lor \neg \left(y \leq 1.32 \cdot 10^{-45}\right)\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.2000000000000002e268 or -1.15000000000000008e118 < y < -2.55e-16 or -9.4999999999999991e-56 < y < -1.3000000000000001e-77 or 1.32000000000000005e-45 < y Initial program 100.0%
Taylor expanded in x around 0 60.0%
if -6.2000000000000002e268 < y < -1.15000000000000008e118Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 70.5%
*-commutative70.5%
Simplified70.5%
if -2.55e-16 < y < -9.4999999999999991e-56 or -1.3000000000000001e-77 < y < 1.32000000000000005e-45Initial program 100.0%
Taylor expanded in y around 0 79.4%
Final simplification68.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -4.2e-16)
t_0
(if (<= y -2e-56)
(* x (+ y 1.0))
(if (<= y -1.3e-77) (* y z) (if (<= y 1.1e-41) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -4.2e-16) {
tmp = t_0;
} else if (y <= -2e-56) {
tmp = x * (y + 1.0);
} else if (y <= -1.3e-77) {
tmp = y * z;
} else if (y <= 1.1e-41) {
tmp = x;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = y * (x + z)
if (y <= (-4.2d-16)) then
tmp = t_0
else if (y <= (-2d-56)) then
tmp = x * (y + 1.0d0)
else if (y <= (-1.3d-77)) then
tmp = y * z
else if (y <= 1.1d-41) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -4.2e-16) {
tmp = t_0;
} else if (y <= -2e-56) {
tmp = x * (y + 1.0);
} else if (y <= -1.3e-77) {
tmp = y * z;
} else if (y <= 1.1e-41) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -4.2e-16: tmp = t_0 elif y <= -2e-56: tmp = x * (y + 1.0) elif y <= -1.3e-77: tmp = y * z elif y <= 1.1e-41: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -4.2e-16) tmp = t_0; elseif (y <= -2e-56) tmp = Float64(x * Float64(y + 1.0)); elseif (y <= -1.3e-77) tmp = Float64(y * z); elseif (y <= 1.1e-41) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x + z); tmp = 0.0; if (y <= -4.2e-16) tmp = t_0; elseif (y <= -2e-56) tmp = x * (y + 1.0); elseif (y <= -1.3e-77) tmp = y * z; elseif (y <= 1.1e-41) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.2e-16], t$95$0, If[LessEqual[y, -2e-56], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -1.3e-77], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.1e-41], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -4.2 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2 \cdot 10^{-56}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;y \leq -1.3 \cdot 10^{-77}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-41}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.2000000000000002e-16 or 1.1e-41 < y Initial program 100.0%
Taylor expanded in y around inf 96.8%
+-commutative96.8%
Simplified96.8%
if -4.2000000000000002e-16 < y < -2.0000000000000001e-56Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
if -2.0000000000000001e-56 < y < -1.3000000000000001e-77Initial program 99.8%
Taylor expanded in x around 0 84.7%
if -1.3000000000000001e-77 < y < 1.1e-41Initial program 100.0%
Taylor expanded in y around 0 78.4%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e-120) (not (<= x 4.7e-39))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-120) || !(x <= 4.7e-39)) {
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 <= (-5.5d-120)) .or. (.not. (x <= 4.7d-39))) 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 <= -5.5e-120) || !(x <= 4.7e-39)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e-120) or not (x <= 4.7e-39): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e-120) || !(x <= 4.7e-39)) 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 <= -5.5e-120) || ~((x <= 4.7e-39))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e-120], N[Not[LessEqual[x, 4.7e-39]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-120} \lor \neg \left(x \leq 4.7 \cdot 10^{-39}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -5.5000000000000001e-120 or 4.7000000000000002e-39 < x Initial program 100.0%
Taylor expanded in x around inf 82.2%
+-commutative82.2%
Simplified82.2%
if -5.5000000000000001e-120 < x < 4.7000000000000002e-39Initial program 100.0%
Taylor expanded in x around 0 72.3%
Final simplification78.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.6) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.6) || !(y <= 1.0)) {
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 <= (-5.6d0)) .or. (.not. (y <= 1.0d0))) 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 <= -5.6) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.6) or not (y <= 1.0): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.6) || !(y <= 1.0)) 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 <= -5.6) || ~((y <= 1.0))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.6], N[Not[LessEqual[y, 1.0]], $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 -5.6 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -5.5999999999999996 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 98.0%
+-commutative98.0%
Simplified98.0%
if -5.5999999999999996 < y < 1Initial program 100.0%
Taylor expanded in x around inf 97.4%
associate-/l*93.1%
Simplified93.1%
Taylor expanded in x around 0 98.7%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.8e-16) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.8e-16) || !(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 <= (-5.8d-16)) .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 <= -5.8e-16) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.8e-16) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.8e-16) || !(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 <= -5.8e-16) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.8e-16], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-16} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.7999999999999996e-16 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in z around 0 50.8%
*-commutative50.8%
Simplified50.8%
if -5.7999999999999996e-16 < y < 1Initial program 100.0%
Taylor expanded in y around 0 71.9%
Final simplification59.9%
(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 33.1%
Final simplification33.1%
herbie shell --seed 2024089
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))