
(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%
(FPCore (x y z)
:precision binary64
(if (<= y -3.3e+182)
(* y z)
(if (<= y -2.5e+95)
(* y x)
(if (<= y -1.7e-15)
(* y z)
(if (<= y 2.45e-14) x (if (<= y 1.6e+47) (* y z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.3e+182) {
tmp = y * z;
} else if (y <= -2.5e+95) {
tmp = y * x;
} else if (y <= -1.7e-15) {
tmp = y * z;
} else if (y <= 2.45e-14) {
tmp = x;
} else if (y <= 1.6e+47) {
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 <= (-3.3d+182)) then
tmp = y * z
else if (y <= (-2.5d+95)) then
tmp = y * x
else if (y <= (-1.7d-15)) then
tmp = y * z
else if (y <= 2.45d-14) then
tmp = x
else if (y <= 1.6d+47) 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 <= -3.3e+182) {
tmp = y * z;
} else if (y <= -2.5e+95) {
tmp = y * x;
} else if (y <= -1.7e-15) {
tmp = y * z;
} else if (y <= 2.45e-14) {
tmp = x;
} else if (y <= 1.6e+47) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.3e+182: tmp = y * z elif y <= -2.5e+95: tmp = y * x elif y <= -1.7e-15: tmp = y * z elif y <= 2.45e-14: tmp = x elif y <= 1.6e+47: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.3e+182) tmp = Float64(y * z); elseif (y <= -2.5e+95) tmp = Float64(y * x); elseif (y <= -1.7e-15) tmp = Float64(y * z); elseif (y <= 2.45e-14) tmp = x; elseif (y <= 1.6e+47) 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 <= -3.3e+182) tmp = y * z; elseif (y <= -2.5e+95) tmp = y * x; elseif (y <= -1.7e-15) tmp = y * z; elseif (y <= 2.45e-14) tmp = x; elseif (y <= 1.6e+47) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.3e+182], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.5e+95], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.7e-15], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.45e-14], x, If[LessEqual[y, 1.6e+47], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.3 \cdot 10^{+182}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{+95}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{-15}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{+47}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.3000000000000001e182 or -2.50000000000000012e95 < y < -1.7e-15 or 2.44999999999999997e-14 < y < 1.6e47Initial program 99.9%
Taylor expanded in x around 0 69.2%
if -3.3000000000000001e182 < y < -2.50000000000000012e95 or 1.6e47 < y Initial program 100.0%
Taylor expanded in x around inf 63.4%
+-commutative63.4%
Simplified63.4%
Taylor expanded in y around inf 63.4%
if -1.7e-15 < y < 2.44999999999999997e-14Initial program 100.0%
Taylor expanded in y around 0 73.9%
Final simplification69.9%
(FPCore (x y z)
:precision binary64
(if (or (<= y -3.4e-15)
(and (not (<= y 9e-126))
(or (<= y 5.8e-101) (not (<= y 205000000.0)))))
(* y (+ x z))
(* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -3.4e-15) || (!(y <= 9e-126) && ((y <= 5.8e-101) || !(y <= 205000000.0)))) {
tmp = y * (x + 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 ((y <= (-3.4d-15)) .or. (.not. (y <= 9d-126)) .and. (y <= 5.8d-101) .or. (.not. (y <= 205000000.0d0))) then
tmp = y * (x + 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 ((y <= -3.4e-15) || (!(y <= 9e-126) && ((y <= 5.8e-101) || !(y <= 205000000.0)))) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -3.4e-15) or (not (y <= 9e-126) and ((y <= 5.8e-101) or not (y <= 205000000.0))): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -3.4e-15) || (!(y <= 9e-126) && ((y <= 5.8e-101) || !(y <= 205000000.0)))) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -3.4e-15) || (~((y <= 9e-126)) && ((y <= 5.8e-101) || ~((y <= 205000000.0))))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -3.4e-15], And[N[Not[LessEqual[y, 9e-126]], $MachinePrecision], Or[LessEqual[y, 5.8e-101], N[Not[LessEqual[y, 205000000.0]], $MachinePrecision]]]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-15} \lor \neg \left(y \leq 9 \cdot 10^{-126}\right) \land \left(y \leq 5.8 \cdot 10^{-101} \lor \neg \left(y \leq 205000000\right)\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -3.4e-15 or 9.0000000000000005e-126 < y < 5.800000000000001e-101 or 2.05e8 < y Initial program 100.0%
Taylor expanded in y around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -3.4e-15 < y < 9.0000000000000005e-126 or 5.800000000000001e-101 < y < 2.05e8Initial program 100.0%
Taylor expanded in x around inf 78.0%
+-commutative78.0%
Simplified78.0%
Final simplification89.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -8e-15)
t_0
(if (<= y 1.7e-125)
(+ x (* y x))
(if (or (<= y 6e-101) (not (<= y 11000.0))) t_0 (* x (+ y 1.0)))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -8e-15) {
tmp = t_0;
} else if (y <= 1.7e-125) {
tmp = x + (y * x);
} else if ((y <= 6e-101) || !(y <= 11000.0)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * (x + z)
if (y <= (-8d-15)) then
tmp = t_0
else if (y <= 1.7d-125) then
tmp = x + (y * x)
else if ((y <= 6d-101) .or. (.not. (y <= 11000.0d0))) then
tmp = t_0
else
tmp = x * (y + 1.0d0)
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 <= -8e-15) {
tmp = t_0;
} else if (y <= 1.7e-125) {
tmp = x + (y * x);
} else if ((y <= 6e-101) || !(y <= 11000.0)) {
tmp = t_0;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -8e-15: tmp = t_0 elif y <= 1.7e-125: tmp = x + (y * x) elif (y <= 6e-101) or not (y <= 11000.0): tmp = t_0 else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -8e-15) tmp = t_0; elseif (y <= 1.7e-125) tmp = Float64(x + Float64(y * x)); elseif ((y <= 6e-101) || !(y <= 11000.0)) tmp = t_0; else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x + z); tmp = 0.0; if (y <= -8e-15) tmp = t_0; elseif (y <= 1.7e-125) tmp = x + (y * x); elseif ((y <= 6e-101) || ~((y <= 11000.0))) tmp = t_0; else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8e-15], t$95$0, If[LessEqual[y, 1.7e-125], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 6e-101], N[Not[LessEqual[y, 11000.0]], $MachinePrecision]], t$95$0, N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -8 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-125}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-101} \lor \neg \left(y \leq 11000\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -8.0000000000000006e-15 or 1.69999999999999988e-125 < y < 6.0000000000000006e-101 or 11000 < y Initial program 100.0%
Taylor expanded in y around inf 99.0%
+-commutative99.0%
Simplified99.0%
if -8.0000000000000006e-15 < y < 1.69999999999999988e-125Initial program 100.0%
Taylor expanded in z around 0 77.9%
if 6.0000000000000006e-101 < y < 11000Initial program 99.9%
Taylor expanded in x around inf 78.5%
+-commutative78.5%
Simplified78.5%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.85e+167) (not (<= z 5e+100))) (* y z) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.85e+167) || !(z <= 5e+100)) {
tmp = 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.85d+167)) .or. (.not. (z <= 5d+100))) then
tmp = 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.85e+167) || !(z <= 5e+100)) {
tmp = y * z;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.85e+167) or not (z <= 5e+100): tmp = y * z else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.85e+167) || !(z <= 5e+100)) tmp = 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.85e+167) || ~((z <= 5e+100))) tmp = y * z; else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.85e+167], N[Not[LessEqual[z, 5e+100]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+167} \lor \neg \left(z \leq 5 \cdot 10^{+100}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -1.85e167 or 4.9999999999999999e100 < z Initial program 100.0%
Taylor expanded in x around 0 85.4%
if -1.85e167 < z < 4.9999999999999999e100Initial program 100.0%
Taylor expanded in x around inf 83.0%
+-commutative83.0%
Simplified83.0%
Final simplification83.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -6e-14) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6e-14) || !(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 <= (-6d-14)) .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 <= -6e-14) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6e-14) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6e-14) || !(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 <= -6e-14) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6e-14], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-14} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.9999999999999997e-14 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 54.8%
+-commutative54.8%
Simplified54.8%
Taylor expanded in y around inf 53.5%
if -5.9999999999999997e-14 < y < 1Initial program 100.0%
Taylor expanded in y around 0 73.2%
Final simplification63.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 38.1%
herbie shell --seed 2024090
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))