
(FPCore (x y) :precision binary64 (- x (* (/ 3.0 8.0) y)))
double code(double x, double y) {
return x - ((3.0 / 8.0) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - ((3.0d0 / 8.0d0) * y)
end function
public static double code(double x, double y) {
return x - ((3.0 / 8.0) * y);
}
def code(x, y): return x - ((3.0 / 8.0) * y)
function code(x, y) return Float64(x - Float64(Float64(3.0 / 8.0) * y)) end
function tmp = code(x, y) tmp = x - ((3.0 / 8.0) * y); end
code[x_, y_] := N[(x - N[(N[(3.0 / 8.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{3}{8} \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- x (* (/ 3.0 8.0) y)))
double code(double x, double y) {
return x - ((3.0 / 8.0) * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - ((3.0d0 / 8.0d0) * y)
end function
public static double code(double x, double y) {
return x - ((3.0 / 8.0) * y);
}
def code(x, y): return x - ((3.0 / 8.0) * y)
function code(x, y) return Float64(x - Float64(Float64(3.0 / 8.0) * y)) end
function tmp = code(x, y) tmp = x - ((3.0 / 8.0) * y); end
code[x_, y_] := N[(x - N[(N[(3.0 / 8.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{3}{8} \cdot y
\end{array}
(FPCore (x y) :precision binary64 (fma y -0.375 x))
double code(double x, double y) {
return fma(y, -0.375, x);
}
function code(x, y) return fma(y, -0.375, x) end
code[x_, y_] := N[(y * -0.375 + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, -0.375, x\right)
\end{array}
Initial program 99.9%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f64N/A
metadata-evalN/A
metadata-eval100.0
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (/ 3.0 8.0)))) (if (<= t_0 -2e+16) (* y -0.375) (if (<= t_0 4e+43) x (* y -0.375)))))
double code(double x, double y) {
double t_0 = y * (3.0 / 8.0);
double tmp;
if (t_0 <= -2e+16) {
tmp = y * -0.375;
} else if (t_0 <= 4e+43) {
tmp = x;
} else {
tmp = y * -0.375;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * (3.0d0 / 8.0d0)
if (t_0 <= (-2d+16)) then
tmp = y * (-0.375d0)
else if (t_0 <= 4d+43) then
tmp = x
else
tmp = y * (-0.375d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * (3.0 / 8.0);
double tmp;
if (t_0 <= -2e+16) {
tmp = y * -0.375;
} else if (t_0 <= 4e+43) {
tmp = x;
} else {
tmp = y * -0.375;
}
return tmp;
}
def code(x, y): t_0 = y * (3.0 / 8.0) tmp = 0 if t_0 <= -2e+16: tmp = y * -0.375 elif t_0 <= 4e+43: tmp = x else: tmp = y * -0.375 return tmp
function code(x, y) t_0 = Float64(y * Float64(3.0 / 8.0)) tmp = 0.0 if (t_0 <= -2e+16) tmp = Float64(y * -0.375); elseif (t_0 <= 4e+43) tmp = x; else tmp = Float64(y * -0.375); end return tmp end
function tmp_2 = code(x, y) t_0 = y * (3.0 / 8.0); tmp = 0.0; if (t_0 <= -2e+16) tmp = y * -0.375; elseif (t_0 <= 4e+43) tmp = x; else tmp = y * -0.375; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(3.0 / 8.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+16], N[(y * -0.375), $MachinePrecision], If[LessEqual[t$95$0, 4e+43], x, N[(y * -0.375), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{3}{8}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+16}:\\
\;\;\;\;y \cdot -0.375\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+43}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot -0.375\\
\end{array}
\end{array}
if (*.f64 (/.f64 #s(literal 3 binary64) #s(literal 8 binary64)) y) < -2e16 or 4.00000000000000006e43 < (*.f64 (/.f64 #s(literal 3 binary64) #s(literal 8 binary64)) y) Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f6476.9
Simplified76.9%
if -2e16 < (*.f64 (/.f64 #s(literal 3 binary64) #s(literal 8 binary64)) y) < 4.00000000000000006e43Initial program 100.0%
Taylor expanded in x around inf
Simplified77.0%
Final simplification77.0%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf
Simplified51.9%
herbie shell --seed 2024199
(FPCore (x y)
:name "Diagrams.Solve.Polynomial:quartForm from diagrams-solve-0.1, A"
:precision binary64
(- x (* (/ 3.0 8.0) y)))