
(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 7 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 egg-rr100.0%
(FPCore (x y z) :precision binary64 (if (<= y -8e-57) (* z y) (if (<= y 4.2e-35) x (if (<= y 2.9e+103) (* z y) (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e-57) {
tmp = z * y;
} else if (y <= 4.2e-35) {
tmp = x;
} else if (y <= 2.9e+103) {
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 <= (-8d-57)) then
tmp = z * y
else if (y <= 4.2d-35) then
tmp = x
else if (y <= 2.9d+103) 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 <= -8e-57) {
tmp = z * y;
} else if (y <= 4.2e-35) {
tmp = x;
} else if (y <= 2.9e+103) {
tmp = z * y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e-57: tmp = z * y elif y <= 4.2e-35: tmp = x elif y <= 2.9e+103: tmp = z * y else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e-57) tmp = Float64(z * y); elseif (y <= 4.2e-35) tmp = x; elseif (y <= 2.9e+103) 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 <= -8e-57) tmp = z * y; elseif (y <= 4.2e-35) tmp = x; elseif (y <= 2.9e+103) tmp = z * y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e-57], N[(z * y), $MachinePrecision], If[LessEqual[y, 4.2e-35], x, If[LessEqual[y, 2.9e+103], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-57}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-35}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+103}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -7.99999999999999964e-57 or 4.2e-35 < y < 2.8999999999999998e103Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6464.5
Simplified64.5%
if -7.99999999999999964e-57 < y < 4.2e-35Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6479.2
Simplified79.2%
distribute-lft1-inN/A
lower-*.f64N/A
lower-+.f6479.2
Applied egg-rr79.2%
Taylor expanded in y around 0
Simplified79.2%
*-lft-identity79.2
Applied egg-rr79.2%
if 2.8999999999999998e103 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6460.1
Simplified60.1%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6460.1
Simplified60.1%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -160000000000.0) t_0 (if (<= y 1.0) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -160000000000.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -160000000000.0) tmp = t_0; elseif (y <= 1.0) tmp = fma(z, y, 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, -160000000000.0], t$95$0, If[LessEqual[y, 1.0], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -160000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.6e11 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.7
Simplified99.7%
if -1.6e11 < y < 1Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6498.7
Simplified98.7%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.7
Applied egg-rr98.7%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (<= z -8.5e-16) (fma z y x) (if (<= z 1.3e-139) (fma y x x) (fma z y x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e-16) {
tmp = fma(z, y, x);
} else if (z <= 1.3e-139) {
tmp = fma(y, x, x);
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -8.5e-16) tmp = fma(z, y, x); elseif (z <= 1.3e-139) tmp = fma(y, x, x); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -8.5e-16], N[(z * y + x), $MachinePrecision], If[LessEqual[z, 1.3e-139], N[(y * x + x), $MachinePrecision], N[(z * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;z \leq 1.3 \cdot 10^{-139}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if z < -8.5000000000000001e-16 or 1.2999999999999999e-139 < z Initial program 100.0%
Taylor expanded in z around inf
lower-*.f6491.6
Simplified91.6%
lift-*.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6491.6
Applied egg-rr91.6%
if -8.5000000000000001e-16 < z < 1.2999999999999999e-139Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6489.6
Simplified89.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.35e+30) (* z y) (if (<= z 2.55e+160) (fma y x x) (* z y))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.35e+30) {
tmp = z * y;
} else if (z <= 2.55e+160) {
tmp = fma(y, x, x);
} else {
tmp = z * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.35e+30) tmp = Float64(z * y); elseif (z <= 2.55e+160) tmp = fma(y, x, x); else tmp = Float64(z * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.35e+30], N[(z * y), $MachinePrecision], If[LessEqual[z, 2.55e+160], N[(y * x + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{+30}:\\
\;\;\;\;z \cdot y\\
\mathbf{elif}\;z \leq 2.55 \cdot 10^{+160}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if z < -1.3499999999999999e30 or 2.5500000000000001e160 < z Initial program 100.0%
Taylor expanded in x around 0
lower-*.f6478.5
Simplified78.5%
if -1.3499999999999999e30 < z < 2.5500000000000001e160Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6480.4
Simplified80.4%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (<= y -160000000000.0) (* x y) (if (<= y 1000000000.0) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -160000000000.0) {
tmp = x * y;
} else if (y <= 1000000000.0) {
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 <= (-160000000000.0d0)) then
tmp = x * y
else if (y <= 1000000000.0d0) 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 <= -160000000000.0) {
tmp = x * y;
} else if (y <= 1000000000.0) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -160000000000.0: tmp = x * y elif y <= 1000000000.0: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -160000000000.0) tmp = Float64(x * y); elseif (y <= 1000000000.0) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -160000000000.0) tmp = x * y; elseif (y <= 1000000000.0) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -160000000000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1000000000.0], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -160000000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1000000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.6e11 or 1e9 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6452.0
Simplified52.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6451.7
Simplified51.7%
if -1.6e11 < y < 1e9Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6472.9
Simplified72.9%
distribute-lft1-inN/A
lower-*.f64N/A
lower-+.f6472.8
Applied egg-rr72.8%
Taylor expanded in y around 0
Simplified71.8%
*-lft-identity71.8
Applied egg-rr71.8%
Final simplification62.6%
(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 x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lower-fma.f6463.3
Simplified63.3%
distribute-lft1-inN/A
lower-*.f64N/A
lower-+.f6463.3
Applied egg-rr63.3%
Taylor expanded in y around 0
Simplified40.3%
*-lft-identity40.3
Applied egg-rr40.3%
herbie shell --seed 2024208
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))