Average Error: 6.8 → 0.2
Time: 34.5s
Precision: 64
Internal Precision: 128
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
\[(\left(x.im + x.re\right) \cdot \left(\left(x.re - x.im\right) \cdot x.im\right) + \left(\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re\right))_*\]

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.8
Target0.2
Herbie0.2
\[\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right)\]

Derivation

  1. Initial program 6.8

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  2. Using strategy rm
  3. Applied difference-of-squares6.8

    \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  4. Applied associate-*l*0.2

    \[\leadsto \color{blue}{\left(x.re + x.im\right) \cdot \left(\left(x.re - x.im\right) \cdot x.im\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  5. Using strategy rm
  6. Applied fma-def0.2

    \[\leadsto \color{blue}{(\left(x.re + x.im\right) \cdot \left(\left(x.re - x.im\right) \cdot x.im\right) + \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right))_*}\]
  7. Final simplification0.2

    \[\leadsto (\left(x.im + x.re\right) \cdot \left(\left(x.re - x.im\right) \cdot x.im\right) + \left(\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re\right))_*\]

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"

  :herbie-target
  (+ (* (* x.re x.im) (* 2 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))

  (+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re)))

Details

Time bar (total: 33.7s)Debug log

sample120.0ms

Algorithm
intervals
Results
474×(pre true 80)
474×(body real 80)

simplify202.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
202.0ms
(+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re))

prune12.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 5.7b

localize29.0ms

Local error

Found 4 expressions with local error:

