Diagrams.TwoD.Ellipse:ellipse from diagrams-lib-1.3.0.3

Percentage Accurate: 100.0% → 100.0%
Time: 12.0s
Alternatives: 6
Speedup: 1.0×

Specification

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

\\
\sqrt{1 - x \cdot x}
\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: 100.0% accurate, 1.0× speedup?

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

\\
\sqrt{1 - x \cdot x}
\end{array}

Alternative 1: 100.0% accurate, 0.5× speedup?

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

\\
\sqrt{-\mathsf{fma}\left(x, x, -1\right)}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\sqrt{1 - x \cdot x} \]
  2. Step-by-step derivation
    1. sqr-neg100.0%

      \[\leadsto \sqrt{1 - \color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
    2. remove-double-neg100.0%

      \[\leadsto \sqrt{\color{blue}{-\left(-\left(1 - \left(-x\right) \cdot \left(-x\right)\right)\right)}} \]
    3. cancel-sign-sub100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(1 + x \cdot \left(-x\right)\right)}\right)} \]
    4. +-commutative100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(x \cdot \left(-x\right) + 1\right)}\right)} \]
    5. distribute-neg-in100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x \cdot \left(-x\right)\right) + \left(-1\right)\right)}} \]
    6. distribute-lft-neg-out100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{\left(-x\right) \cdot \left(-x\right)} + \left(-1\right)\right)} \]
    7. sub-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x\right) \cdot \left(-x\right) - 1\right)}} \]
    8. sqr-neg100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{x \cdot x} - 1\right)} \]
    9. fma-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    10. metadata-eval100.0%

      \[\leadsto \sqrt{-\mathsf{fma}\left(x, x, \color{blue}{-1}\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{fma}\left(x, x, -1\right)}} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 2: 100.0% accurate, 1.0× speedup?

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

\\
\sqrt{1 - x \cdot x}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\sqrt{1 - x \cdot x} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 3: 99.5% accurate, 4.6× speedup?

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

\\
\frac{\frac{1}{\frac{1}{-1 + x \cdot \left(0.25 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}}}{-1 + \left(x \cdot x\right) \cdot -0.5}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\sqrt{1 - x \cdot x} \]
  2. Step-by-step derivation
    1. sqr-neg100.0%

      \[\leadsto \sqrt{1 - \color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
    2. remove-double-neg100.0%

      \[\leadsto \sqrt{\color{blue}{-\left(-\left(1 - \left(-x\right) \cdot \left(-x\right)\right)\right)}} \]
    3. cancel-sign-sub100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(1 + x \cdot \left(-x\right)\right)}\right)} \]
    4. +-commutative100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(x \cdot \left(-x\right) + 1\right)}\right)} \]
    5. distribute-neg-in100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x \cdot \left(-x\right)\right) + \left(-1\right)\right)}} \]
    6. distribute-lft-neg-out100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{\left(-x\right) \cdot \left(-x\right)} + \left(-1\right)\right)} \]
    7. sub-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x\right) \cdot \left(-x\right) - 1\right)}} \]
    8. sqr-neg100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{x \cdot x} - 1\right)} \]
    9. fma-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    10. metadata-eval100.0%

      \[\leadsto \sqrt{-\mathsf{fma}\left(x, x, \color{blue}{-1}\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{fma}\left(x, x, -1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 99.1%

    \[\leadsto \color{blue}{1 + -0.5 \cdot {x}^{2}} \]
  6. Step-by-step derivation
    1. +-commutative99.1%

      \[\leadsto \color{blue}{-0.5 \cdot {x}^{2} + 1} \]
    2. unpow299.1%

      \[\leadsto -0.5 \cdot \color{blue}{\left(x \cdot x\right)} + 1 \]
    3. fma-define99.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, x \cdot x, 1\right)} \]
  7. Simplified99.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, x \cdot x, 1\right)} \]
  8. Step-by-step derivation
    1. fma-undefine99.1%

      \[\leadsto \color{blue}{-0.5 \cdot \left(x \cdot x\right) + 1} \]
    2. flip-+99.1%

      \[\leadsto \color{blue}{\frac{\left(-0.5 \cdot \left(x \cdot x\right)\right) \cdot \left(-0.5 \cdot \left(x \cdot x\right)\right) - 1 \cdot 1}{-0.5 \cdot \left(x \cdot x\right) - 1}} \]
    3. *-commutative99.1%

      \[\leadsto \frac{\color{blue}{\left(\left(x \cdot x\right) \cdot -0.5\right)} \cdot \left(-0.5 \cdot \left(x \cdot x\right)\right) - 1 \cdot 1}{-0.5 \cdot \left(x \cdot x\right) - 1} \]
    4. *-commutative99.1%

      \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot -0.5\right)} - 1 \cdot 1}{-0.5 \cdot \left(x \cdot x\right) - 1} \]
    5. metadata-eval99.1%

      \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - \color{blue}{1}}{-0.5 \cdot \left(x \cdot x\right) - 1} \]
    6. *-commutative99.1%

      \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - 1}{\color{blue}{\left(x \cdot x\right) \cdot -0.5} - 1} \]
  9. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - 1}{\left(x \cdot x\right) \cdot -0.5 - 1}} \]
  10. Step-by-step derivation
    1. swap-sqr99.1%

      \[\leadsto \frac{\color{blue}{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(-0.5 \cdot -0.5\right)} - 1}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    2. metadata-eval99.1%

      \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \color{blue}{0.25} - 1}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
  11. Applied egg-rr99.1%

    \[\leadsto \frac{\color{blue}{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot 0.25} - 1}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
  12. Step-by-step derivation
    1. metadata-eval99.1%

      \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \color{blue}{\left(-0.5 \cdot -0.5\right)} - 1}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    2. swap-sqr99.1%

      \[\leadsto \frac{\color{blue}{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right)} - 1}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    3. associate-*r*99.1%

      \[\leadsto \frac{\color{blue}{\left(x \cdot \left(x \cdot -0.5\right)\right)} \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - 1}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    4. associate-*r*99.1%

      \[\leadsto \frac{\left(x \cdot \left(x \cdot -0.5\right)\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.5\right)\right)} - 1}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    5. difference-of-sqr-199.1%

      \[\leadsto \frac{\color{blue}{\left(x \cdot \left(x \cdot -0.5\right) + 1\right) \cdot \left(x \cdot \left(x \cdot -0.5\right) - 1\right)}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    6. remove-double-div99.1%

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}} \cdot \left(x \cdot \left(x \cdot -0.5\right) - 1\right)}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    7. sub-neg99.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}} \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.5\right) + \left(-1\right)\right)}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    8. metadata-eval99.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}} \cdot \left(x \cdot \left(x \cdot -0.5\right) + \color{blue}{-1}\right)}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    9. associate-/r/99.1%

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}{x \cdot \left(x \cdot -0.5\right) + -1}}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    10. clear-num99.1%

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{\frac{x \cdot \left(x \cdot -0.5\right) + -1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}}}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    11. clear-num99.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{\color{blue}{\frac{1}{\frac{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}{x \cdot \left(x \cdot -0.5\right) + -1}}}}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    12. associate-/r/99.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{\color{blue}{\frac{1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}} \cdot \left(x \cdot \left(x \cdot -0.5\right) + -1\right)}}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    13. remove-double-div99.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{\color{blue}{\left(x \cdot \left(x \cdot -0.5\right) + 1\right)} \cdot \left(x \cdot \left(x \cdot -0.5\right) + -1\right)}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    14. metadata-eval99.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{\left(x \cdot \left(x \cdot -0.5\right) + 1\right) \cdot \left(x \cdot \left(x \cdot -0.5\right) + \color{blue}{\left(-1\right)}\right)}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    15. sub-neg99.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{\left(x \cdot \left(x \cdot -0.5\right) + 1\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.5\right) - 1\right)}}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    16. difference-of-sqr-199.1%

      \[\leadsto \frac{\frac{1}{\frac{1}{\color{blue}{\left(x \cdot \left(x \cdot -0.5\right)\right) \cdot \left(x \cdot \left(x \cdot -0.5\right)\right) - 1}}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
  13. Applied egg-rr99.1%

    \[\leadsto \frac{\color{blue}{\frac{1}{\frac{1}{-1 + x \cdot \left(0.25 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}}}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
  14. Final simplification99.1%

    \[\leadsto \frac{\frac{1}{\frac{1}{-1 + x \cdot \left(0.25 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}}}{-1 + \left(x \cdot x\right) \cdot -0.5} \]
  15. Add Preprocessing

Alternative 4: 99.5% accurate, 5.0× speedup?

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

\\
\frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{-1 + x \cdot \left(0.25 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\sqrt{1 - x \cdot x} \]
  2. Step-by-step derivation
    1. sqr-neg100.0%

      \[\leadsto \sqrt{1 - \color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
    2. remove-double-neg100.0%

      \[\leadsto \sqrt{\color{blue}{-\left(-\left(1 - \left(-x\right) \cdot \left(-x\right)\right)\right)}} \]
    3. cancel-sign-sub100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(1 + x \cdot \left(-x\right)\right)}\right)} \]
    4. +-commutative100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(x \cdot \left(-x\right) + 1\right)}\right)} \]
    5. distribute-neg-in100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x \cdot \left(-x\right)\right) + \left(-1\right)\right)}} \]
    6. distribute-lft-neg-out100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{\left(-x\right) \cdot \left(-x\right)} + \left(-1\right)\right)} \]
    7. sub-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x\right) \cdot \left(-x\right) - 1\right)}} \]
    8. sqr-neg100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{x \cdot x} - 1\right)} \]
    9. fma-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    10. metadata-eval100.0%

      \[\leadsto \sqrt{-\mathsf{fma}\left(x, x, \color{blue}{-1}\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{fma}\left(x, x, -1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 99.1%

    \[\leadsto \color{blue}{1 + -0.5 \cdot {x}^{2}} \]
  6. Step-by-step derivation
    1. +-commutative99.1%

      \[\leadsto \color{blue}{-0.5 \cdot {x}^{2} + 1} \]
    2. unpow299.1%

      \[\leadsto -0.5 \cdot \color{blue}{\left(x \cdot x\right)} + 1 \]
    3. fma-define99.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, x \cdot x, 1\right)} \]
  7. Simplified99.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, x \cdot x, 1\right)} \]
  8. Step-by-step derivation
    1. fma-undefine99.1%

      \[\leadsto \color{blue}{-0.5 \cdot \left(x \cdot x\right) + 1} \]
    2. *-commutative99.1%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot -0.5} + 1 \]
  9. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot -0.5 + 1} \]
  10. Step-by-step derivation
    1. flip-+99.1%

      \[\leadsto \color{blue}{\frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - 1 \cdot 1}{\left(x \cdot x\right) \cdot -0.5 - 1}} \]
    2. metadata-eval99.1%

      \[\leadsto \frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - \color{blue}{1}}{\left(x \cdot x\right) \cdot -0.5 - 1} \]
    3. clear-num99.1%

      \[\leadsto \color{blue}{\frac{1}{\frac{\left(x \cdot x\right) \cdot -0.5 - 1}{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - 1}}} \]
    4. clear-num99.1%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - 1}{\left(x \cdot x\right) \cdot -0.5 - 1}}}} \]
    5. metadata-eval99.1%

      \[\leadsto \frac{1}{\frac{1}{\frac{\left(\left(x \cdot x\right) \cdot -0.5\right) \cdot \left(\left(x \cdot x\right) \cdot -0.5\right) - \color{blue}{1 \cdot 1}}{\left(x \cdot x\right) \cdot -0.5 - 1}}} \]
    6. flip-+99.1%

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\left(x \cdot x\right) \cdot -0.5 + 1}}} \]
    7. associate-*l*99.1%

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{x \cdot \left(x \cdot -0.5\right)} + 1}} \]
  11. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\frac{1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}} \]
  12. Step-by-step derivation
    1. *-un-lft-identity99.1%

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}} \]
    2. *-inverses99.1%

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot \left(x \cdot -0.5\right) + -1}{x \cdot \left(x \cdot -0.5\right) + -1}} \cdot \frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}} \]
    3. associate-/r/99.1%

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot \left(x \cdot -0.5\right) + -1}{\frac{x \cdot \left(x \cdot -0.5\right) + -1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}}}} \]
    4. +-commutative99.1%

      \[\leadsto \frac{1}{\frac{\color{blue}{-1 + x \cdot \left(x \cdot -0.5\right)}}{\frac{x \cdot \left(x \cdot -0.5\right) + -1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}}} \]
    5. clear-num99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{\frac{1}{\frac{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}}{x \cdot \left(x \cdot -0.5\right) + -1}}}}} \]
    6. associate-/r/99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{\frac{1}{\frac{1}{x \cdot \left(x \cdot -0.5\right) + 1}} \cdot \left(x \cdot \left(x \cdot -0.5\right) + -1\right)}}} \]
    7. remove-double-div99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{\left(x \cdot \left(x \cdot -0.5\right) + 1\right)} \cdot \left(x \cdot \left(x \cdot -0.5\right) + -1\right)}} \]
    8. metadata-eval99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\left(x \cdot \left(x \cdot -0.5\right) + 1\right) \cdot \left(x \cdot \left(x \cdot -0.5\right) + \color{blue}{\left(-1\right)}\right)}} \]
    9. sub-neg99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\left(x \cdot \left(x \cdot -0.5\right) + 1\right) \cdot \color{blue}{\left(x \cdot \left(x \cdot -0.5\right) - 1\right)}}} \]
    10. difference-of-sqr-199.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{\left(x \cdot \left(x \cdot -0.5\right)\right) \cdot \left(x \cdot \left(x \cdot -0.5\right)\right) - 1}}} \]
    11. sub-neg99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{\left(x \cdot \left(x \cdot -0.5\right)\right) \cdot \left(x \cdot \left(x \cdot -0.5\right)\right) + \left(-1\right)}}} \]
    12. swap-sqr99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left(\left(x \cdot -0.5\right) \cdot \left(x \cdot -0.5\right)\right)} + \left(-1\right)}} \]
    13. swap-sqr99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot \left(-0.5 \cdot -0.5\right)\right)} + \left(-1\right)}} \]
    14. metadata-eval99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\left(x \cdot x\right) \cdot \left(\left(x \cdot x\right) \cdot \color{blue}{0.25}\right) + \left(-1\right)}} \]
    15. *-commutative99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\left(x \cdot x\right) \cdot \color{blue}{\left(0.25 \cdot \left(x \cdot x\right)\right)} + \left(-1\right)}} \]
    16. associate-*r*99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{x \cdot \left(x \cdot \left(0.25 \cdot \left(x \cdot x\right)\right)\right)} + \left(-1\right)}} \]
    17. metadata-eval99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{x \cdot \left(x \cdot \left(0.25 \cdot \left(x \cdot x\right)\right)\right) + \color{blue}{-1}}} \]
    18. +-commutative99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{\color{blue}{-1 + x \cdot \left(x \cdot \left(0.25 \cdot \left(x \cdot x\right)\right)\right)}}} \]
    19. *-commutative99.1%

      \[\leadsto \frac{1}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{-1 + x \cdot \color{blue}{\left(\left(0.25 \cdot \left(x \cdot x\right)\right) \cdot x\right)}}} \]
  13. Applied egg-rr99.1%

    \[\leadsto \frac{1}{\color{blue}{\frac{-1 + x \cdot \left(x \cdot -0.5\right)}{-1 + x \cdot \left(0.25 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)}}} \]
  14. Add Preprocessing

