
(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 (* (* 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}
Initial program 99.9%
Final simplification99.9%
(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(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 * (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[(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):\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot -2\right)\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%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around inf 96.9%
unpow296.9%
*-commutative96.9%
associate-*r*96.9%
Simplified96.9%
if -1.5 < x < 1.5Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
Taylor expanded in x around 0 97.9%
unpow297.9%
Simplified97.9%
Final simplification97.4%
(FPCore (x) :precision binary64 (if (or (<= x -1.1) (not (<= x 1.5))) (* x (* x (* x -2.0))) (/ x (+ (/ 0.3333333333333333 x) 0.2222222222222222))))
double code(double x) {
double tmp;
if ((x <= -1.1) || !(x <= 1.5)) {
tmp = x * (x * (x * -2.0));
} else {
tmp = x / ((0.3333333333333333 / x) + 0.2222222222222222);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.1d0)) .or. (.not. (x <= 1.5d0))) then
tmp = x * (x * (x * (-2.0d0)))
else
tmp = x / ((0.3333333333333333d0 / x) + 0.2222222222222222d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.1) || !(x <= 1.5)) {
tmp = x * (x * (x * -2.0));
} else {
tmp = x / ((0.3333333333333333 / x) + 0.2222222222222222);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.1) or not (x <= 1.5): tmp = x * (x * (x * -2.0)) else: tmp = x / ((0.3333333333333333 / x) + 0.2222222222222222) return tmp
function code(x) tmp = 0.0 if ((x <= -1.1) || !(x <= 1.5)) tmp = Float64(x * Float64(x * Float64(x * -2.0))); else tmp = Float64(x / Float64(Float64(0.3333333333333333 / x) + 0.2222222222222222)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.1) || ~((x <= 1.5))) tmp = x * (x * (x * -2.0)); else tmp = x / ((0.3333333333333333 / x) + 0.2222222222222222); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.1], N[Not[LessEqual[x, 1.5]], $MachinePrecision]], N[(x * N[(x * N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(0.3333333333333333 / x), $MachinePrecision] + 0.2222222222222222), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \lor \neg \left(x \leq 1.5\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(x \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{0.3333333333333333}{x} + 0.2222222222222222}\\
\end{array}
\end{array}
if x < -1.1000000000000001 or 1.5 < x Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in x around inf 96.9%
unpow296.9%
*-commutative96.9%
associate-*r*96.9%
Simplified96.9%
if -1.1000000000000001 < x < 1.5Initial program 99.8%
associate-*l*99.7%
Simplified99.7%
sub-neg99.7%
distribute-lft-in99.8%
distribute-rgt-neg-in99.8%
metadata-eval99.8%
Applied egg-rr99.8%
flip-+99.7%
clear-num99.6%
distribute-lft-out--99.6%
swap-sqr99.5%
metadata-eval99.5%
associate-*r*99.5%
associate-*r*99.5%
swap-sqr99.5%
pow299.5%
pow299.5%
pow-prod-up99.5%
metadata-eval99.5%
metadata-eval99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 99.4%
associate-*r/99.4%
metadata-eval99.4%
Simplified99.4%
expm1-log1p-u99.4%
expm1-udef51.1%
un-div-inv51.1%
+-commutative51.1%
Applied egg-rr51.1%
expm1-def99.5%
expm1-log1p99.5%
Simplified99.5%
Final simplification98.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}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
Final simplification99.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.9%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 63.7%
unpow263.7%
Simplified63.7%
Final simplification63.7%
(FPCore (x) :precision binary64 6.75)
double code(double x) {
return 6.75;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 6.75d0
end function
public static double code(double x) {
return 6.75;
}
def code(x): return 6.75
function code(x) return 6.75 end
function tmp = code(x) tmp = 6.75; end
code[x_] := 6.75
\begin{array}{l}
\\
6.75
\end{array}
Initial program 99.9%
associate-*l*99.8%
Simplified99.8%
associate-*r*99.9%
*-commutative99.9%
flip3--74.5%
associate-*l/69.3%
metadata-eval69.3%
add-log-exp62.2%
exp-lft-sqr62.2%
log-prod62.2%
add-log-exp62.2%
add-log-exp69.3%
+-commutative69.3%
distribute-rgt-out69.3%
+-commutative69.3%
fma-def69.3%
Applied egg-rr69.3%
Taylor expanded in x around 0 50.5%
unpow250.5%
*-commutative50.5%
associate-*l*50.6%
Simplified50.6%
Taylor expanded in x around inf 3.3%
Final simplification3.3%
(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 2023230
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:herbie-target
(* x (* x (- 3.0 (* x 2.0))))
(* (* x x) (- 3.0 (* x 2.0))))