Falkner and Boettcher, Appendix A

?

Percentage Accurate: 89.0% → 98.5%
Time: 18.7s
Precision: binary64
Cost: 14660

?

\[\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \]
\[\begin{array}{l} t_0 := a \cdot {k}^{m}\\ t_1 := \frac{t_0}{\left(1 + k \cdot 10\right) + k \cdot k}\\ \mathbf{if}\;t_1 \leq 2 \cdot 10^{+184}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a k m)
 :precision binary64
 (/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))
(FPCore (a k m)
 :precision binary64
 (let* ((t_0 (* a (pow k m))) (t_1 (/ t_0 (+ (+ 1.0 (* k 10.0)) (* k k)))))
   (if (<= t_1 2e+184) t_1 t_0)))
double code(double a, double k, double m) {
	return (a * pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
double code(double a, double k, double m) {
	double t_0 = a * pow(k, m);
	double t_1 = t_0 / ((1.0 + (k * 10.0)) + (k * k));
	double tmp;
	if (t_1 <= 2e+184) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, k, m)
    real(8), intent (in) :: a
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    code = (a * (k ** m)) / ((1.0d0 + (10.0d0 * k)) + (k * k))
end function
real(8) function code(a, k, m)
    real(8), intent (in) :: a
    real(8), intent (in) :: k
    real(8), intent (in) :: m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = a * (k ** m)
    t_1 = t_0 / ((1.0d0 + (k * 10.0d0)) + (k * k))
    if (t_1 <= 2d+184) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double k, double m) {
	return (a * Math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k));
}
public static double code(double a, double k, double m) {
	double t_0 = a * Math.pow(k, m);
	double t_1 = t_0 / ((1.0 + (k * 10.0)) + (k * k));
	double tmp;
	if (t_1 <= 2e+184) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, k, m):
	return (a * math.pow(k, m)) / ((1.0 + (10.0 * k)) + (k * k))
def code(a, k, m):
	t_0 = a * math.pow(k, m)
	t_1 = t_0 / ((1.0 + (k * 10.0)) + (k * k))
	tmp = 0
	if t_1 <= 2e+184:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(a, k, m)
	return Float64(Float64(a * (k ^ m)) / Float64(Float64(1.0 + Float64(10.0 * k)) + Float64(k * k)))
end
function code(a, k, m)
	t_0 = Float64(a * (k ^ m))
	t_1 = Float64(t_0 / Float64(Float64(1.0 + Float64(k * 10.0)) + Float64(k * k)))
	tmp = 0.0
	if (t_1 <= 2e+184)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(a, k, m)
	tmp = (a * (k ^ m)) / ((1.0 + (10.0 * k)) + (k * k));
