Average Error: 30.7 → 0.3
Time: 24.9s
Precision: 64
Internal Precision: 128
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.012791786131647819 \lor \neg \left(x \le 0.00019298388935161008\right):\\ \;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \frac{\sin x}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;(\frac{1}{720} \cdot \left({x}^{4}\right) + \left((\left(\frac{-1}{24} \cdot x\right) \cdot x + \frac{1}{2})_*\right))_*\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -0.012791786131647819 or 0.00019298388935161008 < x

    1. Initial program 1.0

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied flip--1.2

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{x \cdot x}\]
    4. Applied associate-/l/1.2

      \[\leadsto \color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)}}\]
    5. Simplified1.0

      \[\leadsto \frac{\color{blue}{\sin x \cdot \sin x}}{\left(x \cdot x\right) \cdot \left(1 + \cos x\right)}\]
    6. Using strategy rm
    7. Applied times-frac1.0

      \[\leadsto \color{blue}{\frac{\sin x}{x \cdot x} \cdot \frac{\sin x}{1 + \cos x}}\]
    8. Simplified0.7

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

    if -0.012791786131647819 < x < 0.00019298388935161008

    1. Initial program 61.5

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\left(\frac{1}{720} \cdot {x}^{4} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}}\]
    3. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.012791786131647819 \lor \neg \left(x \le 0.00019298388935161008\right):\\ \;\;\;\;\tan \left(\frac{x}{2}\right) \cdot \frac{\sin x}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;(\frac{1}{720} \cdot \left({x}^{4}\right) + \left((\left(\frac{-1}{24} \cdot x\right) \cdot x + \frac{1}{2})_*\right))_*\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1 (cos x)) (* x x)))

Details

Time bar (total: 24.2s)Debug log

sample128.0ms

Algorithm
intervals
Results
256×(pre true 80)
76×(body real 80)
47×(body real 2560)
45×(body real 640)
42×(body real 1280)
31×(body real 320)
15×(body real 160)

simplify13.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
13.0ms
(/ (- 1 (cos x)) (* x x))

prune34.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.4b

localize26.0ms

Local error

Found 2 expressions with local error:

14.4b
(/ (- 1 (cos x)) (* x x))
1.9b
(- 1 (cos x))

rewrite11.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
add-exp-log
add-cbrt-cube
*-un-lft-identity
add-sqr-sqrt
associate-/l*
times-frac
associate-/l/
add-log-exp
flip--
log1p-expm1-u
flip3--
pow1
expm1-log1p-u
div-inv
div-exp
div-sub
frac-2neg
sub-neg
associate-/r*
clear-num
cbrt-undiv
Counts
2 → 37
Calls
2 calls:
Slowest
8.0ms
(/ (- 1 (cos x)) (* x x))
2.0ms
(- 1 (cos x))

series81.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
51.0ms
(/ (- 1 (cos x)) (* x x))
29.0ms
(- 1 (cos x))

simplify754.0ms

Counts
19 → 43
Calls
19 calls:
Slowest
367.0ms
(/ (* (* (- 1 (cos x)) (- 1 (cos x))) (- 1 (cos x))) (* (* (* x x) (* x x)) (* x x)))
83.0ms
(- (+ (* 1/720 (pow x 4)) 1/2) (* 1/24 (pow x 2)))
77.0ms
(- (+ (* 1/2 (pow x 2)) (* 1/720 (pow x 6))) (* 1/24 (pow x 4)))
46.0ms
(- (log (- 1 (cos x))) (log (* x x)))
30.0ms
(/ (- 1 (cos x)) (pow x 2))

prune389.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 0.0b

localize29.0ms

Local error

Found 4 expressions with local error:

14.3b
(/ (* (sin x) (sin x)) (* (* x x) (+ 1 (cos x))))
0.4b
(+ 1 (cos x))
0.3b
(* (sin x) (sin x))
0.1b
(* (* x x) (+ 1 (cos x)))

rewrite36.0ms

