
(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 (+ x (* y (+ x z))))
double code(double x, double y, double z) {
return x + (y * (x + z));
}
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 * (x + z))
end function
public static double code(double x, double y, double z) {
return x + (y * (x + z));
}
def code(x, y, z): return x + (y * (x + z))
function code(x, y, z) return Float64(x + Float64(y * Float64(x + z))) end
function tmp = code(x, y, z) tmp = x + (y * (x + z)); end
code[x_, y_, z_] := N[(x + N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x + z\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -260.0) t_0 (if (<= y 0.075) (+ x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -260.0) {
tmp = t_0;
} else if (y <= 0.075) {
tmp = x + (y * z);
} 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 <= (-260.0d0)) then
tmp = t_0
else if (y <= 0.075d0) then
tmp = x + (y * z)
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 <= -260.0) {
tmp = t_0;
} else if (y <= 0.075) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -260.0: tmp = t_0 elif y <= 0.075: tmp = x + (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -260.0) tmp = t_0; elseif (y <= 0.075) tmp = Float64(x + Float64(y * z)); 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 <= -260.0) tmp = t_0; elseif (y <= 0.075) tmp = x + (y * z); 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, -260.0], t$95$0, If[LessEqual[y, 0.075], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -260:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.075:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -260 or 0.0749999999999999972 < y Initial program 99.9%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.3
Applied rewrites98.3%
if -260 < y < 0.0749999999999999972Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6499.2
Applied rewrites99.2%
Final simplification98.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -3.8e-23) t_0 (if (<= y 2.7e-99) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -3.8e-23) {
tmp = t_0;
} else if (y <= 2.7e-99) {
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 <= -3.8e-23) tmp = t_0; elseif (y <= 2.7e-99) 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, -3.8e-23], t$95$0, If[LessEqual[y, 2.7e-99], 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 -3.8 \cdot 10^{-23}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-99}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.80000000000000011e-23 or 2.7e-99 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6494.0
Applied rewrites94.0%
if -3.80000000000000011e-23 < y < 2.7e-99Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6473.3
Applied rewrites73.3%
Final simplification84.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.42e+51) (* y z) (if (<= z 1.35e+117) (fma y x x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.42e+51) {
tmp = y * z;
} else if (z <= 1.35e+117) {
tmp = fma(y, x, x);
} else {
tmp = y * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.42e+51) tmp = Float64(y * z); elseif (z <= 1.35e+117) tmp = fma(y, x, x); else tmp = Float64(y * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.42e+51], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.35e+117], N[(y * x + x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.42 \cdot 10^{+51}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+117}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.41999999999999998e51 or 1.3500000000000001e117 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6471.4
Applied rewrites71.4%
if -1.41999999999999998e51 < z < 1.3500000000000001e117Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6479.4
Applied rewrites79.4%
(FPCore (x y z) :precision binary64 (if (<= x -1.9e-11) (* x y) (if (<= x 8.5e+32) (* y z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.9e-11) {
tmp = x * y;
} else if (x <= 8.5e+32) {
tmp = y * z;
} 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.9d-11)) then
tmp = x * y
else if (x <= 8.5d+32) then
tmp = y * z
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.9e-11) {
tmp = x * y;
} else if (x <= 8.5e+32) {
tmp = y * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.9e-11: tmp = x * y elif x <= 8.5e+32: tmp = y * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.9e-11) tmp = Float64(x * y); elseif (x <= 8.5e+32) tmp = Float64(y * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.9e-11) tmp = x * y; elseif (x <= 8.5e+32) tmp = y * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.9e-11], N[(x * y), $MachinePrecision], If[LessEqual[x, 8.5e+32], N[(y * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+32}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.8999999999999999e-11 or 8.4999999999999998e32 < x Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6488.9
Applied rewrites88.9%
Taylor expanded in y around inf
Applied rewrites46.4%
if -1.8999999999999999e-11 < x < 8.4999999999999998e32Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6458.5
Applied rewrites58.5%
(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.0
Applied rewrites63.0%
Taylor expanded in y around inf
Applied rewrites28.0%
herbie shell --seed 2024238
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))