
(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 4 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 58.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 2.0) (* x x)))
double code(double x) {
double tmp;
if (((1.0 + x) * (1.0 + x)) <= 2.0) {
tmp = x * 2.0;
} 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 * 2.0d0
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 * 2.0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 + x) * (1.0 + x)) <= 2.0: tmp = x * 2.0 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 * 2.0); 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 * 2.0; 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 * 2.0), $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 \cdot 2\\
\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 7.5%
Taylor expanded in x around 0
lower-*.f6499.0
Applied rewrites99.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-*.f6497.7
Applied rewrites97.7%
Final simplification98.3%
(FPCore (x) :precision binary64 (* x 2.0))
double code(double x) {
return x * 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 2.0d0
end function
public static double code(double x) {
return x * 2.0;
}
def code(x): return x * 2.0
function code(x) return Float64(x * 2.0) end
function tmp = code(x) tmp = x * 2.0; end
code[x_] := N[(x * 2.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 2
\end{array}
Initial program 58.8%
Taylor expanded in x around 0
lower-*.f6446.2
Applied rewrites46.2%
Final simplification46.2%
(FPCore (x) :precision binary64 (- 1.0 1.0))
double code(double x) {
return 1.0 - 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 - 1.0d0
end function
public static double code(double x) {
return 1.0 - 1.0;
}
def code(x): return 1.0 - 1.0
function code(x) return Float64(1.0 - 1.0) end
function tmp = code(x) tmp = 1.0 - 1.0; end
code[x_] := N[(1.0 - 1.0), $MachinePrecision]
\begin{array}{l}
\\
1 - 1
\end{array}
Initial program 58.8%
Taylor expanded in x around 0
Applied rewrites3.5%
herbie shell --seed 2024288
(FPCore (x)
:name "Expanding a square"
:precision binary64
(- (* (+ x 1.0) (+ x 1.0)) 1.0))