Falkner and Boettcher, Appendix B, 1

Percentage Accurate: 99.2% → 99.2%
Time: 16.6s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
	return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
    real(8), intent (in) :: v
    code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
	return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v):
	return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v)
	return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0)))
end
function tmp = code(v)
	tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\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 7 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.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))
double code(double v) {
	return acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
real(8) function code(v)
    real(8), intent (in) :: v
    code = acos(((1.0d0 - (5.0d0 * (v * v))) / ((v * v) - 1.0d0)))
end function
public static double code(double v) {
	return Math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
}
def code(v):
	return math.acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)))
function code(v)
	return acos(Float64(Float64(1.0 - Float64(5.0 * Float64(v * v))) / Float64(Float64(v * v) - 1.0)))
end
function tmp = code(v)
	tmp = acos(((1.0 - (5.0 * (v * v))) / ((v * v) - 1.0)));
end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(5.0 * N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right)
\end{array}

Alternative 1: 99.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right)\\ \frac{\frac{\pi \cdot \left(\pi \cdot \pi\right)}{8} - {t\_0}^{3}}{\frac{\pi \cdot \pi}{4} + t\_0 \cdot \left(t\_0 + \frac{\pi}{2}\right)} \end{array} \end{array} \]
(FPCore (v)
 :precision binary64
 (let* ((t_0 (asin (/ (+ 1.0 (* (* v v) -5.0)) (+ (* v v) -1.0)))))
   (/
    (- (/ (* PI (* PI PI)) 8.0) (pow t_0 3.0))
    (+ (/ (* PI PI) 4.0) (* t_0 (+ t_0 (/ PI 2.0)))))))
double code(double v) {
	double t_0 = asin(((1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0)));
	return (((((double) M_PI) * (((double) M_PI) * ((double) M_PI))) / 8.0) - pow(t_0, 3.0)) / (((((double) M_PI) * ((double) M_PI)) / 4.0) + (t_0 * (t_0 + (((double) M_PI) / 2.0))));
}
public static double code(double v) {
	double t_0 = Math.asin(((1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0)));
	return (((Math.PI * (Math.PI * Math.PI)) / 8.0) - Math.pow(t_0, 3.0)) / (((Math.PI * Math.PI) / 4.0) + (t_0 * (t_0 + (Math.PI / 2.0))));
}
def code(v):
	t_0 = math.asin(((1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0)))
	return (((math.pi * (math.pi * math.pi)) / 8.0) - math.pow(t_0, 3.0)) / (((math.pi * math.pi) / 4.0) + (t_0 * (t_0 + (math.pi / 2.0))))
function code(v)
	t_0 = asin(Float64(Float64(1.0 + Float64(Float64(v * v) * -5.0)) / Float64(Float64(v * v) + -1.0)))
	return Float64(Float64(Float64(Float64(pi * Float64(pi * pi)) / 8.0) - (t_0 ^ 3.0)) / Float64(Float64(Float64(pi * pi) / 4.0) + Float64(t_0 * Float64(t_0 + Float64(pi / 2.0)))))
end
function tmp = code(v)
	t_0 = asin(((1.0 + ((v * v) * -5.0)) / ((v * v) + -1.0)));
	tmp = (((pi * (pi * pi)) / 8.0) - (t_0 ^ 3.0)) / (((pi * pi) / 4.0) + (t_0 * (t_0 + (pi / 2.0))));
