
(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
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 (* (+ x z) y))) (if (<= y -180000000.0) t_0 (if (<= y 0.0003) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x + z) * y;
double tmp;
if (y <= -180000000.0) {
tmp = t_0;
} else if (y <= 0.0003) {
tmp = fma(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 <= -180000000.0) tmp = t_0; elseif (y <= 0.0003) tmp = fma(z, y, 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, -180000000.0], t$95$0, If[LessEqual[y, 0.0003], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + z\right) \cdot y\\
\mathbf{if}\;y \leq -180000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0003:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.8e8 or 2.99999999999999974e-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.8e8 < y < 2.99999999999999974e-4Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6499.8
Applied rewrites99.8%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Final simplification99.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.7e+35) (fma z y x) (if (<= z 1.1e-28) (fma y x x) (fma z y x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.7e+35) {
tmp = fma(z, y, x);
} else if (z <= 1.1e-28) {
tmp = fma(y, x, x);
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.7e+35) tmp = fma(z, y, x); elseif (z <= 1.1e-28) tmp = fma(y, x, x); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.7e+35], N[(z * y + x), $MachinePrecision], If[LessEqual[z, 1.1e-28], N[(y * x + x), $MachinePrecision], N[(z * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+35}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{-28}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if z < -1.7000000000000001e35 or 1.09999999999999998e-28 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6491.5
Applied rewrites91.5%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6491.5
Applied rewrites91.5%
if -1.7000000000000001e35 < z < 1.09999999999999998e-28Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6486.8
Applied rewrites86.8%
(FPCore (x y z) :precision binary64 (if (<= z -2.1e+35) (* z y) (if (<= z 1.15e+101) (fma y x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.1e+35) {
tmp = z * y;
} else if (z <= 1.15e+101) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.1e+35) tmp = Float64(z * y); elseif (z <= 1.15e+101) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.1e+35], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.15e+101], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{+35}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+101}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -2.0999999999999999e35 or 1.1500000000000001e101 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6475.1
Applied rewrites75.1%
if -2.0999999999999999e35 < z < 1.1500000000000001e101Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6482.1
Applied rewrites82.1%
Final simplification78.8%
(FPCore (x y z) :precision binary64 (if (<= z -6.8e+30) (* z y) (if (<= z 1.1e-28) (* x y) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.8e+30) {
tmp = z * y;
} else if (z <= 1.1e-28) {
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 <= (-6.8d+30)) then
tmp = z * y
else if (z <= 1.1d-28) 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 <= -6.8e+30) {
tmp = z * y;
} else if (z <= 1.1e-28) {
tmp = x * y;
} else {
tmp = z * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -6.8e+30: tmp = z * y elif z <= 1.1e-28: tmp = x * y else: tmp = z * y return tmp
function code(x, y, z) tmp = 0.0 if (z <= -6.8e+30) tmp = Float64(z * y); elseif (z <= 1.1e-28) 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 <= -6.8e+30) tmp = z * y; elseif (z <= 1.1e-28) tmp = x * y; else tmp = z * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -6.8e+30], N[(z * y), $MachinePrecision], If[LessEqual[z, 1.1e-28], N[(x * y), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{+30}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{-28}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -6.8000000000000005e30 or 1.09999999999999998e-28 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6468.3
Applied rewrites68.3%
if -6.8000000000000005e30 < z < 1.09999999999999998e-28Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6486.5
Applied rewrites86.5%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6438.6
Applied rewrites38.6%
Final simplification56.0%
(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.f6458.7
Applied rewrites58.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6425.7
Applied rewrites25.7%
Final simplification25.7%
herbie shell --seed 2024214
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))