
(FPCore (x) :precision binary64 :pre TRUE (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x * x) * ((3) - (x * (2))) END code
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 :pre TRUE (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x * x) * ((3) - (x * (2))) END code
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
(FPCore (x) :precision binary64 :pre TRUE (* x (* (fma -2.0 x 3.0) x)))
double code(double x) {
return x * (fma(-2.0, x, 3.0) * x);
}
function code(x) return Float64(x * Float64(fma(-2.0, x, 3.0) * x)) end
code[x_] := N[(x * N[(N[(-2.0 * x + 3.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = x * ((((-2) * x) + (3)) * x) END code
x \cdot \left(\mathsf{fma}\left(-2, x, 3\right) \cdot x\right)
Initial program 99.8%
Applied rewrites99.8%
(FPCore (x)
:precision binary64
:pre TRUE
(let* ((t_0 (* (* x x) (- 3.0 (* x 2.0))))
(t_1 (* (* x x) (* -2.0 x))))
(if (<= t_0 -400000000.0)
t_1
(if (<= t_0 4e-10) (/ x (/ 1.0 (* 3.0 x))) t_1))))double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double t_1 = (x * x) * (-2.0 * x);
double tmp;
if (t_0 <= -400000000.0) {
tmp = t_1;
} else if (t_0 <= 4e-10) {
tmp = x / (1.0 / (3.0 * x));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
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) * ((-2.0d0) * x)
if (t_0 <= (-400000000.0d0)) then
tmp = t_1
else if (t_0 <= 4d-10) then
tmp = x / (1.0d0 / (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) * (-2.0 * x);
double tmp;
if (t_0 <= -400000000.0) {
tmp = t_1;
} else if (t_0 <= 4e-10) {
tmp = x / (1.0 / (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) * (-2.0 * x) tmp = 0 if t_0 <= -400000000.0: tmp = t_1 elif t_0 <= 4e-10: tmp = x / (1.0 / (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(-2.0 * x)) tmp = 0.0 if (t_0 <= -400000000.0) tmp = t_1; elseif (t_0 <= 4e-10) tmp = Float64(x / Float64(1.0 / 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) * (-2.0 * x); tmp = 0.0; if (t_0 <= -400000000.0) tmp = t_1; elseif (t_0 <= 4e-10) tmp = x / (1.0 / (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[(-2.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -400000000.0], t$95$1, If[LessEqual[t$95$0, 4e-10], N[(x / N[(1.0 / N[(3.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET t_0 = ((x * x) * ((3) - (x * (2)))) IN LET t_1 = ((x * x) * ((-2) * x)) IN LET tmp_1 = IF (t_0 <= (400000000000000014572878926199096631666218826239855843596160411834716796875e-84)) THEN (x / ((1) / ((3) * x))) ELSE t_1 ENDIF IN LET tmp = IF (t_0 <= (-4e8)) THEN t_1 ELSE tmp_1 ENDIF IN tmp END code
\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(-2 \cdot x\right)\\
\mathbf{if}\;t\_0 \leq -400000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;\frac{x}{\frac{1}{3 \cdot x}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -4e8 or 4.0000000000000001e-10 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites75.2%
if -4e8 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 4.0000000000000001e-10Initial program 99.8%
Applied rewrites99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites62.0%
(FPCore (x)
:precision binary64
:pre TRUE
(let* ((t_0 (* (* x x) (- 3.0 (* x 2.0))))
(t_1 (* (* x x) (* -2.0 x))))
(if (<= t_0 -400000000.0)
t_1
(if (<= t_0 4e-10) (* (* x x) 3.0) t_1))))double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double t_1 = (x * x) * (-2.0 * x);
double tmp;
if (t_0 <= -400000000.0) {
tmp = t_1;
} else if (t_0 <= 4e-10) {
tmp = (x * x) * 3.0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
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) * ((-2.0d0) * x)
if (t_0 <= (-400000000.0d0)) then
tmp = t_1
else if (t_0 <= 4d-10) then
tmp = (x * x) * 3.0d0
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) * (-2.0 * x);
double tmp;
if (t_0 <= -400000000.0) {
tmp = t_1;
} else if (t_0 <= 4e-10) {
tmp = (x * x) * 3.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x): t_0 = (x * x) * (3.0 - (x * 2.0)) t_1 = (x * x) * (-2.0 * x) tmp = 0 if t_0 <= -400000000.0: tmp = t_1 elif t_0 <= 4e-10: tmp = (x * x) * 3.0 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(-2.0 * x)) tmp = 0.0 if (t_0 <= -400000000.0) tmp = t_1; elseif (t_0 <= 4e-10) tmp = Float64(Float64(x * x) * 3.0); 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) * (-2.0 * x); tmp = 0.0; if (t_0 <= -400000000.0) tmp = t_1; elseif (t_0 <= 4e-10) tmp = (x * x) * 3.0; 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[(-2.0 * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -400000000.0], t$95$1, If[LessEqual[t$95$0, 4e-10], N[(N[(x * x), $MachinePrecision] * 3.0), $MachinePrecision], t$95$1]]]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET t_0 = ((x * x) * ((3) - (x * (2)))) IN LET t_1 = ((x * x) * ((-2) * x)) IN LET tmp_1 = IF (t_0 <= (400000000000000014572878926199096631666218826239855843596160411834716796875e-84)) THEN ((x * x) * (3)) ELSE t_1 ENDIF IN LET tmp = IF (t_0 <= (-4e8)) THEN t_1 ELSE tmp_1 ENDIF IN tmp END code
\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(-2 \cdot x\right)\\
\mathbf{if}\;t\_0 \leq -400000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-10}:\\
\;\;\;\;\left(x \cdot x\right) \cdot 3\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -4e8 or 4.0000000000000001e-10 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) Initial program 99.8%
Taylor expanded in x around inf
Applied rewrites75.2%
if -4e8 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 4.0000000000000001e-10Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites62.0%
(FPCore (x) :precision binary64 :pre TRUE (* (* x x) 3.0))
double code(double x) {
return (x * x) * 3.0;
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x * x) * (3) END code
\left(x \cdot x\right) \cdot 3
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites62.0%
(FPCore (x) :precision binary64 :pre TRUE (* x (* 3.0 x)))
double code(double x) {
return x * (3.0 * x);
}
real(8) function code(x)
use fmin_fmax_functions
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]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = x * ((3) * x) END code
x \cdot \left(3 \cdot x\right)
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites62.0%
Applied rewrites62.0%
herbie shell --seed 2026092
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
(* (* x x) (- 3.0 (* x 2.0))))