Average Error: 31.5 → 0.2
Time: 17.2s
Precision: 64
Internal Precision: 128
\[\frac{1 - \cos x}{x \cdot x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.0321479252886361 \lor \neg \left(x \le 0.033869857145841065\right):\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left({x}^{4} \cdot \frac{1}{720} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \end{array}\]

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -0.0321479252886361 or 0.033869857145841065 < x

    1. Initial program 1.1

      \[\frac{1 - \cos x}{x \cdot x}\]
    2. Using strategy rm
    3. Applied associate-/r*0.5

      \[\leadsto \color{blue}{\frac{\frac{1 - \cos x}{x}}{x}}\]

    if -0.0321479252886361 < x < 0.033869857145841065

    1. Initial program 61.3

      \[\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. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.0321479252886361 \lor \neg \left(x \le 0.033869857145841065\right):\\ \;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\left({x}^{4} \cdot \frac{1}{720} + \frac{1}{2}\right) - \frac{1}{24} \cdot {x}^{2}\\ \end{array}\]

Reproduce

herbie shell --seed 2019021 
(FPCore (x)
  :name "cos2 (problem 3.4.1)"
  (/ (- 1 (cos x)) (* x x)))

Details

Time bar (total: 16.7s)Debug log

sample140.0ms

Algorithm
intervals
Results
62.0ms48×body2560valid
25.0ms57×body640valid
21.0ms34×body1280valid
10.0ms30×body320valid
8.0ms70×body80valid
6.0ms17×body160valid

simplify16.0ms

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

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 30.8b

localize11.0ms

Local error

Found 2 expressions with local error:

13.6b
(/ (- 1 (cos x)) (* x x))
2.2b
(- 1 (cos x))

rewrite5.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--
flip3--
pow1
div-inv
div-exp
div-sub
frac-2neg
sub-neg
associate-/r*
clear-num
cbrt-undiv
Counts
2 → 33
Calls
2 calls:
Slowest
4.0ms
(/ (- 1 (cos x)) (* x x))
1.0ms
(- 1 (cos x))

series92.0ms

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

simplify645.0ms

Counts
19 → 39
Calls
19 calls:
Slowest
353.0ms
(/ (* (* (- 1 (cos x)) (- 1 (cos x))) (- 1 (cos x))) (* (* (* x x) (* x x)) (* x x)))
67.0ms
(- (+ (* 1/720 (pow x 4)) 1/2) (* 1/24 (pow x 2)))
66.0ms
(- (+ (* 1/2 (pow x 2)) (* 1/720 (pow x 6))) (* 1/24 (pow x 4)))
25.0ms
(/ (- 1 (cos x)) (pow x 2))
24.0ms
(/ (- 1 (cos x)) (pow x 2))

prune304.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 0.0b

localize13.0ms

Local error

Found 4 expressions with local error:

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

rewrite22.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
associate-*r/
associate-*l*
div-exp
cbrt-undiv
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 → 76
Calls
4 calls:
Slowest
10.0ms
(/ (* (sin x) (sin x)) (* (* x x) (+ 1 (cos x))))
6.0ms
(* (sin x) (sin x))
3.0ms
(* (* x x) (+ 1 (cos x)))
1.0ms
(+ 1 (cos x))

series92.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
45.0ms
(/ (* (sin x) (sin x)) (* (* x x) (+ 1 (cos x))))
19.0ms
(* (* x x) (+ 1 (cos x)))
16.0ms
(* (sin x) (sin x))
12.0ms
(+ 1 (cos x))

simplify3.8s

Counts
51 → 88
Calls
51 calls:
Slowest
768.0ms
(* (* (* (* x x) (* x x)) (* x x)) (* (* (+ 1 (cos x)) (+ 1 (cos x))) (+ 1 (cos x))))
426.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)))))
313.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)))))
269.0ms
(- (log (* (sin x) (sin x))) (log (* (* x x) (+ 1 (cos x)))))
265.0ms
(- (+ (log (sin x)) (log (sin x))) (log (* (* x x) (+ 1 (cos x)))))

prune603.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 0b

localize8.0ms

Local error

Found 4 expressions with local error:

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

rewrite12.0ms

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

series80.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
38.0ms
(/ (* (sin x) (sin x)) (* x (* x (+ 1 (cos x)))))
20.0ms
(* x (+ 1 (cos x)))
14.0ms
(* (sin x) (sin x))
8.0ms
(+ 1 (cos x))

simplify1.8s

Counts
44 → 80
Calls
44 calls:
Slowest
267.0ms
(- (log (* (sin x) (sin x))) (log (* x (* x (+ 1 (cos x))))))
266.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))))))
255.0ms
(- (+ (log (sin x)) (log (sin x))) (log (* x (* x (+ 1 (cos x))))))
209.0ms
(/ (pow (sin x) 2) (* (pow x 2) (+ (cos x) 1)))
195.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))))))

prune602.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 0b

localize11.0ms

Local error

Found 2 expressions with local error:

12.5b
(/ (* x x) (sin x))
0.5b
(/ (tan (/ x 2)) (/ (* x x) (sin x)))

rewrite9.0ms

Algorithm
rewrite-expression-head
Rules
36×times-frac
20×add-cube-cbrt
20×*-un-lft-identity
20×add-sqr-sqrt
10×associate-/r*
add-exp-log
add-cbrt-cube
div-inv
associate-/l*
div-exp
cbrt-undiv
add-log-exp
frac-2neg
clear-num
pow1
associate-/l/
associate-/r/
tan-quot
Counts
2 → 66
Calls
2 calls:
Slowest
5.0ms
(/ (tan (/ x 2)) (/ (* x x) (sin x)))
3.0ms
(/ (* x x) (sin x))

series87.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
59.0ms
(/ (tan (/ x 2)) (/ (* x x) (sin x)))
28.0ms
(/ (* x x) (sin x))

simplify2.2s

Counts
74 → 72
Calls
74 calls:
Slowest
807.0ms
(/ (* (* (tan (/ x 2)) (tan (/ x 2))) (tan (/ x 2))) (* (* (/ (* x x) (sin x)) (/ (* x x) (sin x))) (/ (* x x) (sin x))))
176.0ms
(/ (* (* (* x x) (* x x)) (* x x)) (* (* (sin x) (sin x)) (sin x)))
164.0ms
(/ (* (sin x) (sin (* 1/2 x))) (* (cos (* 1/2 x)) (pow x 2)))
134.0ms
(/ (* (sin x) (sin (* 1/2 x))) (* (cos (* 1/2 x)) (pow x 2)))
81.0ms
(- (log (tan (/ x 2))) (- (log (* x x)) (log (sin x))))

prune626.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 0b

regimes142.0ms

Accuracy

98.6% (0.2b remaining)

Error of 0.2b against oracle of 0.0b and baseline of 15.8b

bsearch94.0ms

end0.0ms

sample5.1s

Algorithm
intervals
Results
2.3s1631×body2560valid
1.1s1427×body640valid
958.0ms1274×body1280valid
297.0ms939×body320valid
257.0ms2227×body80valid
110.0ms502×body160valid