
(FPCore (x) :precision binary64 :pre TRUE (* (* 3.0 (- 2.0 (* x 3.0))) x))
double code(double x) {
return (3.0 * (2.0 - (x * 3.0))) * x;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (3.0d0 * (2.0d0 - (x * 3.0d0))) * x
end function
public static double code(double x) {
return (3.0 * (2.0 - (x * 3.0))) * x;
}
def code(x): return (3.0 * (2.0 - (x * 3.0))) * x
function code(x) return Float64(Float64(3.0 * Float64(2.0 - Float64(x * 3.0))) * x) end
function tmp = code(x) tmp = (3.0 * (2.0 - (x * 3.0))) * x; end
code[x_] := N[(N[(3.0 * N[(2.0 - N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = ((3) * ((2) - (x * (3)))) * x END code
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 :pre TRUE (* (* 3.0 (- 2.0 (* x 3.0))) x))
double code(double x) {
return (3.0 * (2.0 - (x * 3.0))) * x;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (3.0d0 * (2.0d0 - (x * 3.0d0))) * x
end function
public static double code(double x) {
return (3.0 * (2.0 - (x * 3.0))) * x;
}
def code(x): return (3.0 * (2.0 - (x * 3.0))) * x
function code(x) return Float64(Float64(3.0 * Float64(2.0 - Float64(x * 3.0))) * x) end
function tmp = code(x) tmp = (3.0 * (2.0 - (x * 3.0))) * x; end
code[x_] := N[(N[(3.0 * N[(2.0 - N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = ((3) * ((2) - (x * (3)))) * x END code
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
(FPCore (x) :precision binary64 :pre TRUE (fma 6.0 x (* (* x x) -9.0)))
double code(double x) {
return fma(6.0, x, ((x * x) * -9.0));
}
function code(x) return fma(6.0, x, Float64(Float64(x * x) * -9.0)) end
code[x_] := N[(6.0 * x + N[(N[(x * x), $MachinePrecision] * -9.0), $MachinePrecision]), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = ((6) * x) + ((x * x) * (-9)) END code
\mathsf{fma}\left(6, x, \left(x \cdot x\right) \cdot -9\right)
Initial program 99.7%
Applied rewrites99.8%
(FPCore (x) :precision binary64 :pre TRUE (* (fma -9.0 x 6.0) x))
double code(double x) {
return fma(-9.0, x, 6.0) * x;
}
function code(x) return Float64(fma(-9.0, x, 6.0) * x) end
code[x_] := N[(N[(-9.0 * x + 6.0), $MachinePrecision] * x), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (((-9) * x) + (6)) * x END code
\mathsf{fma}\left(-9, x, 6\right) \cdot x
Initial program 99.7%
Applied rewrites99.8%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (* (* 3.0 (- 2.0 (* x 3.0))) x) -2000.0) (* (* -9.0 x) x) (* 6.0 x)))
double code(double x) {
double tmp;
if (((3.0 * (2.0 - (x * 3.0))) * x) <= -2000.0) {
tmp = (-9.0 * x) * x;
} else {
tmp = 6.0 * x;
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if (((3.0d0 * (2.0d0 - (x * 3.0d0))) * x) <= (-2000.0d0)) then
tmp = ((-9.0d0) * x) * x
else
tmp = 6.0d0 * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((3.0 * (2.0 - (x * 3.0))) * x) <= -2000.0) {
tmp = (-9.0 * x) * x;
} else {
tmp = 6.0 * x;
}
return tmp;
}
def code(x): tmp = 0 if ((3.0 * (2.0 - (x * 3.0))) * x) <= -2000.0: tmp = (-9.0 * x) * x else: tmp = 6.0 * x return tmp
function code(x) tmp = 0.0 if (Float64(Float64(3.0 * Float64(2.0 - Float64(x * 3.0))) * x) <= -2000.0) tmp = Float64(Float64(-9.0 * x) * x); else tmp = Float64(6.0 * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((3.0 * (2.0 - (x * 3.0))) * x) <= -2000.0) tmp = (-9.0 * x) * x; else tmp = 6.0 * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(3.0 * N[(2.0 - N[(x * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], -2000.0], N[(N[(-9.0 * x), $MachinePrecision] * x), $MachinePrecision], N[(6.0 * x), $MachinePrecision]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp = IF ((((3) * ((2) - (x * (3)))) * x) <= (-2000)) THEN (((-9) * x) * x) ELSE ((6) * x) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \leq -2000:\\
\;\;\;\;\left(-9 \cdot x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;6 \cdot x\\
\end{array}
if (*.f64 (*.f64 #s(literal 3 binary64) (-.f64 #s(literal 2 binary64) (*.f64 x #s(literal 3 binary64)))) x) < -2e3Initial program 99.7%
Taylor expanded in x around inf
Applied rewrites51.6%
if -2e3 < (*.f64 (*.f64 #s(literal 3 binary64) (-.f64 #s(literal 2 binary64) (*.f64 x #s(literal 3 binary64)))) x) Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites51.1%
(FPCore (x) :precision binary64 :pre TRUE (* 6.0 x))
double code(double x) {
return 6.0 * x;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 6.0d0 * x
end function
public static double code(double x) {
return 6.0 * x;
}
def code(x): return 6.0 * x
function code(x) return Float64(6.0 * x) end
function tmp = code(x) tmp = 6.0 * x; end
code[x_] := N[(6.0 * x), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (6) * x END code
6 \cdot x
Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites51.1%
herbie shell --seed 2026092
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E"
:precision binary64
(* (* 3.0 (- 2.0 (* x 3.0))) x))