Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, A

Percentage Accurate: 99.9% → 99.9%
Time: 5.6s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ 1 - x \cdot \left(0.253 + x \cdot 0.12\right) \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (* x (+ 0.253 (* x 0.12)))))
double code(double x) {
	return 1.0 - (x * (0.253 + (x * 0.12)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - (x * (0.253d0 + (x * 0.12d0)))
end function
public static double code(double x) {
	return 1.0 - (x * (0.253 + (x * 0.12)));
}
def code(x):
	return 1.0 - (x * (0.253 + (x * 0.12)))
function code(x)
	return Float64(1.0 - Float64(x * Float64(0.253 + Float64(x * 0.12))))
end
function tmp = code(x)
	tmp = 1.0 - (x * (0.253 + (x * 0.12)));
end
code[x_] := N[(1.0 - N[(x * N[(0.253 + N[(x * 0.12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - x \cdot \left(0.253 + x \cdot 0.12\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 - x \cdot \left(0.253 + x \cdot 0.12\right) \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (* x (+ 0.253 (* x 0.12)))))
double code(double x) {
	return 1.0 - (x * (0.253 + (x * 0.12)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - (x * (0.253d0 + (x * 0.12d0)))
end function
public static double code(double x) {
	return 1.0 - (x * (0.253 + (x * 0.12)));
}
def code(x):
	return 1.0 - (x * (0.253 + (x * 0.12)))
function code(x)
	return Float64(1.0 - Float64(x * Float64(0.253 + Float64(x * 0.12))))
end
function tmp = code(x)
	tmp = 1.0 - (x * (0.253 + (x * 0.12)));
end
code[x_] := N[(1.0 - N[(x * N[(0.253 + N[(x * 0.12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - x \cdot \left(0.253 + x \cdot 0.12\right)
\end{array}

Alternative 1: 99.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ 1 - x \cdot \mathsf{fma}\left(x, 0.12, 0.253\right) \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (* x (fma x 0.12 0.253))))
double code(double x) {
	return 1.0 - (x * fma(x, 0.12, 0.253));
}
function code(x)
	return Float64(1.0 - Float64(x * fma(x, 0.12, 0.253)))
end
code[x_] := N[(1.0 - N[(x * N[(x * 0.12 + 0.253), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - x \cdot \mathsf{fma}\left(x, 0.12, 0.253\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[1 - x \cdot \left(0.253 + x \cdot 0.12\right) \]
  2. Step-by-step derivation
    1. +-commutative99.8%

      \[\leadsto 1 - x \cdot \color{blue}{\left(x \cdot 0.12 + 0.253\right)} \]
    2. fma-def99.9%

      \[\leadsto 1 - x \cdot \color{blue}{\mathsf{fma}\left(x, 0.12, 0.253\right)} \]
  3. Simplified99.9%

    \[\leadsto \color{blue}{1 - x \cdot \mathsf{fma}\left(x, 0.12, 0.253\right)} \]
  4. Final simplification99.9%

    \[\leadsto 1 - x \cdot \mathsf{fma}\left(x, 0.12, 0.253\right) \]

Alternative 2: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 1 - x \cdot \left(0.253 + x \cdot 0.12\right) \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (* x (+ 0.253 (* x 0.12)))))
double code(double x) {
	return 1.0 - (x * (0.253 + (x * 0.12)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - (x * (0.253d0 + (x * 0.12d0)))
end function
public static double code(double x) {
	return 1.0 - (x * (0.253 + (x * 0.12)));
}
def code(x):
	return 1.0 - (x * (0.253 + (x * 0.12)))
function code(x)
	return Float64(1.0 - Float64(x * Float64(0.253 + Float64(x * 0.12))))
end
function tmp = code(x)
	tmp = 1.0 - (x * (0.253 + (x * 0.12)));
end
code[x_] := N[(1.0 - N[(x * N[(0.253 + N[(x * 0.12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - x \cdot \left(0.253 + x \cdot 0.12\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[1 - x \cdot \left(0.253 + x \cdot 0.12\right) \]
  2. Final simplification99.8%

    \[\leadsto 1 - x \cdot \left(0.253 + x \cdot 0.12\right) \]

Alternative 3: 97.7% accurate, 1.3× speedup?

\[\begin{array}{l} \\ 1 - 0.12 \cdot \left(x \cdot x\right) \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (* 0.12 (* x x))))
double code(double x) {
	return 1.0 - (0.12 * (x * x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - (0.12d0 * (x * x))
end function
public static double code(double x) {
	return 1.0 - (0.12 * (x * x));
}
def code(x):
	return 1.0 - (0.12 * (x * x))
function code(x)
	return Float64(1.0 - Float64(0.12 * Float64(x * x)))
end
function tmp = code(x)
	tmp = 1.0 - (0.12 * (x * x));
end
code[x_] := N[(1.0 - N[(0.12 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - 0.12 \cdot \left(x \cdot x\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[1 - x \cdot \left(0.253 + x \cdot 0.12\right) \]
  2. Taylor expanded in x around inf 97.5%

    \[\leadsto 1 - \color{blue}{0.12 \cdot {x}^{2}} \]
  3. Step-by-step derivation
    1. unpow297.5%

      \[\leadsto 1 - 0.12 \cdot \color{blue}{\left(x \cdot x\right)} \]
  4. Applied egg-rr97.5%

    \[\leadsto 1 - 0.12 \cdot \color{blue}{\left(x \cdot x\right)} \]
  5. Final simplification97.5%

    \[\leadsto 1 - 0.12 \cdot \left(x \cdot x\right) \]

Alternative 4: 97.8% accurate, 1.3× speedup?

\[\begin{array}{l} \\ 1 - x \cdot \left(x \cdot 0.12\right) \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (* x (* x 0.12))))
double code(double x) {
	return 1.0 - (x * (x * 0.12));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - (x * (x * 0.12d0))
end function
public static double code(double x) {
	return 1.0 - (x * (x * 0.12));
}
def code(x):
	return 1.0 - (x * (x * 0.12))
function code(x)
	return Float64(1.0 - Float64(x * Float64(x * 0.12)))
end
function tmp = code(x)
	tmp = 1.0 - (x * (x * 0.12));
end
code[x_] := N[(1.0 - N[(x * N[(x * 0.12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - x \cdot \left(x \cdot 0.12\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[1 - x \cdot \left(0.253 + x \cdot 0.12\right) \]
  2. Step-by-step derivation
    1. +-commutative99.8%

      \[\leadsto 1 - x \cdot \color{blue}{\left(x \cdot 0.12 + 0.253\right)} \]
    2. distribute-rgt-in99.8%

      \[\leadsto 1 - \color{blue}{\left(\left(x \cdot 0.12\right) \cdot x + 0.253 \cdot x\right)} \]
    3. fma-def99.8%

      \[\leadsto 1 - \color{blue}{\mathsf{fma}\left(x \cdot 0.12, x, 0.253 \cdot x\right)} \]
    4. *-commutative99.8%

      \[\leadsto 1 - \mathsf{fma}\left(x \cdot 0.12, x, \color{blue}{x \cdot 0.253}\right) \]
  3. Applied egg-rr99.8%

    \[\leadsto 1 - \color{blue}{\mathsf{fma}\left(x \cdot 0.12, x, x \cdot 0.253\right)} \]
  4. Applied egg-rr99.8%

    \[\leadsto 1 - \color{blue}{\left(\frac{0.064009}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}} - \frac{{\left(x \cdot 0.12\right)}^{2}}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}}\right)} \]
  5. Step-by-step derivation
    1. div-sub99.8%

      \[\leadsto 1 - \color{blue}{\frac{0.064009 - {\left(x \cdot 0.12\right)}^{2}}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}}} \]
    2. *-rgt-identity99.8%

      \[\leadsto 1 - \frac{\color{blue}{\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot 1}}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}} \]
    3. associate-*r/99.8%

      \[\leadsto 1 - \color{blue}{\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}}} \]
    4. associate-/r/99.7%

      \[\leadsto 1 - \left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x\right)} \]
    5. associate-*r*99.7%

      \[\leadsto 1 - \color{blue}{\left(\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot \frac{1}{\mathsf{fma}\left(x, -0.12, 0.253\right)}\right) \cdot x} \]
    6. associate-*r/99.8%

      \[\leadsto 1 - \color{blue}{\frac{\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot 1}{\mathsf{fma}\left(x, -0.12, 0.253\right)}} \cdot x \]
    7. *-rgt-identity99.8%

      \[\leadsto 1 - \frac{\color{blue}{0.064009 - {\left(x \cdot 0.12\right)}^{2}}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    8. unpow299.8%

      \[\leadsto 1 - \frac{0.064009 - \color{blue}{\left(x \cdot 0.12\right) \cdot \left(x \cdot 0.12\right)}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    9. swap-sqr99.7%

      \[\leadsto 1 - \frac{0.064009 - \color{blue}{\left(x \cdot x\right) \cdot \left(0.12 \cdot 0.12\right)}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    10. unpow299.7%

      \[\leadsto 1 - \frac{0.064009 - \color{blue}{{x}^{2}} \cdot \left(0.12 \cdot 0.12\right)}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    11. metadata-eval99.7%

      \[\leadsto 1 - \frac{0.064009 - {x}^{2} \cdot \color{blue}{0.0144}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
  6. Simplified99.7%

    \[\leadsto 1 - \color{blue}{\frac{0.064009 - {x}^{2} \cdot 0.0144}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x} \]
  7. Taylor expanded in x around inf 97.5%

    \[\leadsto 1 - \color{blue}{\left(0.12 \cdot x\right)} \cdot x \]
  8. Final simplification97.5%

    \[\leadsto 1 - x \cdot \left(x \cdot 0.12\right) \]

Alternative 5: 51.3% accurate, 1.8× speedup?

\[\begin{array}{l} \\ 1 - x \cdot 0.253 \end{array} \]
(FPCore (x) :precision binary64 (- 1.0 (* x 0.253)))
double code(double x) {
	return 1.0 - (x * 0.253);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 - (x * 0.253d0)
end function
public static double code(double x) {
	return 1.0 - (x * 0.253);
}
def code(x):
	return 1.0 - (x * 0.253)
function code(x)
	return Float64(1.0 - Float64(x * 0.253))
end
function tmp = code(x)
	tmp = 1.0 - (x * 0.253);
end
code[x_] := N[(1.0 - N[(x * 0.253), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
1 - x \cdot 0.253
\end{array}
Derivation
  1. Initial program 99.8%

    \[1 - x \cdot \left(0.253 + x \cdot 0.12\right) \]
  2. Taylor expanded in x around 0 50.6%

    \[\leadsto 1 - \color{blue}{0.253 \cdot x} \]
  3. Step-by-step derivation
    1. *-commutative50.6%

      \[\leadsto 1 - \color{blue}{x \cdot 0.253} \]
  4. Simplified50.6%

    \[\leadsto 1 - \color{blue}{x \cdot 0.253} \]
  5. Final simplification50.6%

    \[\leadsto 1 - x \cdot 0.253 \]

Alternative 6: 10.5% accurate, 9.0× speedup?

\[\begin{array}{l} \\ 1.5334083333333333 \end{array} \]
(FPCore (x) :precision binary64 1.5334083333333333)
double code(double x) {
	return 1.5334083333333333;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.5334083333333333d0
end function
public static double code(double x) {
	return 1.5334083333333333;
}
def code(x):
	return 1.5334083333333333
function code(x)
	return 1.5334083333333333
end
function tmp = code(x)
	tmp = 1.5334083333333333;
end
code[x_] := 1.5334083333333333
\begin{array}{l}

\\
1.5334083333333333
\end{array}
Derivation
  1. Initial program 99.8%

    \[1 - x \cdot \left(0.253 + x \cdot 0.12\right) \]
  2. Step-by-step derivation
    1. +-commutative99.8%

      \[\leadsto 1 - x \cdot \color{blue}{\left(x \cdot 0.12 + 0.253\right)} \]
    2. distribute-rgt-in99.8%

      \[\leadsto 1 - \color{blue}{\left(\left(x \cdot 0.12\right) \cdot x + 0.253 \cdot x\right)} \]
    3. fma-def99.8%

      \[\leadsto 1 - \color{blue}{\mathsf{fma}\left(x \cdot 0.12, x, 0.253 \cdot x\right)} \]
    4. *-commutative99.8%

      \[\leadsto 1 - \mathsf{fma}\left(x \cdot 0.12, x, \color{blue}{x \cdot 0.253}\right) \]
  3. Applied egg-rr99.8%

    \[\leadsto 1 - \color{blue}{\mathsf{fma}\left(x \cdot 0.12, x, x \cdot 0.253\right)} \]
  4. Applied egg-rr99.8%

    \[\leadsto 1 - \color{blue}{\left(\frac{0.064009}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}} - \frac{{\left(x \cdot 0.12\right)}^{2}}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}}\right)} \]
  5. Step-by-step derivation
    1. div-sub99.8%

      \[\leadsto 1 - \color{blue}{\frac{0.064009 - {\left(x \cdot 0.12\right)}^{2}}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}}} \]
    2. *-rgt-identity99.8%

      \[\leadsto 1 - \frac{\color{blue}{\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot 1}}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}} \]
    3. associate-*r/99.8%

      \[\leadsto 1 - \color{blue}{\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(x, -0.12, 0.253\right)}{x}}} \]
    4. associate-/r/99.7%

      \[\leadsto 1 - \left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x\right)} \]
    5. associate-*r*99.7%

      \[\leadsto 1 - \color{blue}{\left(\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot \frac{1}{\mathsf{fma}\left(x, -0.12, 0.253\right)}\right) \cdot x} \]
    6. associate-*r/99.8%

      \[\leadsto 1 - \color{blue}{\frac{\left(0.064009 - {\left(x \cdot 0.12\right)}^{2}\right) \cdot 1}{\mathsf{fma}\left(x, -0.12, 0.253\right)}} \cdot x \]
    7. *-rgt-identity99.8%

      \[\leadsto 1 - \frac{\color{blue}{0.064009 - {\left(x \cdot 0.12\right)}^{2}}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    8. unpow299.8%

      \[\leadsto 1 - \frac{0.064009 - \color{blue}{\left(x \cdot 0.12\right) \cdot \left(x \cdot 0.12\right)}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    9. swap-sqr99.7%

      \[\leadsto 1 - \frac{0.064009 - \color{blue}{\left(x \cdot x\right) \cdot \left(0.12 \cdot 0.12\right)}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    10. unpow299.7%

      \[\leadsto 1 - \frac{0.064009 - \color{blue}{{x}^{2}} \cdot \left(0.12 \cdot 0.12\right)}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
    11. metadata-eval99.7%

      \[\leadsto 1 - \frac{0.064009 - {x}^{2} \cdot \color{blue}{0.0144}}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x \]
  6. Simplified99.7%

    \[\leadsto 1 - \color{blue}{\frac{0.064009 - {x}^{2} \cdot 0.0144}{\mathsf{fma}\left(x, -0.12, 0.253\right)} \cdot x} \]
  7. Taylor expanded in x around inf 59.0%

    \[\leadsto 1 - \frac{0.064009 - {x}^{2} \cdot 0.0144}{\color{blue}{-0.12 \cdot x}} \cdot x \]
  8. Step-by-step derivation
    1. *-commutative59.0%

      \[\leadsto 1 - \frac{0.064009 - {x}^{2} \cdot 0.0144}{\color{blue}{x \cdot -0.12}} \cdot x \]
  9. Simplified59.0%

    \[\leadsto 1 - \frac{0.064009 - {x}^{2} \cdot 0.0144}{\color{blue}{x \cdot -0.12}} \cdot x \]
  10. Taylor expanded in x around 0 10.4%

    \[\leadsto \color{blue}{1.5334083333333333} \]
  11. Final simplification10.4%

    \[\leadsto 1.5334083333333333 \]

Reproduce

?
herbie shell --seed 2023320 
(FPCore (x)
  :name "Numeric.SpecFunctions:invIncompleteGamma from math-functions-0.1.5.2, A"
  :precision binary64
  (- 1.0 (* x (+ 0.253 (* x 0.12)))))