
(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 -8.5e+117)
(* y z)
(if (<= y -9.8e+30)
(* y x)
(if (<= y -8.8e-19)
(* y z)
(if (<= y 1.2e-17) x (if (<= y 1.9e+70) (* y z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.5e+117) {
tmp = y * z;
} else if (y <= -9.8e+30) {
tmp = y * x;
} else if (y <= -8.8e-19) {
tmp = y * z;
} else if (y <= 1.2e-17) {
tmp = x;
} else if (y <= 1.9e+70) {
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 <= (-8.5d+117)) then
tmp = y * z
else if (y <= (-9.8d+30)) then
tmp = y * x
else if (y <= (-8.8d-19)) then
tmp = y * z
else if (y <= 1.2d-17) then
tmp = x
else if (y <= 1.9d+70) 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 <= -8.5e+117) {
tmp = y * z;
} else if (y <= -9.8e+30) {
tmp = y * x;
} else if (y <= -8.8e-19) {
tmp = y * z;
} else if (y <= 1.2e-17) {
tmp = x;
} else if (y <= 1.9e+70) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.5e+117: tmp = y * z elif y <= -9.8e+30: tmp = y * x elif y <= -8.8e-19: tmp = y * z elif y <= 1.2e-17: tmp = x elif y <= 1.9e+70: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.5e+117) tmp = Float64(y * z); elseif (y <= -9.8e+30) tmp = Float64(y * x); elseif (y <= -8.8e-19) tmp = Float64(y * z); elseif (y <= 1.2e-17) tmp = x; elseif (y <= 1.9e+70) 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 <= -8.5e+117) tmp = y * z; elseif (y <= -9.8e+30) tmp = y * x; elseif (y <= -8.8e-19) tmp = y * z; elseif (y <= 1.2e-17) tmp = x; elseif (y <= 1.9e+70) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.5e+117], N[(y * z), $MachinePrecision], If[LessEqual[y, -9.8e+30], N[(y * x), $MachinePrecision], If[LessEqual[y, -8.8e-19], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.2e-17], x, If[LessEqual[y, 1.9e+70], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+117}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -9.8 \cdot 10^{+30}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -8.8 \cdot 10^{-19}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-17}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+70}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.49999999999999966e117 or -9.79999999999999969e30 < y < -8.7999999999999994e-19 or 1.19999999999999993e-17 < y < 1.8999999999999999e70Initial program 100.0%
Taylor expanded in z around inf 69.8%
Taylor expanded in x around 0 66.2%
if -8.49999999999999966e117 < y < -9.79999999999999969e30 or 1.8999999999999999e70 < y Initial program 100.0%
Taylor expanded in x around inf 66.3%
+-commutative66.3%
Simplified66.3%
Taylor expanded in y around inf 66.3%
if -8.7999999999999994e-19 < y < 1.19999999999999993e-17Initial program 100.0%
Taylor expanded in y around 0 78.0%
Final simplification71.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.1e-28) (not (<= x 1.45e-126))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.1e-28) || !(x <= 1.45e-126)) {
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 <= (-3.1d-28)) .or. (.not. (x <= 1.45d-126))) 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 <= -3.1e-28) || !(x <= 1.45e-126)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.1e-28) or not (x <= 1.45e-126): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.1e-28) || !(x <= 1.45e-126)) 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 <= -3.1e-28) || ~((x <= 1.45e-126))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.1e-28], N[Not[LessEqual[x, 1.45e-126]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-28} \lor \neg \left(x \leq 1.45 \cdot 10^{-126}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.09999999999999992e-28 or 1.44999999999999994e-126 < x Initial program 100.0%
Taylor expanded in x around inf 83.6%
+-commutative83.6%
Simplified83.6%
if -3.09999999999999992e-28 < x < 1.44999999999999994e-126Initial program 100.0%
Taylor expanded in z around inf 92.6%
Taylor expanded in x around 0 78.7%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.95e-28) (* x (+ y 1.0)) (if (<= x 1.6e-126) (* y z) (+ x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e-28) {
tmp = x * (y + 1.0);
} else if (x <= 1.6e-126) {
tmp = y * 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 (x <= (-1.95d-28)) then
tmp = x * (y + 1.0d0)
else if (x <= 1.6d-126) then
tmp = y * 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 (x <= -1.95e-28) {
tmp = x * (y + 1.0);
} else if (x <= 1.6e-126) {
tmp = y * z;
} else {
tmp = x + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.95e-28: tmp = x * (y + 1.0) elif x <= 1.6e-126: tmp = y * z else: tmp = x + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.95e-28) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 1.6e-126) tmp = Float64(y * z); else tmp = Float64(x + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.95e-28) tmp = x * (y + 1.0); elseif (x <= 1.6e-126) tmp = y * z; else tmp = x + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.95e-28], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.6e-126], N[(y * z), $MachinePrecision], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-28}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-126}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot x\\
\end{array}
\end{array}
if x < -1.94999999999999999e-28Initial program 100.0%
Taylor expanded in x around inf 85.9%
+-commutative85.9%
Simplified85.9%
if -1.94999999999999999e-28 < x < 1.6e-126Initial program 100.0%
Taylor expanded in z around inf 92.6%
Taylor expanded in x around 0 78.7%
if 1.6e-126 < x Initial program 100.0%
Taylor expanded in z around 0 81.6%
*-commutative81.6%
Simplified81.6%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (<= x -8.2e+18) (* x (+ y 1.0)) (if (<= x 7e-39) (+ x (* y z)) (+ x (* y x)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.2e+18) {
tmp = x * (y + 1.0);
} else if (x <= 7e-39) {
tmp = x + (y * 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 (x <= (-8.2d+18)) then
tmp = x * (y + 1.0d0)
else if (x <= 7d-39) then
tmp = x + (y * 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 (x <= -8.2e+18) {
tmp = x * (y + 1.0);
} else if (x <= 7e-39) {
tmp = x + (y * z);
} else {
tmp = x + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.2e+18: tmp = x * (y + 1.0) elif x <= 7e-39: tmp = x + (y * z) else: tmp = x + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.2e+18) tmp = Float64(x * Float64(y + 1.0)); elseif (x <= 7e-39) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -8.2e+18) tmp = x * (y + 1.0); elseif (x <= 7e-39) tmp = x + (y * z); else tmp = x + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.2e+18], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7e-39], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{+18}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-39}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot x\\
\end{array}
\end{array}
if x < -8.2e18Initial program 100.0%
Taylor expanded in x around inf 89.4%
+-commutative89.4%
Simplified89.4%
if -8.2e18 < x < 6.99999999999999999e-39Initial program 100.0%
Taylor expanded in z around inf 86.6%
if 6.99999999999999999e-39 < x Initial program 100.0%
Taylor expanded in z around 0 89.6%
*-commutative89.6%
Simplified89.6%
Final simplification88.1%
(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%
+-commutative52.9%
Simplified52.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))))