
(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-define100.0%
+-commutative100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -4.4e+197)
(* y z)
(if (<= y -1.8)
(* y x)
(if (<= y 2.05e-19)
x
(if (or (<= y 2.3e+198) (not (<= y 7.2e+220))) (* y z) (* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+197) {
tmp = y * z;
} else if (y <= -1.8) {
tmp = y * x;
} else if (y <= 2.05e-19) {
tmp = x;
} else if ((y <= 2.3e+198) || !(y <= 7.2e+220)) {
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 <= (-4.4d+197)) then
tmp = y * z
else if (y <= (-1.8d0)) then
tmp = y * x
else if (y <= 2.05d-19) then
tmp = x
else if ((y <= 2.3d+198) .or. (.not. (y <= 7.2d+220))) 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 <= -4.4e+197) {
tmp = y * z;
} else if (y <= -1.8) {
tmp = y * x;
} else if (y <= 2.05e-19) {
tmp = x;
} else if ((y <= 2.3e+198) || !(y <= 7.2e+220)) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.4e+197: tmp = y * z elif y <= -1.8: tmp = y * x elif y <= 2.05e-19: tmp = x elif (y <= 2.3e+198) or not (y <= 7.2e+220): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.4e+197) tmp = Float64(y * z); elseif (y <= -1.8) tmp = Float64(y * x); elseif (y <= 2.05e-19) tmp = x; elseif ((y <= 2.3e+198) || !(y <= 7.2e+220)) 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 <= -4.4e+197) tmp = y * z; elseif (y <= -1.8) tmp = y * x; elseif (y <= 2.05e-19) tmp = x; elseif ((y <= 2.3e+198) || ~((y <= 7.2e+220))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.4e+197], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.8], N[(y * x), $MachinePrecision], If[LessEqual[y, 2.05e-19], x, If[Or[LessEqual[y, 2.3e+198], N[Not[LessEqual[y, 7.2e+220]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+197}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.8:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+198} \lor \neg \left(y \leq 7.2 \cdot 10^{+220}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.39999999999999979e197 or 2.04999999999999993e-19 < y < 2.3000000000000001e198 or 7.20000000000000038e220 < y Initial program 100.0%
Taylor expanded in x around 0 67.6%
if -4.39999999999999979e197 < y < -1.80000000000000004 or 2.3000000000000001e198 < y < 7.20000000000000038e220Initial program 100.0%
Taylor expanded in x around inf 65.9%
+-commutative65.9%
Simplified65.9%
Taylor expanded in y around inf 62.2%
if -1.80000000000000004 < y < 2.04999999999999993e-19Initial program 100.0%
Taylor expanded in y around 0 66.0%
Final simplification65.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -4800000000.0)
t_0
(if (<= y -1.12e-85)
(* x (+ y 1.0))
(if (<= y -2.6e-128) (* y z) (if (<= y 2.6e-19) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -4800000000.0) {
tmp = t_0;
} else if (y <= -1.12e-85) {
tmp = x * (y + 1.0);
} else if (y <= -2.6e-128) {
tmp = y * z;
} else if (y <= 2.6e-19) {
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 <= (-4800000000.0d0)) then
tmp = t_0
else if (y <= (-1.12d-85)) then
tmp = x * (y + 1.0d0)
else if (y <= (-2.6d-128)) then
tmp = y * z
else if (y <= 2.6d-19) 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 <= -4800000000.0) {
tmp = t_0;
} else if (y <= -1.12e-85) {
tmp = x * (y + 1.0);
} else if (y <= -2.6e-128) {
tmp = y * z;
} else if (y <= 2.6e-19) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -4800000000.0: tmp = t_0 elif y <= -1.12e-85: tmp = x * (y + 1.0) elif y <= -2.6e-128: tmp = y * z elif y <= 2.6e-19: 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 <= -4800000000.0) tmp = t_0; elseif (y <= -1.12e-85) tmp = Float64(x * Float64(y + 1.0)); elseif (y <= -2.6e-128) tmp = Float64(y * z); elseif (y <= 2.6e-19) 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 <= -4800000000.0) tmp = t_0; elseif (y <= -1.12e-85) tmp = x * (y + 1.0); elseif (y <= -2.6e-128) tmp = y * z; elseif (y <= 2.6e-19) 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, -4800000000.0], t$95$0, If[LessEqual[y, -1.12e-85], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -2.6e-128], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.6e-19], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -4800000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.12 \cdot 10^{-85}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{-128}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-19}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.8e9 or 2.60000000000000013e-19 < y Initial program 100.0%
Taylor expanded in y around inf 99.6%
+-commutative99.6%
Simplified99.6%
if -4.8e9 < y < -1.12000000000000004e-85Initial program 99.9%
Taylor expanded in x around inf 65.8%
+-commutative65.8%
Simplified65.8%
if -1.12000000000000004e-85 < y < -2.59999999999999981e-128Initial program 100.0%
Taylor expanded in x around 0 80.0%
if -2.59999999999999981e-128 < y < 2.60000000000000013e-19Initial program 100.0%
Taylor expanded in y around 0 71.5%
Final simplification86.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e+32) (not (<= x 1.6e-16))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e+32) || !(x <= 1.6e-16)) {
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.8d+32)) .or. (.not. (x <= 1.6d-16))) 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.8e+32) || !(x <= 1.6e-16)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e+32) or not (x <= 1.6e-16): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e+32) || !(x <= 1.6e-16)) 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.8e+32) || ~((x <= 1.6e-16))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e+32], N[Not[LessEqual[x, 1.6e-16]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{+32} \lor \neg \left(x \leq 1.6 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.8000000000000003e32 or 1.60000000000000011e-16 < x Initial program 100.0%
Taylor expanded in x around inf 85.7%
+-commutative85.7%
Simplified85.7%
if -3.8000000000000003e32 < x < 1.60000000000000011e-16Initial program 100.0%
Taylor expanded in x around 0 69.8%
Final simplification76.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8) || !(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 <= (-1.8d0)) .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 <= -1.8) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8) || !(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 <= -1.8) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.80000000000000004 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 47.7%
+-commutative47.7%
Simplified47.7%
Taylor expanded in y around inf 46.0%
if -1.80000000000000004 < y < 1Initial program 100.0%
Taylor expanded in y around 0 65.0%
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 32.1%
herbie shell --seed 2024107
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))