
(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 (* (+ x z) (/ (* y (- z x)) (- z x)))))
double code(double x, double y, double z) {
return x + ((x + z) * ((y * (z - x)) / (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 + ((x + z) * ((y * (z - x)) / (z - x)))
end function
public static double code(double x, double y, double z) {
return x + ((x + z) * ((y * (z - x)) / (z - x)));
}
def code(x, y, z): return x + ((x + z) * ((y * (z - x)) / (z - x)))
function code(x, y, z) return Float64(x + Float64(Float64(x + z) * Float64(Float64(y * Float64(z - x)) / Float64(z - x)))) end
function tmp = code(x, y, z) tmp = x + ((x + z) * ((y * (z - x)) / (z - x))); end
code[x_, y_, z_] := N[(x + N[(N[(x + z), $MachinePrecision] * N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x + z\right) \cdot \frac{y \cdot \left(z - x\right)}{z - x}
\end{array}
Initial program 100.0%
distribute-rgt-in98.4%
fma-def99.6%
*-commutative99.6%
Applied egg-rr99.6%
fma-udef98.4%
flip-+52.4%
pow152.4%
pow152.4%
pow-prod-up52.4%
*-commutative52.4%
metadata-eval52.4%
pow252.4%
*-commutative52.4%
*-commutative52.4%
*-commutative52.4%
Applied egg-rr52.4%
unpow252.4%
unpow252.4%
difference-of-squares52.5%
*-commutative52.5%
distribute-rgt-in52.5%
*-commutative52.5%
distribute-lft-out--52.5%
times-frac98.0%
+-commutative98.0%
*-commutative98.0%
distribute-lft-out--99.9%
Simplified99.9%
Taylor expanded in y around 0 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.9e-72) (not (<= z 5.2e-86))) (+ x (* z y)) (+ x (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.9e-72) || !(z <= 5.2e-86)) {
tmp = x + (z * y);
} else {
tmp = x + (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 ((z <= (-2.9d-72)) .or. (.not. (z <= 5.2d-86))) then
tmp = x + (z * y)
else
tmp = x + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.9e-72) || !(z <= 5.2e-86)) {
tmp = x + (z * y);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.9e-72) or not (z <= 5.2e-86): tmp = x + (z * y) else: tmp = x + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.9e-72) || !(z <= 5.2e-86)) tmp = Float64(x + Float64(z * y)); else tmp = Float64(x + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.9e-72) || ~((z <= 5.2e-86))) tmp = x + (z * y); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.9e-72], N[Not[LessEqual[z, 5.2e-86]], $MachinePrecision]], N[(x + N[(z * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.9 \cdot 10^{-72} \lor \neg \left(z \leq 5.2 \cdot 10^{-86}\right):\\
\;\;\;\;x + z \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if z < -2.89999999999999998e-72 or 5.2000000000000002e-86 < z Initial program 100.0%
Taylor expanded in z around inf 89.8%
if -2.89999999999999998e-72 < z < 5.2000000000000002e-86Initial program 100.0%
Taylor expanded in z around 0 90.9%
Final simplification90.2%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 1.0) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.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 <= (-1.0d0)) then
tmp = x * y
else if (y <= 1.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 <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.0: 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 <= 1.0) 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 <= 1.0) 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, 1.0], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 51.1%
Taylor expanded in y around inf 50.6%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around 0 68.4%
Taylor expanded in y around 0 67.3%
Final simplification58.9%
(FPCore (x y z) :precision binary64 (+ x (* (+ x z) y)))
double code(double x, double y, double z) {
return x + ((x + z) * 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 + ((x + z) * y)
end function
public static double code(double x, double y, double z) {
return x + ((x + z) * y);
}
def code(x, y, z): return x + ((x + z) * y)
function code(x, y, z) return Float64(x + Float64(Float64(x + z) * y)) end
function tmp = code(x, y, z) tmp = x + ((x + z) * y); end
code[x_, y_, z_] := N[(x + N[(N[(x + z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x + z\right) \cdot y
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (+ x (* x y)))
double code(double x, double y, double z) {
return x + (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 + (x * y)
end function
public static double code(double x, double y, double z) {
return x + (x * y);
}
def code(x, y, z): return x + (x * y)
function code(x, y, z) return Float64(x + Float64(x * y)) end
function tmp = code(x, y, z) tmp = x + (x * y); end
code[x_, y_, z_] := N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + x \cdot y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0 59.7%
Final simplification59.7%
(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 z around 0 59.7%
Taylor expanded in y around 0 34.9%
Final simplification34.9%
herbie shell --seed 2023196
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))