
(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 3 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 (+ 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}
Initial program 100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ z x)))) (if (<= y -5.5e-20) t_0 (if (<= y 1.4e-11) (+ z x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z + x);
double tmp;
if (y <= -5.5e-20) {
tmp = t_0;
} else if (y <= 1.4e-11) {
tmp = z + 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 = y * (z + x)
if (y <= (-5.5d-20)) then
tmp = t_0
else if (y <= 1.4d-11) then
tmp = z + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z + x);
double tmp;
if (y <= -5.5e-20) {
tmp = t_0;
} else if (y <= 1.4e-11) {
tmp = z + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z + x) tmp = 0 if y <= -5.5e-20: tmp = t_0 elif y <= 1.4e-11: tmp = z + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z + x)) tmp = 0.0 if (y <= -5.5e-20) tmp = t_0; elseif (y <= 1.4e-11) tmp = Float64(z + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z + x); tmp = 0.0; if (y <= -5.5e-20) tmp = t_0; elseif (y <= 1.4e-11) tmp = z + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.5e-20], t$95$0, If[LessEqual[y, 1.4e-11], N[(z + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z + x\right)\\
\mathbf{if}\;y \leq -5.5 \cdot 10^{-20}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-11}:\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.4999999999999996e-20 or 1.4e-11 < y Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites95.9%
if -5.4999999999999996e-20 < y < 1.4e-11Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites30.1%
Taylor expanded in x around 0
Applied rewrites54.7%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return 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 = z + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites65.3%
Taylor expanded in x around 0
Applied rewrites28.3%
herbie shell --seed 2024321
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
:pre (TRUE)
(+ x (* y (+ z x))))