
(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
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.0) t_0 (if (<= y 9.2e-7) (+ (* y z) x) 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 <= 9.2e-7) {
tmp = (y * z) + 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 = y * (x + z)
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 9.2d-7) then
tmp = (y * z) + x
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 <= 9.2e-7) {
tmp = (y * z) + x;
} 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 <= 9.2e-7: tmp = (y * z) + 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.0) tmp = t_0; elseif (y <= 9.2e-7) tmp = Float64(Float64(y * z) + x); 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 <= 9.2e-7) tmp = (y * z) + x; 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, 9.2e-7], N[(N[(y * z), $MachinePrecision] + x), $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 9.2 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 9.1999999999999998e-7 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.2
Applied rewrites99.2%
if -1 < y < 9.1999999999999998e-7Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6499.4
Applied rewrites99.4%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -12500000.0) t_0 (if (<= y 3.2e-74) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -12500000.0) {
tmp = t_0;
} else if (y <= 3.2e-74) {
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 <= -12500000.0) tmp = t_0; elseif (y <= 3.2e-74) 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, -12500000.0], t$95$0, If[LessEqual[y, 3.2e-74], 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 -12500000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.2 \cdot 10^{-74}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.25e7 or 3.1999999999999999e-74 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
if -1.25e7 < y < 3.1999999999999999e-74Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6477.0
Applied rewrites77.0%
Final simplification88.2%
(FPCore (x y z) :precision binary64 (if (<= x -3.65e-152) (fma y x x) (if (<= x 7.5e-74) (* y z) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.65e-152) {
tmp = fma(y, x, x);
} else if (x <= 7.5e-74) {
tmp = y * z;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3.65e-152) tmp = fma(y, x, x); elseif (x <= 7.5e-74) tmp = Float64(y * z); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3.65e-152], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 7.5e-74], N[(y * z), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.65 \cdot 10^{-152}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-74}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -3.64999999999999991e-152 or 7.5e-74 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6480.9
Applied rewrites80.9%
if -3.64999999999999991e-152 < x < 7.5e-74Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6478.9
Applied rewrites78.9%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (<= z -3.8e-45) (* y z) (if (<= z 3.6e-43) (* y x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e-45) {
tmp = y * z;
} else if (z <= 3.6e-43) {
tmp = y * 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 (z <= (-3.8d-45)) then
tmp = y * z
else if (z <= 3.6d-43) then
tmp = y * x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -3.8e-45) {
tmp = y * z;
} else if (z <= 3.6e-43) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -3.8e-45: tmp = y * z elif z <= 3.6e-43: tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -3.8e-45) tmp = Float64(y * z); elseif (z <= 3.6e-43) tmp = Float64(y * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -3.8e-45) tmp = y * z; elseif (z <= 3.6e-43) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -3.8e-45], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.6e-43], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-45}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-43}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -3.79999999999999997e-45 or 3.5999999999999999e-43 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6462.6
Applied rewrites62.6%
if -3.79999999999999997e-45 < z < 3.5999999999999999e-43Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.0
Applied rewrites88.0%
Taylor expanded in y around inf
Applied rewrites44.1%
Final simplification54.8%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * x
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6462.4
Applied rewrites62.4%
Taylor expanded in y around inf
Applied rewrites27.4%
herbie shell --seed 2024243
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))