
(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 (* (fma -2.0 x 3.0) (* x x)))
double code(double x) {
return fma(-2.0, x, 3.0) * (x * x);
}
function code(x) return Float64(fma(-2.0, x, 3.0) * Float64(x * x)) end
code[x_] := N[(N[(-2.0 * x + 3.0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-2, x, 3\right) \cdot \left(x \cdot x\right)
\end{array}
Initial program 99.8%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqr-neg-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lift-*.f64N/A
lower-*.f64N/A
Applied rewrites99.8%
(FPCore (x) :precision binary64 (if (<= (* (* x x) (- 3.0 (* x 2.0))) -2e+24) (* -3.0 (* x x)) (* (* x x) 3.0)))
double code(double x) {
double tmp;
if (((x * x) * (3.0 - (x * 2.0))) <= -2e+24) {
tmp = -3.0 * (x * x);
} else {
tmp = (x * x) * 3.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x * x) * (3.0d0 - (x * 2.0d0))) <= (-2d+24)) then
tmp = (-3.0d0) * (x * x)
else
tmp = (x * x) * 3.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x * x) * (3.0 - (x * 2.0))) <= -2e+24) {
tmp = -3.0 * (x * x);
} else {
tmp = (x * x) * 3.0;
}
return tmp;
}
def code(x): tmp = 0 if ((x * x) * (3.0 - (x * 2.0))) <= -2e+24: tmp = -3.0 * (x * x) else: tmp = (x * x) * 3.0 return tmp
function code(x) tmp = 0.0 if (Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) <= -2e+24) tmp = Float64(-3.0 * Float64(x * x)); else tmp = Float64(Float64(x * x) * 3.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x * x) * (3.0 - (x * 2.0))) <= -2e+24) tmp = -3.0 * (x * x); else tmp = (x * x) * 3.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -2e+24], N[(-3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * 3.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \leq -2 \cdot 10^{+24}:\\
\;\;\;\;-3 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot 3\\
\end{array}
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -2e24Initial program 99.9%
Applied rewrites89.7%
Taylor expanded in x around 0
lower-*.f64N/A
unpow2N/A
lower-*.f6450.1
Applied rewrites50.1%
if -2e24 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites85.7%
(FPCore (x) :precision binary64 (if (or (<= x -1.5) (not (<= x 1.5))) (* (* x x) (* -2.0 x)) (* (* x x) 3.0)))
double code(double x) {
double tmp;
if ((x <= -1.5) || !(x <= 1.5)) {
tmp = (x * x) * (-2.0 * x);
} 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) * ((-2.0d0) * x)
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) * (-2.0 * x);
} 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) * (-2.0 * x) else: tmp = (x * x) * 3.0 return tmp
function code(x) tmp = 0.0 if ((x <= -1.5) || !(x <= 1.5)) tmp = Float64(Float64(x * x) * Float64(-2.0 * x)); else tmp = Float64(Float64(x * 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) * (-2.0 * x); 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[(N[(x * x), $MachinePrecision] * N[(-2.0 * x), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * 3.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \lor \neg \left(x \leq 1.5\right):\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(-2 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot 3\\
\end{array}
\end{array}
if x < -1.5 or 1.5 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6498.2
Applied rewrites98.2%
if -1.5 < x < 1.5Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.6%
Final simplification98.4%
(FPCore (x) :precision binary64 (if (<= x -5.4e-124) (* -9.0 x) (* -3.0 (* x x))))
double code(double x) {
double tmp;
if (x <= -5.4e-124) {
tmp = -9.0 * x;
} else {
tmp = -3.0 * (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5.4d-124)) then
tmp = (-9.0d0) * x
else
tmp = (-3.0d0) * (x * x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -5.4e-124) {
tmp = -9.0 * x;
} else {
tmp = -3.0 * (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= -5.4e-124: tmp = -9.0 * x else: tmp = -3.0 * (x * x) return tmp
function code(x) tmp = 0.0 if (x <= -5.4e-124) tmp = Float64(-9.0 * x); else tmp = Float64(-3.0 * Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -5.4e-124) tmp = -9.0 * x; else tmp = -3.0 * (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -5.4e-124], N[(-9.0 * x), $MachinePrecision], N[(-3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-124}:\\
\;\;\;\;-9 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-3 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < -5.40000000000000035e-124Initial program 99.8%
Applied rewrites64.8%
Taylor expanded in x around -inf
Applied rewrites69.7%
Taylor expanded in x around 0
Applied rewrites6.7%
if -5.40000000000000035e-124 < x Initial program 99.9%
Applied rewrites70.2%
Taylor expanded in x around 0
lower-*.f64N/A
unpow2N/A
lower-*.f6455.5
Applied rewrites55.5%
(FPCore (x) :precision binary64 (* (* (fma -2.0 x 3.0) x) x))
double code(double x) {
return (fma(-2.0, x, 3.0) * x) * x;
}
function code(x) return Float64(Float64(fma(-2.0, x, 3.0) * x) * x) end
code[x_] := N[(N[(N[(-2.0 * x + 3.0), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(\mathsf{fma}\left(-2, x, 3\right) \cdot x\right) \cdot x
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
(FPCore (x) :precision binary64 (* -9.0 x))
double code(double x) {
return -9.0 * x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (-9.0d0) * x
end function
public static double code(double x) {
return -9.0 * x;
}
def code(x): return -9.0 * x
function code(x) return Float64(-9.0 * x) end
function tmp = code(x) tmp = -9.0 * x; end
code[x_] := N[(-9.0 * x), $MachinePrecision]
\begin{array}{l}
\\
-9 \cdot x
\end{array}
Initial program 99.8%
Applied rewrites68.4%
Taylor expanded in x around -inf
Applied rewrites50.1%
Taylor expanded in x around 0
Applied rewrites5.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 2024337
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:alt
(! :herbie-platform default (* x (* x (- 3 (* x 2)))))
(* (* x x) (- 3.0 (* x 2.0))))