end
code[v_] := Block[{t$95$0 = N[ArcSin[N[(N[(1.0 + N[(N[(v * v), $MachinePrecision] * -5.0), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[(N[(N[(Pi * N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] / 8.0), $MachinePrecision] - N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(Pi * Pi), $MachinePrecision] / 4.0), $MachinePrecision] + N[(t$95$0 * N[(t$95$0 + N[(Pi / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right)\\
\frac{\frac{\pi \cdot \left(\pi \cdot \pi\right)}{8} - {t\_0}^{3}}{\frac{\pi \cdot \pi}{4} + t\_0 \cdot \left(t\_0 + \frac{\pi}{2}\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\frac{\frac{\pi \cdot \left(\pi \cdot \pi\right)}{8} - {\sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right)}^{3}}{\frac{\pi \cdot \pi}{4} + \sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right) \cdot \left(\frac{\pi}{2} + \sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right)\right)}} \]
  4. Final simplification99.4%

    \[\leadsto \frac{\frac{\pi \cdot \left(\pi \cdot \pi\right)}{8} - {\sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right)}^{3}}{\frac{\pi \cdot \pi}{4} + \sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right) \cdot \left(\sin^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{v \cdot v + -1}\right) + \frac{\pi}{2}\right)} \]
  5. Add Preprocessing

Alternative 2: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \pi - \cos^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{1 - v \cdot v}\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (- PI (acos (/ (+ 1.0 (* (* v v) -5.0)) (- 1.0 (* v v))))))
double code(double v) {
	return ((double) M_PI) - acos(((1.0 + ((v * v) * -5.0)) / (1.0 - (v * v))));
}
public static double code(double v) {
	return Math.PI - Math.acos(((1.0 + ((v * v) * -5.0)) / (1.0 - (v * v))));
}
def code(v):
	return math.pi - math.acos(((1.0 + ((v * v) * -5.0)) / (1.0 - (v * v))))
function code(v)
	return Float64(pi - acos(Float64(Float64(1.0 + Float64(Float64(v * v) * -5.0)) / Float64(1.0 - Float64(v * v)))))
end
function tmp = code(v)
	tmp = pi - acos(((1.0 + ((v * v) * -5.0)) / (1.0 - (v * v))));
end
code[v_] := N[(Pi - N[ArcCos[N[(N[(1.0 + N[(N[(v * v), $MachinePrecision] * -5.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - N[(v * v), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi - \cos^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{1 - v \cdot v}\right)
\end{array}
Derivation
  1. Initial program 99.4%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-2negN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right) \]
    2. distribute-frac-negN/A

      \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)\right) \]
    3. acos-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    4. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI}\left(\right), \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)}\right) \]
    5. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \cos^{-1} \color{blue}{\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)}\right) \]
    6. acos-lowering-acos.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    8. sub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\left(1 + \left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    9. +-lowering-+.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\mathsf{neg}\left(\left(v \cdot v\right) \cdot 5\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    11. distribute-rgt-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\left(v \cdot v\right) \cdot \left(\mathsf{neg}\left(5\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(v \cdot v\right), \left(\mathsf{neg}\left(5\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), \left(\mathsf{neg}\left(5\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    14. metadata-evalN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    15. neg-sub0N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(0 - \left(v \cdot v - 1\right)\right)\right)\right)\right) \]
    16. associate--r-N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(\left(0 - v \cdot v\right) + 1\right)\right)\right)\right) \]
    17. neg-sub0N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(\left(\mathsf{neg}\left(v \cdot v\right)\right) + 1\right)\right)\right)\right) \]
    18. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(1 + \left(\mathsf{neg}\left(v \cdot v\right)\right)\right)\right)\right)\right) \]
    19. sub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(1 - v \cdot v\right)\right)\right)\right) \]
    20. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \mathsf{\_.f64}\left(1, \left(v \cdot v\right)\right)\right)\right)\right) \]
    21. *-lowering-*.f6499.4%

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \mathsf{\_.f64}\left(1, \mathsf{*.f64}\left(v, v\right)\right)\right)\right)\right) \]
  4. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\pi - \cos^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{1 - v \cdot v}\right)} \]
  5. Add Preprocessing

Alternative 3: 99.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right) \end{array} \]
(FPCore (v)
 :precision binary64
 (acos (/ (- 1.0 (* (* v v) 5.0)) (+ (* v v) -1.0))))
double code(double v) {
	return acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
real(8) function code(v)
    real(8), intent (in) :: v
    code = acos(((1.0d0 - ((v * v) * 5.0d0)) / ((v * v) + (-1.0d0))))
end function
public static double code(double v) {
	return Math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
}
def code(v):
	return math.acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)))
function code(v)
	return acos(Float64(Float64(1.0 - Float64(Float64(v * v) * 5.0)) / Float64(Float64(v * v) + -1.0)))
end
function tmp = code(v)
	tmp = acos(((1.0 - ((v * v) * 5.0)) / ((v * v) + -1.0)));
