Average Error: 28.2 → 8.4
Time: 19.5s
Precision: 64
Internal Precision: 128
\[\frac{\cos \left(2 \cdot x\right)}{{cos}^{2} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
\[\begin{array}{l} \mathbf{if}\;x \le -61357.354317215366 \lor \neg \left(x \le -9.238259325850402 \cdot 10^{-152}\right):\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(\left(cos \cdot \left(sin \cdot x\right)\right) \cdot sin\right)\right) \cdot cos}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x \cdot x}}{\left(sin \cdot cos\right) \cdot \left(sin \cdot cos\right)} + (\left(\frac{\frac{2}{3}}{\left(sin \cdot cos\right) \cdot \left(sin \cdot cos\right)}\right) \cdot \left(x \cdot x\right) + \left(\frac{-2}{\left(sin \cdot cos\right) \cdot \left(sin \cdot cos\right)}\right))_*\\ \end{array}\]

Error

Bits error versus x

Bits error versus cos

Bits error versus sin

Derivation

  1. Split input into 2 regimes
  2. if x < -61357.354317215366 or -9.238259325850402e-152 < x

    1. Initial program 28.3

      \[\frac{\cos \left(2 \cdot x\right)}{{cos}^{2} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
    2. Using strategy rm
    3. Applied unpow228.3

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(cos \cdot cos\right)} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
    4. Applied associate-*l*23.8

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{cos \cdot \left(cos \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)\right)}}\]
    5. Using strategy rm
    6. Applied unpow223.8

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{cos \cdot \left(cos \cdot \left(\left(x \cdot \color{blue}{\left(sin \cdot sin\right)}\right) \cdot x\right)\right)}\]
    7. Applied associate-*r*15.9

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{cos \cdot \left(cos \cdot \left(\color{blue}{\left(\left(x \cdot sin\right) \cdot sin\right)} \cdot x\right)\right)}\]
    8. Using strategy rm
    9. Applied associate-*r*13.1

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{cos \cdot \color{blue}{\left(\left(cos \cdot \left(\left(x \cdot sin\right) \cdot sin\right)\right) \cdot x\right)}}\]
    10. Using strategy rm
    11. Applied associate-*r*8.3

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{cos \cdot \left(\color{blue}{\left(\left(cos \cdot \left(x \cdot sin\right)\right) \cdot sin\right)} \cdot x\right)}\]

    if -61357.354317215366 < x < -9.238259325850402e-152

    1. Initial program 27.4

      \[\frac{\cos \left(2 \cdot x\right)}{{cos}^{2} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
    2. Using strategy rm
    3. Applied unpow227.4

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(cos \cdot cos\right)} \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)}\]
    4. Applied associate-*l*23.8

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{\color{blue}{cos \cdot \left(cos \cdot \left(\left(x \cdot {sin}^{2}\right) \cdot x\right)\right)}}\]
    5. Using strategy rm
    6. Applied unpow223.8

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{cos \cdot \left(cos \cdot \left(\left(x \cdot \color{blue}{\left(sin \cdot sin\right)}\right) \cdot x\right)\right)}\]
    7. Applied associate-*r*21.0

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{cos \cdot \left(cos \cdot \left(\color{blue}{\left(\left(x \cdot sin\right) \cdot sin\right)} \cdot x\right)\right)}\]
    8. Using strategy rm
    9. Applied associate-*r*18.0

      \[\leadsto \frac{\cos \left(2 \cdot x\right)}{cos \cdot \color{blue}{\left(\left(cos \cdot \left(\left(x \cdot sin\right) \cdot sin\right)\right) \cdot x\right)}}\]
    10. Taylor expanded around 0 27.7

      \[\leadsto \color{blue}{\left(\frac{1}{{x}^{2} \cdot \left({sin}^{2} \cdot {cos}^{2}\right)} + \frac{2}{3} \cdot \frac{{x}^{2}}{{sin}^{2} \cdot {cos}^{2}}\right) - 2 \cdot \frac{1}{{sin}^{2} \cdot {cos}^{2}}}\]
    11. Simplified9.9

      \[\leadsto \color{blue}{(\left(\frac{\frac{2}{3}}{\left(cos \cdot sin\right) \cdot \left(cos \cdot sin\right)}\right) \cdot \left(x \cdot x\right) + \left(\frac{-2}{\left(cos \cdot sin\right) \cdot \left(cos \cdot sin\right)}\right))_* + \frac{\frac{1}{x \cdot x}}{\left(cos \cdot sin\right) \cdot \left(cos \cdot sin\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification8.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -61357.354317215366 \lor \neg \left(x \le -9.238259325850402 \cdot 10^{-152}\right):\\ \;\;\;\;\frac{\cos \left(2 \cdot x\right)}{\left(x \cdot \left(\left(cos \cdot \left(sin \cdot x\right)\right) \cdot sin\right)\right) \cdot cos}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x \cdot x}}{\left(sin \cdot cos\right) \cdot \left(sin \cdot cos\right)} + (\left(\frac{\frac{2}{3}}{\left(sin \cdot cos\right) \cdot \left(sin \cdot cos\right)}\right) \cdot \left(x \cdot x\right) + \left(\frac{-2}{\left(sin \cdot cos\right) \cdot \left(sin \cdot cos\right)}\right))_*\\ \end{array}\]

Reproduce

herbie shell --seed 2019004 +o rules:numerics
(FPCore (x cos sin)
  :name "cos(2*x)/(cos^2(x)*sin^2(x))"
  (/ (cos (* 2 x)) (* (pow cos 2) (* (* x (pow sin 2)) x))))

Details

Time bar (total: 17.6s)Debug log

sample138.0ms

Algorithm
intervals

simplify163.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

163.0ms
(/ (cos (* 2 x)) (* (pow cos 2) (* (* x (pow sin 2)) x)))

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 26.9b

localize25.0ms

Local error

Found 4 expressions with local error:

20.1b
(* (pow cos 2) (* (* x (pow sin 2)) x))
5.9b
(* x (pow sin 2))
3.4b
(* (* x (pow sin 2)) x)
0.9b
(/ (cos (* 2 x)) (* (pow cos 2) (* (* x (pow sin 2)) x)))

rewrite25.0ms

Algorithm
rewrite-expression-head
Counts
4 → 68
Calls

4 calls. Slowest were:

10.0ms
(/ (cos (* 2 x)) (* (pow cos 2) (* (* x (pow sin 2)) x)))
9.0ms
(* (pow cos 2) (* (* x (pow sin 2)) x))
4.0ms
(* (* x (pow sin 2)) x)

series122.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

53.0ms
(/ (cos (* 2 x)) (* (pow cos 2) (* (* x (pow sin 2)) x)))
37.0ms
(* (pow cos 2) (* (* x (pow sin 2)) x))
16.0ms
(* (* x (pow sin 2)) x)
16.0ms
(* x (pow sin 2))

simplify2.4s

Counts
35 → 80
Calls

35 calls. Slowest were:

430.0ms
(* (* (* (pow cos 2) (pow cos 2)) (pow cos 2)) (* (* (* (* x (pow sin 2)) x) (* (* x (pow sin 2)) x)) (* (* x (pow sin 2)) x)))
200.0ms
(- (log (cos (* 2 x))) (log (* (pow cos 2) (* (* x (pow sin 2)) x))))
200.0ms
(- (+ (/ 1 (* (pow x 2) (* (pow sin 2) (pow cos 2)))) (* 2/3 (/ (pow x 2) (* (pow sin 2) (pow cos 2))))) (* 2 (/ 1 (* (pow sin 2) (pow cos 2)))))

prune776.0ms

Pruning

13 alts after pruning (13 fresh and 0 done)

Merged error: 11.7b

localize9.0ms

Local error

Found 4 expressions with local error:

7.7b
(* cos (* cos (* (* x (pow sin 2)) x)))
5.9b
(* x (pow sin 2))
5.1b
(* cos (* (* x (pow sin 2)) x))
3.4b
(* (* x (pow sin 2)) x)

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 47
Calls

4 calls. Slowest were:

9.0ms
(* cos (* cos (* (* x (pow sin 2)) x)))
4.0ms
(* cos (* (* x (pow sin 2)) x))
3.0ms
(* (* x (pow sin 2)) x)

series103.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

36.0ms
(* cos (* cos (* (* x (pow sin 2)) x)))
35.0ms
(* cos (* (* x (pow sin 2)) x))
16.0ms
(* (* x (pow sin 2)) x)
16.0ms
(* x (pow sin 2))

simplify405.0ms

Counts
16 → 59
Calls

16 calls. Slowest were:

87.0ms
(* (pow x 2) (* (pow sin 2) (pow cos 2)))
76.0ms
(* (pow x 2) (* (pow sin 2) (pow cos 2)))
75.0ms
(* (pow x 2) (* (pow sin 2) (pow cos 2)))

prune618.0ms

Pruning

14 alts after pruning (14 fresh and 0 done)

Merged error: 8.3b

localize16.0ms

Local error

Found 4 expressions with local error:

7.7b
(* cos (* cos (* (* (* x sin) sin) x)))
5.1b
(* cos (* (* (* x sin) sin) x))
3.4b
(* (* (* x sin) sin) x)
0.9b
(/ (cos (* 2 x)) (* cos (* cos (* (* (* x sin) sin) x))))

rewrite40.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

13.0ms
(* cos (* cos (* (* (* x sin) sin) x)))
12.0ms
(/ (cos (* 2 x)) (* cos (* cos (* (* (* x sin) sin) x))))
8.0ms
(* (* (* x sin) sin) x)

series207.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

78.0ms
(/ (cos (* 2 x)) (* cos (* cos (* (* (* x sin) sin) x))))
57.0ms
(* cos (* (* (* x sin) sin) x))
43.0ms
(* cos (* cos (* (* (* x sin) sin) x)))
28.0ms
(* (* (* x sin) sin) x)

simplify1.9s

Counts
26 → 67
Calls

26 calls. Slowest were:

309.0ms
(- (+ (/ 1 (* (pow x 2) (* (pow sin 2) (pow cos 2)))) (* 2/3 (/ (pow x 2) (* (pow sin 2) (pow cos 2))))) (* 2 (/ 1 (* (pow sin 2) (pow cos 2)))))
246.0ms
(/ (cos (* 2 x)) (* (pow cos 2) (* (pow x 2) (pow sin 2))))
215.0ms
(/ (cos (* 2 x)) (* (pow cos 2) (* (pow x 2) (pow sin 2))))

prune764.0ms

Pruning

15 alts after pruning (15 fresh and 0 done)

Merged error: 6.2b

localize11.0ms

Local error

Found 4 expressions with local error:

7.7b
(* cos (* (* cos (* (* x sin) sin)) x))
7.1b
(* cos (* (* x sin) sin))
3.4b
(* (* cos (* (* x sin) sin)) x)
0.9b
(/ (cos (* 2 x)) (* cos (* (* cos (* (* x sin) sin)) x)))

rewrite289.0ms

Algorithm
rewrite-expression-head
Counts
4 → 55
Calls

4 calls. Slowest were:

267.0ms
(/ (cos (* 2 x)) (* cos (* (* cos (* (* x sin) sin)) x)))
12.0ms
(* cos (* (* cos (* (* x sin) sin)) x))
7.0ms
(* (* cos (* (* x sin) sin)) x)

series156.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

50.0ms
(/ (cos (* 2 x)) (* cos (* (* cos (* (* x sin) sin)) x)))
38.0ms
(* (* cos (* (* x sin) sin)) x)
36.0ms
(* cos (* (* cos (* (* x sin) sin)) x))
32.0ms
(* cos (* (* x sin) sin))

simplify2.3s

Counts
24 → 67
Calls

24 calls. Slowest were:

308.0ms
(/ (* (cos x) (cos x)) (* cos (* (* cos (* (* x sin) sin)) x)))
292.0ms
(- (+ (/ 1 (* (pow x 2) (* (pow sin 2) (pow cos 2)))) (* 2/3 (/ (pow x 2) (* (pow sin 2) (pow cos 2))))) (* 2 (/ 1 (* (pow sin 2) (pow cos 2)))))
278.0ms
(/ (cos (* 2 x)) (* (pow cos 2) (* (pow x 2) (pow sin 2))))

prune771.0ms

Pruning

16 alts after pruning (16 fresh and 0 done)

Merged error: 5.0b

regimes699.0ms

Accuracy

-3.7% (5.0b remaining)

Error of 8.4b against oracle of 3.4b and baseline of 8.3b

bsearch444.0ms

end0.0ms

sample5.3s

Algorithm
intervals