
(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 8 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%
+-commutativeN/A
*-commutativeN/A
fma-defineN/A
fma-lowering-fma.f64N/A
+-commutativeN/A
+-lowering-+.f64100.0%
Applied egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= y -1.8e-7) (* z y) (if (<= y 1.45e-143) x (if (<= y 3.3e+224) (* z y) (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.8e-7) {
tmp = z * y;
} else if (y <= 1.45e-143) {
tmp = x;
} else if (y <= 3.3e+224) {
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 (y <= (-1.8d-7)) then
tmp = z * y
else if (y <= 1.45d-143) then
tmp = x
else if (y <= 3.3d+224) 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 (y <= -1.8e-7) {
tmp = z * y;
} else if (y <= 1.45e-143) {
tmp = x;
} else if (y <= 3.3e+224) {
tmp = z * y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.8e-7: tmp = z * y elif y <= 1.45e-143: tmp = x elif y <= 3.3e+224: tmp = z * y else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.8e-7) tmp = Float64(z * y); elseif (y <= 1.45e-143) tmp = x; elseif (y <= 3.3e+224) tmp = Float64(z * y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.8e-7) tmp = z * y; elseif (y <= 1.45e-143) tmp = x; elseif (y <= 3.3e+224) tmp = z * y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.8e-7], N[(z * y), $MachinePrecision], If[LessEqual[y, 1.45e-143], x, If[LessEqual[y, 3.3e+224], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-7}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-143}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{+224}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.79999999999999997e-7 or 1.45e-143 < y < 3.29999999999999996e224Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f6458.0%
Simplified58.0%
if -1.79999999999999997e-7 < y < 1.45e-143Initial program 100.0%
Taylor expanded in y around 0
Simplified76.1%
if 3.29999999999999996e224 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6466.4%
Simplified66.4%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6466.4%
Simplified66.4%
Final simplification64.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.0) t_0 (if (<= y 0.00021) (+ 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.00021) {
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.00021d0) 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.00021) {
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.00021: 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.00021) 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.00021) 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.00021], 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.00021:\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 2.1000000000000001e-4 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6497.9%
Simplified97.9%
if -1 < y < 2.1000000000000001e-4Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6498.1%
Simplified98.1%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -0.0074) t_0 (if (<= y 1.26e-143) (* x (+ y 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -0.0074) {
tmp = t_0;
} else if (y <= 1.26e-143) {
tmp = x * (y + 1.0);
} 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 <= (-0.0074d0)) then
tmp = t_0
else if (y <= 1.26d-143) then
tmp = x * (y + 1.0d0)
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 <= -0.0074) {
tmp = t_0;
} else if (y <= 1.26e-143) {
tmp = x * (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -0.0074: tmp = t_0 elif y <= 1.26e-143: tmp = x * (y + 1.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -0.0074) tmp = t_0; elseif (y <= 1.26e-143) tmp = Float64(x * Float64(y + 1.0)); 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 <= -0.0074) tmp = t_0; elseif (y <= 1.26e-143) tmp = x * (y + 1.0); 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, -0.0074], t$95$0, If[LessEqual[y, 1.26e-143], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -0.0074:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.26 \cdot 10^{-143}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0074000000000000003 or 1.2600000000000001e-143 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6489.2%
Simplified89.2%
if -0.0074000000000000003 < y < 1.2600000000000001e-143Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6476.6%
Simplified76.6%
Final simplification85.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (+ y 1.0)))) (if (<= x -6e+35) t_0 (if (<= x 1.75e+50) (* z y) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y + 1.0);
double tmp;
if (x <= -6e+35) {
tmp = t_0;
} else if (x <= 1.75e+50) {
tmp = 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 = x * (y + 1.0d0)
if (x <= (-6d+35)) then
tmp = t_0
else if (x <= 1.75d+50) then
tmp = 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 = x * (y + 1.0);
double tmp;
if (x <= -6e+35) {
tmp = t_0;
} else if (x <= 1.75e+50) {
tmp = z * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y + 1.0) tmp = 0 if x <= -6e+35: tmp = t_0 elif x <= 1.75e+50: tmp = z * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y + 1.0)) tmp = 0.0 if (x <= -6e+35) tmp = t_0; elseif (x <= 1.75e+50) tmp = Float64(z * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y + 1.0); tmp = 0.0; if (x <= -6e+35) tmp = t_0; elseif (x <= 1.75e+50) tmp = z * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6e+35], t$95$0, If[LessEqual[x, 1.75e+50], N[(z * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + 1\right)\\
\mathbf{if}\;x \leq -6 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{+50}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -5.99999999999999981e35 or 1.75000000000000003e50 < x Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6488.0%
Simplified88.0%
if -5.99999999999999981e35 < x < 1.75000000000000003e50Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6468.3%
Simplified68.3%
Final simplification76.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 0.00021) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 0.00021) {
tmp = x;
} 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 (y <= (-1.0d0)) then
tmp = x * y
else if (y <= 0.00021d0) then
tmp = x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 0.00021) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 0.00021: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 0.00021) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 0.00021) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.00021], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.00021:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 2.1000000000000001e-4 < y Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6446.3%
Simplified46.3%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6444.3%
Simplified44.3%
if -1 < y < 2.1000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0
Simplified65.5%
Final simplification54.3%
(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 x)
double code(double x, double y, double z) {
return 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
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0
Simplified32.6%
herbie shell --seed 2024149
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))