Algorithm
rewrite-expression-head
Rules
20×add-exp-log
20×add-cbrt-cube
11×pow1
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
cbrt-unprod
prod-exp
associate-*r*
add-log-exp
log1p-expm1-u
associate-*r/
associate-*l*
div-exp
cbrt-undiv
expm1-log1p-u
flip-+
flip3-+
sin-mult
sqr-sin
*-commutative
associate-/r/
pow-prod-down
associate-/l/
associate-/l*
div-inv
pow-prod-up
div-sub
pow-plus
times-frac
distribute-lft-in
frac-2neg
associate-/r*
clear-num
+-commutative
distribute-rgt-in
pow2
Counts
4 → 84
Calls
4 calls:
Slowest
18.0ms
(/ (* (sin x) (sin x)) (* (* x x) (+ 1 (cos x))))
7.0ms
(* (* x x) (+ 1 (cos x)))
7.0ms
(* (sin x) (sin x))
2.0ms
(+ 1 (cos x))

series99.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
55.0ms
(/ (* (sin x) (sin x)) (* (* x x) (+ 1 (cos x))))
20.0ms
(* (* x x) (+ 1 (cos x)))
16.0ms
(* (sin x) (sin x))
9.0ms
(+ 1 (cos x))

simplify4.2s

Counts
51 → 96
Calls
51 calls:
Slowest
438.0ms
(/ (* (* (* (sin x) (sin x)) (* (sin x) (sin x))) (* (sin x) (sin x))) (* (* (* (* x x) (+ 1 (cos x))) (* (* x x) (+ 1 (cos x)))) (* (* x x) (+ 1 (cos x)))))
420.0ms
(/ (* (* (* (sin x) (sin x)) (sin x)) (* (* (sin x) (sin x)) (sin x))) (* (* (* (* x x) (+ 1 (cos x))) (* (* x x) (+ 1 (cos x)))) (* (* x x) (+ 1 (cos x)))))
347.0ms
(/ (* (* (* (sin x) (sin x)) (sin x)) (* (* (sin x) (sin x)) (sin x))) (* (* (* (* x x) (* x x)) (* x x)) (* (* (+ 1 (cos x)) (+ 1 (cos x))) (+ 1 (cos x)))))
321.0ms
(/ (pow (sin x) 2) (* (pow x 2) (+ (cos x) 1)))
309.0ms
(/ (* (* (* (sin x) (sin x)) (* (sin x) (sin x))) (* (sin x) (sin x))) (* (* (* (* x x) (* x x)) (* x x)) (* (* (+ 1 (cos x)) (+ 1 (cos x))) (+ 1 (cos x)))))

prune945.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 0.0b

localize11.0ms

Local error

Found 4 expressions with local error:

14.3b
(/ (* (* x x) (+ 1 (cos x))) (* (sin x) (sin x)))
0.4b
(+ 1 (cos x))
0.3b
(* (sin x) (sin x))
0.1b
(* (* x x) (+ 1 (cos x)))

rewrite38.0ms

Algorithm
rewrite-expression-head
Rules
20×add-exp-log
20×add-cbrt-cube
11×pow1
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
cbrt-unprod
prod-exp
associate-*r*
add-log-exp
log1p-expm1-u
associate-*r/
associate-*l*
div-exp
cbrt-undiv
expm1-log1p-u
flip-+
flip3-+
associate-/l/
sin-mult
*-commutative
pow-prod-down
associate-/l*
div-inv
sqr-sin
pow-prod-up
associate-/r/
pow-plus
times-frac
distribute-lft-in
frac-2neg
associate-/r*
clear-num
+-commutative
distribute-rgt-in
pow2
Counts
4 → 83
Calls
4 calls:
Slowest
17.0ms
(/ (* (* x x) (+ 1 (cos x))) (* (sin x) (sin x)))
10.0ms
(* (* x x) (+ 1 (cos x)))
8.0ms
(* (sin x) (sin x))
2.0ms
(+ 1 (cos x))

series140.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
69.0ms
(/ (* (* x x) (+ 1 (cos x))) (* (sin x) (sin x)))
29.0ms
(* (* x x) (+ 1 (cos x)))
26.0ms
(* (sin x) (sin x))
15.0ms
(+ 1 (cos x))

simplify4.7s

Counts
49 → 95
Calls
49 calls:
Slowest
601.0ms
(/ (* (pow x 2) (+ (cos x) 1)) (pow (sin x) 2))
578.0ms
(/ (* (pow x 2) (+ (cos x) 1)) (pow (sin x) 2))
427.0ms
(/ (* (* (* (* x x) (+ 1 (cos x))) (* (* x x) (+ 1 (cos x)))) (* (* x x) (+ 1 (cos x)))) (* (* (* (sin x) (sin x)) (* (sin x) (sin x))) (* (sin x) (sin x))))
388.0ms
(/ (* (* (* (* x x) (+ 1 (cos x))) (* (* x x) (+ 1 (cos x)))) (* (* x x) (+ 1 (cos x)))) (* (* (* (sin x) (sin x)) (sin x)) (* (* (sin x) (sin x)) (sin x))))
326.0ms
(* (* x x) (- (* 1 1) (* (cos x) (cos x))))

