
(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 5 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 (if (or (<= x -1.4e+60) (not (<= x 7.5e-69))) (+ x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e+60) || !(x <= 7.5e-69)) {
tmp = x + (x * y);
} else {
tmp = x + (y * z);
}
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.4d+60)) .or. (.not. (x <= 7.5d-69))) then
tmp = x + (x * y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.4e+60) || !(x <= 7.5e-69)) {
tmp = x + (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.4e+60) or not (x <= 7.5e-69): tmp = x + (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.4e+60) || !(x <= 7.5e-69)) tmp = Float64(x + Float64(x * y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.4e+60) || ~((x <= 7.5e-69))) tmp = x + (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.4e+60], N[Not[LessEqual[x, 7.5e-69]], $MachinePrecision]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.4 \cdot 10^{+60} \lor \neg \left(x \leq 7.5 \cdot 10^{-69}\right):\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.4e60 or 7.5e-69 < x Initial program 100.0%
Taylor expanded in z around 0 88.4%
*-commutative88.4%
Simplified88.4%
if -1.4e60 < x < 7.5e-69Initial program 100.0%
Taylor expanded in z around inf 90.2%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e-39) (not (<= x 3.9e-100))) (+ x (* x y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e-39) || !(x <= 3.9e-100)) {
tmp = x + (x * y);
} else {
tmp = y * z;
}
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 <= (-7.5d-39)) .or. (.not. (x <= 3.9d-100))) then
tmp = x + (x * y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e-39) || !(x <= 3.9e-100)) {
tmp = x + (x * y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e-39) or not (x <= 3.9e-100): tmp = x + (x * y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e-39) || !(x <= 3.9e-100)) tmp = Float64(x + Float64(x * y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.5e-39) || ~((x <= 3.9e-100))) tmp = x + (x * y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e-39], N[Not[LessEqual[x, 3.9e-100]], $MachinePrecision]], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-39} \lor \neg \left(x \leq 3.9 \cdot 10^{-100}\right):\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -7.49999999999999971e-39 or 3.89999999999999977e-100 < x Initial program 100.0%
Taylor expanded in z around 0 82.8%
*-commutative82.8%
Simplified82.8%
if -7.49999999999999971e-39 < x < 3.89999999999999977e-100Initial program 100.0%
Taylor expanded in z around inf 92.1%
Taylor expanded in x around 0 81.1%
Final simplification82.1%
(FPCore (x y z) :precision binary64 (if (<= x -1.38e-36) x (if (<= x 1.2e+70) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.38e-36) {
tmp = x;
} else if (x <= 1.2e+70) {
tmp = y * z;
} else {
tmp = 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 <= (-1.38d-36)) then
tmp = x
else if (x <= 1.2d+70) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.38e-36) {
tmp = x;
} else if (x <= 1.2e+70) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.38e-36: tmp = x elif x <= 1.2e+70: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.38e-36) tmp = x; elseif (x <= 1.2e+70) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.38e-36) tmp = x; elseif (x <= 1.2e+70) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.38e-36], x, If[LessEqual[x, 1.2e+70], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.38 \cdot 10^{-36}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{+70}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.38e-36 or 1.19999999999999993e70 < x Initial program 100.0%
Taylor expanded in z around 0 87.3%
*-commutative87.3%
Simplified87.3%
Taylor expanded in y around 0 44.6%
if -1.38e-36 < x < 1.19999999999999993e70Initial program 100.0%
Taylor expanded in z around inf 86.8%
Taylor expanded in x around 0 73.3%
(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 58.1%
*-commutative58.1%
Simplified58.1%
Taylor expanded in y around 0 30.4%
herbie shell --seed 2024191
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))