
(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(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) -20.0) (* (* -9.0 x) x) (* 6.0 x)))
double code(double x) {
double tmp;
if (((3.0 * (2.0 - (x * 3.0))) * x) <= -20.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) <= (-20.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) <= -20.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) <= -20.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) <= -20.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) <= -20.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], -20.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 -20:\\
\;\;\;\;\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) < -20Initial program 99.6%
Taylor expanded in x around inf
lower-*.f6497.0
Applied rewrites97.0%
if -20 < (*.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 rewrites97.9%
(FPCore (x) :precision binary64 (if (<= (* (* 3.0 (- 2.0 (* x 3.0))) x) -20.0) (* (* x x) -9.0) (* 6.0 x)))
double code(double x) {
double tmp;
if (((3.0 * (2.0 - (x * 3.0))) * x) <= -20.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) <= (-20.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) <= -20.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) <= -20.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) <= -20.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) <= -20.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], -20.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 -20:\\
\;\;\;\;\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) < -20Initial program 99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6496.9
Applied rewrites96.9%
if -20 < (*.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 rewrites97.9%
(FPCore (x) :precision binary64 (if (<= x 0.68) (* 6.0 x) (* -6.0 x)))
double code(double x) {
double tmp;
if (x <= 0.68) {
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.68d0) 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.68) {
tmp = 6.0 * x;
} else {
tmp = -6.0 * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = 6.0 * x else: tmp = -6.0 * x return tmp
function code(x) tmp = 0.0 if (x <= 0.68) 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.68) tmp = 6.0 * x; else tmp = -6.0 * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(6.0 * x), $MachinePrecision], N[(-6.0 * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;6 \cdot x\\
\mathbf{else}:\\
\;\;\;\;-6 \cdot x\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.7%
Taylor expanded in x around 0
Applied rewrites62.9%
if 0.680000000000000049 < x Initial program 99.7%
Applied rewrites0.0%
lift-*.f64N/A
lift-fma.f64N/A
distribute-rgt-inN/A
associate-*l*N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
sqrt-prodN/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
metadata-evalN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
Applied rewrites95.4%
Taylor expanded in x around 0
lower-*.f647.4
Applied rewrites7.4%
(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.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 rewrites49.8%
lift-*.f64N/A
lift-fma.f64N/A
distribute-rgt-inN/A
associate-*l*N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
sqrt-prodN/A
*-commutativeN/A
lift-*.f64N/A
rem-square-sqrtN/A
metadata-evalN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f6499.8
Applied rewrites99.8%
Applied rewrites56.8%
Taylor expanded in x around 0
lower-*.f644.0
Applied rewrites4.0%
(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 2024333
(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))