
(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 -1.0) t_0 (if (<= y 1.0) (+ x (* z y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
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 <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.0d0) 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 <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = x + (z * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.0: 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 <= -1.0) tmp = t_0; elseif (y <= 1.0) 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 <= -1.0) tmp = t_0; elseif (y <= 1.0) 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, -1.0], t$95$0, If[LessEqual[y, 1.0], 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 -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.5
Applied rewrites99.5%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.0
Applied rewrites98.0%
Final simplification98.7%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1200.0) t_0 (if (<= y 4800.0) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1200.0) {
tmp = t_0;
} else if (y <= 4800.0) {
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 <= -1200.0) tmp = t_0; elseif (y <= 4800.0) 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, -1200.0], t$95$0, If[LessEqual[y, 4800.0], 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 -1200:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4800:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1200 or 4800 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
if -1200 < y < 4800Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6471.8
Applied rewrites71.8%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (<= z -5.4e+67) (* z y) (if (<= z 2.7e+36) (fma y x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.4e+67) {
tmp = z * y;
} else if (z <= 2.7e+36) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -5.4e+67) tmp = Float64(z * y); elseif (z <= 2.7e+36) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -5.4e+67], N[(z * y), $MachinePrecision], If[LessEqual[z, 2.7e+36], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{+67}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+36}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -5.3999999999999998e67 or 2.7000000000000001e36 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6472.7
Applied rewrites72.7%
if -5.3999999999999998e67 < z < 2.7000000000000001e36Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6486.9
Applied rewrites86.9%
Final simplification80.6%
(FPCore (x y z) :precision binary64 (if (<= z -6.8e-61) (* z y) (if (<= z 1.72e-56) (* x y) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e-61) {
tmp = z * y;
} else if (z <= 1.72e-56) {
tmp = x * y;
} else {
tmp = z * 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 (z <= (-6.8d-61)) then
tmp = z * y
else if (z <= 1.72d-56) then
tmp = x * y
else
tmp = z * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e-61) {
tmp = z * y;
} else if (z <= 1.72e-56) {
tmp = x * y;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.8e-61: tmp = z * y elif z <= 1.72e-56: tmp = x * y else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.8e-61) tmp = Float64(z * y); elseif (z <= 1.72e-56) tmp = Float64(x * y); else tmp = Float64(z * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -6.8e-61) tmp = z * y; elseif (z <= 1.72e-56) tmp = x * y; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.8e-61], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.72e-56], N[(x * y), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{-61}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.72 \cdot 10^{-56}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -6.7999999999999996e-61 or 1.72000000000000009e-56 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6464.0
Applied rewrites64.0%
if -6.7999999999999996e-61 < z < 1.72000000000000009e-56Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6495.0
Applied rewrites95.0%
Taylor expanded in y around inf
Applied rewrites47.4%
Final simplification57.3%
(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.f6462.9
Applied rewrites62.9%
Taylor expanded in y around inf
Applied rewrites28.3%
Final simplification28.3%
herbie shell --seed 2024221
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))