
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 3.0d0 * ((((x * 3.0d0) * x) - (x * 4.0d0)) + 1.0d0)
end function
public static double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
def code(x): return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
function code(x) return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0)) end
function tmp = code(x) tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0); end
code[x_] := N[(3.0 * N[(N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))
double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 3.0d0 * ((((x * 3.0d0) * x) - (x * 4.0d0)) + 1.0d0)
end function
public static double code(double x) {
return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0);
}
def code(x): return 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0)
function code(x) return Float64(3.0 * Float64(Float64(Float64(Float64(x * 3.0) * x) - Float64(x * 4.0)) + 1.0)) end
function tmp = code(x) tmp = 3.0 * ((((x * 3.0) * x) - (x * 4.0)) + 1.0); end
code[x_] := N[(3.0 * N[(N[(N[(N[(x * 3.0), $MachinePrecision] * x), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 \cdot \left(\left(\left(x \cdot 3\right) \cdot x - x \cdot 4\right) + 1\right)
\end{array}
(FPCore (x) :precision binary64 (fma (* x x) 9.0 (fma -12.0 x 3.0)))
double code(double x) {
return fma((x * x), 9.0, fma(-12.0, x, 3.0));
}
function code(x) return fma(Float64(x * x), 9.0, fma(-12.0, x, 3.0)) end
code[x_] := N[(N[(x * x), $MachinePrecision] * 9.0 + N[(-12.0 * x + 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot x, 9, \mathsf{fma}\left(-12, x, 3\right)\right)
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-+.f64N/A
distribute-lft-inN/A
metadata-evalN/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
associate-+l+N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift-*.f64N/A
swap-sqrN/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-evalN/A
Applied rewrites99.9%
(FPCore (x) :precision binary64 (if (<= (- (* (* 3.0 x) x) (* 4.0 x)) 0.0001) (fma -12.0 x 3.0) (* (fma 9.0 x -12.0) x)))
double code(double x) {
double tmp;
if ((((3.0 * x) * x) - (4.0 * x)) <= 0.0001) {
tmp = fma(-12.0, x, 3.0);
} else {
tmp = fma(9.0, x, -12.0) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(Float64(3.0 * x) * x) - Float64(4.0 * x)) <= 0.0001) tmp = fma(-12.0, x, 3.0); else tmp = Float64(fma(9.0, x, -12.0) * x); end return tmp end
code[x_] := If[LessEqual[N[(N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision] - N[(4.0 * x), $MachinePrecision]), $MachinePrecision], 0.0001], N[(-12.0 * x + 3.0), $MachinePrecision], N[(N[(9.0 * x + -12.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(3 \cdot x\right) \cdot x - 4 \cdot x \leq 0.0001:\\
\;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(9, x, -12\right) \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 1.00000000000000005e-4Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6498.8
Applied rewrites98.8%
if 1.00000000000000005e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.7%
Taylor expanded in x around inf
unpow2N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
distribute-rgt-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-fma.f6498.4
Applied rewrites98.4%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= (- (* (* 3.0 x) x) (* 4.0 x)) 10.0) (fma -12.0 x 3.0) (* 9.0 (* x x))))
double code(double x) {
double tmp;
if ((((3.0 * x) * x) - (4.0 * x)) <= 10.0) {
tmp = fma(-12.0, x, 3.0);
} else {
tmp = 9.0 * (x * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(Float64(3.0 * x) * x) - Float64(4.0 * x)) <= 10.0) tmp = fma(-12.0, x, 3.0); else tmp = Float64(9.0 * Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[N[(N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision] - N[(4.0 * x), $MachinePrecision]), $MachinePrecision], 10.0], N[(-12.0 * x + 3.0), $MachinePrecision], N[(9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(3 \cdot x\right) \cdot x - 4 \cdot x \leq 10:\\
\;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\
\mathbf{else}:\\
\;\;\;\;9 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 10Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6498.2
Applied rewrites98.2%
if 10 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.2
Applied rewrites98.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (if (<= (- (* (* 3.0 x) x) (* 4.0 x)) 10.0) (fma -12.0 x 3.0) (* (* 9.0 x) x)))
double code(double x) {
double tmp;
if ((((3.0 * x) * x) - (4.0 * x)) <= 10.0) {
tmp = fma(-12.0, x, 3.0);
} else {
tmp = (9.0 * x) * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(Float64(3.0 * x) * x) - Float64(4.0 * x)) <= 10.0) tmp = fma(-12.0, x, 3.0); else tmp = Float64(Float64(9.0 * x) * x); end return tmp end
code[x_] := If[LessEqual[N[(N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision] - N[(4.0 * x), $MachinePrecision]), $MachinePrecision], 10.0], N[(-12.0 * x + 3.0), $MachinePrecision], N[(N[(9.0 * x), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(3 \cdot x\right) \cdot x - 4 \cdot x \leq 10:\\
\;\;\;\;\mathsf{fma}\left(-12, x, 3\right)\\
\mathbf{else}:\\
\;\;\;\;\left(9 \cdot x\right) \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 10Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6498.2
Applied rewrites98.2%
if 10 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.2
Applied rewrites98.2%
Applied rewrites98.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (fma (fma 9.0 x -12.0) x 3.0))
double code(double x) {
return fma(fma(9.0, x, -12.0), x, 3.0);
}
function code(x) return fma(fma(9.0, x, -12.0), x, 3.0) end
code[x_] := N[(N[(9.0 * x + -12.0), $MachinePrecision] * x + 3.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(9, x, -12\right), x, 3\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-out--N/A
associate-*r*N/A
unpow2N/A
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
metadata-evalN/A
distribute-lft-neg-inN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*r*N/A
unpow2N/A
distribute-rgt-out--N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
Applied rewrites99.9%
(FPCore (x) :precision binary64 (fma -12.0 x 3.0))
double code(double x) {
return fma(-12.0, x, 3.0);
}
function code(x) return fma(-12.0, x, 3.0) end
code[x_] := N[(-12.0 * x + 3.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-12, x, 3\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f6450.3
Applied rewrites50.3%
(FPCore (x) :precision binary64 3.0)
double code(double x) {
return 3.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 3.0d0
end function
public static double code(double x) {
return 3.0;
}
def code(x): return 3.0
function code(x) return 3.0 end
function tmp = code(x) tmp = 3.0; end
code[x_] := 3.0
\begin{array}{l}
\\
3
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites49.3%
(FPCore (x) :precision binary64 (+ 3.0 (- (* (* 9.0 x) x) (* 12.0 x))))
double code(double x) {
return 3.0 + (((9.0 * x) * x) - (12.0 * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 3.0d0 + (((9.0d0 * x) * x) - (12.0d0 * x))
end function
public static double code(double x) {
return 3.0 + (((9.0 * x) * x) - (12.0 * x));
}
def code(x): return 3.0 + (((9.0 * x) * x) - (12.0 * x))
function code(x) return Float64(3.0 + Float64(Float64(Float64(9.0 * x) * x) - Float64(12.0 * x))) end
function tmp = code(x) tmp = 3.0 + (((9.0 * x) * x) - (12.0 * x)); end
code[x_] := N[(3.0 + N[(N[(N[(9.0 * x), $MachinePrecision] * x), $MachinePrecision] - N[(12.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
3 + \left(\left(9 \cdot x\right) \cdot x - 12 \cdot x\right)
\end{array}
herbie shell --seed 2024249
(FPCore (x)
:name "Diagrams.Tangent:$catParam from diagrams-lib-1.3.0.3, D"
:precision binary64
:alt
(! :herbie-platform default (+ 3 (- (* (* 9 x) x) (* 12 x))))
(* 3.0 (+ (- (* (* x 3.0) x) (* x 4.0)) 1.0)))