
(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 6 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(-9.0 * Float64(x * x))) end
code[x_] := N[(x * 6.0 + N[(-9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 6, -9 \cdot \left(x \cdot x\right)\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
sub-negN/A
distribute-lft-inN/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
associate-*l*N/A
lower-fma.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
swap-sqrN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x) :precision binary64 (if (<= (* (* 3.0 (- 2.0 (* x 3.0))) x) -10000000000000.0) (* (* -9.0 x) x) (* 6.0 x)))
double code(double x) {
double tmp;
if (((3.0 * (2.0 - (x * 3.0))) * x) <= -10000000000000.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) <= (-10000000000000.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) <= -10000000000000.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) <= -10000000000000.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) <= -10000000000000.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) <= -10000000000000.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], -10000000000000.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 -10000000000000:\\
\;\;\;\;\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) < -1e13Initial program 99.6%
Taylor expanded in x around inf
lower-*.f6499.2
Applied rewrites99.2%
if -1e13 < (*.f64 (*.f64 #s(literal 3 binary64) (-.f64 #s(literal 2 binary64) (*.f64 x #s(literal 3 binary64)))) x) Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.6%
(FPCore (x) :precision binary64 (if (<= (* (* 3.0 (- 2.0 (* x 3.0))) x) -10000000000000.0) (* (* x x) -9.0) (* 6.0 x)))
double code(double x) {
double tmp;
if (((3.0 * (2.0 - (x * 3.0))) * x) <= -10000000000000.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) <= (-10000000000000.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) <= -10000000000000.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) <= -10000000000000.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) <= -10000000000000.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) <= -10000000000000.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], -10000000000000.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 -10000000000000:\\
\;\;\;\;\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) < -1e13Initial program 99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.1
Applied rewrites99.1%
if -1e13 < (*.f64 (*.f64 #s(literal 3 binary64) (-.f64 #s(literal 2 binary64) (*.f64 x #s(literal 3 binary64)))) x) Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites98.6%
(FPCore (x) :precision binary64 (if (<= x 0.66) (* 6.0 x) (* -6.0 x)))
double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = 6.0 * x;
} else {
tmp = -6.0 * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.66d0) then
tmp = 6.0d0 * x
else
tmp = (-6.0d0) * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.66) {
tmp = 6.0 * x;
} else {
tmp = -6.0 * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.66: tmp = 6.0 * x else: tmp = -6.0 * x return tmp
function code(x) tmp = 0.0 if (x <= 0.66) tmp = Float64(6.0 * x); else tmp = Float64(-6.0 * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.66) tmp = 6.0 * x; else tmp = -6.0 * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.66], N[(6.0 * x), $MachinePrecision], N[(-6.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.66:\\
\;\;\;\;6 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-6 \cdot x\\
\end{array}
\end{array}
if x < 0.660000000000000031Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites70.4%
if 0.660000000000000031 < x Initial program 99.6%
Applied rewrites98.7%
Taylor expanded in x around 0
lower-*.f648.2
Applied rewrites8.2%
(FPCore (x) :precision binary64 (* (fma x -9.0 6.0) x))
double code(double x) {
return fma(x, -9.0, 6.0) * x;
}
function code(x) return Float64(fma(x, -9.0, 6.0) * x) end
code[x_] := N[(N[(x * -9.0 + 6.0), $MachinePrecision] * x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, -9, 6\right) \cdot x
\end{array}
Initial program 99.7%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
+-commutativeN/A
distribute-rgt-inN/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
associate-*l*N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-evalN/A
metadata-evalN/A
metadata-eval99.8
Applied rewrites99.8%
(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%
Applied rewrites48.6%
Taylor expanded in x around 0
lower-*.f644.3
Applied rewrites4.3%
(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 2024322
(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))