
(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 (* 3.0 x) x (* x (* (* x x) -2.0))))
double code(double x) {
return fma((3.0 * x), x, (x * ((x * x) * -2.0)));
}
function code(x) return fma(Float64(3.0 * x), x, Float64(x * Float64(Float64(x * x) * -2.0))) end
code[x_] := N[(N[(3.0 * x), $MachinePrecision] * x + N[(x * N[(N[(x * x), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(3 \cdot x, x, x \cdot \left(\left(x \cdot x\right) \cdot -2\right)\right)
\end{array}
Initial program 99.8%
sub-negN/A
distribute-rgt-inN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
distribute-rgt-neg-inN/A
associate-*l*N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (let* ((t_0 (* (* x x) (- 3.0 (* x 2.0)))) (t_1 (* (* x x) (* x -2.0)))) (if (<= t_0 -100000.0) t_1 (if (<= t_0 20.0) (* x (* 3.0 x)) t_1))))
double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double t_1 = (x * x) * (x * -2.0);
double tmp;
if (t_0 <= -100000.0) {
tmp = t_1;
} else if (t_0 <= 20.0) {
tmp = x * (3.0 * x);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (x * x) * (3.0d0 - (x * 2.0d0))
t_1 = (x * x) * (x * (-2.0d0))
if (t_0 <= (-100000.0d0)) then
tmp = t_1
else if (t_0 <= 20.0d0) then
tmp = x * (3.0d0 * x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double t_1 = (x * x) * (x * -2.0);
double tmp;
if (t_0 <= -100000.0) {
tmp = t_1;
} else if (t_0 <= 20.0) {
tmp = x * (3.0 * x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x): t_0 = (x * x) * (3.0 - (x * 2.0)) t_1 = (x * x) * (x * -2.0) tmp = 0 if t_0 <= -100000.0: tmp = t_1 elif t_0 <= 20.0: tmp = x * (3.0 * x) else: tmp = t_1 return tmp
function code(x) t_0 = Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) t_1 = Float64(Float64(x * x) * Float64(x * -2.0)) tmp = 0.0 if (t_0 <= -100000.0) tmp = t_1; elseif (t_0 <= 20.0) tmp = Float64(x * Float64(3.0 * x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x) t_0 = (x * x) * (3.0 - (x * 2.0)); t_1 = (x * x) * (x * -2.0); tmp = 0.0; if (t_0 <= -100000.0) tmp = t_1; elseif (t_0 <= 20.0) tmp = x * (3.0 * x); else tmp = t_1; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] * N[(x * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -100000.0], t$95$1, If[LessEqual[t$95$0, 20.0], N[(x * N[(3.0 * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)\\
t_1 := \left(x \cdot x\right) \cdot \left(x \cdot -2\right)\\
\mathbf{if}\;t\_0 \leq -100000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 20:\\
\;\;\;\;x \cdot \left(3 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -1e5 or 20 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f6497.9
Simplified97.9%
if -1e5 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 20Initial program 99.8%
Taylor expanded in x around 0
metadata-evalN/A
lft-mult-inverseN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-*r*N/A
remove-double-negN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
Simplified97.0%
Final simplification97.5%
(FPCore (x) :precision binary64 (if (<= (* (* x x) (- 3.0 (* x 2.0))) -100000.0) (* (* x x) -3.0) (* x (* 3.0 x))))
double code(double x) {
double tmp;
if (((x * x) * (3.0 - (x * 2.0))) <= -100000.0) {
tmp = (x * x) * -3.0;
} else {
tmp = x * (3.0 * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x * x) * (3.0d0 - (x * 2.0d0))) <= (-100000.0d0)) then
tmp = (x * x) * (-3.0d0)
else
tmp = x * (3.0d0 * x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x * x) * (3.0 - (x * 2.0))) <= -100000.0) {
tmp = (x * x) * -3.0;
} else {
tmp = x * (3.0 * x);
}
return tmp;
}
def code(x): tmp = 0 if ((x * x) * (3.0 - (x * 2.0))) <= -100000.0: tmp = (x * x) * -3.0 else: tmp = x * (3.0 * x) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) <= -100000.0) tmp = Float64(Float64(x * x) * -3.0); else tmp = Float64(x * Float64(3.0 * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x * x) * (3.0 - (x * 2.0))) <= -100000.0) tmp = (x * x) * -3.0; else tmp = x * (3.0 * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -100000.0], N[(N[(x * x), $MachinePrecision] * -3.0), $MachinePrecision], N[(x * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right) \leq -100000:\\
\;\;\;\;\left(x \cdot x\right) \cdot -3\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(3 \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -1e5Initial program 100.0%
Taylor expanded in x around 0
Simplified0.3%
metadata-evalN/A
div-invN/A
/-lowering-/.f64N/A
*-lowering-*.f640.3
Applied egg-rr0.3%
frac-2negN/A
distribute-lft-neg-inN/A
associate-/l*N/A
Applied egg-rr48.8%
if -1e5 < (*.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
metadata-evalN/A
lft-mult-inverseN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-*r*N/A
remove-double-negN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
Simplified86.0%
Final simplification76.6%
(FPCore (x) :precision binary64 (* x (fma (* x x) -2.0 (* 3.0 x))))
double code(double x) {
return x * fma((x * x), -2.0, (3.0 * x));
}
function code(x) return Float64(x * fma(Float64(x * x), -2.0, Float64(3.0 * x))) end
code[x_] := N[(x * N[(N[(x * x), $MachinePrecision] * -2.0 + N[(3.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x \cdot x, -2, 3 \cdot x\right)
\end{array}
Initial program 99.8%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
distribute-lft-inN/A
associate-*r*N/A
metadata-evalN/A
div-invN/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
div-invN/A
metadata-evalN/A
*-lowering-*.f6499.9
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (* x (* x (fma x -2.0 3.0))))
double code(double x) {
return x * (x * fma(x, -2.0, 3.0));
}
function code(x) return Float64(x * Float64(x * fma(x, -2.0, 3.0))) end
code[x_] := N[(x * N[(x * N[(x * -2.0 + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \mathsf{fma}\left(x, -2, 3\right)\right)
\end{array}
Initial program 99.8%
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (* x (* 3.0 x)))
double code(double x) {
return x * (3.0 * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (3.0d0 * x)
end function
public static double code(double x) {
return x * (3.0 * x);
}
def code(x): return x * (3.0 * x)
function code(x) return Float64(x * Float64(3.0 * x)) end
function tmp = code(x) tmp = x * (3.0 * x); end
code[x_] := N[(x * N[(3.0 * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(3 \cdot x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
metadata-evalN/A
lft-mult-inverseN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-lowering-*.f64N/A
unpow2N/A
associate-*r*N/A
remove-double-negN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
Simplified64.2%
Final simplification64.2%
(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 2024199
(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))))