
(FPCore (x) :precision binary64 (* (* 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)
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]
\begin{array}{l}
\\
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (* 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)
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]
\begin{array}{l}
\\
\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x
\end{array}
(FPCore (x) :precision binary64 (fma x 6.0 (* (* 9.0 (- x)) x)))
double code(double x) {
return fma(x, 6.0, ((9.0 * -x) * x));
}
function code(x) return fma(x, 6.0, Float64(Float64(9.0 * Float64(-x)) * x)) end
code[x_] := N[(x * 6.0 + N[(N[(9.0 * (-x)), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 6, \left(9 \cdot \left(-x\right)\right) \cdot x\right)
\end{array}
Initial program 99.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-rgt-inN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
metadata-evalN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites99.8%
(FPCore (x) :precision binary64 (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)
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]]
\begin{array}{l}
\\
\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}
\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
lower-*.f6497.0
Applied rewrites97.0%
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 rewrites97.1%
(FPCore (x) :precision binary64 (if (<= (* (* 3.0 (- 2.0 (* x 3.0))) x) -2000.0) (* (* x x) -9.0) (* 6.0 x)))
double code(double x) {
double tmp;
if (((3.0 * (2.0 - (x * 3.0))) * x) <= -2000.0) {
tmp = (x * x) * -9.0;
} else {
tmp = 6.0 * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((3.0d0 * (2.0d0 - (x * 3.0d0))) * x) <= (-2000.0d0)) then
tmp = (x * x) * (-9.0d0)
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 = (x * x) * -9.0;
} else {
tmp = 6.0 * x;
}
return tmp;
}
def code(x): tmp = 0 if ((3.0 * (2.0 - (x * 3.0))) * x) <= -2000.0: tmp = (x * x) * -9.0 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(x * x) * -9.0); 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 = (x * x) * -9.0; 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[(x * x), $MachinePrecision] * -9.0), $MachinePrecision], N[(6.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(3 \cdot \left(2 - x \cdot 3\right)\right) \cdot x \leq -2000:\\
\;\;\;\;\left(x \cdot x\right) \cdot -9\\
\mathbf{else}:\\
\;\;\;\;6 \cdot x\\
\end{array}
\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
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6497.0
Applied rewrites97.0%
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 rewrites97.1%
(FPCore (x) :precision binary64 (fma x 6.0 (* (* x x) -9.0)))
double code(double x) {
return fma(x, 6.0, ((x * x) * -9.0));
}
function code(x) return fma(x, 6.0, Float64(Float64(x * x) * -9.0)) end
code[x_] := N[(x * 6.0 + N[(N[(x * x), $MachinePrecision] * -9.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 6, \left(x \cdot x\right) \cdot -9\right)
\end{array}
Initial program 99.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-rgt-inN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
metadata-evalN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites99.8%
lift-*.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
metadata-evalN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x) :precision binary64 (* (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]
\begin{array}{l}
\\
\mathsf{fma}\left(-9, x, 6\right) \cdot x
\end{array}
Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6499.7
Applied rewrites99.7%
(FPCore (x) :precision binary64 (* 6.0 x))
double code(double x) {
return 6.0 * x;
}
real(8) function code(x)
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]
\begin{array}{l}
\\
6 \cdot x
\end{array}
Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites53.9%
(FPCore (x) :precision binary64 (* -6.0 x))
double code(double x) {
return -6.0 * x;
}
real(8) function code(x)
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]
\begin{array}{l}
\\
-6 \cdot x
\end{array}
Initial program 99.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
distribute-rgt-inN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
metadata-evalN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites99.8%
Applied rewrites47.0%
Taylor expanded in x around 0
metadata-evalN/A
distribute-lft-neg-inN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lft-mult-inverseN/A
metadata-eval3.6
Applied rewrites3.6%
(FPCore (x) :precision binary64 (- (* 6.0 x) (* 9.0 (* x x))))
double code(double x) {
return (6.0 * x) - (9.0 * (x * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (6.0d0 * x) - (9.0d0 * (x * x))
end function
public static double code(double x) {
return (6.0 * x) - (9.0 * (x * x));
}
def code(x): return (6.0 * x) - (9.0 * (x * x))
function code(x) return Float64(Float64(6.0 * x) - Float64(9.0 * Float64(x * x))) end
function tmp = code(x) tmp = (6.0 * x) - (9.0 * (x * x)); end
code[x_] := N[(N[(6.0 * x), $MachinePrecision] - N[(9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
6 \cdot x - 9 \cdot \left(x \cdot x\right)
\end{array}
herbie shell --seed 2024332
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, E"
:precision binary64
:alt
(! :herbie-platform default (- (* 6 x) (* 9 (* x x))))
(* (* 3.0 (- 2.0 (* x 3.0))) x))