?

Average Error: 1.0 → 0.0
Time: 45.6s
Precision: binary64
Cost: 59712

?

\[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
\[\begin{array}{l} t_0 := \cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right)\\ 2 \cdot \frac{2 \cdot t_0 - \left(t_0 + \cos \left(\left(\cos^{-1} \left(\frac{g}{-h}\right) - \pi\right) \cdot -0.3333333333333333\right)\right)}{2} \end{array} \]
(FPCore (g h)
 :precision binary64
 (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
(FPCore (g h)
 :precision binary64
 (let* ((t_0 (cos (* 0.3333333333333333 (+ (acos (/ (- g) h)) (* PI 2.0))))))
   (*
    2.0
    (/
     (-
      (* 2.0 t_0)
      (+ t_0 (cos (* (- (acos (/ g (- h))) PI) -0.3333333333333333))))
     2.0))))
double code(double g, double h) {
	return 2.0 * cos((((2.0 * ((double) M_PI)) / 3.0) + (acos((-g / h)) / 3.0)));
}
double code(double g, double h) {
	double t_0 = cos((0.3333333333333333 * (acos((-g / h)) + (((double) M_PI) * 2.0))));
	return 2.0 * (((2.0 * t_0) - (t_0 + cos(((acos((g / -h)) - ((double) M_PI)) * -0.3333333333333333)))) / 2.0);
}
public static double code(double g, double h) {
	return 2.0 * Math.cos((((2.0 * Math.PI) / 3.0) + (Math.acos((-g / h)) / 3.0)));
}
public static double code(double g, double h) {
	double t_0 = Math.cos((0.3333333333333333 * (Math.acos((-g / h)) + (Math.PI * 2.0))));
	return 2.0 * (((2.0 * t_0) - (t_0 + Math.cos(((Math.acos((g / -h)) - Math.PI) * -0.3333333333333333)))) / 2.0);
}
def code(g, h):
	return 2.0 * math.cos((((2.0 * math.pi) / 3.0) + (math.acos((-g / h)) / 3.0)))
def code(g, h):
	t_0 = math.cos((0.3333333333333333 * (math.acos((-g / h)) + (math.pi * 2.0))))
	return 2.0 * (((2.0 * t_0) - (t_0 + math.cos(((math.acos((g / -h)) - math.pi) * -0.3333333333333333)))) / 2.0)
function code(g, h)
	return Float64(2.0 * cos(Float64(Float64(Float64(2.0 * pi) / 3.0) + Float64(acos(Float64(Float64(-g) / h)) / 3.0))))
end
function code(g, h)
	t_0 = cos(Float64(0.3333333333333333 * Float64(acos(Float64(Float64(-g) / h)) + Float64(pi * 2.0))))
	return Float64(2.0 * Float64(Float64(Float64(2.0 * t_0) - Float64(t_0 + cos(Float64(Float64(acos(Float64(g / Float64(-h))) - pi) * -0.3333333333333333)))) / 2.0))
end
function tmp = code(g, h)
	tmp = 2.0 * cos((((2.0 * pi) / 3.0) + (acos((-g / h)) / 3.0)));
end
function tmp = code(g, h)
	t_0 = cos((0.3333333333333333 * (acos((-g / h)) + (pi * 2.0))));
	tmp = 2.0 * (((2.0 * t_0) - (t_0 + cos(((acos((g / -h)) - pi) * -0.3333333333333333)))) / 2.0);
end
code[g_, h_] := N[(2.0 * N[Cos[N[(N[(N[(2.0 * Pi), $MachinePrecision] / 3.0), $MachinePrecision] + N[(N[ArcCos[N[((-g) / h), $MachinePrecision]], $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[g_, h_] := Block[{t$95$0 = N[Cos[N[(0.3333333333333333 * N[(N[ArcCos[N[((-g) / h), $MachinePrecision]], $MachinePrecision] + N[(Pi * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(2.0 * N[(N[(N[(2.0 * t$95$0), $MachinePrecision] - N[(t$95$0 + N[Cos[N[(N[(N[ArcCos[N[(g / (-h)), $MachinePrecision]], $MachinePrecision] - Pi), $MachinePrecision] * -0.3333333333333333), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]]
2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\begin{array}{l}
t_0 := \cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right)\\
2 \cdot \frac{2 \cdot t_0 - \left(t_0 + \cos \left(\left(\cos^{-1} \left(\frac{g}{-h}\right) - \pi\right) \cdot -0.3333333333333333\right)\right)}{2}
\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 1.0

    \[2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]
  2. Simplified1.0

    \[\leadsto \color{blue}{2 \cdot \cos \left(\frac{2 \cdot \pi + \cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)} \]
    Proof

    [Start]1.0

    \[ 2 \cdot \cos \left(\frac{2 \cdot \pi}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]

    rational_best-simplify-64 [=>]1.0

    \[ 2 \cdot \cos \color{blue}{\left(\frac{2 \cdot \pi + \cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)} \]
  3. Applied egg-rr1.0

    \[\leadsto 2 \cdot \cos \left(\frac{\color{blue}{2 \cdot \cos^{-1} \left(\frac{-g}{h}\right) - \left(\frac{\pi}{-0.5} + \cos^{-1} \left(\frac{-g}{h}\right)\right)}}{3}\right) \]
  4. Applied egg-rr1.0

    \[\leadsto 2 \cdot \cos \color{blue}{\left(\frac{\pi}{3} + \left(\frac{\cos^{-1} \left(\frac{g}{-h}\right)}{3} + \frac{\pi}{3}\right)\right)} \]
  5. Applied egg-rr1.0

    \[\leadsto 2 \cdot \color{blue}{\frac{\left(\cos \left(\left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right) \cdot 0.3333333333333333\right) + \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{-3}\right)\right) - \left(\cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{-3}\right) + \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{-3} + \left(\pi - \left(\pi \cdot 0.3333333333333333\right) \cdot 2\right)\right)\right)}{2}} \]
  6. Simplified0.0

    \[\leadsto 2 \cdot \color{blue}{\frac{2 \cdot \cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right) - \left(\cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right) + \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right) - \pi}{-3}\right)\right)}{2}} \]
    Proof

    [Start]1.0

    \[ 2 \cdot \frac{\left(\cos \left(\left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right) \cdot 0.3333333333333333\right) + \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{-3}\right)\right) - \left(\cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{-3}\right) + \cos \left(\frac{\cos^{-1} \left(\frac{-g}{h}\right)}{-3} + \left(\pi - \left(\pi \cdot 0.3333333333333333\right) \cdot 2\right)\right)\right)}{2} \]
  7. Applied egg-rr0.0

    \[\leadsto 2 \cdot \frac{2 \cdot \cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right) - \left(\cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right) + \cos \color{blue}{\left(\left(\cos^{-1} \left(\frac{g}{-h}\right) - \pi\right) \cdot -0.3333333333333333\right)}\right)}{2} \]
  8. Final simplification0.0

    \[\leadsto 2 \cdot \frac{2 \cdot \cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right) - \left(\cos \left(0.3333333333333333 \cdot \left(\cos^{-1} \left(\frac{-g}{h}\right) + \pi \cdot 2\right)\right) + \cos \left(\left(\cos^{-1} \left(\frac{g}{-h}\right) - \pi\right) \cdot -0.3333333333333333\right)\right)}{2} \]

Alternatives

Alternative 1
Error1.0
Cost26752
\[\begin{array}{l} t_0 := \cos^{-1} \left(\frac{-g}{h}\right)\\ 2 \cdot \cos \left(\frac{2 \cdot t_0 - \left(\frac{\pi}{-0.5} + t_0\right)}{3}\right) \end{array} \]
Alternative 2
Error1.0
Cost19904
\[2 \cdot \cos \left(\frac{2 \cdot \pi + \cos^{-1} \left(\frac{-g}{h}\right)}{3}\right) \]

Error

Reproduce?

herbie shell --seed 2023099 
(FPCore (g h)
  :name "2-ancestry mixing, negative discriminant"
  :precision binary64
  (* 2.0 (cos (+ (/ (* 2.0 PI) 3.0) (/ (acos (/ (- g) h)) 3.0)))))