
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
def code(x): return (x * x) * (3.0 - (x * 2.0))
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function tmp = code(x) tmp = (x * x) * (3.0 - (x * 2.0)); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
def code(x): return (x * x) * (3.0 - (x * 2.0))
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function tmp = code(x) tmp = (x * x) * (3.0 - (x * 2.0)); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}
(FPCore (x) :precision binary64 (* x (* x (- 3.0 (* x 2.0)))))
double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (3.0d0 - (x * 2.0d0)))
end function
public static double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
def code(x): return x * (x * (3.0 - (x * 2.0)))
function code(x) return Float64(x * Float64(x * Float64(3.0 - Float64(x * 2.0)))) end
function tmp = code(x) tmp = x * (x * (3.0 - (x * 2.0))); end
code[x_] := N[(x * N[(x * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (or (<= x -1.5) (not (<= x 1.5))) (* x (* x (* x -2.0))) (* x (* x 3.0))))
double code(double x) {
double tmp;
if ((x <= -1.5) || !(x <= 1.5)) {
tmp = x * (x * (x * -2.0));
} else {
tmp = x * (x * 3.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.5d0)) .or. (.not. (x <= 1.5d0))) then
tmp = x * (x * (x * (-2.0d0)))
else
tmp = x * (x * 3.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.5) || !(x <= 1.5)) {
tmp = x * (x * (x * -2.0));
} else {
tmp = x * (x * 3.0);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.5) or not (x <= 1.5): tmp = x * (x * (x * -2.0)) else: tmp = x * (x * 3.0) return tmp
function code(x) tmp = 0.0 if ((x <= -1.5) || !(x <= 1.5)) tmp = Float64(x * Float64(x * Float64(x * -2.0))); else tmp = Float64(x * Float64(x * 3.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.5) || ~((x <= 1.5))) tmp = x * (x * (x * -2.0)); else tmp = x * (x * 3.0); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.5], N[Not[LessEqual[x, 1.5]], $MachinePrecision]], N[(x * N[(x * N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 1.5\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\end{array}
\end{array}
if x < -1.5 or 1.5 < x Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around inf 98.2%
unpow298.2%
*-commutative98.2%
associate-*r*98.2%
Simplified98.2%
if -1.5 < x < 1.5Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 98.8%
Final simplification98.5%
(FPCore (x) :precision binary64 (if (or (<= x -1.15) (not (<= x 1.5))) (* x (* x (* x -2.0))) (/ x (+ 0.2222222222222222 (/ 0.3333333333333333 x)))))
double code(double x) {
double tmp;
if ((x <= -1.15) || !(x <= 1.5)) {
tmp = x * (x * (x * -2.0));
} else {
tmp = x / (0.2222222222222222 + (0.3333333333333333 / x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.15d0)) .or. (.not. (x <= 1.5d0))) then
tmp = x * (x * (x * (-2.0d0)))
else
tmp = x / (0.2222222222222222d0 + (0.3333333333333333d0 / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.15) || !(x <= 1.5)) {
tmp = x * (x * (x * -2.0));
} else {
tmp = x / (0.2222222222222222 + (0.3333333333333333 / x));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.15) or not (x <= 1.5): tmp = x * (x * (x * -2.0)) else: tmp = x / (0.2222222222222222 + (0.3333333333333333 / x)) return tmp
function code(x) tmp = 0.0 if ((x <= -1.15) || !(x <= 1.5)) tmp = Float64(x * Float64(x * Float64(x * -2.0))); else tmp = Float64(x / Float64(0.2222222222222222 + Float64(0.3333333333333333 / x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.15) || ~((x <= 1.5))) tmp = x * (x * (x * -2.0)); else tmp = x / (0.2222222222222222 + (0.3333333333333333 / x)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.15], N[Not[LessEqual[x, 1.5]], $MachinePrecision]], N[(x * N[(x * N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(0.2222222222222222 + N[(0.3333333333333333 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.15 \lor \neg \left(x \leq 1.5\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{0.2222222222222222 + \frac{0.3333333333333333}{x}}\\
\end{array}
\end{array}
if x < -1.1499999999999999 or 1.5 < x Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around inf 98.2%
unpow298.2%
*-commutative98.2%
associate-*r*98.2%
Simplified98.2%
if -1.1499999999999999 < x < 1.5Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
flip--99.8%
associate-*r/99.8%
metadata-eval99.8%
swap-sqr99.8%
metadata-eval99.8%
+-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
*-commutative99.8%
associate-/l*99.7%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
clear-num99.7%
un-div-inv99.7%
div-inv99.7%
sub-neg99.7%
associate-*r*99.7%
distribute-rgt-neg-in99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 98.9%
associate-*r/98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.6%
(FPCore (x) :precision binary64 (* 3.0 (* x x)))
double code(double x) {
return 3.0 * (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 3.0d0 * (x * x)
end function
public static double code(double x) {
return 3.0 * (x * x);
}
def code(x): return 3.0 * (x * x)
function code(x) return Float64(3.0 * Float64(x * x)) end
function tmp = code(x) tmp = 3.0 * (x * x); end
code[x_] := N[(3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(x \cdot x\right)
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 64.2%
unpow264.2%
Simplified64.2%
Final simplification64.2%
(FPCore (x) :precision binary64 (* x (* x 3.0)))
double code(double x) {
return x * (x * 3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * 3.0d0)
end function
public static double code(double x) {
return x * (x * 3.0);
}
def code(x): return x * (x * 3.0)
function code(x) return Float64(x * Float64(x * 3.0)) end
function tmp = code(x) tmp = x * (x * 3.0); end
code[x_] := N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 3\right)
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 64.3%
Final simplification64.3%
(FPCore (x) :precision binary64 (* x 4.5))
double code(double x) {
return x * 4.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 4.5d0
end function
public static double code(double x) {
return x * 4.5;
}
def code(x): return x * 4.5
function code(x) return Float64(x * 4.5) end
function tmp = code(x) tmp = x * 4.5; end
code[x_] := N[(x * 4.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 4.5
\end{array}
Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
flip--99.5%
associate-*r/99.5%
metadata-eval99.5%
swap-sqr99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.5%
Applied egg-rr99.5%
*-commutative99.5%
associate-/l*99.4%
associate-*l*99.4%
Simplified99.4%
Taylor expanded in x around 0 99.8%
Taylor expanded in x around 0 49.0%
Taylor expanded in x around inf 2.9%
Final simplification2.9%
(FPCore (x) :precision binary64 (* x (* x (- 3.0 (* x 2.0)))))
double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (3.0d0 - (x * 2.0d0)))
end function
public static double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
def code(x): return x * (x * (3.0 - (x * 2.0)))
function code(x) return Float64(x * Float64(x * Float64(3.0 - Float64(x * 2.0)))) end
function tmp = code(x) tmp = x * (x * (3.0 - (x * 2.0))); end
code[x_] := N[(x * N[(x * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\end{array}
herbie shell --seed 2023228
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:herbie-target
(* x (* x (- 3.0 (* x 2.0))))
(* (* x x) (- 3.0 (* x 2.0))))