end
code[v_] := N[ArcCos[N[(N[(1.0 - N[(N[(v * v), $MachinePrecision] * 5.0), $MachinePrecision]), $MachinePrecision] / N[(N[(v * v), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right)
\end{array}
Derivation
  1. Initial program 99.4%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Final simplification99.4%

    \[\leadsto \cos^{-1} \left(\frac{1 - \left(v \cdot v\right) \cdot 5}{v \cdot v + -1}\right) \]
  4. Add Preprocessing

Alternative 4: 98.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\pi}{2} - \sin^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right) \end{array} \]
(FPCore (v) :precision binary64 (- (/ PI 2.0) (asin (+ -1.0 (* (* v v) 4.0)))))
double code(double v) {
	return (((double) M_PI) / 2.0) - asin((-1.0 + ((v * v) * 4.0)));
}
public static double code(double v) {
	return (Math.PI / 2.0) - Math.asin((-1.0 + ((v * v) * 4.0)));
}
def code(v):
	return (math.pi / 2.0) - math.asin((-1.0 + ((v * v) * 4.0)))
function code(v)
	return Float64(Float64(pi / 2.0) - asin(Float64(-1.0 + Float64(Float64(v * v) * 4.0))))
end
function tmp = code(v)
	tmp = (pi / 2.0) - asin((-1.0 + ((v * v) * 4.0)));
end
code[v_] := N[(N[(Pi / 2.0), $MachinePrecision] - N[ArcSin[N[(-1.0 + N[(N[(v * v), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\pi}{2} - \sin^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right)
\end{array}
Derivation
  1. Initial program 99.4%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Taylor expanded in v around 0

    \[\leadsto \mathsf{acos.f64}\left(\color{blue}{\left(4 \cdot {v}^{2} - 1\right)}\right) \]
  4. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \mathsf{acos.f64}\left(\left(4 \cdot {v}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
    2. metadata-evalN/A

      \[\leadsto \mathsf{acos.f64}\left(\left(4 \cdot {v}^{2} + -1\right)\right) \]
    3. +-commutativeN/A

      \[\leadsto \mathsf{acos.f64}\left(\left(-1 + 4 \cdot {v}^{2}\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \left(4 \cdot {v}^{2}\right)\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \left({v}^{2} \cdot 4\right)\right)\right) \]
    6. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \mathsf{*.f64}\left(\left(v \cdot v\right), 4\right)\right)\right) \]
    8. *-lowering-*.f6498.8%

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), 4\right)\right)\right) \]
  5. Simplified98.8%

    \[\leadsto \cos^{-1} \color{blue}{\left(-1 + \left(v \cdot v\right) \cdot 4\right)} \]
  6. Step-by-step derivation
    1. acos-asinN/A

      \[\leadsto \frac{\mathsf{PI}\left(\right)}{2} - \color{blue}{\sin^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right)} \]
    2. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\frac{\mathsf{PI}\left(\right)}{2}\right), \color{blue}{\sin^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right)}\right) \]
    3. /-lowering-/.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI}\left(\right), 2\right), \sin^{-1} \color{blue}{\left(-1 + \left(v \cdot v\right) \cdot 4\right)}\right) \]
    4. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \sin^{-1} \left(\color{blue}{-1} + \left(v \cdot v\right) \cdot 4\right)\right) \]
    5. asin-lowering-asin.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\left(-1 + \left(v \cdot v\right) \cdot 4\right)\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(-1, \left(\left(v \cdot v\right) \cdot 4\right)\right)\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(-1, \mathsf{*.f64}\left(\left(v \cdot v\right), 4\right)\right)\right)\right) \]
    8. *-lowering-*.f6498.8%

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{PI.f64}\left(\right), 2\right), \mathsf{asin.f64}\left(\mathsf{+.f64}\left(-1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), 4\right)\right)\right)\right) \]
  7. Applied egg-rr98.8%

    \[\leadsto \color{blue}{\frac{\pi}{2} - \sin^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right)} \]
  8. Add Preprocessing

