Average Error: 43.6 → 0.8
Time: 36.7s
Precision: 64
Internal Precision: 128
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(0.5 \cdot \sin re\right) \cdot \left(\frac{-1}{60} \cdot {im}^{5} + im \cdot -2\right) + \left(0.5 \cdot \sin re\right) \cdot \left(\frac{-1}{3} \cdot {im}^{3}\right)\]

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original43.6
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(\frac{1}{6} \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(\frac{1}{120} \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.6

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-\left(\frac{1}{3} \cdot {im}^{3} + \left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)}\]
  3. Using strategy rm
  4. Applied distribute-neg-in0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(\left(-\frac{1}{3} \cdot {im}^{3}\right) + \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)\right)}\]
  5. Applied distribute-lft-in0.8

    \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(-\frac{1}{3} \cdot {im}^{3}\right) + \left(0.5 \cdot \sin re\right) \cdot \left(-\left(\frac{1}{60} \cdot {im}^{5} + 2 \cdot im\right)\right)}\]
  6. Simplified0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(-\frac{1}{3} \cdot {im}^{3}\right) + \color{blue}{\left(im \cdot -2 + \frac{-1}{60} \cdot {im}^{5}\right) \cdot \left(0.5 \cdot \sin re\right)}\]
  7. Final simplification0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(\frac{-1}{60} \cdot {im}^{5} + im \cdot -2\right) + \left(0.5 \cdot \sin re\right) \cdot \left(\frac{-1}{3} \cdot {im}^{3}\right)\]

Reproduce

herbie shell --seed 2019004 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

Details

Time bar (total: 35.0s)Debug log

sample467.0ms

Algorithm
intervals

simplify532.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

532.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 44.0b

localize27.0ms

Local error

Found 2 expressions with local error:

6.9b
(- (exp (- im)) (exp im))
0.0b
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))

rewrite41.0ms

Algorithm
rewrite-expression-head
Counts
2 → 37
Calls

2 calls. Slowest were:

27.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
13.0ms
(- (exp (- im)) (exp im))

series182.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

120.0ms
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))
62.0ms
(- (exp (- im)) (exp im))

simplify995.0ms

Counts
24 → 43
Calls

24 calls. Slowest were:

157.0ms
(- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))
154.0ms
(* 0.5 (* (sin re) (- (exp (- im)) (exp im))))
137.0ms
(* 0.5 (* (sin re) (- (exp (* -1 im)) (exp im))))

prune480.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.2b

localize24.0ms

Local error

Found 4 expressions with local error:

0.2b
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
0.2b
(* 1/3 (pow im 3))
0.0b
(* 1/60 (pow im 5))
0.0b
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))

rewrite31.0ms

Algorithm
rewrite-expression-head
Counts
4 → 64
Calls

4 calls. Slowest were:

19.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
9.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
1.0ms
(* 1/3 (pow im 3))

series237.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

177.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))
24.0ms
(+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))
20.0ms
(* 1/60 (pow im 5))
15.0ms
(* 1/3 (pow im 3))

simplify2.9s

Counts
39 → 76
Calls

39 calls. Slowest were:

301.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/60 (pow im 5)) (* 2 im))))
282.0ms
(* (* (* (* 0.5 (sin re)) (* 0.5 (sin re))) (* 0.5 (sin re))) (* (* (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
233.0ms
(* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))

prune1.1s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 0.1b

localize35.0ms

Local error

Found 4 expressions with local error:

0.2b
(* (+ (* im -2) (* -1/60 (pow im 5))) (* 0.5 (sin re)))
0.2b
(* 1/3 (pow im 3))
0.1b
(* (* 0.5 (sin re)) (- (* 1/3 (pow im 3))))
0.0b
(* -1/60 (pow im 5))

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
4 → 60
Calls

4 calls. Slowest were:

13.0ms
(* (+ (* im -2) (* -1/60 (pow im 5))) (* 0.5 (sin re)))
12.0ms
(* (* 0.5 (sin re)) (- (* 1/3 (pow im 3))))
2.0ms
(* -1/60 (pow im 5))

series228.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

91.0ms
(* (+ (* im -2) (* -1/60 (pow im 5))) (* 0.5 (sin re)))
83.0ms
(* (* 0.5 (sin re)) (- (* 1/3 (pow im 3))))
28.0ms
(* 1/3 (pow im 3))
26.0ms
(* -1/60 (pow im 5))

simplify1.7s

Counts
36 → 72
Calls

36 calls. Slowest were:

381.0ms
(+ (log (* 0.5 (sin re))) (log (- (* 1/3 (pow im 3)))))
191.0ms
(* (* 0.5 (sin re)) (- (* 1/3 (pow im 3))))
153.0ms
(* (+ (pow (* im -2) 3) (pow (* -1/60 (pow im 5)) 3)) (* 0.5 (sin re)))

prune1.1s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 0.0b

localize23.0ms

Local error

Found 4 expressions with local error:

14.1b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
14.1b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
14.1b
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
0.5b
(* (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))) (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))

rewrite81.0ms

Algorithm
rewrite-expression-head
Counts
4 → 65
Calls

4 calls. Slowest were:

25.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
21.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
20.0ms
(* (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))) (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))

series1.4s

Counts
4 → 12
Calls

4 calls. Slowest were:

366.0ms
(* (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))) (cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im)))))))
357.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
326.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))
317.0ms
(cbrt (* (* 0.5 (sin re)) (- (+ (* 1/3 (pow im 3)) (+ (* 1/60 (pow im 5)) (* 2 im))))))

simplify8.8s

Counts
49 → 77
Calls

49 calls. Slowest were:

409.0ms
(+ (* (cbrt 0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ -1 im))))))) (* 20/3 (/ (* (cbrt 0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ -1 im))))))) (pow im 2))))
380.0ms
(+ (* 20/3 (/ (* (cbrt -0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ 1 im))))))) (pow im 2))) (* (cbrt -0.5) (exp (* 1/3 (- (log (* 1/60 (sin re))) (* 5 (log (/ 1 im))))))))
380.0ms
(- (+ (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))) (* 1/18 (* (pow im 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re))))))))) (* 1/18 (* (pow re 2) (* (cbrt -0.5) (exp (* 1/3 (+ (log 2) (+ (log im) (log re)))))))))

prune1.4s

Pruning

12 alts after pruning (10 fresh and 2 done)

Merged error: 0.0b

regimes671.0ms

Accuracy

0% (0.7b remaining)

Error of 0.8b against oracle of 0.1b and baseline of 0.8b

bsearch9.0ms

end0.0ms

sample12.5s

Algorithm
intervals