Alternative 5: 99.5% accurate, 15.0× speedup?

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

\\
1 + \left(x \cdot x\right) \cdot -0.5
\end{array}
Derivation
  1. Initial program 100.0%

    \[\sqrt{1 - x \cdot x} \]
  2. Step-by-step derivation
    1. sqr-neg100.0%

      \[\leadsto \sqrt{1 - \color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
    2. remove-double-neg100.0%

      \[\leadsto \sqrt{\color{blue}{-\left(-\left(1 - \left(-x\right) \cdot \left(-x\right)\right)\right)}} \]
    3. cancel-sign-sub100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(1 + x \cdot \left(-x\right)\right)}\right)} \]
    4. +-commutative100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(x \cdot \left(-x\right) + 1\right)}\right)} \]
    5. distribute-neg-in100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x \cdot \left(-x\right)\right) + \left(-1\right)\right)}} \]
    6. distribute-lft-neg-out100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{\left(-x\right) \cdot \left(-x\right)} + \left(-1\right)\right)} \]
    7. sub-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x\right) \cdot \left(-x\right) - 1\right)}} \]
    8. sqr-neg100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{x \cdot x} - 1\right)} \]
    9. fma-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    10. metadata-eval100.0%

      \[\leadsto \sqrt{-\mathsf{fma}\left(x, x, \color{blue}{-1}\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{fma}\left(x, x, -1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 99.1%

    \[\leadsto \color{blue}{1 + -0.5 \cdot {x}^{2}} \]
  6. Step-by-step derivation
    1. +-commutative99.1%

      \[\leadsto \color{blue}{-0.5 \cdot {x}^{2} + 1} \]
    2. unpow299.1%

      \[\leadsto -0.5 \cdot \color{blue}{\left(x \cdot x\right)} + 1 \]
    3. fma-define99.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, x \cdot x, 1\right)} \]
  7. Simplified99.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5, x \cdot x, 1\right)} \]
  8. Step-by-step derivation
    1. fma-undefine99.1%

      \[\leadsto \color{blue}{-0.5 \cdot \left(x \cdot x\right) + 1} \]
    2. *-commutative99.1%

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot -0.5} + 1 \]
  9. Applied egg-rr99.1%

    \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot -0.5 + 1} \]
  10. Final simplification99.1%

    \[\leadsto 1 + \left(x \cdot x\right) \cdot -0.5 \]
  11. Add Preprocessing