Alternative 5: 98.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \pi - \cos^{-1} \left(1 + v \cdot \left(v \cdot -4\right)\right) \end{array} \]
(FPCore (v) :precision binary64 (- PI (acos (+ 1.0 (* v (* v -4.0))))))
double code(double v) {
	return ((double) M_PI) - acos((1.0 + (v * (v * -4.0))));
}
public static double code(double v) {
	return Math.PI - Math.acos((1.0 + (v * (v * -4.0))));
}
def code(v):
	return math.pi - math.acos((1.0 + (v * (v * -4.0))))
function code(v)
	return Float64(pi - acos(Float64(1.0 + Float64(v * Float64(v * -4.0)))))
end
function tmp = code(v)
	tmp = pi - acos((1.0 + (v * (v * -4.0))));
end
code[v_] := N[(Pi - N[ArcCos[N[(1.0 + N[(v * N[(v * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi - \cos^{-1} \left(1 + v \cdot \left(v \cdot -4\right)\right)
\end{array}
Derivation
  1. Initial program 99.4%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. frac-2negN/A

      \[\leadsto \cos^{-1} \left(\frac{\mathsf{neg}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right)\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right) \]
    2. distribute-frac-negN/A

      \[\leadsto \cos^{-1} \left(\mathsf{neg}\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)\right) \]
    3. acos-negN/A

      \[\leadsto \mathsf{PI}\left(\right) - \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)} \]
    4. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI}\left(\right), \color{blue}{\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)}\right) \]
    5. PI-lowering-PI.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \cos^{-1} \color{blue}{\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)}\right) \]
    6. acos-lowering-acos.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)}\right)\right)\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\left(1 - 5 \cdot \left(v \cdot v\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    8. sub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\left(1 + \left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    9. +-lowering-+.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\mathsf{neg}\left(5 \cdot \left(v \cdot v\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    10. *-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\mathsf{neg}\left(\left(v \cdot v\right) \cdot 5\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    11. distribute-rgt-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \left(\left(v \cdot v\right) \cdot \left(\mathsf{neg}\left(5\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(v \cdot v\right), \left(\mathsf{neg}\left(5\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), \left(\mathsf{neg}\left(5\right)\right)\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    14. metadata-evalN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(\mathsf{neg}\left(\left(v \cdot v - 1\right)\right)\right)\right)\right)\right) \]
    15. neg-sub0N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(0 - \left(v \cdot v - 1\right)\right)\right)\right)\right) \]
    16. associate--r-N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(\left(0 - v \cdot v\right) + 1\right)\right)\right)\right) \]
    17. neg-sub0N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(\left(\mathsf{neg}\left(v \cdot v\right)\right) + 1\right)\right)\right)\right) \]
    18. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(1 + \left(\mathsf{neg}\left(v \cdot v\right)\right)\right)\right)\right)\right) \]
    19. sub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \left(1 - v \cdot v\right)\right)\right)\right) \]
    20. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \mathsf{\_.f64}\left(1, \left(v \cdot v\right)\right)\right)\right)\right) \]
    21. *-lowering-*.f6499.4%

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), -5\right)\right), \mathsf{\_.f64}\left(1, \mathsf{*.f64}\left(v, v\right)\right)\right)\right)\right) \]
  4. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\pi - \cos^{-1} \left(\frac{1 + \left(v \cdot v\right) \cdot -5}{1 - v \cdot v}\right)} \]
  5. Taylor expanded in v around 0

    \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\color{blue}{\left(1 + -4 \cdot {v}^{2}\right)}\right)\right) \]
  6. Step-by-step derivation
    1. +-lowering-+.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{+.f64}\left(1, \left(-4 \cdot {v}^{2}\right)\right)\right)\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{+.f64}\left(1, \left(-4 \cdot \left(v \cdot v\right)\right)\right)\right)\right) \]
    3. associate-*r*N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{+.f64}\left(1, \left(\left(-4 \cdot v\right) \cdot v\right)\right)\right)\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{+.f64}\left(1, \left(v \cdot \left(-4 \cdot v\right)\right)\right)\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(v, \left(-4 \cdot v\right)\right)\right)\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(v, \left(v \cdot -4\right)\right)\right)\right)\right) \]
    7. *-lowering-*.f6498.8%

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{PI.f64}\left(\right), \mathsf{acos.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(v, \mathsf{*.f64}\left(v, -4\right)\right)\right)\right)\right) \]
  7. Simplified98.8%

    \[\leadsto \pi - \cos^{-1} \color{blue}{\left(1 + v \cdot \left(v \cdot -4\right)\right)} \]
  8. Add Preprocessing

