
(FPCore (x) :precision binary64 (* x (- 1.0 (* x 0.5))))
double code(double x) {
return x * (1.0 - (x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 - (x * 0.5d0))
end function
public static double code(double x) {
return x * (1.0 - (x * 0.5));
}
def code(x): return x * (1.0 - (x * 0.5))
function code(x) return Float64(x * Float64(1.0 - Float64(x * 0.5))) end
function tmp = code(x) tmp = x * (1.0 - (x * 0.5)); end
code[x_] := N[(x * N[(1.0 - N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot 0.5\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* x (- 1.0 (* x 0.5))))
double code(double x) {
return x * (1.0 - (x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 - (x * 0.5d0))
end function
public static double code(double x) {
return x * (1.0 - (x * 0.5));
}
def code(x): return x * (1.0 - (x * 0.5))
function code(x) return Float64(x * Float64(1.0 - Float64(x * 0.5))) end
function tmp = code(x) tmp = x * (1.0 - (x * 0.5)); end
code[x_] := N[(x * N[(1.0 - N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot 0.5\right)
\end{array}
(FPCore (x) :precision binary64 (* x (- 1.0 (* x 0.5))))
double code(double x) {
return x * (1.0 - (x * 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 - (x * 0.5d0))
end function
public static double code(double x) {
return x * (1.0 - (x * 0.5));
}
def code(x): return x * (1.0 - (x * 0.5))
function code(x) return Float64(x * Float64(1.0 - Float64(x * 0.5))) end
function tmp = code(x) tmp = x * (1.0 - (x * 0.5)); end
code[x_] := N[(x * N[(1.0 - N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot 0.5\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (or (<= x -2.0) (not (<= x 2.0))) (* x (* x -0.5)) x))
double code(double x) {
double tmp;
if ((x <= -2.0) || !(x <= 2.0)) {
tmp = x * (x * -0.5);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-2.0d0)) .or. (.not. (x <= 2.0d0))) then
tmp = x * (x * (-0.5d0))
else
tmp = x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -2.0) || !(x <= 2.0)) {
tmp = x * (x * -0.5);
} else {
tmp = x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -2.0) or not (x <= 2.0): tmp = x * (x * -0.5) else: tmp = x return tmp
function code(x) tmp = 0.0 if ((x <= -2.0) || !(x <= 2.0)) tmp = Float64(x * Float64(x * -0.5)); else tmp = x; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -2.0) || ~((x <= 2.0))) tmp = x * (x * -0.5); else tmp = x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -2.0], N[Not[LessEqual[x, 2.0]], $MachinePrecision]], N[(x * N[(x * -0.5), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \lor \neg \left(x \leq 2\right):\\
\;\;\;\;x \cdot \left(x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2 or 2 < x Initial program 100.0%
Taylor expanded in x around inf 97.1%
*-commutative97.1%
unpow297.1%
associate-*r*97.1%
Simplified97.1%
if -2 < x < 2Initial program 100.0%
Taylor expanded in x around 0 96.9%
Final simplification97.0%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 49.8%
Final simplification49.8%
herbie shell --seed 2023196
(FPCore (x)
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, B"
:precision binary64
(* x (- 1.0 (* x 0.5))))