
(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 5 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
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 (if (<= x -1.85e+47) (fma y x x) (if (<= x 0.47) (fma z y x) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.85e+47) {
tmp = fma(y, x, x);
} else if (x <= 0.47) {
tmp = fma(z, y, x);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.85e+47) tmp = fma(y, x, x); elseif (x <= 0.47) tmp = fma(z, y, x); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.85e+47], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 0.47], N[(z * y + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 0.47:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -1.8500000000000002e47 or 0.46999999999999997 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6494.5
Applied rewrites94.5%
if -1.8500000000000002e47 < x < 0.46999999999999997Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6492.8
Applied rewrites92.8%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6492.8
Applied rewrites92.8%
(FPCore (x y z) :precision binary64 (if (<= x -2.8e-67) (fma y x x) (if (<= x 5.6e-139) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.8e-67) {
tmp = fma(y, x, x);
} else if (x <= 5.6e-139) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.8e-67) tmp = fma(y, x, x); elseif (x <= 5.6e-139) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.8e-67], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 5.6e-139], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-67}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-139}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -2.8000000000000001e-67 or 5.5999999999999997e-139 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6484.9
Applied rewrites84.9%
if -2.8000000000000001e-67 < x < 5.5999999999999997e-139Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6482.5
Applied rewrites82.5%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.85e+47) (* x y) (if (<= x 0.47) (* z y) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.85e+47) {
tmp = x * y;
} else if (x <= 0.47) {
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 <= (-1.85d+47)) then
tmp = x * y
else if (x <= 0.47d0) 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 <= -1.85e+47) {
tmp = x * y;
} else if (x <= 0.47) {
tmp = z * y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.85e+47: tmp = x * y elif x <= 0.47: tmp = z * y else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.85e+47) tmp = Float64(x * y); elseif (x <= 0.47) 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 <= -1.85e+47) tmp = x * y; elseif (x <= 0.47) tmp = z * y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.85e+47], N[(x * y), $MachinePrecision], If[LessEqual[x, 0.47], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+47}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 0.47:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.8500000000000002e47 or 0.46999999999999997 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6494.5
Applied rewrites94.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6446.0
Applied rewrites46.0%
if -1.8500000000000002e47 < x < 0.46999999999999997Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6468.7
Applied rewrites68.7%
Final simplification57.6%
(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.f6463.1
Applied rewrites63.1%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6427.9
Applied rewrites27.9%
Final simplification27.9%
herbie shell --seed 2024219
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))