Alternative 6: 98.6% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \cos^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right) \end{array} \]
(FPCore (v) :precision binary64 (acos (+ -1.0 (* (* v v) 4.0))))
double code(double v) {
	return acos((-1.0 + ((v * v) * 4.0)));
}
real(8) function code(v)
    real(8), intent (in) :: v
    code = acos(((-1.0d0) + ((v * v) * 4.0d0)))
end function
public static double code(double v) {
	return Math.acos((-1.0 + ((v * v) * 4.0)));
}
def code(v):
	return math.acos((-1.0 + ((v * v) * 4.0)))
function code(v)
	return acos(Float64(-1.0 + Float64(Float64(v * v) * 4.0)))
end
function tmp = code(v)
	tmp = acos((-1.0 + ((v * v) * 4.0)));
end
code[v_] := N[ArcCos[N[(-1.0 + N[(N[(v * v), $MachinePrecision] * 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} \left(-1 + \left(v \cdot v\right) \cdot 4\right)
\end{array}
Derivation
  1. Initial program 99.4%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Taylor expanded in v around 0

    \[\leadsto \mathsf{acos.f64}\left(\color{blue}{\left(4 \cdot {v}^{2} - 1\right)}\right) \]
  4. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \mathsf{acos.f64}\left(\left(4 \cdot {v}^{2} + \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
    2. metadata-evalN/A

      \[\leadsto \mathsf{acos.f64}\left(\left(4 \cdot {v}^{2} + -1\right)\right) \]
    3. +-commutativeN/A

      \[\leadsto \mathsf{acos.f64}\left(\left(-1 + 4 \cdot {v}^{2}\right)\right) \]
    4. +-lowering-+.f64N/A

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \left(4 \cdot {v}^{2}\right)\right)\right) \]
    5. *-commutativeN/A

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \left({v}^{2} \cdot 4\right)\right)\right) \]
    6. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \mathsf{*.f64}\left(\left(v \cdot v\right), 4\right)\right)\right) \]
    8. *-lowering-*.f6498.8%

      \[\leadsto \mathsf{acos.f64}\left(\mathsf{+.f64}\left(-1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(v, v\right), 4\right)\right)\right) \]
  5. Simplified98.8%

    \[\leadsto \cos^{-1} \color{blue}{\left(-1 + \left(v \cdot v\right) \cdot 4\right)} \]
  6. Add Preprocessing

Alternative 7: 97.9% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \cos^{-1} -1 \end{array} \]
(FPCore (v) :precision binary64 (acos -1.0))
double code(double v) {
	return acos(-1.0);
}
real(8) function code(v)
    real(8), intent (in) :: v
    code = acos((-1.0d0))
end function
public static double code(double v) {
	return Math.acos(-1.0);
}
def code(v):
	return math.acos(-1.0)
function code(v)
	return acos(-1.0)
end
function tmp = code(v)
	tmp = acos(-1.0);
end
code[v_] := N[ArcCos[-1.0], $MachinePrecision]
\begin{array}{l}

\\
\cos^{-1} -1
\end{array}
Derivation
  1. Initial program 99.4%

    \[\cos^{-1} \left(\frac{1 - 5 \cdot \left(v \cdot v\right)}{v \cdot v - 1}\right) \]
  2. Add Preprocessing
  3. Taylor expanded in v around 0

    \[\leadsto \mathsf{acos.f64}\left(\color{blue}{-1}\right) \]
  4. Step-by-step derivation
    1. Simplified98.2%

      \[\leadsto \cos^{-1} \color{blue}{-1} \]
    2. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2024158 
    (FPCore (v)
      :name "Falkner and Boettcher, Appendix B, 1"
      :precision binary64
      (acos (/ (- 1.0 (* 5.0 (* v v))) (- (* v v) 1.0))))