
(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 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%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ x z) y))) (if (<= y -1620000.0) t_0 (if (<= y 1.0) (+ (* z y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x + z) * y;
double tmp;
if (y <= -1620000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = (z * y) + 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 = (x + z) * y
if (y <= (-1620000.0d0)) then
tmp = t_0
else if (y <= 1.0d0) then
tmp = (z * y) + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x + z) * y;
double tmp;
if (y <= -1620000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = (z * y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x + z) * y tmp = 0 if y <= -1620000.0: tmp = t_0 elif y <= 1.0: tmp = (z * y) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x + z) * y) tmp = 0.0 if (y <= -1620000.0) tmp = t_0; elseif (y <= 1.0) tmp = Float64(Float64(z * y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x + z) * y; tmp = 0.0; if (y <= -1620000.0) tmp = t_0; elseif (y <= 1.0) tmp = (z * y) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1620000.0], t$95$0, If[LessEqual[y, 1.0], N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + z\right) \cdot y\\
\mathbf{if}\;y \leq -1620000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.62e6 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.6
Applied rewrites98.6%
if -1.62e6 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6499.2
Applied rewrites99.2%
Final simplification98.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ x z) y))) (if (<= y -7.6e-55) t_0 (if (<= y 13500.0) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x + z) * y;
double tmp;
if (y <= -7.6e-55) {
tmp = t_0;
} else if (y <= 13500.0) {
tmp = fma(y, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x + z) * y) tmp = 0.0 if (y <= -7.6e-55) tmp = t_0; elseif (y <= 13500.0) tmp = fma(y, x, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -7.6e-55], t$95$0, If[LessEqual[y, 13500.0], N[(y * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + z\right) \cdot y\\
\mathbf{if}\;y \leq -7.6 \cdot 10^{-55}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 13500:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.5999999999999993e-55 or 13500 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6496.2
Applied rewrites96.2%
if -7.5999999999999993e-55 < y < 13500Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6475.6
Applied rewrites75.6%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (<= z -1.15e+134) (* z y) (if (<= z 0.175) (fma y x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.15e+134) {
tmp = z * y;
} else if (z <= 0.175) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.15e+134) tmp = Float64(z * y); elseif (z <= 0.175) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.15e+134], N[(z * y), $MachinePrecision], If[LessEqual[z, 0.175], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+134}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 0.175:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.1499999999999999e134 or 0.17499999999999999 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6476.3
Applied rewrites76.3%
if -1.1499999999999999e134 < z < 0.17499999999999999Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6483.5
Applied rewrites83.5%
(FPCore (x y z) :precision binary64 (if (<= x -8.8e+115) (* x y) (if (<= x 2.5e+78) (* z y) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -8.8e+115) {
tmp = x * y;
} else if (x <= 2.5e+78) {
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 <= (-8.8d+115)) then
tmp = x * y
else if (x <= 2.5d+78) 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 <= -8.8e+115) {
tmp = x * y;
} else if (x <= 2.5e+78) {
tmp = z * y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -8.8e+115: tmp = x * y elif x <= 2.5e+78: tmp = z * y else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -8.8e+115) tmp = Float64(x * y); elseif (x <= 2.5e+78) 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 <= -8.8e+115) tmp = x * y; elseif (x <= 2.5e+78) tmp = z * y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -8.8e+115], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.5e+78], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{+115}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+78}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -8.8000000000000001e115 or 2.49999999999999992e78 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6495.9
Applied rewrites95.9%
Taylor expanded in y around inf
Applied rewrites42.6%
if -8.8000000000000001e115 < x < 2.49999999999999992e78Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6457.1
Applied rewrites57.1%
Final simplification51.8%
(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 z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6462.7
Applied rewrites62.7%
Taylor expanded in y around inf
Applied rewrites24.7%
Final simplification24.7%
herbie shell --seed 2024240
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))