
(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 (+ x z) y x))
double code(double x, double y, double z) {
return fma((x + z), y, x);
}
function code(x, y, z) return fma(Float64(x + z), y, x) end
code[x_, y_, z_] := N[(N[(x + z), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + z, y, x\right)
\end{array}
Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -1.8e+210)
(* x y)
(if (<= y -1.4e-28)
(* z y)
(if (<= y 3.4e-43) x (if (<= y 1.05e+87) (* z y) (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.8e+210) {
tmp = x * y;
} else if (y <= -1.4e-28) {
tmp = z * y;
} else if (y <= 3.4e-43) {
tmp = x;
} else if (y <= 1.05e+87) {
tmp = z * y;
} 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 <= (-1.8d+210)) then
tmp = x * y
else if (y <= (-1.4d-28)) then
tmp = z * y
else if (y <= 3.4d-43) then
tmp = x
else if (y <= 1.05d+87) then
tmp = z * y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.8e+210) {
tmp = x * y;
} else if (y <= -1.4e-28) {
tmp = z * y;
} else if (y <= 3.4e-43) {
tmp = x;
} else if (y <= 1.05e+87) {
tmp = z * y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.8e+210: tmp = x * y elif y <= -1.4e-28: tmp = z * y elif y <= 3.4e-43: tmp = x elif y <= 1.05e+87: tmp = z * y else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.8e+210) tmp = Float64(x * y); elseif (y <= -1.4e-28) tmp = Float64(z * y); elseif (y <= 3.4e-43) tmp = x; elseif (y <= 1.05e+87) tmp = Float64(z * y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.8e+210) tmp = x * y; elseif (y <= -1.4e-28) tmp = z * y; elseif (y <= 3.4e-43) tmp = x; elseif (y <= 1.05e+87) tmp = z * y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.8e+210], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.4e-28], N[(z * y), $MachinePrecision], If[LessEqual[y, 3.4e-43], x, If[LessEqual[y, 1.05e+87], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{+210}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.4 \cdot 10^{-28}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-43}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{+87}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.8000000000000001e210 or 1.05e87 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6463.4
Simplified63.4%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6463.4
Simplified63.4%
if -1.8000000000000001e210 < y < -1.3999999999999999e-28 or 3.4000000000000001e-43 < y < 1.05e87Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6461.4
Simplified61.4%
if -1.3999999999999999e-28 < y < 3.4000000000000001e-43Initial program 100.0%
Taylor expanded in y around 0
Simplified77.8%
Final simplification69.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -52000000.0) t_0 (if (<= y 1.3e-16) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -52000000.0) {
tmp = t_0;
} else if (y <= 1.3e-16) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -52000000.0) tmp = t_0; elseif (y <= 1.3e-16) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -52000000.0], t$95$0, If[LessEqual[y, 1.3e-16], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -52000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.2e7 or 1.2999999999999999e-16 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6499.3
Simplified99.3%
if -5.2e7 < y < 1.2999999999999999e-16Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified100.0%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (<= x -4.2e+115) (fma y x x) (if (<= x 3.2e-152) (fma z y x) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.2e+115) {
tmp = fma(y, x, x);
} else if (x <= 3.2e-152) {
tmp = fma(z, y, x);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4.2e+115) tmp = fma(y, x, x); elseif (x <= 3.2e-152) tmp = fma(z, y, x); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.2e+115], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 3.2e-152], N[(z * y + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.2 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-152}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -4.20000000000000007e115 or 3.20000000000000013e-152 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6486.9
Simplified86.9%
if -4.20000000000000007e115 < x < 3.20000000000000013e-152Initial program 100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0
Applied egg-rr100.0%
Taylor expanded in x around 0
Simplified88.3%
(FPCore (x y z) :precision binary64 (if (<= x -2.8e-26) (fma y x x) (if (<= x 3e-152) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e-26) {
tmp = fma(y, x, x);
} else if (x <= 3e-152) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.8e-26) tmp = fma(y, x, x); elseif (x <= 3e-152) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.8e-26], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 3e-152], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-26}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-152}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -2.8000000000000001e-26 or 3e-152 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6482.9
Simplified82.9%
if -2.8000000000000001e-26 < x < 3e-152Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6475.0
Simplified75.0%
Final simplification80.2%
(FPCore (x y z) :precision binary64 (if (<= y -2.8e-15) (* x y) (if (<= y 6.7e-15) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.8e-15) {
tmp = x * y;
} else if (y <= 6.7e-15) {
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 <= (-2.8d-15)) then
tmp = x * y
else if (y <= 6.7d-15) 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 <= -2.8e-15) {
tmp = x * y;
} else if (y <= 6.7e-15) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.8e-15: tmp = x * y elif y <= 6.7e-15: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.8e-15) tmp = Float64(x * y); elseif (y <= 6.7e-15) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.8e-15) tmp = x * y; elseif (y <= 6.7e-15) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.8e-15], N[(x * y), $MachinePrecision], If[LessEqual[y, 6.7e-15], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-15}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 6.7 \cdot 10^{-15}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.80000000000000014e-15 or 6.70000000000000001e-15 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6454.3
Simplified54.3%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6453.8
Simplified53.8%
if -2.80000000000000014e-15 < y < 6.70000000000000001e-15Initial program 100.0%
Taylor expanded in y around 0
Simplified74.4%
Final simplification63.4%
(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
Simplified36.0%
herbie shell --seed 2024198
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))