prune769.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.0b

localize9.0ms

Local error

Found 4 expressions with local error:

28.1b
(sqrt (* (* x x) (+ 1 (cos x))))
28.1b
(sqrt (* (* x x) (+ 1 (cos x))))
14.3b
(/ (* (sin x) (sin x)) (* (sqrt (* (* x x) (+ 1 (cos x)))) (sqrt (* (* x x) (+ 1 (cos x))))))
0.4b
(+ 1 (cos x))

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
18×associate-*r/
16×add-exp-log
16×sqrt-div
16×add-cbrt-cube
flip-+
flip3-+
associate-/r/
add-log-exp
log1p-expm1-u
cbrt-unprod
add-cube-cbrt
prod-exp
div-exp
*-un-lft-identity
cbrt-undiv
pow1
frac-times
expm1-log1p-u
add-sqr-sqrt
sqrt-prod
associate-*l/
pow1/2
associate-/l/
associate-/l*
sin-mult
div-inv
sqr-sin
div-sub
times-frac
frac-2neg
associate-/r*
clear-num
+-commutative
Counts
4 → 71
Calls
4 calls:
Slowest
14.0ms
(/ (* (sin x) (sin x)) (* (sqrt (* (* x x) (+ 1 (cos x)))) (sqrt (* (* x x) (+ 1 (cos x))))))
2.0ms
(sqrt (* (* x x) (+ 1 (cos x))))
2.0ms
(sqrt (* (* x x) (+ 1 (cos x))))
1.0ms
(+ 1 (cos x))

series166.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
54.0ms
(sqrt (* (* x x) (+ 1 (cos x))))
48.0ms
(sqrt (* (* x x) (+ 1 (cos x))))
48.0ms
(/ (* (sin x) (sin x)) (* (sqrt (* (* x x) (+ 1 (cos x)))) (sqrt (* (* x x) (+ 1 (cos x))))))
15.0ms
(+ 1 (cos x))

simplify5.2s

Counts
40 → 83
Calls
40 calls:
Slowest
399.0ms
(- (+ (* (sqrt 2) x) (* 1/48 (/ (pow x 5) (sqrt 2)))) (+ (* 1/4 (/ (pow x 3) (sqrt 2))) (* 1/32 (/ (pow x 5) (pow (sqrt 2) 3)))))
357.0ms
(/ (* (* (* (sin x) (sin x)) (sin x)) (* (* (sin x) (sin x)) (sin x))) (* (* (* (sqrt (* (* x x) (+ 1 (cos x)))) (sqrt (* (* x x) (+ 1 (cos x))))) (* (sqrt (* (* x x) (+ 1 (cos x)))) (sqrt (* (* x x) (+ 1 (cos x)))))) (* (sqrt (* (* x x) (+ 1 (cos x)))) (sqrt (* (* x x) (+ 1 (cos x)))))))
342.0ms
(- (+ (* (sqrt 2) x) (* 1/48 (/ (pow x 5) (sqrt 2)))) (+ (* 1/4 (/ (pow x 3) (sqrt 2))) (* 1/32 (/ (pow x 5) (pow (sqrt 2) 3)))))
334.0ms
(sqrt (* (* x x) (- (* 1 1) (* (cos x) (cos x)))))
239.0ms
(- (+ (log (sin x)) (log (sin x))) (log (* (sqrt (* (* x x) (+ 1 (cos x)))) (sqrt (* (* x x) (+ 1 (cos x)))))))

prune947.0ms

Pruning

8 alts after pruning (6 fresh and 2 done)

Merged error: 0.0b

regimes83.0ms

Accuracy

99.2% (0.1b remaining)

Error of 0.3b against oracle of 0.2b and baseline of 15.0b

bsearch137.0ms

end0.0ms

sample5.2s

Algorithm
intervals
Results
8000×(pre true 80)
2314×(body real 80)
1586×(body real 2560)
1464×(body real 640)
1248×(body real 1280)
887×(body real 320)
501×(body real 160)