Eccentricity of an ellipse

Percentage Accurate: 75.7% → 100.0%
Time: 8.4s
Alternatives: 4
Speedup: 211.0×

Specification

?
\[\left(0 \leq b \land b \leq a\right) \land a \leq 1\]
\[\begin{array}{l} \\ \sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \end{array} \]
(FPCore (a b)
 :precision binary64
 (sqrt (fabs (/ (- (* a a) (* b b)) (* a a)))))
double code(double a, double b) {
	return sqrt(fabs((((a * a) - (b * b)) / (a * a))));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = sqrt(abs((((a * a) - (b * b)) / (a * a))))
end function
public static double code(double a, double b) {
	return Math.sqrt(Math.abs((((a * a) - (b * b)) / (a * a))));
}
def code(a, b):
	return math.sqrt(math.fabs((((a * a) - (b * b)) / (a * a))))
function code(a, b)
	return sqrt(abs(Float64(Float64(Float64(a * a) - Float64(b * b)) / Float64(a * a))))
end
function tmp = code(a, b)
	tmp = sqrt(abs((((a * a) - (b * b)) / (a * a))));
end
code[a_, b_] := N[Sqrt[N[Abs[N[(N[(N[(a * a), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\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 4 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: 75.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \end{array} \]
(FPCore (a b)
 :precision binary64
 (sqrt (fabs (/ (- (* a a) (* b b)) (* a a)))))
double code(double a, double b) {
	return sqrt(fabs((((a * a) - (b * b)) / (a * a))));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = sqrt(abs((((a * a) - (b * b)) / (a * a))))
end function
public static double code(double a, double b) {
	return Math.sqrt(Math.abs((((a * a) - (b * b)) / (a * a))));
}
def code(a, b):
	return math.sqrt(math.fabs((((a * a) - (b * b)) / (a * a))))
function code(a, b)
	return sqrt(abs(Float64(Float64(Float64(a * a) - Float64(b * b)) / Float64(a * a))))
end
function tmp = code(a, b)
	tmp = sqrt(abs((((a * a) - (b * b)) / (a * a))));
end
code[a_, b_] := N[Sqrt[N[Abs[N[(N[(N[(a * a), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|}
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\left|1 - \frac{\frac{b}{\frac{a}{b}}}{a}\right|} \end{array} \]
(FPCore (a b) :precision binary64 (sqrt (fabs (- 1.0 (/ (/ b (/ a b)) a)))))
double code(double a, double b) {
	return sqrt(fabs((1.0 - ((b / (a / b)) / a))));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = sqrt(abs((1.0d0 - ((b / (a / b)) / a))))
end function
public static double code(double a, double b) {
	return Math.sqrt(Math.abs((1.0 - ((b / (a / b)) / a))));
}
def code(a, b):
	return math.sqrt(math.fabs((1.0 - ((b / (a / b)) / a))))
function code(a, b)
	return sqrt(abs(Float64(1.0 - Float64(Float64(b / Float64(a / b)) / a))))
end
function tmp = code(a, b)
	tmp = sqrt(abs((1.0 - ((b / (a / b)) / a))));
end
code[a_, b_] := N[Sqrt[N[Abs[N[(1.0 - N[(N[(b / N[(a / b), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\sqrt{\left|1 - \frac{\frac{b}{\frac{a}{b}}}{a}\right|}
\end{array}
Derivation
  1. Initial program 72.6%

    \[\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \]
  2. Step-by-step derivation
    1. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|\right)\right) \]
    2. div-subN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a}{a \cdot a} - \frac{b \cdot b}{a \cdot a}\right|\right)\right) \]
    3. fabs-subN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right|\right)\right) \]
    4. fabs-lowering-fabs.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right)\right)\right) \]
    5. sub-negN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(\frac{a \cdot a}{a \cdot a}\right)\right)\right)\right)\right) \]
    6. *-inversesN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(1\right)\right)\right)\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + -1\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\left(\frac{b \cdot b}{a \cdot a}\right), -1\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\left(b \cdot b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
    11. *-lowering-*.f6472.6%

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \mathsf{*.f64}\left(a, a\right)\right), -1\right)\right)\right) \]
  3. Simplified72.6%

    \[\leadsto \color{blue}{\sqrt{\left|\frac{b \cdot b}{a \cdot a} + -1\right|}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(1\right)\right)\right)\right)\right) \]
    2. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(-1 \cdot -1\right)\right)\right)\right)\right) \]
    3. sub-negN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} - -1 \cdot -1\right)\right)\right) \]
    4. --lowering--.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\left(\frac{b \cdot b}{a \cdot a}\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    5. associate-/r*N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\left(\frac{\frac{b \cdot b}{a}}{a}\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    6. /-lowering-/.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(\frac{b \cdot b}{a}\right), a\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    7. associate-/l*N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(b \cdot \frac{b}{a}\right), a\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    8. clear-numN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(b \cdot \frac{1}{\frac{a}{b}}\right), a\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    9. un-div-invN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(\frac{b}{\frac{a}{b}}\right), a\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    10. /-lowering-/.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(b, \left(\frac{a}{b}\right)\right), a\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    11. /-lowering-/.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(b, \mathsf{/.f64}\left(a, b\right)\right), a\right), \left(-1 \cdot -1\right)\right)\right)\right) \]
    12. metadata-eval100.0%

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{/.f64}\left(b, \mathsf{/.f64}\left(a, b\right)\right), a\right), 1\right)\right)\right) \]
  6. Applied egg-rr100.0%

    \[\leadsto \sqrt{\left|\color{blue}{\frac{\frac{b}{\frac{a}{b}}}{a} - 1}\right|} \]
  7. Final simplification100.0%

    \[\leadsto \sqrt{\left|1 - \frac{\frac{b}{\frac{a}{b}}}{a}\right|} \]
  8. Add Preprocessing