Alternative 6: 98.9% accurate, 105.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 100.0%

    \[\sqrt{1 - x \cdot x} \]
  2. Step-by-step derivation
    1. sqr-neg100.0%

      \[\leadsto \sqrt{1 - \color{blue}{\left(-x\right) \cdot \left(-x\right)}} \]
    2. remove-double-neg100.0%

      \[\leadsto \sqrt{\color{blue}{-\left(-\left(1 - \left(-x\right) \cdot \left(-x\right)\right)\right)}} \]
    3. cancel-sign-sub100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(1 + x \cdot \left(-x\right)\right)}\right)} \]
    4. +-commutative100.0%

      \[\leadsto \sqrt{-\left(-\color{blue}{\left(x \cdot \left(-x\right) + 1\right)}\right)} \]
    5. distribute-neg-in100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x \cdot \left(-x\right)\right) + \left(-1\right)\right)}} \]
    6. distribute-lft-neg-out100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{\left(-x\right) \cdot \left(-x\right)} + \left(-1\right)\right)} \]
    7. sub-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\left(\left(-x\right) \cdot \left(-x\right) - 1\right)}} \]
    8. sqr-neg100.0%

      \[\leadsto \sqrt{-\left(\color{blue}{x \cdot x} - 1\right)} \]
    9. fma-neg100.0%

      \[\leadsto \sqrt{-\color{blue}{\mathsf{fma}\left(x, x, -1\right)}} \]
    10. metadata-eval100.0%

      \[\leadsto \sqrt{-\mathsf{fma}\left(x, x, \color{blue}{-1}\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{fma}\left(x, x, -1\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 98.2%

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

Reproduce

?
herbie shell --seed 2024097 
(FPCore (x)
  :name "Diagrams.TwoD.Ellipse:ellipse from diagrams-lib-1.3.0.3"
  :precision binary64
  (sqrt (- 1.0 (* x x))))