Average Error: 58.0 → 1.3
Time: 17.2s
Precision: binary64
Cost: 105216
\[\left(\left(-1000 \leq a \land a \leq 1000\right) \land \left(-100 \leq n \land n \leq 100\right)\right) \land \left(-1000 \leq b \land b \leq 1000\right)\]
\[{a}^{n} - {b}^{n} \]
\[{n}^{2} \cdot \left(0.5 \cdot {\log a}^{2} + {\log b}^{2} \cdot -0.5\right) + \left(n \cdot \log \left(\frac{a}{b}\right) + \left({n}^{3} \cdot \left(0.16666666666666666 \cdot {\log a}^{3} - 0.16666666666666666 \cdot {\log b}^{3}\right) + {n}^{4} \cdot \left(0.041666666666666664 \cdot {\log a}^{4} + {\log b}^{4} \cdot -0.041666666666666664\right)\right)\right) \]
(FPCore (a n b) :precision binary64 (- (pow a n) (pow b n)))
(FPCore (a n b)
 :precision binary64
 (+
  (* (pow n 2.0) (+ (* 0.5 (pow (log a) 2.0)) (* (pow (log b) 2.0) -0.5)))
  (+
   (* n (log (/ a b)))
   (+
    (*
     (pow n 3.0)
     (-
      (* 0.16666666666666666 (pow (log a) 3.0))
      (* 0.16666666666666666 (pow (log b) 3.0))))
    (*
     (pow n 4.0)
     (+
      (* 0.041666666666666664 (pow (log a) 4.0))
      (* (pow (log b) 4.0) -0.041666666666666664)))))))
