
(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 5 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 (fma x 3.0 (* x (* x (- 2.0))))))
double code(double x) {
return x * fma(x, 3.0, (x * (x * -2.0)));
}
function code(x) return Float64(x * fma(x, 3.0, Float64(x * Float64(x * Float64(-2.0))))) end
code[x_] := N[(x * N[(x * 3.0 + N[(x * N[(x * (-2.0)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, 3, x \cdot \left(x \cdot \left(-2\right)\right)\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
*-commutative99.8%
cancel-sign-sub-inv99.8%
metadata-eval99.8%
*-commutative99.8%
distribute-lft-in99.8%
fma-define99.8%
add-sqr-sqrt46.8%
sqrt-unprod75.8%
swap-sqr75.8%
metadata-eval75.8%
metadata-eval75.8%
swap-sqr75.8%
sqrt-unprod28.9%
add-sqr-sqrt53.0%
Applied egg-rr53.0%
add-sqr-sqrt28.9%
sqrt-unprod75.8%
swap-sqr75.8%
metadata-eval75.8%
metadata-eval75.8%
swap-sqr75.8%
sqrt-unprod46.8%
add-sqr-sqrt99.8%
metadata-eval99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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.8%
Simplified99.8%
Taylor expanded in x around inf 97.5%
*-commutative97.5%
Simplified97.5%
if -1.5 < x < 1.5Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 97.4%
*-commutative97.4%
Simplified97.4%
Final simplification97.5%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (/ (* x x) (- 0.3333333333333333))))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = (x * x) / -0.3333333333333333;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = x * (x * 3.0d0)
else
tmp = (x * x) / -0.3333333333333333d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = (x * x) / -0.3333333333333333;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = (x * x) / -0.3333333333333333 return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(Float64(x * x) / Float64(-0.3333333333333333)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = x * (x * 3.0); else tmp = (x * x) / -0.3333333333333333; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] / (-0.3333333333333333)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{-0.3333333333333333}\\
\end{array}
\end{array}
if x < 1.5Initial program 99.8%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around 0 85.0%
*-commutative85.0%
Simplified85.0%
if 1.5 < x Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around inf 100.0%
sub-neg100.0%
associate-*r/100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 0.4%
clear-num0.4%
un-div-inv0.4%
div-inv0.4%
metadata-eval0.4%
Applied egg-rr0.4%
associate-/r*0.4%
unpow30.4%
unpow20.4%
associate-/l*0.4%
*-inverses0.4%
*-rgt-identity0.4%
Simplified0.4%
add-sqr-sqrt0.4%
sqrt-unprod0.4%
sqr-neg0.4%
sqrt-unprod0.0%
add-sqr-sqrt50.3%
unpow250.3%
distribute-lft-neg-in50.3%
Applied egg-rr50.3%
Final simplification76.7%
(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.8%
Simplified99.8%
(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.8%
Simplified99.8%
Taylor expanded in x around 0 64.8%
*-commutative64.8%
Simplified64.8%
(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 2024138
(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))))