
(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 (fma x 9.0 -12.0) x 3.0))
double code(double x) {
return fma(fma(x, 9.0, -12.0), x, 3.0);
}
function code(x) return fma(fma(x, 9.0, -12.0), x, 3.0) end
code[x_] := N[(N[(x * 9.0 + -12.0), $MachinePrecision] * x + 3.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, 9, -12\right), x, 3\right)
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
distribute-rgt-inN/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
distribute-lft-out--N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
lift-fma.f64N/A
*-commutativeN/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-*.f64N/A
*-commutativeN/A
lift-fma.f64N/A
lift-*.f64N/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
metadata-eval99.9
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (if (<= (- (* x (* x 3.0)) (* x 4.0)) 0.0005) (fma x -12.0 3.0) (* x (fma 9.0 x -12.0))))
double code(double x) {
double tmp;
if (((x * (x * 3.0)) - (x * 4.0)) <= 0.0005) {
tmp = fma(x, -12.0, 3.0);
} else {
tmp = x * fma(9.0, x, -12.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x * Float64(x * 3.0)) - Float64(x * 4.0)) <= 0.0005) tmp = fma(x, -12.0, 3.0); else tmp = Float64(x * fma(9.0, x, -12.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision], 0.0005], N[(x * -12.0 + 3.0), $MachinePrecision], N[(x * N[(9.0 * x + -12.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(x \cdot 3\right) - x \cdot 4 \leq 0.0005:\\
\;\;\;\;\mathsf{fma}\left(x, -12, 3\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(9, x, -12\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
metadata-eval98.7
Simplified98.7%
if 5.0000000000000001e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
distribute-rgt-inN/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
distribute-lft-out--N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval99.8
Applied egg-rr99.8%
Taylor expanded in x around inf
unpow2N/A
associate-*l*N/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.f6499.0
Simplified99.0%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= (- (* x (* x 3.0)) (* x 4.0)) 0.0005) (fma x -12.0 3.0) (* x (* x 9.0))))
double code(double x) {
double tmp;
if (((x * (x * 3.0)) - (x * 4.0)) <= 0.0005) {
tmp = fma(x, -12.0, 3.0);
} else {
tmp = x * (x * 9.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x * Float64(x * 3.0)) - Float64(x * 4.0)) <= 0.0005) tmp = fma(x, -12.0, 3.0); else tmp = Float64(x * Float64(x * 9.0)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision], 0.0005], N[(x * -12.0 + 3.0), $MachinePrecision], N[(x * N[(x * 9.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(x \cdot 3\right) - x \cdot 4 \leq 0.0005:\\
\;\;\;\;\mathsf{fma}\left(x, -12, 3\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot 9\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
metadata-eval98.7
Simplified98.7%
if 5.0000000000000001e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
distribute-rgt-inN/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
distribute-lft-out--N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval99.8
Applied egg-rr99.8%
Taylor expanded in x around inf
lower-*.f64N/A
unpow2N/A
lower-*.f6496.6
Simplified96.6%
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6496.7
Applied egg-rr96.7%
Final simplification97.7%
(FPCore (x) :precision binary64 (if (<= (- (* x (* x 3.0)) (* x 4.0)) 0.0005) (fma x -12.0 3.0) (* 9.0 (* x x))))
double code(double x) {
double tmp;
if (((x * (x * 3.0)) - (x * 4.0)) <= 0.0005) {
tmp = fma(x, -12.0, 3.0);
} else {
tmp = 9.0 * (x * x);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x * Float64(x * 3.0)) - Float64(x * 4.0)) <= 0.0005) tmp = fma(x, -12.0, 3.0); else tmp = Float64(9.0 * Float64(x * x)); end return tmp end
code[x_] := If[LessEqual[N[(N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision], 0.0005], N[(x * -12.0 + 3.0), $MachinePrecision], N[(9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(x \cdot 3\right) - x \cdot 4 \leq 0.0005:\\
\;\;\;\;\mathsf{fma}\left(x, -12, 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))) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
metadata-eval98.7
Simplified98.7%
if 5.0000000000000001e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.6%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
distribute-rgt-inN/A
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
distribute-lft-out--N/A
associate-*l*N/A
metadata-evalN/A
lower-fma.f64N/A
lower-*.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval99.8
Applied egg-rr99.8%
Taylor expanded in x around inf
lower-*.f64N/A
unpow2N/A
lower-*.f6496.6
Simplified96.6%
Final simplification97.7%
(FPCore (x) :precision binary64 (if (<= (- (* x (* x 3.0)) (* x 4.0)) 0.0005) (fma x -12.0 3.0) (* x x)))
double code(double x) {
double tmp;
if (((x * (x * 3.0)) - (x * 4.0)) <= 0.0005) {
tmp = fma(x, -12.0, 3.0);
} else {
tmp = x * x;
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(x * Float64(x * 3.0)) - Float64(x * 4.0)) <= 0.0005) tmp = fma(x, -12.0, 3.0); else tmp = Float64(x * x); end return tmp end
code[x_] := If[LessEqual[N[(N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision], 0.0005], N[(x * -12.0 + 3.0), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(x \cdot 3\right) - x \cdot 4 \leq 0.0005:\\
\;\;\;\;\mathsf{fma}\left(x, -12, 3\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
metadata-eval98.7
Simplified98.7%
if 5.0000000000000001e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.6%
Taylor expanded in x around inf
unpow3N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6430.5
Simplified30.5%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6462.7
Simplified62.7%
Final simplification81.0%
(FPCore (x) :precision binary64 (if (<= (- (* x (* x 3.0)) (* x 4.0)) 0.0005) 3.0 (* x x)))
double code(double x) {
double tmp;
if (((x * (x * 3.0)) - (x * 4.0)) <= 0.0005) {
tmp = 3.0;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((x * (x * 3.0d0)) - (x * 4.0d0)) <= 0.0005d0) then
tmp = 3.0d0
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((x * (x * 3.0)) - (x * 4.0)) <= 0.0005) {
tmp = 3.0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x): tmp = 0 if ((x * (x * 3.0)) - (x * 4.0)) <= 0.0005: tmp = 3.0 else: tmp = x * x return tmp
function code(x) tmp = 0.0 if (Float64(Float64(x * Float64(x * 3.0)) - Float64(x * 4.0)) <= 0.0005) tmp = 3.0; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((x * (x * 3.0)) - (x * 4.0)) <= 0.0005) tmp = 3.0; else tmp = x * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision] - N[(x * 4.0), $MachinePrecision]), $MachinePrecision], 0.0005], 3.0, N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot \left(x \cdot 3\right) - x \cdot 4 \leq 0.0005:\\
\;\;\;\;3\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) < 5.0000000000000001e-4Initial program 100.0%
Taylor expanded in x around 0
Simplified97.1%
if 5.0000000000000001e-4 < (-.f64 (*.f64 (*.f64 x #s(literal 3 binary64)) x) (*.f64 x #s(literal 4 binary64))) Initial program 99.6%
Taylor expanded in x around inf
unpow3N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6430.5
Simplified30.5%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6462.7
Simplified62.7%
Final simplification80.2%
(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
Simplified51.4%
(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 2024214
(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)))