Alternative 2: 99.0% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -1 - \frac{b}{a \cdot \frac{a}{b}}\\ {\left(t\_0 \cdot t\_0\right)}^{-0.25} \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (- -1.0 (/ b (* a (/ a b)))))) (pow (* t_0 t_0) -0.25)))
double code(double a, double b) {
	double t_0 = -1.0 - (b / (a * (a / b)));
	return pow((t_0 * t_0), -0.25);
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_0
    t_0 = (-1.0d0) - (b / (a * (a / b)))
    code = (t_0 * t_0) ** (-0.25d0)
end function
public static double code(double a, double b) {
	double t_0 = -1.0 - (b / (a * (a / b)));
	return Math.pow((t_0 * t_0), -0.25);
}
def code(a, b):
	t_0 = -1.0 - (b / (a * (a / b)))
	return math.pow((t_0 * t_0), -0.25)
function code(a, b)
	t_0 = Float64(-1.0 - Float64(b / Float64(a * Float64(a / b))))
	return Float64(t_0 * t_0) ^ -0.25
end
function tmp = code(a, b)
	t_0 = -1.0 - (b / (a * (a / b)));
	tmp = (t_0 * t_0) ^ -0.25;
end
code[a_, b_] := Block[{t$95$0 = N[(-1.0 - N[(b / N[(a * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[Power[N[(t$95$0 * t$95$0), $MachinePrecision], -0.25], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -1 - \frac{b}{a \cdot \frac{a}{b}}\\
{\left(t\_0 \cdot t\_0\right)}^{-0.25}
\end{array}
\end{array}
Derivation
  1. Initial program 72.6%

    \[\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \]
  2. Step-by-step derivation
    1. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|\right)\right) \]
    2. div-subN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a}{a \cdot a} - \frac{b \cdot b}{a \cdot a}\right|\right)\right) \]
    3. fabs-subN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right|\right)\right) \]
    4. fabs-lowering-fabs.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right)\right)\right) \]
    5. sub-negN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(\frac{a \cdot a}{a \cdot a}\right)\right)\right)\right)\right) \]
    6. *-inversesN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(1\right)\right)\right)\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + -1\right)\right)\right) \]
    8. +-lowering-+.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\left(\frac{b \cdot b}{a \cdot a}\right), -1\right)\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\left(b \cdot b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
    11. *-lowering-*.f6472.6%

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \mathsf{*.f64}\left(a, a\right)\right), -1\right)\right)\right) \]
  3. Simplified72.6%

    \[\leadsto \color{blue}{\sqrt{\left|\frac{b \cdot b}{a \cdot a} + -1\right|}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(-1 + \frac{b \cdot b}{a \cdot a}\right)\right)\right) \]
    2. flip-+N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \frac{b \cdot b}{a \cdot a} \cdot \frac{b \cdot b}{a \cdot a}}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    3. *-rgt-identityN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \left(\frac{b \cdot b}{a \cdot a} \cdot \frac{b \cdot b}{a \cdot a}\right) \cdot 1}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    4. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \left(\frac{b \cdot b}{a \cdot a} \cdot \frac{b \cdot b}{a \cdot a}\right) \cdot \left(-1 \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    5. swap-sqrN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    6. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{1 \cdot 1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{\left(-1 \cdot -1\right) \cdot 1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{\left(-1 \cdot -1\right) \cdot \left(-1 \cdot -1\right) - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
    10. /-lowering-/.f64N/A

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{/.f64}\left(\left(\left(-1 \cdot -1\right) \cdot \left(-1 \cdot -1\right) - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)\right), \left(-1 - \frac{b \cdot b}{a \cdot a}\right)\right)\right)\right) \]
  6. Applied egg-rr88.7%

    \[\leadsto \sqrt{\left|\color{blue}{\frac{1 - \frac{b \cdot b}{a \cdot \frac{a}{\frac{\frac{b}{\frac{a}{b}}}{a}}}}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}}\right|} \]
  7. Taylor expanded in b around 0

    \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{/.f64}\left(\color{blue}{1}, \mathsf{\_.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(b, \mathsf{/.f64}\left(a, b\right)\right), a\right)\right)\right)\right)\right) \]
  8. Step-by-step derivation
    1. Simplified99.0%

      \[\leadsto \sqrt{\left|\frac{\color{blue}{1}}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|} \]
    2. Step-by-step derivation
      1. pow1/2N/A

        \[\leadsto {\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\color{blue}{\frac{1}{2}}} \]
      2. sqr-powN/A

        \[\leadsto {\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot \color{blue}{{\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      3. pow-prod-downN/A

        \[\leadsto {\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right| \cdot \left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\color{blue}{\left(\frac{\frac{1}{2}}{2}\right)}} \]
    3. Applied egg-rr99.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{-1 - \frac{b}{\frac{a}{\frac{b}{a}}}} \cdot \frac{1}{-1 - \frac{b}{\frac{a}{\frac{b}{a}}}}\right)}^{0.25}} \]
    4. Step-by-step derivation
      1. frac-timesN/A

        \[\leadsto {\left(\frac{1 \cdot 1}{\left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right) \cdot \left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right)}\right)}^{\frac{1}{4}} \]
      2. metadata-evalN/A

        \[\leadsto {\left(\frac{1}{\left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right) \cdot \left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right)}\right)}^{\frac{1}{4}} \]
      3. inv-powN/A

        \[\leadsto {\left({\left(\left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right) \cdot \left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right)\right)}^{-1}\right)}^{\frac{1}{4}} \]
      4. pow-powN/A

        \[\leadsto {\left(\left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right) \cdot \left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right)\right)}^{\color{blue}{\left(-1 \cdot \frac{1}{4}\right)}} \]
      5. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{pow.f64}\left(\left(\left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right) \cdot \left(-1 - \frac{b}{\frac{a}{\frac{b}{a}}}\right)\right), \color{blue}{\left(-1 \cdot \frac{1}{4}\right)}\right) \]
    5. Applied egg-rr99.0%

      \[\leadsto \color{blue}{{\left(\left(-1 - \frac{b}{a \cdot \frac{a}{b}}\right) \cdot \left(-1 - \frac{b}{a \cdot \frac{a}{b}}\right)\right)}^{-0.25}} \]
    6. Add Preprocessing

    Alternative 3: 98.5% accurate, 19.2× speedup?

    \[\begin{array}{l} \\ 1 + -0.5 \cdot \frac{\frac{b \cdot b}{a}}{a} \end{array} \]
    (FPCore (a b) :precision binary64 (+ 1.0 (* -0.5 (/ (/ (* b b) a) a))))
    double code(double a, double b) {
    	return 1.0 + (-0.5 * (((b * b) / a) / a));
    }
    
    real(8) function code(a, b)
        real(8), intent (in) :: a
        real(8), intent (in) :: b
        code = 1.0d0 + ((-0.5d0) * (((b * b) / a) / a))
    end function
    
    public static double code(double a, double b) {
    	return 1.0 + (-0.5 * (((b * b) / a) / a));
    }
    
    def code(a, b):
    	return 1.0 + (-0.5 * (((b * b) / a) / a))
    
    function code(a, b)
    	return Float64(1.0 + Float64(-0.5 * Float64(Float64(Float64(b * b) / a) / a)))
    end
    
    function tmp = code(a, b)
    	tmp = 1.0 + (-0.5 * (((b * b) / a) / a));
    end
    
    code[a_, b_] := N[(1.0 + N[(-0.5 * N[(N[(N[(b * b), $MachinePrecision] / a), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    1 + -0.5 \cdot \frac{\frac{b \cdot b}{a}}{a}
    \end{array}
    
    Derivation
    1. Initial program 72.6%

      \[\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \]
    2. Step-by-step derivation
      1. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|\right)\right) \]
      2. div-subN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a}{a \cdot a} - \frac{b \cdot b}{a \cdot a}\right|\right)\right) \]
      3. fabs-subN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right|\right)\right) \]
      4. fabs-lowering-fabs.f64N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right)\right)\right) \]
      5. sub-negN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(\frac{a \cdot a}{a \cdot a}\right)\right)\right)\right)\right) \]
      6. *-inversesN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(1\right)\right)\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + -1\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\left(\frac{b \cdot b}{a \cdot a}\right), -1\right)\right)\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\left(b \cdot b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
      11. *-lowering-*.f6472.6%

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \mathsf{*.f64}\left(a, a\right)\right), -1\right)\right)\right) \]
    3. Simplified72.6%

      \[\leadsto \color{blue}{\sqrt{\left|\frac{b \cdot b}{a \cdot a} + -1\right|}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(-1 + \frac{b \cdot b}{a \cdot a}\right)\right)\right) \]
      2. flip-+N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \frac{b \cdot b}{a \cdot a} \cdot \frac{b \cdot b}{a \cdot a}}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      3. *-rgt-identityN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \left(\frac{b \cdot b}{a \cdot a} \cdot \frac{b \cdot b}{a \cdot a}\right) \cdot 1}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \left(\frac{b \cdot b}{a \cdot a} \cdot \frac{b \cdot b}{a \cdot a}\right) \cdot \left(-1 \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      5. swap-sqrN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{-1 \cdot -1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{1 \cdot 1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      8. metadata-evalN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{\left(-1 \cdot -1\right) \cdot 1 - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{\left(-1 \cdot -1\right) \cdot \left(-1 \cdot -1\right) - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)}{-1 - \frac{b \cdot b}{a \cdot a}}\right)\right)\right) \]
      10. /-lowering-/.f64N/A

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{/.f64}\left(\left(\left(-1 \cdot -1\right) \cdot \left(-1 \cdot -1\right) - \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right) \cdot \left(\frac{b \cdot b}{a \cdot a} \cdot -1\right)\right), \left(-1 - \frac{b \cdot b}{a \cdot a}\right)\right)\right)\right) \]
    6. Applied egg-rr88.7%

      \[\leadsto \sqrt{\left|\color{blue}{\frac{1 - \frac{b \cdot b}{a \cdot \frac{a}{\frac{\frac{b}{\frac{a}{b}}}{a}}}}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}}\right|} \]
    7. Taylor expanded in b around 0

      \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{/.f64}\left(\color{blue}{1}, \mathsf{\_.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(b, \mathsf{/.f64}\left(a, b\right)\right), a\right)\right)\right)\right)\right) \]
    8. Step-by-step derivation
      1. Simplified99.0%

        \[\leadsto \sqrt{\left|\frac{\color{blue}{1}}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|} \]
      2. Step-by-step derivation
        1. pow1/2N/A

          \[\leadsto {\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\color{blue}{\frac{1}{2}}} \]
        2. sqr-powN/A

          \[\leadsto {\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot \color{blue}{{\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}} \]
        3. pow-prod-downN/A

          \[\leadsto {\left(\left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right| \cdot \left|\frac{1}{-1 - \frac{\frac{b}{\frac{a}{b}}}{a}}\right|\right)}^{\color{blue}{\left(\frac{\frac{1}{2}}{2}\right)}} \]
      3. Applied egg-rr99.0%

        \[\leadsto \color{blue}{{\left(\frac{1}{-1 - \frac{b}{\frac{a}{\frac{b}{a}}}} \cdot \frac{1}{-1 - \frac{b}{\frac{a}{\frac{b}{a}}}}\right)}^{0.25}} \]
      4. Taylor expanded in b around 0

        \[\leadsto \color{blue}{1 + \frac{-1}{2} \cdot \frac{{b}^{2}}{{a}^{2}}} \]
      5. Step-by-step derivation
        1. +-lowering-+.f64N/A

          \[\leadsto \mathsf{+.f64}\left(1, \color{blue}{\left(\frac{-1}{2} \cdot \frac{{b}^{2}}{{a}^{2}}\right)}\right) \]
        2. *-lowering-*.f64N/A

          \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \color{blue}{\left(\frac{{b}^{2}}{{a}^{2}}\right)}\right)\right) \]
        3. unpow2N/A

          \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(\frac{{b}^{2}}{a \cdot \color{blue}{a}}\right)\right)\right) \]
        4. associate-/r*N/A

          \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \left(\frac{\frac{{b}^{2}}{a}}{\color{blue}{a}}\right)\right)\right) \]
        5. /-lowering-/.f64N/A

          \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\left(\frac{{b}^{2}}{a}\right), \color{blue}{a}\right)\right)\right) \]
        6. /-lowering-/.f64N/A

          \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left({b}^{2}\right), a\right), a\right)\right)\right) \]
        7. unpow2N/A

          \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(b \cdot b\right), a\right), a\right)\right)\right) \]
        8. *-lowering-*.f6498.4%

          \[\leadsto \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\frac{-1}{2}, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), a\right), a\right)\right)\right) \]
      6. Simplified98.4%

        \[\leadsto \color{blue}{1 + -0.5 \cdot \frac{\frac{b \cdot b}{a}}{a}} \]
      7. Add Preprocessing

      Alternative 4: 97.9% accurate, 211.0× speedup?

      \[\begin{array}{l} \\ 1 \end{array} \]
      (FPCore (a b) :precision binary64 1.0)
      double code(double a, double b) {
      	return 1.0;
      }
      
      real(8) function code(a, b)
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          code = 1.0d0
      end function
      
      public static double code(double a, double b) {
      	return 1.0;
      }
      
      def code(a, b):
      	return 1.0
      
      function code(a, b)
      	return 1.0
      end
      
      function tmp = code(a, b)
      	tmp = 1.0;
      end
      
      code[a_, b_] := 1.0
      
      \begin{array}{l}
      
      \\
      1
      \end{array}
      
      Derivation
      1. Initial program 72.6%

        \[\sqrt{\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|} \]
      2. Step-by-step derivation
        1. sqrt-lowering-sqrt.f64N/A

          \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a - b \cdot b}{a \cdot a}\right|\right)\right) \]
        2. div-subN/A

          \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{a \cdot a}{a \cdot a} - \frac{b \cdot b}{a \cdot a}\right|\right)\right) \]
        3. fabs-subN/A

          \[\leadsto \mathsf{sqrt.f64}\left(\left(\left|\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right|\right)\right) \]
        4. fabs-lowering-fabs.f64N/A

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} - \frac{a \cdot a}{a \cdot a}\right)\right)\right) \]
        5. sub-negN/A

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(\frac{a \cdot a}{a \cdot a}\right)\right)\right)\right)\right) \]
        6. *-inversesN/A

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + \left(\mathsf{neg}\left(1\right)\right)\right)\right)\right) \]
        7. metadata-evalN/A

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\left(\frac{b \cdot b}{a \cdot a} + -1\right)\right)\right) \]
        8. +-lowering-+.f64N/A

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\left(\frac{b \cdot b}{a \cdot a}\right), -1\right)\right)\right) \]
        9. /-lowering-/.f64N/A

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\left(b \cdot b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
        10. *-lowering-*.f64N/A

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \left(a \cdot a\right)\right), -1\right)\right)\right) \]
        11. *-lowering-*.f6472.6%

          \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\mathsf{+.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(b, b\right), \mathsf{*.f64}\left(a, a\right)\right), -1\right)\right)\right) \]
      3. Simplified72.6%

        \[\leadsto \color{blue}{\sqrt{\left|\frac{b \cdot b}{a \cdot a} + -1\right|}} \]
      4. Add Preprocessing
      5. Taylor expanded in b around 0

        \[\leadsto \mathsf{sqrt.f64}\left(\mathsf{fabs.f64}\left(\color{blue}{-1}\right)\right) \]
      6. Step-by-step derivation
        1. Simplified97.8%

          \[\leadsto \sqrt{\left|\color{blue}{-1}\right|} \]
        2. Step-by-step derivation
          1. metadata-evalN/A

            \[\leadsto \sqrt{1} \]
          2. metadata-eval97.8%

            \[\leadsto 1 \]
        3. Applied egg-rr97.8%

          \[\leadsto \color{blue}{1} \]
        4. Add Preprocessing

        Reproduce

        ?
        herbie shell --seed 2024139 
        (FPCore (a b)
          :name "Eccentricity of an ellipse"
          :precision binary64
          :pre (and (and (<= 0.0 b) (<= b a)) (<= a 1.0))
          (sqrt (fabs (/ (- (* a a) (* b b)) (* a a)))))