
(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 0.00095) (+ 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 <= 0.00095) {
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 <= 0.00095d0) 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 <= 0.00095) {
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 <= 0.00095: 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 <= 0.00095) 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 <= 0.00095) 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, 0.00095], 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 0.00095:\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 9.49999999999999998e-4 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
if -1 < y < 9.49999999999999998e-4Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.9
Applied rewrites98.9%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.15e-9) t_0 (if (<= y 1.7e-67) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.15e-9) {
tmp = t_0;
} else if (y <= 1.7e-67) {
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 <= -1.15e-9) tmp = t_0; elseif (y <= 1.7e-67) 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, -1.15e-9], t$95$0, If[LessEqual[y, 1.7e-67], 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 -1.15 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-67}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.15e-9 or 1.70000000000000005e-67 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6495.6
Applied rewrites95.6%
if -1.15e-9 < y < 1.70000000000000005e-67Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6469.8
Applied rewrites69.8%
Final simplification84.4%
(FPCore (x y z) :precision binary64 (if (<= z -1.8e+25) (* z y) (if (<= z 9e-30) (fma y x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.8e+25) {
tmp = z * y;
} else if (z <= 9e-30) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.8e+25) tmp = Float64(z * y); elseif (z <= 9e-30) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.8e+25], N[(z * y), $MachinePrecision], If[LessEqual[z, 9e-30], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.8 \cdot 10^{+25}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 9 \cdot 10^{-30}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.80000000000000008e25 or 8.99999999999999935e-30 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6469.9
Applied rewrites69.9%
if -1.80000000000000008e25 < z < 8.99999999999999935e-30Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6485.5
Applied rewrites85.5%
Final simplification77.5%
(FPCore (x y z) :precision binary64 (if (<= z -9e+21) (* z y) (if (<= z 4.6e-173) (* x y) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -9e+21) {
tmp = z * y;
} else if (z <= 4.6e-173) {
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 <= (-9d+21)) then
tmp = z * y
else if (z <= 4.6d-173) 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 <= -9e+21) {
tmp = z * y;
} else if (z <= 4.6e-173) {
tmp = x * y;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -9e+21: tmp = z * y elif z <= 4.6e-173: tmp = x * y else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -9e+21) tmp = Float64(z * y); elseif (z <= 4.6e-173) 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 <= -9e+21) tmp = z * y; elseif (z <= 4.6e-173) tmp = x * y; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -9e+21], N[(z * y), $MachinePrecision], If[LessEqual[z, 4.6e-173], N[(x * y), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+21}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 4.6 \cdot 10^{-173}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -9e21 or 4.59999999999999976e-173 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6463.1
Applied rewrites63.1%
if -9e21 < z < 4.59999999999999976e-173Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6487.8
Applied rewrites87.8%
Taylor expanded in y around inf
Applied rewrites47.0%
Final simplification56.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 x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6459.7
Applied rewrites59.7%
Taylor expanded in y around inf
Applied rewrites28.9%
Final simplification28.9%
herbie shell --seed 2024220
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))