
(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 (* (* (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
(let* ((t_0 (* (* x x) (- 3.0 (* x 2.0)))))
(if (or (<= t_0 -40000.0) (not (<= t_0 0.005)))
(* (* x x) (* -2.0 x))
(* (* 3.0 x) x))))
double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double tmp;
if ((t_0 <= -40000.0) || !(t_0 <= 0.005)) {
tmp = (x * x) * (-2.0 * x);
} else {
tmp = (3.0 * x) * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (x * x) * (3.0d0 - (x * 2.0d0))
if ((t_0 <= (-40000.0d0)) .or. (.not. (t_0 <= 0.005d0))) then
tmp = (x * x) * ((-2.0d0) * x)
else
tmp = (3.0d0 * x) * x
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double tmp;
if ((t_0 <= -40000.0) || !(t_0 <= 0.005)) {
tmp = (x * x) * (-2.0 * x);
} else {
tmp = (3.0 * x) * x;
}
return tmp;
}
def code(x): t_0 = (x * x) * (3.0 - (x * 2.0)) tmp = 0 if (t_0 <= -40000.0) or not (t_0 <= 0.005): tmp = (x * x) * (-2.0 * x) else: tmp = (3.0 * x) * x return tmp
function code(x) t_0 = Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) tmp = 0.0 if ((t_0 <= -40000.0) || !(t_0 <= 0.005)) tmp = Float64(Float64(x * x) * Float64(-2.0 * x)); else tmp = Float64(Float64(3.0 * x) * x); end return tmp end
function tmp_2 = code(x) t_0 = (x * x) * (3.0 - (x * 2.0)); tmp = 0.0; if ((t_0 <= -40000.0) || ~((t_0 <= 0.005))) tmp = (x * x) * (-2.0 * x); else tmp = (3.0 * x) * x; 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]}, If[Or[LessEqual[t$95$0, -40000.0], N[Not[LessEqual[t$95$0, 0.005]], $MachinePrecision]], N[(N[(x * x), $MachinePrecision] * N[(-2.0 * x), $MachinePrecision]), $MachinePrecision], N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)\\
\mathbf{if}\;t\_0 \leq -40000 \lor \neg \left(t\_0 \leq 0.005\right):\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(-2 \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(3 \cdot x\right) \cdot x\\
\end{array}
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -4e4 or 0.0050000000000000001 < (*.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
lower-*.f6498.9
Applied rewrites98.9%
if -4e4 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 0.0050000000000000001Initial program 99.6%
Taylor expanded in x around 0
Applied rewrites97.6%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6497.7
Applied rewrites97.7%
Final simplification98.3%
(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(Float64(3.0 * x) * x) end
function tmp = code(x) tmp = (3.0 * x) * x; end
code[x_] := N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\left(3 \cdot x\right) \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites63.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6463.8
Applied rewrites63.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(Float64(x * x) * 3.0) end
function tmp = code(x) tmp = (x * x) * 3.0; end
code[x_] := N[(N[(x * x), $MachinePrecision] * 3.0), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot 3
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites63.7%
(FPCore (x) :precision binary64 (* (* -9.0 x) -0.5))
double code(double x) {
return (-9.0 * x) * -0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-9.0d0) * x) * (-0.5d0)
end function
public static double code(double x) {
return (-9.0 * x) * -0.5;
}
def code(x): return (-9.0 * x) * -0.5
function code(x) return Float64(Float64(-9.0 * x) * -0.5) end
function tmp = code(x) tmp = (-9.0 * x) * -0.5; end
code[x_] := N[(N[(-9.0 * x), $MachinePrecision] * -0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(-9 \cdot x\right) \cdot -0.5
\end{array}
Initial program 99.8%
Applied rewrites69.4%
Taylor expanded in x around 0
lower-*.f6448.6
Applied rewrites48.6%
Taylor expanded in x around inf
Applied rewrites2.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 2024320
(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))))