Average Error: 37.1 → 0.5
Time: 17.5s
Precision: 64
Internal Precision: 128
\[\sin \left(x + \varepsilon\right) - \sin x\]
\[\begin{array}{l} \mathbf{if}\;\varepsilon \le -1.2264245780452515 \cdot 10^{-08}:\\ \;\;\;\;\left(\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon\right) - \sin x\\ \mathbf{elif}\;\varepsilon \le 1.7206170988045887 \cdot 10^{-16}:\\ \;\;\;\;2 \cdot \left(\sin \left(\frac{\varepsilon}{2}\right) \cdot \cos \left(\frac{\left(x + x\right) + \varepsilon}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos x \cdot \sin \varepsilon - \sin x\right) + \sin x \cdot \cos \varepsilon\\ \end{array}\]

Error

Bits error versus x

Bits error versus eps

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.1
Target14.9
Herbie0.5
\[2 \cdot \left(\cos \left(x + \frac{\varepsilon}{2}\right) \cdot \sin \left(\frac{\varepsilon}{2}\right)\right)\]

Derivation

  1. Split input into 3 regimes
  2. if eps < -1.2264245780452515e-08

    1. Initial program 29.8

      \[\sin \left(x + \varepsilon\right) - \sin x\]
    2. Using strategy rm
    3. Applied sin-sum0.6

      \[\leadsto \color{blue}{\left(\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon\right)} - \sin x\]

    if -1.2264245780452515e-08 < eps < 1.7206170988045887e-16

    1. Initial program 45.1

      \[\sin \left(x + \varepsilon\right) - \sin x\]
    2. Using strategy rm
    3. Applied diff-sin45.1

      \[\leadsto \color{blue}{2 \cdot \left(\sin \left(\frac{\left(x + \varepsilon\right) - x}{2}\right) \cdot \cos \left(\frac{\left(x + \varepsilon\right) + x}{2}\right)\right)}\]
    4. Simplified0.2

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

    if 1.7206170988045887e-16 < eps

    1. Initial program 29.5

      \[\sin \left(x + \varepsilon\right) - \sin x\]
    2. Using strategy rm
    3. Applied sin-sum1.1

      \[\leadsto \color{blue}{\left(\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon\right)} - \sin x\]
    4. Applied associate--l+1.2

      \[\leadsto \color{blue}{\sin x \cdot \cos \varepsilon + \left(\cos x \cdot \sin \varepsilon - \sin x\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\varepsilon \le -1.2264245780452515 \cdot 10^{-08}:\\ \;\;\;\;\left(\sin x \cdot \cos \varepsilon + \cos x \cdot \sin \varepsilon\right) - \sin x\\ \mathbf{elif}\;\varepsilon \le 1.7206170988045887 \cdot 10^{-16}:\\ \;\;\;\;2 \cdot \left(\sin \left(\frac{\varepsilon}{2}\right) \cdot \cos \left(\frac{\left(x + x\right) + \varepsilon}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos x \cdot \sin \varepsilon - \sin x\right) + \sin x \cdot \cos \varepsilon\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 
(FPCore (x eps)
  :name "2sin (example 3.3)"

  :herbie-target
  (* 2 (* (cos (+ x (/ eps 2))) (sin (/ eps 2))))

  (- (sin (+ x eps)) (sin x)))

Details

Time bar (total: 16.2s)Debug log

sample242.0ms

Algorithm
intervals
Results
256×(pre true 80)
115×(body real 1280)
60×(body real 640)
27×(body real 2560)
25×(body real 80)
17×(body real 320)
12×(body real 160)

simplify4.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
4.0ms
(- (sin (+ x eps)) (sin x))

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 38.4b

localize13.0ms

Local error

Found 2 expressions with local error:

3.8b
(sin (+ x eps))
1.7b
(- (sin (+ x eps)) (sin x))

rewrite7.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
*-un-lft-identity
add-sqr-sqrt
add-cube-cbrt
add-exp-log
sin-sum
add-cbrt-cube
pow1
difference-of-squares
distribute-lft-out--
flip--
associate--l+
diff-sin
diff-log
flip3--
sub-neg
Counts
2 → 24
Calls
2 calls:
Slowest
5.0ms
(- (sin (+ x eps)) (sin x))
2.0ms
(sin (+ x eps))

series64.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
48.0ms
(- (sin (+ x eps)) (sin x))
16.0ms
(sin (+ x eps))

simplify466.0ms

Counts
13 → 30
Calls
13 calls:
Slowest
339.0ms
(- eps (+ (* 1/2 (* x (pow eps 2))) (* 1/2 (* (pow x 2) eps))))
39.0ms
(- (+ x eps) (* 1/6 (pow x 3)))
20.0ms
(* (sin (/ (- (+ x eps) x) 2)) (cos (/ (+ (+ x eps) x) 2)))
19.0ms
(/ (exp (sin (+ x eps))) (exp (sin x)))
10.0ms
(- (sin (+ x eps)) (sin x))

prune280.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.4b

localize37.0ms

Local error

Found 2 expressions with local error:

4.0b
(cos (/ (+ (+ x x) eps) 2))
0.3b
(* (cos (/ (+ (+ x x) eps) 2)) (sin (/ eps 2)))

rewrite14.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
add-exp-log
add-cbrt-cube
*-un-lft-identity
pow1
add-sqr-sqrt
associate-*l*
associate-*r*
add-log-exp
cbrt-unprod
*-commutative
prod-exp
pow-prod-down
Counts
2 → 24
Calls
2 calls:
Slowest
9.0ms
(* (cos (/ (+ (+ x x) eps) 2)) (sin (/ eps 2)))
4.0ms
(cos (/ (+ (+ x x) eps) 2))

series87.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
69.0ms
(* (cos (/ (+ (+ x x) eps) 2)) (sin (/ eps 2)))
17.0ms
(cos (/ (+ (+ x x) eps) 2))

simplify717.0ms

Counts
14 → 30
Calls
14 calls:
Slowest
317.0ms
(- (* 1/2 eps) (+ (* 1/4 (* x (pow eps 2))) (* 1/4 (* (pow x 2) eps))))
233.0ms
(- 1 (+ (* 1/2 (* x eps)) (* 1/2 (pow x 2))))
59.0ms
(* (* (* (cos (/ (+ (+ x x) eps) 2)) (cos (/ (+ (+ x x) eps) 2))) (cos (/ (+ (+ x x) eps) 2))) (* (* (sin (/ eps 2)) (sin (/ eps 2))) (sin (/ eps 2))))
16.0ms
(* (cos (* 1/2 (+ (* 2 x) eps))) (sin (* 1/2 eps)))
15.0ms
(* (cos (* 1/2 (+ (* 2 x) eps))) (sin (* 1/2 eps)))

prune316.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.3b

localize15.0ms

Local error

Found 4 expressions with local error:

4.0b
(cos (/ (+ (+ x x) eps) 2))
0.6b
(log (exp (cos (/ (+ (+ x x) eps) 2))))
0.3b
(* (log (exp (cos (/ (+ (+ x x) eps) 2)))) (sin (/ eps 2)))
0.1b
(exp (cos (/ (+ (+ x x) eps) 2)))

rewrite36.0ms

Algorithm
rewrite-expression-head
Rules
10×add-cube-cbrt
10×*-un-lft-identity
10×add-sqr-sqrt
exp-prod
log-pow
pow1
associate-*l*
add-exp-log
add-cbrt-cube
add-log-exp
associate-*r*
log-prod
rem-exp-log
cbrt-unprod
*-commutative
prod-exp
pow-prod-down
rem-log-exp
Counts
4 → 54
Calls
4 calls:
Slowest
14.0ms
(* (log (exp (cos (/ (+ (+ x x) eps) 2)))) (sin (/ eps 2)))
8.0ms
(exp (cos (/ (+ (+ x x) eps) 2)))
8.0ms
(log (exp (cos (/ (+ (+ x x) eps) 2))))
4.0ms
(cos (/ (+ (+ x x) eps) 2))

series200.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
88.0ms
(* (log (exp (cos (/ (+ (+ x x) eps) 2)))) (sin (/ eps 2)))
60.0ms
(exp (cos (/ (+ (+ x x) eps) 2)))
27.0ms
(cos (/ (+ (+ x x) eps) 2))
26.0ms
(log (exp (cos (/ (+ (+ x x) eps) 2))))

simplify1.5s

Counts
34 → 66
Calls
34 calls:
Slowest
322.0ms
(- E (+ (* 1/2 (* x (* E eps))) (* 1/2 (* (pow x 2) E))))
274.0ms
(- (* 1/2 eps) (+ (* 1/4 (* x (pow eps 2))) (* 1/4 (* (pow x 2) eps))))
218.0ms
(- 1 (+ (* 1/2 (* x eps)) (* 1/2 (pow x 2))))
216.0ms
(- 1 (+ (* 1/2 (* x eps)) (* 1/2 (pow x 2))))
102.0ms
(* (* (* (log (exp (cos (/ (+ (+ x x) eps) 2)))) (log (exp (cos (/ (+ (+ x x) eps) 2))))) (log (exp (cos (/ (+ (+ x x) eps) 2))))) (* (* (sin (/ eps 2)) (sin (/ eps 2))) (sin (/ eps 2))))

prune890.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.3b

localize49.0ms

Local error

Found 4 expressions with local error:

4.0b
(cos (/ (+ x (+ x eps)) 2))
4.0b
(cos (/ (+ x (+ x eps)) 2))
4.0b
(cos (/ (+ (+ x x) eps) 2))
0.6b
(log (exp (cos (/ (+ (+ x x) eps) 2))))

rewrite17.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
pow1
add-log-exp
log-pow
add-exp-log
add-cbrt-cube
exp-prod
log-prod
rem-log-exp
Counts
4 → 36
Calls
4 calls:
Slowest
8.0ms
(log (exp (cos (/ (+ (+ x x) eps) 2))))
4.0ms
(cos (/ (+ (+ x x) eps) 2))
2.0ms
(cos (/ (+ x (+ x eps)) 2))
2.0ms
(cos (/ (+ x (+ x eps)) 2))

series67.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
17.0ms
(cos (/ (+ x (+ x eps)) 2))
17.0ms
(cos (/ (+ x (+ x eps)) 2))
16.0ms
(log (exp (cos (/ (+ (+ x x) eps) 2))))
16.0ms
(cos (/ (+ (+ x x) eps) 2))

simplify882.0ms

Counts
19 → 48
Calls
19 calls:
Slowest
195.0ms
(- 1 (+ (* 1/2 (* x eps)) (* 1/2 (pow x 2))))
182.0ms
(- 1 (+ (* 1/2 (* x eps)) (* 1/2 (pow x 2))))
155.0ms
(- 1 (+ (* 1/2 (* x eps)) (* 1/2 (pow x 2))))
149.0ms
(- 1 (+ (* 1/2 (* x eps)) (* 1/2 (pow x 2))))
25.0ms
(cos (* 1/2 (+ (* 2 x) eps)))

prune882.0ms

Pruning

8 alts after pruning (7 fresh and 1 done)

Merged error: 0.3b

regimes285.0ms

Accuracy

98.9% (0.2b remaining)

Error of 0.5b against oracle of 0.4b and baseline of 14.9b

bsearch286.0ms

end0.0ms

sample8.8s

Algorithm
intervals
Results
8000×(pre true 80)
3311×(body real 1280)
1789×(body real 640)
1090×(body real 80)
772×(body real 320)
664×(body real 2560)
374×(body real 160)