
(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 (+ 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 (if (<= y -1.8e+104) (* x y) (if (<= y -3.1e-10) (* y z) (if (<= y 2.7e-26) x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.8e+104) {
tmp = x * y;
} else if (y <= -3.1e-10) {
tmp = y * z;
} else if (y <= 2.7e-26) {
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 <= (-1.8d+104)) then
tmp = x * y
else if (y <= (-3.1d-10)) then
tmp = y * z
else if (y <= 2.7d-26) 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 <= -1.8e+104) {
tmp = x * y;
} else if (y <= -3.1e-10) {
tmp = y * z;
} else if (y <= 2.7e-26) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.8e+104: tmp = x * y elif y <= -3.1e-10: tmp = y * z elif y <= 2.7e-26: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.8e+104) tmp = Float64(x * y); elseif (y <= -3.1e-10) tmp = Float64(y * z); elseif (y <= 2.7e-26) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.8e+104) tmp = x * y; elseif (y <= -3.1e-10) tmp = y * z; elseif (y <= 2.7e-26) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.8e+104], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.1e-10], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.7e-26], x, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+104}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.1 \cdot 10^{-10}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-26}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.8e104Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6462.2%
Simplified62.2%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6462.2%
Simplified62.2%
if -1.8e104 < y < -3.10000000000000015e-10 or 2.69999999999999982e-26 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6459.8%
Simplified59.8%
if -3.10000000000000015e-10 < y < 2.69999999999999982e-26Initial program 100.0%
Taylor expanded in y around 0
Simplified73.9%
Final simplification66.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -380.0) t_0 (if (<= y 3.25e-21) (+ x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -380.0) {
tmp = t_0;
} else if (y <= 3.25e-21) {
tmp = x + (y * z);
} 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 <= (-380.0d0)) then
tmp = t_0
else if (y <= 3.25d-21) then
tmp = x + (y * z)
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 <= -380.0) {
tmp = t_0;
} else if (y <= 3.25e-21) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -380.0: tmp = t_0 elif y <= 3.25e-21: tmp = x + (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -380.0) tmp = t_0; elseif (y <= 3.25e-21) tmp = Float64(x + Float64(y * z)); 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 <= -380.0) tmp = t_0; elseif (y <= 3.25e-21) tmp = x + (y * z); 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, -380.0], t$95$0, If[LessEqual[y, 3.25e-21], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -380:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.25 \cdot 10^{-21}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -380 or 3.24999999999999993e-21 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6498.1%
Simplified98.1%
if -380 < y < 3.24999999999999993e-21Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6498.7%
Simplified98.7%
Final simplification98.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -2.06e-10) t_0 (if (<= y 1.55e-26) (+ x (* x y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -2.06e-10) {
tmp = t_0;
} else if (y <= 1.55e-26) {
tmp = x + (x * y);
} 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 <= (-2.06d-10)) then
tmp = t_0
else if (y <= 1.55d-26) then
tmp = x + (x * y)
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 <= -2.06e-10) {
tmp = t_0;
} else if (y <= 1.55e-26) {
tmp = x + (x * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -2.06e-10: tmp = t_0 elif y <= 1.55e-26: tmp = x + (x * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -2.06e-10) tmp = t_0; elseif (y <= 1.55e-26) tmp = Float64(x + Float64(x * y)); 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 <= -2.06e-10) tmp = t_0; elseif (y <= 1.55e-26) tmp = x + (x * y); 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, -2.06e-10], t$95$0, If[LessEqual[y, 1.55e-26], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -2.06 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-26}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.0600000000000001e-10 or 1.54999999999999992e-26 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6496.7%
Simplified96.7%
if -2.0600000000000001e-10 < y < 1.54999999999999992e-26Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
*-lowering-*.f6474.2%
Simplified74.2%
Final simplification86.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.12e-10) t_0 (if (<= y 4.05e-25) (* x (+ y 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.12e-10) {
tmp = t_0;
} else if (y <= 4.05e-25) {
tmp = x * (y + 1.0);
} 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 <= (-1.12d-10)) then
tmp = t_0
else if (y <= 4.05d-25) then
tmp = x * (y + 1.0d0)
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 <= -1.12e-10) {
tmp = t_0;
} else if (y <= 4.05e-25) {
tmp = x * (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1.12e-10: tmp = t_0 elif y <= 4.05e-25: tmp = x * (y + 1.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -1.12e-10) tmp = t_0; elseif (y <= 4.05e-25) tmp = Float64(x * Float64(y + 1.0)); 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 <= -1.12e-10) tmp = t_0; elseif (y <= 4.05e-25) tmp = x * (y + 1.0); 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, -1.12e-10], t$95$0, If[LessEqual[y, 4.05e-25], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1.12 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.05 \cdot 10^{-25}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.12e-10 or 4.05000000000000001e-25 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6496.7%
Simplified96.7%
if -1.12e-10 < y < 4.05000000000000001e-25Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6474.2%
Simplified74.2%
Final simplification86.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y 1.0)))) (if (<= x -1.8e-109) t_0 (if (<= x 7.6e-79) (* y z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + 1.0);
double tmp;
if (x <= -1.8e-109) {
tmp = t_0;
} else if (x <= 7.6e-79) {
tmp = y * z;
} 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 = x * (y + 1.0d0)
if (x <= (-1.8d-109)) then
tmp = t_0
else if (x <= 7.6d-79) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y + 1.0);
double tmp;
if (x <= -1.8e-109) {
tmp = t_0;
} else if (x <= 7.6e-79) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + 1.0) tmp = 0 if x <= -1.8e-109: tmp = t_0 elif x <= 7.6e-79: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + 1.0)) tmp = 0.0 if (x <= -1.8e-109) tmp = t_0; elseif (x <= 7.6e-79) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + 1.0); tmp = 0.0; if (x <= -1.8e-109) tmp = t_0; elseif (x <= 7.6e-79) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.8e-109], t$95$0, If[LessEqual[x, 7.6e-79], N[(y * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + 1\right)\\
\mathbf{if}\;x \leq -1.8 \cdot 10^{-109}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.6 \cdot 10^{-79}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.8e-109 or 7.6000000000000002e-79 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6477.6%
Simplified77.6%
if -1.8e-109 < x < 7.6000000000000002e-79Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6480.0%
Simplified80.0%
(FPCore (x y z) :precision binary64 (if (<= y -380.0) (* x y) (if (<= y 5e-25) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -380.0) {
tmp = x * y;
} else if (y <= 5e-25) {
tmp = x;
} else {
tmp = x * y;
}
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 <= (-380.0d0)) then
tmp = x * y
else if (y <= 5d-25) then
tmp = x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -380.0) {
tmp = x * y;
} else if (y <= 5e-25) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -380.0: tmp = x * y elif y <= 5e-25: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -380.0) tmp = Float64(x * y); elseif (y <= 5e-25) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -380.0) tmp = x * y; elseif (y <= 5e-25) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -380.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 5e-25], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -380:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 5 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -380 or 4.99999999999999962e-25 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6448.6%
Simplified48.6%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6446.8%
Simplified46.8%
if -380 < y < 4.99999999999999962e-25Initial program 100.0%
Taylor expanded in y around 0
Simplified70.9%
Final simplification58.5%
(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
Simplified35.8%
herbie shell --seed 2024155
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))