
(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 1.0) (+ (* 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 <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
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 <= 1.0: 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 <= 1.0) 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 <= 1.0) 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, 1.0], 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 1:\\
\;\;\;\;y \cdot z + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.3
Applied rewrites98.3%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Final simplification98.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -3400.0) t_0 (if (<= y 2.4e-126) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -3400.0) {
tmp = t_0;
} else if (y <= 2.4e-126) {
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 <= -3400.0) tmp = t_0; elseif (y <= 2.4e-126) 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, -3400.0], t$95$0, If[LessEqual[y, 2.4e-126], 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 -3400:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-126}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3400 or 2.40000000000000007e-126 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6493.9
Applied rewrites93.9%
if -3400 < y < 2.40000000000000007e-126Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6479.9
Applied rewrites79.9%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.15e-114) (fma y x x) (if (<= x 2.3e-122) (* y z) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-114) {
tmp = fma(y, x, x);
} else if (x <= 2.3e-122) {
tmp = y * z;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.15e-114) tmp = fma(y, x, x); elseif (x <= 2.3e-122) tmp = Float64(y * z); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.15e-114], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 2.3e-122], N[(y * z), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \cdot 10^{-114}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-122}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -1.15e-114 or 2.30000000000000007e-122 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6479.9
Applied rewrites79.9%
if -1.15e-114 < x < 2.30000000000000007e-122Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6473.9
Applied rewrites73.9%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.45e-65) (* y x) (if (<= x 3.5e+121) (* y z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-65) {
tmp = y * x;
} else if (x <= 3.5e+121) {
tmp = y * z;
} else {
tmp = y * x;
}
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 <= (-1.45d-65)) then
tmp = y * x
else if (x <= 3.5d+121) then
tmp = y * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.45e-65) {
tmp = y * x;
} else if (x <= 3.5e+121) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.45e-65: tmp = y * x elif x <= 3.5e+121: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.45e-65) tmp = Float64(y * x); elseif (x <= 3.5e+121) tmp = Float64(y * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.45e-65) tmp = y * x; elseif (x <= 3.5e+121) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.45e-65], N[(y * x), $MachinePrecision], If[LessEqual[x, 3.5e+121], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{-65}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+121}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.4499999999999999e-65 or 3.5e121 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6489.8
Applied rewrites89.8%
Taylor expanded in y around inf
Applied rewrites43.4%
if -1.4499999999999999e-65 < x < 3.5e121Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6460.8
Applied rewrites60.8%
Final simplification53.1%
(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.f6463.0
Applied rewrites63.0%
Taylor expanded in y around inf
Applied rewrites29.1%
herbie shell --seed 2024235
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))