
(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 -7.2e+229)
(* y x)
(if (<= y -1.05e+207)
(* y z)
(if (<= y -6.2e+166)
(* y x)
(if (<= y -5.6e+57)
(* y z)
(if (<= y -4.5e+18)
(* y x)
(if (<= y -1.55e-47)
(* y z)
(if (<= y 3.2e-84)
x
(if (<= y 2.4e-40)
(* y z)
(if (<= y 2.65e-14) x (* y z)))))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e+229) {
tmp = y * x;
} else if (y <= -1.05e+207) {
tmp = y * z;
} else if (y <= -6.2e+166) {
tmp = y * x;
} else if (y <= -5.6e+57) {
tmp = y * z;
} else if (y <= -4.5e+18) {
tmp = y * x;
} else if (y <= -1.55e-47) {
tmp = y * z;
} else if (y <= 3.2e-84) {
tmp = x;
} else if (y <= 2.4e-40) {
tmp = y * z;
} else if (y <= 2.65e-14) {
tmp = x;
} 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 (y <= (-7.2d+229)) then
tmp = y * x
else if (y <= (-1.05d+207)) then
tmp = y * z
else if (y <= (-6.2d+166)) then
tmp = y * x
else if (y <= (-5.6d+57)) then
tmp = y * z
else if (y <= (-4.5d+18)) then
tmp = y * x
else if (y <= (-1.55d-47)) then
tmp = y * z
else if (y <= 3.2d-84) then
tmp = x
else if (y <= 2.4d-40) then
tmp = y * z
else if (y <= 2.65d-14) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -7.2e+229) {
tmp = y * x;
} else if (y <= -1.05e+207) {
tmp = y * z;
} else if (y <= -6.2e+166) {
tmp = y * x;
} else if (y <= -5.6e+57) {
tmp = y * z;
} else if (y <= -4.5e+18) {
tmp = y * x;
} else if (y <= -1.55e-47) {
tmp = y * z;
} else if (y <= 3.2e-84) {
tmp = x;
} else if (y <= 2.4e-40) {
tmp = y * z;
} else if (y <= 2.65e-14) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -7.2e+229: tmp = y * x elif y <= -1.05e+207: tmp = y * z elif y <= -6.2e+166: tmp = y * x elif y <= -5.6e+57: tmp = y * z elif y <= -4.5e+18: tmp = y * x elif y <= -1.55e-47: tmp = y * z elif y <= 3.2e-84: tmp = x elif y <= 2.4e-40: tmp = y * z elif y <= 2.65e-14: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -7.2e+229) tmp = Float64(y * x); elseif (y <= -1.05e+207) tmp = Float64(y * z); elseif (y <= -6.2e+166) tmp = Float64(y * x); elseif (y <= -5.6e+57) tmp = Float64(y * z); elseif (y <= -4.5e+18) tmp = Float64(y * x); elseif (y <= -1.55e-47) tmp = Float64(y * z); elseif (y <= 3.2e-84) tmp = x; elseif (y <= 2.4e-40) tmp = Float64(y * z); elseif (y <= 2.65e-14) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -7.2e+229) tmp = y * x; elseif (y <= -1.05e+207) tmp = y * z; elseif (y <= -6.2e+166) tmp = y * x; elseif (y <= -5.6e+57) tmp = y * z; elseif (y <= -4.5e+18) tmp = y * x; elseif (y <= -1.55e-47) tmp = y * z; elseif (y <= 3.2e-84) tmp = x; elseif (y <= 2.4e-40) tmp = y * z; elseif (y <= 2.65e-14) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -7.2e+229], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.05e+207], N[(y * z), $MachinePrecision], If[LessEqual[y, -6.2e+166], N[(y * x), $MachinePrecision], If[LessEqual[y, -5.6e+57], N[(y * z), $MachinePrecision], If[LessEqual[y, -4.5e+18], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.55e-47], N[(y * z), $MachinePrecision], If[LessEqual[y, 3.2e-84], x, If[LessEqual[y, 2.4e-40], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.65e-14], x, N[(y * z), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{+229}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.05 \cdot 10^{+207}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -6.2 \cdot 10^{+166}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -5.6 \cdot 10^{+57}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -4.5 \cdot 10^{+18}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.55 \cdot 10^{-47}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-84}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-40}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -7.19999999999999973e229 or -1.05e207 < y < -6.19999999999999966e166 or -5.59999999999999999e57 < y < -4.5e18Initial program 100.0%
Taylor expanded in x around inf 79.5%
+-commutative79.5%
Simplified79.5%
Taylor expanded in y around inf 79.5%
if -7.19999999999999973e229 < y < -1.05e207 or -6.19999999999999966e166 < y < -5.59999999999999999e57 or -4.5e18 < y < -1.5499999999999999e-47 or 3.1999999999999999e-84 < y < 2.39999999999999991e-40 or 2.6500000000000001e-14 < y Initial program 100.0%
Taylor expanded in z around inf 78.8%
Taylor expanded in x around 0 73.7%
if -1.5499999999999999e-47 < y < 3.1999999999999999e-84 or 2.39999999999999991e-40 < y < 2.6500000000000001e-14Initial program 100.0%
Taylor expanded in y around 0 76.3%
Final simplification75.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.1e-70) (not (<= x 1.22e+15))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.1e-70) || !(x <= 1.22e+15)) {
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.1d-70)) .or. (.not. (x <= 1.22d+15))) 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.1e-70) || !(x <= 1.22e+15)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.1e-70) or not (x <= 1.22e+15): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.1e-70) || !(x <= 1.22e+15)) 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.1e-70) || ~((x <= 1.22e+15))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.1e-70], N[Not[LessEqual[x, 1.22e+15]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{-70} \lor \neg \left(x \leq 1.22 \cdot 10^{+15}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.1000000000000001e-70 or 1.22e15 < x Initial program 100.0%
Taylor expanded in x around inf 83.2%
+-commutative83.2%
Simplified83.2%
if -2.1000000000000001e-70 < x < 1.22e15Initial program 100.0%
Taylor expanded in z around inf 92.9%
Taylor expanded in x around 0 74.6%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e-131) (not (<= z 3.45e-43))) (+ x (* y z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-131) || !(z <= 3.45e-43)) {
tmp = x + (y * 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 ((z <= (-1.15d-131)) .or. (.not. (z <= 3.45d-43))) then
tmp = x + (y * 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 ((z <= -1.15e-131) || !(z <= 3.45e-43)) {
tmp = x + (y * z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e-131) or not (z <= 3.45e-43): tmp = x + (y * z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e-131) || !(z <= 3.45e-43)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.15e-131) || ~((z <= 3.45e-43))) tmp = x + (y * z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e-131], N[Not[LessEqual[z, 3.45e-43]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-131} \lor \neg \left(z \leq 3.45 \cdot 10^{-43}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -1.15000000000000011e-131 or 3.44999999999999982e-43 < z Initial program 100.0%
Taylor expanded in z around inf 91.4%
if -1.15000000000000011e-131 < z < 3.44999999999999982e-43Initial program 100.0%
Taylor expanded in x around inf 87.8%
+-commutative87.8%
Simplified87.8%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (<= y -22.0) (* y x) (if (<= y 14000.0) x (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -22.0) {
tmp = y * x;
} else if (y <= 14000.0) {
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 <= (-22.0d0)) then
tmp = y * x
else if (y <= 14000.0d0) 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 <= -22.0) {
tmp = y * x;
} else if (y <= 14000.0) {
tmp = x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -22.0: tmp = y * x elif y <= 14000.0: tmp = x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -22.0) tmp = Float64(y * x); elseif (y <= 14000.0) tmp = x; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -22.0) tmp = y * x; elseif (y <= 14000.0) tmp = x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -22.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 14000.0], x, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -22:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 14000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -22 or 14000 < y Initial program 100.0%
Taylor expanded in x around inf 47.4%
+-commutative47.4%
Simplified47.4%
Taylor expanded in y around inf 46.6%
if -22 < y < 14000Initial program 100.0%
Taylor expanded in y around 0 63.1%
Final simplification54.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.2%
Final simplification33.2%
herbie shell --seed 2023290
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))