
(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 (* (- (- 3.0 x) x) (* x x)))
double code(double x) {
return ((3.0 - x) - x) * (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((3.0d0 - x) - x) * (x * x)
end function
public static double code(double x) {
return ((3.0 - x) - x) * (x * x);
}
def code(x): return ((3.0 - x) - x) * (x * x)
function code(x) return Float64(Float64(Float64(3.0 - x) - x) * Float64(x * x)) end
function tmp = code(x) tmp = ((3.0 - x) - x) * (x * x); end
code[x_] := N[(N[(N[(3.0 - x), $MachinePrecision] - x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left(3 - x\right) - x\right) \cdot \left(x \cdot x\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
count-2-revN/A
associate--r+N/A
lower--.f64N/A
lower--.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (* (* -2.0 x) (* x x)))) (if (<= x -1.5) t_0 (if (<= x 1.5) (* (* 3.0 x) x) t_0))))
double code(double x) {
double t_0 = (-2.0 * x) * (x * x);
double tmp;
if (x <= -1.5) {
tmp = t_0;
} else if (x <= 1.5) {
tmp = (3.0 * x) * x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = ((-2.0d0) * x) * (x * x)
if (x <= (-1.5d0)) then
tmp = t_0
else if (x <= 1.5d0) then
tmp = (3.0d0 * x) * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (-2.0 * x) * (x * x);
double tmp;
if (x <= -1.5) {
tmp = t_0;
} else if (x <= 1.5) {
tmp = (3.0 * x) * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x): t_0 = (-2.0 * x) * (x * x) tmp = 0 if x <= -1.5: tmp = t_0 elif x <= 1.5: tmp = (3.0 * x) * x else: tmp = t_0 return tmp
function code(x) t_0 = Float64(Float64(-2.0 * x) * Float64(x * x)) tmp = 0.0 if (x <= -1.5) tmp = t_0; elseif (x <= 1.5) tmp = Float64(Float64(3.0 * x) * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x) t_0 = (-2.0 * x) * (x * x); tmp = 0.0; if (x <= -1.5) tmp = t_0; elseif (x <= 1.5) tmp = (3.0 * x) * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(-2.0 * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.5], t$95$0, If[LessEqual[x, 1.5], N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-2 \cdot x\right) \cdot \left(x \cdot x\right)\\
\mathbf{if}\;x \leq -1.5:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;\left(3 \cdot x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.5 or 1.5 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f6496.8
Applied rewrites96.8%
if -1.5 < x < 1.5Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites98.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Final simplification97.7%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* (* 3.0 x) x) (* (* -3.0 x) x)))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = (3.0 * x) * x;
} else {
tmp = (-3.0 * x) * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = (3.0d0 * x) * x
else
tmp = ((-3.0d0) * x) * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = (3.0 * x) * x;
} else {
tmp = (-3.0 * x) * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = (3.0 * x) * x else: tmp = (-3.0 * x) * x return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(Float64(3.0 * x) * x); else tmp = Float64(Float64(-3.0 * x) * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = (3.0 * x) * x; else tmp = (-3.0 * x) * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision], N[(N[(-3.0 * x), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;\left(3 \cdot x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\left(-3 \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < 1.5Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites84.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6485.0
Applied rewrites85.0%
if 1.5 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites0.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f640.2
Applied rewrites0.2%
lift-*.f64N/A
unpow1N/A
remove-double-negN/A
lift-neg.f64N/A
neg-mul-1N/A
unpow-prod-downN/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-neg-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
neg-mul-1N/A
distribute-rgt-neg-outN/A
lift-*.f64N/A
lower-neg.f6466.3
Applied rewrites66.3%
Taylor expanded in x around 0
lower-*.f6466.3
Applied rewrites66.3%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* 3.0 (* x x)) (* (* -3.0 x) x)))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = 3.0 * (x * x);
} else {
tmp = (-3.0 * x) * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = 3.0d0 * (x * x)
else
tmp = ((-3.0d0) * x) * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = 3.0 * (x * x);
} else {
tmp = (-3.0 * x) * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = 3.0 * (x * x) else: tmp = (-3.0 * x) * x return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(3.0 * Float64(x * x)); else tmp = Float64(Float64(-3.0 * x) * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = 3.0 * (x * x); else tmp = (-3.0 * x) * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(3.0 * N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(-3.0 * x), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;3 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-3 \cdot x\right) \cdot x\\
\end{array}
\end{array}
if x < 1.5Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites84.9%
if 1.5 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites0.2%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f640.2
Applied rewrites0.2%
lift-*.f64N/A
unpow1N/A
remove-double-negN/A
lift-neg.f64N/A
neg-mul-1N/A
unpow-prod-downN/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-neg-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
neg-mul-1N/A
distribute-rgt-neg-outN/A
lift-*.f64N/A
lower-neg.f6466.3
Applied rewrites66.3%
Taylor expanded in x around 0
lower-*.f6466.3
Applied rewrites66.3%
Final simplification80.4%
(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%
Taylor expanded in x around 0
Applied rewrites64.1%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6464.1
Applied rewrites64.1%
lift-*.f64N/A
unpow1N/A
remove-double-negN/A
lift-neg.f64N/A
neg-mul-1N/A
unpow-prod-downN/A
metadata-evalN/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-neg-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
neg-mul-1N/A
distribute-rgt-neg-outN/A
lift-*.f64N/A
lower-neg.f6442.1
Applied rewrites42.1%
Taylor expanded in x around 0
lower-*.f64N/A
unpow2N/A
lower-*.f6442.1
Applied rewrites42.1%
(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 2024298
(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))))