end
function tmp_2 = code(a, k, m)
	t_0 = a * (k ^ m);
	t_1 = t_0 / ((1.0 + (k * 10.0)) + (k * k));
	tmp = 0.0;
	if (t_1 <= 2e+184)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, k_, m_] := N[(N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(10.0 * k), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, k_, m_] := Block[{t$95$0 = N[(a * N[Power[k, m], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / N[(N[(1.0 + N[(k * 10.0), $MachinePrecision]), $MachinePrecision] + N[(k * k), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 2e+184], t$95$1, t$95$0]]]
\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}
\begin{array}{l}
t_0 := a \cdot {k}^{m}\\
t_1 := \frac{t_0}{\left(1 + k \cdot 10\right) + k \cdot k}\\
\mathbf{if}\;t_1 \leq 2 \cdot 10^{+184}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

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.

Herbie found 13 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 1 (*.f64 10 k)) (*.f64 k k))) < 2.00000000000000003e184

    1. Initial program 99.5%

      \[\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \]

    if 2.00000000000000003e184 < (/.f64 (*.f64 a (pow.f64 k m)) (+.f64 (+.f64 1 (*.f64 10 k)) (*.f64 k k)))

    1. Initial program 69.7%

      \[\frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \]
    2. Simplified69.7%

      \[\leadsto \color{blue}{a \cdot \frac{{k}^{m}}{\mathsf{fma}\left(k, k + 10, 1\right)}} \]
      Step-by-step derivation

      [Start]69.7%

      \[ \frac{a \cdot {k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k} \]

      associate-*r/ [<=]69.7%

      \[ \color{blue}{a \cdot \frac{{k}^{m}}{\left(1 + 10 \cdot k\right) + k \cdot k}} \]

      associate-+l+ [=>]69.7%

      \[ a \cdot \frac{{k}^{m}}{\color{blue}{1 + \left(10 \cdot k + k \cdot k\right)}} \]

      +-commutative [=>]69.7%

      \[ a \cdot \frac{{k}^{m}}{\color{blue}{\left(10 \cdot k + k \cdot k\right) + 1}} \]

      distribute-rgt-out [=>]69.7%

      \[ a \cdot \frac{{k}^{m}}{\color{blue}{k \cdot \left(10 + k\right)} + 1} \]

      fma-def [=>]69.7%

      \[ a \cdot \frac{{k}^{m}}{\color{blue}{\mathsf{fma}\left(k, 10 + k, 1\right)}} \]

      +-commutative [=>]69.7%

      \[ a \cdot \frac{{k}^{m}}{\mathsf{fma}\left(k, \color{blue}{k + 10}, 1\right)} \]
    3. Taylor expanded in k around 0 57.6%

      \[\leadsto a \cdot \color{blue}{e^{\log k \cdot m}} \]
    4. Simplified100.0%

      \[\leadsto a \cdot \color{blue}{{k}^{m}} \]
      Step-by-step derivation

      [Start]57.6%

      \[ a \cdot e^{\log k \cdot m} \]

      exp-to-pow [=>]100.0%

      \[ a \cdot \color{blue}{{k}^{m}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot {k}^{m}}{\left(1 + k \cdot 10\right) + k \cdot k} \leq 2 \cdot 10^{+184}:\\ \;\;\;\;\frac{a \cdot {k}^{m}}{\left(1 + k \cdot 10\right) + k \cdot k}\\ \mathbf{else}:\\ \;\;\;\;a \cdot {k}^{m}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy98.5%
Cost14660
\[\begin{array}{l} t_0 := a \cdot {k}^{m}\\ t_1 := \frac{t_0}{\left(1 + k \cdot 10\right) + k \cdot k}\\ \mathbf{if}\;t_1 \leq 2 \cdot 10^{+184}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Accuracy98.4%
Cost6921
\[\begin{array}{l} \mathbf{if}\;m \leq -9 \cdot 10^{-18} \lor \neg \left(m \leq 3 \cdot 10^{-6}\right):\\ \;\;\;\;a \cdot {k}^{m}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{1 + \left(k \cdot k + k \cdot 10\right)}\\ \end{array} \]
Alternative 3
Accuracy58.3%
Cost1745
\[\begin{array}{l} \mathbf{if}\;m \leq -0.095:\\ \;\;\;\;a \cdot \frac{1}{k \cdot k}\\ \mathbf{elif}\;m \leq 11000000000000:\\ \;\;\;\;\frac{a}{1 + \left(k \cdot k + k \cdot 10\right)}\\ \mathbf{elif}\;m \leq 4 \cdot 10^{+110} \lor \neg \left(m \leq 1.5 \cdot 10^{+215}\right):\\ \;\;\;\;\frac{a \cdot \left(a - \left(k \cdot k\right) \cdot \left(a \cdot 100\right)\right)}{a + a \cdot \left(k \cdot 10\right)}\\ \mathbf{else}:\\ \;\;\;\;a + a \cdot \left(k \cdot \left(k \cdot 100\right) + k \cdot -10\right)\\ \end{array} \]
Alternative 4
Accuracy60.9%
Cost1096
\[\begin{array}{l} \mathbf{if}\;m \leq -0.122:\\ \;\;\;\;a \cdot \frac{1}{k \cdot k}\\ \mathbf{elif}\;m \leq 2.2:\\ \;\;\;\;\frac{a}{1 + \left(k \cdot k + k \cdot 10\right)}\\ \mathbf{else}:\\ \;\;\;\;a + a \cdot \left(k \cdot \left(k \cdot 100\right) + k \cdot -10\right)\\ \end{array} \]
Alternative 5
Accuracy47.9%
Cost976
\[\begin{array}{l} t_0 := \frac{a}{1 + k \cdot 10}\\ \mathbf{if}\;m \leq -0.072:\\ \;\;\;\;a \cdot \frac{1}{k \cdot k}\\ \mathbf{elif}\;m \leq 9.2 \cdot 10^{-269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;m \leq 3.15 \cdot 10^{-122}:\\ \;\;\;\;\frac{1}{k} \cdot \frac{a}{k}\\ \mathbf{elif}\;m \leq 5900000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-10 \cdot \left(a \cdot k\right)\\ \end{array} \]
Alternative 6
Accuracy55.8%
Cost968
\[\begin{array}{l} \mathbf{if}\;m \leq -0.16:\\ \;\;\;\;a \cdot \frac{1}{k \cdot k}\\ \mathbf{elif}\;m \leq 5900000000:\\ \;\;\;\;\frac{a}{1 + \left(k \cdot k + k \cdot 10\right)}\\ \mathbf{else}:\\ \;\;\;\;-10 \cdot \left(a \cdot k\right)\\ \end{array} \]
Alternative 7
Accuracy55.8%
Cost840
\[\begin{array}{l} \mathbf{if}\;m \leq -0.075:\\ \;\;\;\;a \cdot \frac{1}{k \cdot k}\\ \mathbf{elif}\;m \leq 5900000000:\\ \;\;\;\;\frac{a}{1 + k \cdot \left(k + 10\right)}\\ \mathbf{else}:\\ \;\;\;\;-10 \cdot \left(a \cdot k\right)\\ \end{array} \]
Alternative 8
Accuracy46.4%
Cost716
\[\begin{array}{l} \mathbf{if}\;m \leq -0.08:\\ \;\;\;\;\frac{a}{k \cdot k}\\ \mathbf{elif}\;m \leq 9.2 \cdot 10^{-269}:\\ \;\;\;\;a\\ \mathbf{elif}\;m \leq 5900000000:\\ \;\;\;\;\frac{\frac{a}{k}}{k}\\ \mathbf{else}:\\ \;\;\;\;-10 \cdot \left(a \cdot k\right)\\ \end{array} \]
Alternative 9
Accuracy46.7%
Cost716
\[\begin{array}{l} \mathbf{if}\;m \leq -0.07:\\ \;\;\;\;a \cdot \frac{1}{k \cdot k}\\ \mathbf{elif}\;m \leq 9.2 \cdot 10^{-269}:\\ \;\;\;\;a\\ \mathbf{elif}\;m \leq 5900000000:\\ \;\;\;\;\frac{\frac{a}{k}}{k}\\ \mathbf{else}:\\ \;\;\;\;-10 \cdot \left(a \cdot k\right)\\ \end{array} \]
Alternative 10
Accuracy54.8%
Cost712
\[\begin{array}{l} \mathbf{if}\;m \leq -0.27:\\ \;\;\;\;a \cdot \frac{1}{k \cdot k}\\ \mathbf{elif}\;m \leq 5900000000:\\ \;\;\;\;\frac{a}{1 + k \cdot k}\\ \mathbf{else}:\\ \;\;\;\;-10 \cdot \left(a \cdot k\right)\\ \end{array} \]
Alternative 11
Accuracy40.3%
Cost585
\[\begin{array}{l} \mathbf{if}\;k \leq 6 \cdot 10^{-273} \lor \neg \left(k \leq 16\right):\\ \;\;\;\;\frac{a}{k \cdot k}\\ \mathbf{else}:\\ \;\;\;\;a\\ \end{array} \]
Alternative 12
Accuracy29.1%
Cost452
\[\begin{array}{l} \mathbf{if}\;m \leq 6200000000:\\ \;\;\;\;a\\ \mathbf{else}:\\ \;\;\;\;-10 \cdot \left(a \cdot k\right)\\ \end{array} \]
Alternative 13
Accuracy22.5%
Cost64
\[a \]

Reproduce?

herbie shell --seed 2023272 
(FPCore (a k m)
  :name "Falkner and Boettcher, Appendix A"
  :precision binary64
  (/ (* a (pow k m)) (+ (+ 1.0 (* 10.0 k)) (* k k))))