5.8b
(* (- (* x.re x.re) (* x.im x.im)) x.im)
0.2b
(* (+ (* x.re x.im) (* x.im x.re)) x.re)
0.1b
(+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
0.0b
(+ (* x.re x.im) (* x.im x.re))

rewrite45.0ms

Algorithm
rewrite-expression-head
Rules
12×associate-*l/
add-log-exp
associate-*l*
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
flip-+
flip3-+
log1p-expm1-u
add-exp-log
frac-add
add-cbrt-cube
pow1
expm1-log1p-u
flip--
flip3--
*-commutative
fma-def
sum-log
+-commutative
difference-of-squares
Counts
4 → 63
Calls
4 calls:
Slowest
21.0ms
(+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
10.0ms
(* (- (* x.re x.re) (* x.im x.im)) x.im)
9.0ms
(* (+ (* x.re x.im) (* x.im x.re)) x.re)
4.0ms
(+ (* x.re x.im) (* x.im x.re))

series120.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
49.0ms
(+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
39.0ms
(* (- (* x.re x.re) (* x.im x.im)) x.im)
20.0ms
(+ (* x.re x.im) (* x.im x.re))
12.0ms
(* (+ (* x.re x.im) (* x.im x.re)) x.re)

simplify5.0s

Counts
32 → 75
Calls
32 calls:
Slowest
1.2s
(* (+ (* (* x.re x.re) (* x.re x.re)) (+ (* (* x.im x.im) (* x.im x.im)) (* (* x.re x.re) (* x.im x.im)))) (- (* x.re x.im) (* x.im x.re)))
467.0ms
(* (- (pow (* x.re x.re) 3) (pow (* x.im x.im) 3)) x.im)
450.0ms
(* (- (* (* x.re x.re) (* x.re x.re)) (* (* x.im x.im) (* x.im x.im))) x.im)
405.0ms
(* (+ (pow (* x.re x.im) 3) (pow (* x.im x.re) 3)) x.re)
405.0ms
(+ (* (* (- (pow (* x.re x.re) 3) (pow (* x.im x.im) 3)) x.im) (+ (* (* x.re x.im) (* x.re x.im)) (- (* (* x.im x.re) (* x.im x.re)) (* (* x.re x.im) (* x.im x.re))))) (* (+ (* (* x.re x.re) (* x.re x.re)) (+ (* (* x.im x.im) (* x.im x.im)) (* (* x.re x.re) (* x.im x.im)))) (* (+ (pow (* x.re x.im) 3) (pow (* x.im x.re) 3)) x.re)))

prune797.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 0.0b

localize14.0ms

Local error

Found 4 expressions with local error:

0.2b
(* (+ x.re x.im) (* (- x.re x.im) x.im))
0.2b
(* (+ (* x.re x.im) (* x.im x.re)) x.re)
0.1b
(+ (* (+ x.re x.im) (* (- x.re x.im) x.im)) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
0.0b
(* (- x.re x.im) x.im)

rewrite32.0ms

Algorithm
rewrite-expression-head
Rules
44×associate-*l/
19×flip-+
19×flip3-+
16×frac-add
12×frac-times
10×flip--
10×flip3--
associate-*l*
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
add-exp-log
associate-*r/
add-cbrt-cube
pow1
log1p-expm1-u
expm1-log1p-u
*-commutative
cbrt-unprod
prod-exp
pow-prod-down
associate-*r*
fma-def
sum-log
+-commutative
Counts
4 → 85
Calls
4 calls:
Slowest
11.0ms
(+ (* (+ x.re x.im) (* (- x.re x.im) x.im)) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
9.0ms
(* (+ x.re x.im) (* (- x.re x.im) x.im))
5.0ms
(* (- x.re x.im) x.im)
5.0ms
(* (+ (* x.re x.im) (* x.im x.re)) x.re)

series158.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
62.0ms
(* (+ x.re x.im) (* (- x.re x.im) x.im))
46.0ms
(+ (* (+ x.re x.im) (* (- x.re x.im) x.im)) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
33.0ms
(* (- x.re x.im) x.im)
16.0ms
(* (+ (* x.re x.im) (* x.im x.re)) x.re)

simplify16.8s

Counts
71 → 97
Calls
71 calls:
Slowest
1.4s
(* (+ x.re x.im) (+ (* (* x.re x.im) (* x.re x.im)) (- (* (* x.im x.re) (* x.im x.re)) (* (* x.re x.im) (* x.im x.re)))))
1.4s
(* (- x.re x.im) (+ (* (* x.re x.im) (* x.re x.im)) (- (* (* x.im x.re) (* x.im x.re)) (* (* x.re x.im) (* x.im x.re)))))
1.2s
(* (* (- x.re x.im) (+ x.re x.im)) (- (* x.re x.im) (* x.im x.re)))
633.0ms
(+ (* (* (+ (pow x.re 3) (pow x.im 3)) (* (- (* x.re x.re) (* x.im x.im)) x.im)) (- (* x.re x.im) (* x.im x.re))) (* (* (+ (* x.re x.re) (- (* x.im x.im) (* x.re x.im))) (+ x.re x.im)) (* (- (* (* x.re x.im) (* x.re x.im)) (* (* x.im x.re) (* x.im x.re))) x.re)))
630.0ms
(* (+ (* x.re x.re) (+ (* x.im x.im) (* x.re x.im))) (- (* x.re x.im) (* x.im x.re)))

prune902.0ms

Pruning

6 alts after pruning (6 fresh and 0 done)

Merged error: 0b

localize5.0ms

Local error

Found 4 expressions with local error:

0.2b
(* (+ (* x.re x.im) (* x.im x.re)) x.re)
0.2b
(fma (+ x.re x.im) (* (- x.re x.im) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
0.0b
(* (- x.re x.im) x.im)
0.0b
(+ (* x.re x.im) (* x.im x.re))

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
add-log-exp
add-cube-cbrt
associate-*l*
*-un-lft-identity
add-sqr-sqrt
log1p-expm1-u
add-exp-log
associate-*l/
add-cbrt-cube
pow1
expm1-log1p-u
flip-+
*-commutative
flip3-+
flip--
fma-udef
flip3--
fma-def
sum-log
+-commutative
Counts
4 → 54
Calls
4 calls:
Slowest
5.0ms
(* (+ (* x.re x.im) (* x.im x.re)) x.re)
3.0ms
(* (- x.re x.im) x.im)
2.0ms
(+ (* x.re x.im) (* x.im x.re))
0.0ms
(fma (+ x.re x.im) (* (- x.re x.im) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re))

series100.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
55.0ms
(fma (+ x.re x.im) (* (- x.re x.im) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re))
21.0ms
(* (- x.re x.im) x.im)
12.0ms
(* (+ (* x.re x.im) (* x.im x.re)) x.re)
12.0ms
(+ (* x.re x.im) (* x.im x.re))

simplify1.5s

Counts
21 → 66
Calls
21 calls:
Slowest
420.0ms
(* (+ (pow (* x.re x.im) 3) (pow (* x.im x.re) 3)) x.re)
374.0ms
(* (- (* x.re x.re) (* x.im x.im)) x.im)
193.0ms
(* (- (* (* x.re x.im) (* x.re x.im)) (* (* x.im x.re) (* x.im x.re))) x.re)
99.0ms
(- (* 3 (* x.im (pow x.re 2))) (pow x.im 3))
96.0ms
(- (* 3 (* x.im (pow x.re 2))) (pow x.im 3))

prune680.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 0b

localize30.0ms

Local error

Found 4 expressions with local error:

0.6b
(cbrt (+ x.re x.im))
0.6b
(cbrt (+ x.re x.im))
0.6b
(cbrt (+ x.re x.im))
0.5b
(* (cbrt (+ x.re x.im)) (cbrt (+ x.re x.im)))

rewrite16.0ms

Algorithm
rewrite-expression-head
Rules
18×cbrt-div
15×cbrt-prod
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
flip-+
flip3-+
pow1
pow1/3
add-exp-log
associate-*l*
associate-*r*
add-log-exp
log1p-expm1-u
add-cbrt-cube
frac-times
expm1-log1p-u
pow-prod-up
associate-*r/
associate-*l/
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 83
Calls
4 calls:
Slowest
11.0ms
(* (cbrt (+ x.re x.im)) (cbrt (+ x.re x.im)))
1.0ms
(cbrt (+ x.re x.im))
1.0ms
(cbrt (+ x.re x.im))
1.0ms
(cbrt (+ x.re x.im))

series683.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
210.0ms
(* (cbrt (+ x.re x.im)) (cbrt (+ x.re x.im)))
185.0ms
(cbrt (+ x.re x.im))
155.0ms
(cbrt (+ x.re x.im))
132.0ms
(cbrt (+ x.re x.im))

simplify2.2s

Counts
59 → 95
Calls
59 calls:
Slowest
236.0ms
(- (+ (pow x.im 2/3) (* 2/3 (* (pow (/ 1 x.im) 1/3) x.re))) (* 1/9 (* (pow (/ 1 (pow x.im 4)) 1/3) (pow x.re 2))))
231.0ms
(- (+ (* 1/3 (* (pow (/ 1 (pow x.im 2)) 1/3) x.re)) (pow x.im 1/3)) (* 1/9 (* (pow (/ 1 (pow x.im 5)) 1/3) (pow x.re 2))))
221.0ms
(- (+ (* 1/3 (* (pow (/ 1 (pow x.im 2)) 1/3) x.re)) (pow x.im 1/3)) (* 1/9 (* (pow (/ 1 (pow x.im 5)) 1/3) (pow x.re 2))))
215.0ms
(- (+ (* 1/3 (* (pow (/ 1 (pow x.im 2)) 1/3) x.re)) (pow x.im 1/3)) (* 1/9 (* (pow (/ 1 (pow x.im 5)) 1/3) (pow x.re 2))))
156.0ms
(* (cbrt (- (* x.re x.re) (* x.im x.im))) (cbrt (+ (pow x.re 3) (pow x.im 3))))

prune1.1s

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 0b

regimes151.0ms

Accuracy

0% (0.2b remaining)

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

bsearch3.0ms

end0.0ms

sample3.0s

Algorithm
intervals
Results
14405×(pre true 80)
14405×(body real 80)