
(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 (+ (* (+ z x) y) x))
double code(double x, double y, double z) {
return ((z + x) * 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 = ((z + x) * y) + x
end function
public static double code(double x, double y, double z) {
return ((z + x) * y) + x;
}
def code(x, y, z): return ((z + x) * y) + x
function code(x, y, z) return Float64(Float64(Float64(z + x) * y) + x) end
function tmp = code(x, y, z) tmp = ((z + x) * y) + x; end
code[x_, y_, z_] := N[(N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\left(z + x\right) \cdot y + x
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z x) y))) (if (<= y -1.0) t_0 (if (<= y 2.7e-9) (+ (* z y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.7e-9) {
tmp = (z * y) + 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 = (z + x) * y
if (y <= (-1.0d0)) then
tmp = t_0
else if (y <= 2.7d-9) then
tmp = (z * y) + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (z + x) * y;
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 2.7e-9) {
tmp = (z * y) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (z + x) * y tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 2.7e-9: tmp = (z * y) + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(z + x) * y) tmp = 0.0 if (y <= -1.0) tmp = t_0; elseif (y <= 2.7e-9) tmp = Float64(Float64(z * y) + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (z + x) * y; tmp = 0.0; if (y <= -1.0) tmp = t_0; elseif (y <= 2.7e-9) tmp = (z * y) + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.0], t$95$0, If[LessEqual[y, 2.7e-9], N[(N[(z * y), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + x\right) \cdot y\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-9}:\\
\;\;\;\;z \cdot y + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 2.7000000000000002e-9 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
if -1 < y < 2.7000000000000002e-9Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (+ z x) y))) (if (<= y -2.85e-58) t_0 (if (<= y 2.9e-39) (fma y x x) t_0))))
double code(double x, double y, double z) {
double t_0 = (z + x) * y;
double tmp;
if (y <= -2.85e-58) {
tmp = t_0;
} else if (y <= 2.9e-39) {
tmp = fma(y, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(z + x) * y) tmp = 0.0 if (y <= -2.85e-58) tmp = t_0; elseif (y <= 2.9e-39) tmp = fma(y, x, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2.85e-58], t$95$0, If[LessEqual[y, 2.9e-39], N[(y * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(z + x\right) \cdot y\\
\mathbf{if}\;y \leq -2.85 \cdot 10^{-58}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{-39}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.85000000000000016e-58 or 2.89999999999999988e-39 < y Initial program 100.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6497.8
Applied rewrites97.8%
if -2.85000000000000016e-58 < y < 2.89999999999999988e-39Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6477.4
Applied rewrites77.4%
(FPCore (x y z) :precision binary64 (if (<= x -2.4e-135) (fma y x x) (if (<= x 1.86e-72) (* z y) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.4e-135) {
tmp = fma(y, x, x);
} else if (x <= 1.86e-72) {
tmp = z * y;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -2.4e-135) tmp = fma(y, x, x); elseif (x <= 1.86e-72) tmp = Float64(z * y); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -2.4e-135], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 1.86e-72], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{-135}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 1.86 \cdot 10^{-72}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
\end{array}
if x < -2.3999999999999999e-135 or 1.85999999999999994e-72 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6482.2
Applied rewrites82.2%
if -2.3999999999999999e-135 < x < 1.85999999999999994e-72Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6472.6
Applied rewrites72.6%
(FPCore (x y z) :precision binary64 (if (<= x -4.5e+24) (* y x) (if (<= x 1e-71) (* z y) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e+24) {
tmp = y * x;
} else if (x <= 1e-71) {
tmp = z * y;
} 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 <= (-4.5d+24)) then
tmp = y * x
else if (x <= 1d-71) then
tmp = z * y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e+24) {
tmp = y * x;
} else if (x <= 1e-71) {
tmp = z * y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.5e+24: tmp = y * x elif x <= 1e-71: tmp = z * y else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.5e+24) tmp = Float64(y * x); elseif (x <= 1e-71) tmp = Float64(z * y); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.5e+24) tmp = y * x; elseif (x <= 1e-71) tmp = z * y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.5e+24], N[(y * x), $MachinePrecision], If[LessEqual[x, 1e-71], N[(z * y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.5 \cdot 10^{+24}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 10^{-71}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -4.50000000000000019e24 or 9.9999999999999992e-72 < x Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6488.8
Applied rewrites88.8%
Taylor expanded in y around inf
Applied rewrites49.2%
if -4.50000000000000019e24 < x < 9.9999999999999992e-72Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6465.5
Applied rewrites65.5%
(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.f6460.5
Applied rewrites60.5%
Taylor expanded in y around inf
Applied rewrites30.5%
herbie shell --seed 2024270
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))