double code(double a, double n, double b) {
	return pow(a, n) - pow(b, n);
}
double code(double a, double n, double b) {
	return (pow(n, 2.0) * ((0.5 * pow(log(a), 2.0)) + (pow(log(b), 2.0) * -0.5))) + ((n * log((a / b))) + ((pow(n, 3.0) * ((0.16666666666666666 * pow(log(a), 3.0)) - (0.16666666666666666 * pow(log(b), 3.0)))) + (pow(n, 4.0) * ((0.041666666666666664 * pow(log(a), 4.0)) + (pow(log(b), 4.0) * -0.041666666666666664)))));
}
real(8) function code(a, n, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: n
    real(8), intent (in) :: b
    code = (a ** n) - (b ** n)
end function
real(8) function code(a, n, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: n
    real(8), intent (in) :: b
    code = ((n ** 2.0d0) * ((0.5d0 * (log(a) ** 2.0d0)) + ((log(b) ** 2.0d0) * (-0.5d0)))) + ((n * log((a / b))) + (((n ** 3.0d0) * ((0.16666666666666666d0 * (log(a) ** 3.0d0)) - (0.16666666666666666d0 * (log(b) ** 3.0d0)))) + ((n ** 4.0d0) * ((0.041666666666666664d0 * (log(a) ** 4.0d0)) + ((log(b) ** 4.0d0) * (-0.041666666666666664d0))))))
end function
public static double code(double a, double n, double b) {
	return Math.pow(a, n) - Math.pow(b, n);
}
public static double code(double a, double n, double b) {
	return (Math.pow(n, 2.0) * ((0.5 * Math.pow(Math.log(a), 2.0)) + (Math.pow(Math.log(b), 2.0) * -0.5))) + ((n * Math.log((a / b))) + ((Math.pow(n, 3.0) * ((0.16666666666666666 * Math.pow(Math.log(a), 3.0)) - (0.16666666666666666 * Math.pow(Math.log(b), 3.0)))) + (Math.pow(n, 4.0) * ((0.041666666666666664 * Math.pow(Math.log(a), 4.0)) + (Math.pow(Math.log(b), 4.0) * -0.041666666666666664)))));
}
def code(a, n, b):
	return math.pow(a, n) - math.pow(b, n)
def code(a, n, b):
	return (math.pow(n, 2.0) * ((0.5 * math.pow(math.log(a), 2.0)) + (math.pow(math.log(b), 2.0) * -0.5))) + ((n * math.log((a / b))) + ((math.pow(n, 3.0) * ((0.16666666666666666 * math.pow(math.log(a), 3.0)) - (0.16666666666666666 * math.pow(math.log(b), 3.0)))) + (math.pow(n, 4.0) * ((0.041666666666666664 * math.pow(math.log(a), 4.0)) + (math.pow(math.log(b), 4.0) * -0.041666666666666664)))))
function code(a, n, b)
	return Float64((a ^ n) - (b ^ n))
end
function code(a, n, b)
	return Float64(Float64((n ^ 2.0) * Float64(Float64(0.5 * (log(a) ^ 2.0)) + Float64((log(b) ^ 2.0) * -0.5))) + Float64(Float64(n * log(Float64(a / b))) + Float64(Float64((n ^ 3.0) * Float64(Float64(0.16666666666666666 * (log(a) ^ 3.0)) - Float64(0.16666666666666666 * (log(b) ^ 3.0)))) + Float64((n ^ 4.0) * Float64(Float64(0.041666666666666664 * (log(a) ^ 4.0)) + Float64((log(b) ^ 4.0) * -0.041666666666666664))))))
end
function tmp = code(a, n, b)
	tmp = (a ^ n) - (b ^ n);
end
function tmp = code(a, n, b)
	tmp = ((n ^ 2.0) * ((0.5 * (log(a) ^ 2.0)) + ((log(b) ^ 2.0) * -0.5))) + ((n * log((a / b))) + (((n ^ 3.0) * ((0.16666666666666666 * (log(a) ^ 3.0)) - (0.16666666666666666 * (log(b) ^ 3.0)))) + ((n ^ 4.0) * ((0.041666666666666664 * (log(a) ^ 4.0)) + ((log(b) ^ 4.0) * -0.041666666666666664)))));
end
code[a_, n_, b_] := N[(N[Power[a, n], $MachinePrecision] - N[Power[b, n], $MachinePrecision]), $MachinePrecision]
code[a_, n_, b_] := N[(N[(N[Power[n, 2.0], $MachinePrecision] * N[(N[(0.5 * N[Power[N[Log[a], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[Log[b], $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(n * N[Log[N[(a / b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[n, 3.0], $MachinePrecision] * N[(N[(0.16666666666666666 * N[Power[N[Log[a], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(0.16666666666666666 * N[Power[N[Log[b], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[n, 4.0], $MachinePrecision] * N[(N[(0.041666666666666664 * N[Power[N[Log[a], $MachinePrecision], 4.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[Log[b], $MachinePrecision], 4.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
{a}^{n} - {b}^{n}
{n}^{2} \cdot \left(0.5 \cdot {\log a}^{2} + {\log b}^{2} \cdot -0.5\right) + \left(n \cdot \log \left(\frac{a}{b}\right) + \left({n}^{3} \cdot \left(0.16666666666666666 \cdot {\log a}^{3} - 0.16666666666666666 \cdot {\log b}^{3}\right) + {n}^{4} \cdot \left(0.041666666666666664 \cdot {\log a}^{4} + {\log b}^{4} \cdot -0.041666666666666664\right)\right)\right)

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 58.0

    \[{a}^{n} - {b}^{n} \]
  2. Taylor expanded in n around 0 1.9

    \[\leadsto \color{blue}{{n}^{2} \cdot \left(0.5 \cdot {\log a}^{2} - 0.5 \cdot {\log b}^{2}\right) + \left(n \cdot \left(\log a - \log b\right) + \left({n}^{3} \cdot \left(0.16666666666666666 \cdot {\log a}^{3} - 0.16666666666666666 \cdot {\log b}^{3}\right) + {n}^{4} \cdot \left(0.041666666666666664 \cdot {\log a}^{4} - 0.041666666666666664 \cdot {\log b}^{4}\right)\right)\right)} \]
  3. Applied egg-rr1.3

    \[\leadsto {n}^{2} \cdot \left(0.5 \cdot {\log a}^{2} - 0.5 \cdot {\log b}^{2}\right) + \left(n \cdot \color{blue}{\log \left(\frac{a}{b}\right)} + \left({n}^{3} \cdot \left(0.16666666666666666 \cdot {\log a}^{3} - 0.16666666666666666 \cdot {\log b}^{3}\right) + {n}^{4} \cdot \left(0.041666666666666664 \cdot {\log a}^{4} - 0.041666666666666664 \cdot {\log b}^{4}\right)\right)\right) \]
  4. Final simplification1.3

    \[\leadsto {n}^{2} \cdot \left(0.5 \cdot {\log a}^{2} + {\log b}^{2} \cdot -0.5\right) + \left(n \cdot \log \left(\frac{a}{b}\right) + \left({n}^{3} \cdot \left(0.16666666666666666 \cdot {\log a}^{3} - 0.16666666666666666 \cdot {\log b}^{3}\right) + {n}^{4} \cdot \left(0.041666666666666664 \cdot {\log a}^{4} + {\log b}^{4} \cdot -0.041666666666666664\right)\right)\right) \]

Alternatives

Alternative 1
Error1.9
Cost85504
\[{n}^{3} \cdot \left(0.16666666666666666 \cdot \left({\log a}^{3} - {\log b}^{3}\right) + n \cdot \left(0.041666666666666664 \cdot \left({\log a}^{4} - {\log b}^{4}\right)\right)\right) + \left(\log a - \log b\right) \cdot \left(n + \left(n \cdot \left(n \cdot 0.5\right)\right) \cdot \left(\log a + \log b\right)\right) \]
Alternative 2
Error2.0
Cost65536
\[\mathsf{fma}\left({n}^{3}, 0.16666666666666666 \cdot \left({\log a}^{3} - {\log b}^{3}\right), \left(\log a - \log b\right) \cdot \left(n + \left(n \cdot \left(n \cdot 0.5\right)\right) \cdot \left(\log a + \log b\right)\right)\right) \]
Alternative 3
Error2.2
Cost6720
\[n \cdot \log \left(\frac{a}{b}\right) \]

Error

Reproduce

herbie shell --seed 1 
(FPCore (a n b)
  :name "pow(a,n)-pow(b,n)"
  :precision binary64
  :pre (and (and (and (<= -1000.0 a) (<= a 1000.0)) (and (<= -100.0 n) (<= n 100.0))) (and (<= -1000.0 b) (<= b 1000.0)))
  (- (pow a n) (pow b n)))