
(FPCore (x) :precision binary64 (- (* (+ x 1.0) (+ x 1.0)) 1.0))
double code(double x) {
return ((x + 1.0) * (x + 1.0)) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x + 1.0d0) * (x + 1.0d0)) - 1.0d0
end function
public static double code(double x) {
return ((x + 1.0) * (x + 1.0)) - 1.0;
}
def code(x): return ((x + 1.0) * (x + 1.0)) - 1.0
function code(x) return Float64(Float64(Float64(x + 1.0) * Float64(x + 1.0)) - 1.0) end
function tmp = code(x) tmp = ((x + 1.0) * (x + 1.0)) - 1.0; end
code[x_] := N[(N[(N[(x + 1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot \left(x + 1\right) - 1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (* (+ x 1.0) (+ x 1.0)) 1.0))
double code(double x) {
return ((x + 1.0) * (x + 1.0)) - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x + 1.0d0) * (x + 1.0d0)) - 1.0d0
end function
public static double code(double x) {
return ((x + 1.0) * (x + 1.0)) - 1.0;
}
def code(x): return ((x + 1.0) * (x + 1.0)) - 1.0
function code(x) return Float64(Float64(Float64(x + 1.0) * Float64(x + 1.0)) - 1.0) end
function tmp = code(x) tmp = ((x + 1.0) * (x + 1.0)) - 1.0; end
code[x_] := N[(N[(N[(x + 1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot \left(x + 1\right) - 1
\end{array}
(FPCore (x) :precision binary64 (* (+ x 2.0) x))
double code(double x) {
return (x + 2.0) * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + 2.0d0) * x
end function
public static double code(double x) {
return (x + 2.0) * x;
}
def code(x): return (x + 2.0) * x
function code(x) return Float64(Float64(x + 2.0) * x) end
function tmp = code(x) tmp = (x + 2.0) * x; end
code[x_] := N[(N[(x + 2.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 2\right) \cdot x
\end{array}
Initial program 55.8%
lift--.f64N/A
lift-*.f64N/A
difference-of-sqr-1N/A
lift-+.f64N/A
associate--l+N/A
metadata-evalN/A
+-rgt-identityN/A
lower-*.f64N/A
lift-+.f64N/A
associate-+l+N/A
metadata-evalN/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= (* (+ 1.0 x) (+ 1.0 x)) 2.0) (+ x x) (* x x)))
double code(double x) {
double tmp;
if (((1.0 + x) * (1.0 + x)) <= 2.0) {
tmp = x + x;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 + x) * (1.0d0 + x)) <= 2.0d0) then
tmp = x + x
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 + x) * (1.0 + x)) <= 2.0) {
tmp = x + x;
} else {
tmp = x * x;
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 + x) * (1.0 + x)) <= 2.0: tmp = x + x else: tmp = x * x return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 + x) * Float64(1.0 + x)) <= 2.0) tmp = Float64(x + x); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 + x) * (1.0 + x)) <= 2.0) tmp = x + x; else tmp = x * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 + x), $MachinePrecision] * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], 2.0], N[(x + x), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + x\right) \cdot \left(1 + x\right) \leq 2:\\
\;\;\;\;x + x\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 (+.f64 x #s(literal 1 binary64)) (+.f64 x #s(literal 1 binary64))) < 2Initial program 9.5%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6497.0
Applied rewrites97.0%
Applied rewrites97.0%
if 2 < (*.f64 (+.f64 x #s(literal 1 binary64)) (+.f64 x #s(literal 1 binary64))) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6498.4
Applied rewrites98.4%
Final simplification97.7%
(FPCore (x) :precision binary64 (+ x x))
double code(double x) {
return x + x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + x
end function
public static double code(double x) {
return x + x;
}
def code(x): return x + x
function code(x) return Float64(x + x) end
function tmp = code(x) tmp = x + x; end
code[x_] := N[(x + x), $MachinePrecision]
\begin{array}{l}
\\
x + x
\end{array}
Initial program 55.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6449.1
Applied rewrites49.1%
Applied rewrites49.1%
herbie shell --seed 2024249
(FPCore (x)
:name "Expanding a square"
:precision binary64
(- (* (+ x 1.0) (+ x 1.0)) 1.0))