
(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 6 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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -22000000000.0) t_0 (if (<= y 0.00055) (+ x (* z y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -22000000000.0) {
tmp = t_0;
} else if (y <= 0.00055) {
tmp = x + (z * 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 <= (-22000000000.0d0)) then
tmp = t_0
else if (y <= 0.00055d0) then
tmp = x + (z * 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 <= -22000000000.0) {
tmp = t_0;
} else if (y <= 0.00055) {
tmp = x + (z * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -22000000000.0: tmp = t_0 elif y <= 0.00055: tmp = x + (z * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -22000000000.0) tmp = t_0; elseif (y <= 0.00055) tmp = Float64(x + Float64(z * 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 <= -22000000000.0) tmp = t_0; elseif (y <= 0.00055) tmp = x + (z * 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, -22000000000.0], t$95$0, If[LessEqual[y, 0.00055], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -22000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00055:\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.2e10 or 5.50000000000000033e-4 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.4
Applied rewrites99.4%
if -2.2e10 < y < 5.50000000000000033e-4Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.4
Applied rewrites98.4%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.1e-22) t_0 (if (<= y 0.00011) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.1e-22) {
tmp = t_0;
} else if (y <= 0.00011) {
tmp = fma(y, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -1.1e-22) tmp = t_0; elseif (y <= 0.00011) tmp = fma(y, x, 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, -1.1e-22], t$95$0, If[LessEqual[y, 0.00011], N[(y * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1.1 \cdot 10^{-22}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00011:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.1e-22 or 1.10000000000000004e-4 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6497.9
Applied rewrites97.9%
if -1.1e-22 < y < 1.10000000000000004e-4Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6469.8
Applied rewrites69.8%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e+106) (* z y) (if (<= z 8e+41) (fma y x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+106) {
tmp = z * y;
} else if (z <= 8e+41) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+106) tmp = Float64(z * y); elseif (z <= 8e+41) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+106], N[(z * y), $MachinePrecision], If[LessEqual[z, 8e+41], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+106}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 8 \cdot 10^{+41}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.69999999999999997e106 or 8.00000000000000005e41 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6478.9
Applied rewrites78.9%
if -1.69999999999999997e106 < z < 8.00000000000000005e41Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6477.8
Applied rewrites77.8%
Final simplification78.2%
(FPCore (x y z) :precision binary64 (if (<= x -2.5e+39) (* x y) (if (<= x 2.35e+86) (* z y) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e+39) {
tmp = x * y;
} else if (x <= 2.35e+86) {
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 (x <= (-2.5d+39)) then
tmp = x * y
else if (x <= 2.35d+86) 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 (x <= -2.5e+39) {
tmp = x * y;
} else if (x <= 2.35e+86) {
tmp = z * y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.5e+39: tmp = x * y elif x <= 2.35e+86: tmp = z * y else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.5e+39) tmp = Float64(x * y); elseif (x <= 2.35e+86) tmp = Float64(z * y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.5e+39) tmp = x * y; elseif (x <= 2.35e+86) tmp = z * y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.5e+39], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.35e+86], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+39}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.35 \cdot 10^{+86}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.50000000000000008e39 or 2.3500000000000001e86 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6489.5
Applied rewrites89.5%
Taylor expanded in y around inf
Applied rewrites43.8%
if -2.50000000000000008e39 < x < 2.3500000000000001e86Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6458.7
Applied rewrites58.7%
Final simplification53.5%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * y;
}
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
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6458.3
Applied rewrites58.3%
Taylor expanded in y around inf
Applied rewrites25.7%
Final simplification25.7%
herbie shell --seed 2024232
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))