
(FPCore (x) :precision binary64 (- 1.0 (* x (+ 0.253 (* x 0.12)))))
double code(double x) {
return 1.0 - (x * (0.253 + (x * 0.12)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - (x * (0.253d0 + (x * 0.12d0)))
end function
public static double code(double x) {
return 1.0 - (x * (0.253 + (x * 0.12)));
}
def code(x): return 1.0 - (x * (0.253 + (x * 0.12)))
function code(x) return Float64(1.0 - Float64(x * Float64(0.253 + Float64(x * 0.12)))) end
function tmp = code(x) tmp = 1.0 - (x * (0.253 + (x * 0.12))); end
code[x_] := N[(1.0 - N[(x * N[(0.253 + N[(x * 0.12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - x \cdot \left(0.253 + x \cdot 0.12\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- 1.0 (* x (+ 0.253 (* x 0.12)))))
double code(double x) {
return 1.0 - (x * (0.253 + (x * 0.12)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - (x * (0.253d0 + (x * 0.12d0)))
end function
public static double code(double x) {
return 1.0 - (x * (0.253 + (x * 0.12)));
}
def code(x): return 1.0 - (x * (0.253 + (x * 0.12)))
function code(x) return Float64(1.0 - Float64(x * Float64(0.253 + Float64(x * 0.12)))) end
function tmp = code(x) tmp = 1.0 - (x * (0.253 + (x * 0.12))); end
code[x_] := N[(1.0 - N[(x * N[(0.253 + N[(x * 0.12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - x \cdot \left(0.253 + x \cdot 0.12\right)
\end{array}
(FPCore (x) :precision binary64 (- 1.0 (* x (+ 0.253 (* x 0.12)))))
double code(double x) {
return 1.0 - (x * (0.253 + (x * 0.12)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - (x * (0.253d0 + (x * 0.12d0)))
end function
public static double code(double x) {
return 1.0 - (x * (0.253 + (x * 0.12)));
}
def code(x): return 1.0 - (x * (0.253 + (x * 0.12)))
function code(x) return Float64(1.0 - Float64(x * Float64(0.253 + Float64(x * 0.12)))) end
function tmp = code(x) tmp = 1.0 - (x * (0.253 + (x * 0.12))); end
code[x_] := N[(1.0 - N[(x * N[(0.253 + N[(x * 0.12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - x \cdot \left(0.253 + x \cdot 0.12\right)
\end{array}
Initial program 99.8%
(FPCore (x) :precision binary64 (if (<= x -4.1) (* x 0.12) (- 1.0 (* x 0.12))))
double code(double x) {
double tmp;
if (x <= -4.1) {
tmp = x * 0.12;
} else {
tmp = 1.0 - (x * 0.12);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-4.1d0)) then
tmp = x * 0.12d0
else
tmp = 1.0d0 - (x * 0.12d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -4.1) {
tmp = x * 0.12;
} else {
tmp = 1.0 - (x * 0.12);
}
return tmp;
}
def code(x): tmp = 0 if x <= -4.1: tmp = x * 0.12 else: tmp = 1.0 - (x * 0.12) return tmp
function code(x) tmp = 0.0 if (x <= -4.1) tmp = Float64(x * 0.12); else tmp = Float64(1.0 - Float64(x * 0.12)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -4.1) tmp = x * 0.12; else tmp = 1.0 - (x * 0.12); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -4.1], N[(x * 0.12), $MachinePrecision], N[(1.0 - N[(x * 0.12), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1:\\
\;\;\;\;x \cdot 0.12\\
\mathbf{else}:\\
\;\;\;\;1 - x \cdot 0.12\\
\end{array}
\end{array}
if x < -4.0999999999999996Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites6.6%
Taylor expanded in x around 0
Applied rewrites6.6%
if -4.0999999999999996 < x Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites65.3%
(FPCore (x) :precision binary64 (+ 0.253 (* x 0.12)))
double code(double x) {
return 0.253 + (x * 0.12);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.253d0 + (x * 0.12d0)
end function
public static double code(double x) {
return 0.253 + (x * 0.12);
}
def code(x): return 0.253 + (x * 0.12)
function code(x) return Float64(0.253 + Float64(x * 0.12)) end
function tmp = code(x) tmp = 0.253 + (x * 0.12); end
code[x_] := N[(0.253 + N[(x * 0.12), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.253 + x \cdot 0.12
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites10.0%
(FPCore (x) :precision binary64 (* x 0.12))
double code(double x) {
return x * 0.12;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 0.12d0
end function
public static double code(double x) {
return x * 0.12;
}
def code(x): return x * 0.12
function code(x) return Float64(x * 0.12) end
function tmp = code(x) tmp = x * 0.12; end
code[x_] := N[(x * 0.12), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.12
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites10.0%
Taylor expanded in x around 0
Applied rewrites3.6%
herbie shell --seed 2024321
(FPCore (x)
:name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, A"
:precision binary64
:pre (TRUE)
(- 1.0 (* x (+ 0.253 (* x 0.12)))))