Average Error: 25.5 → 25.5
Time: 25.0s
Precision: 64
Internal Precision: 128
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.5
Target0.4
Herbie25.5
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Initial program 25.5

    \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt25.5

    \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
  4. Applied *-un-lft-identity25.5

    \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
  5. Applied times-frac25.5

    \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
  6. Final simplification25.5

    \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}\]

Reproduce

herbie shell --seed 2019010 
(FPCore (a b c d)
  :name "Complex division, real part"

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))

Details

Time bar (total: 24.0s)Debug log

sample67.0ms

Algorithm
intervals

simplify9.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
8.0ms
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))

prune12.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 25.4b

localize51.0ms

Local error

Found 3 expressions with local error:

25.3b
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
0.0b
(+ (* a c) (* b d))
0.0b
(+ (* c c) (* d d))

rewrite28.0ms

Algorithm
rewrite-expression-head
Rules
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
times-frac
add-log-exp
add-exp-log
add-cbrt-cube
flip-+
flip3-+
associate-/l*
associate-/r*
pow1
associate-/l/
associate-/r/
sum-log
+-commutative
div-inv
div-exp
frac-2neg
clear-num
cbrt-undiv
Counts
3 → 53
Calls
3 calls:
Slowest
18.0ms
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
4.0ms
(+ (* c c) (* d d))
4.0ms
(+ (* a c) (* b d))

series119.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
65.0ms
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
30.0ms
(+ (* a c) (* b d))
24.0ms
(+ (* c c) (* d d))

simplify939.0ms

Counts
40 → 62
Calls
40 calls:
Slowest
225.0ms
(- (* (* a c) (* a c)) (* (* b d) (* b d)))
154.0ms
(+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d))))
148.0ms
(/ (* (* (+ (* a c) (* b d)) (+ (* a c) (* b d))) (+ (* a c) (* b d))) (* (* (+ (* c c) (* d d)) (+ (* c c) (* d d))) (+ (* c c) (* d d))))
123.0ms
(+ (pow (* a c) 3) (pow (* b d) 3))
37.0ms
(/ (* (cbrt (+ (* a c) (* b d))) (cbrt (+ (* a c) (* b d)))) (* (cbrt (+ (* c c) (* d d))) (cbrt (+ (* c c) (* d d)))))

prune689.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 24.9b

localize11.0ms

Local error

Found 4 expressions with local error:

31.8b
(sqrt (+ (* c c) (* d d)))
31.8b
(sqrt (+ (* c c) (* d d)))
15.8b
(/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))
0.2b
(* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d)))))

rewrite44.0ms

Algorithm
rewrite-expression-head
Rules
37×add-sqr-sqrt
36×times-frac
35×add-cube-cbrt
35×*-un-lft-identity
27×sqrt-prod
24×associate-*r*
16×add-exp-log
11×add-cbrt-cube
10×sqrt-div
flip-+
associate-/r/
associate-*l*
flip3-+
associate-/r*
pow1
add-log-exp
prod-exp
associate-/l*
div-inv
div-exp
associate-/l/
cbrt-unprod
pow1/2
rec-exp
rem-sqrt-square
cbrt-undiv
*-commutative
associate-*r/
associate-*l/
pow-prod-down
frac-2neg
clear-num
frac-times
Counts
4 → 119
Calls
4 calls:
Slowest
19.0ms
(/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))
16.0ms
(* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d)))))
4.0ms
(sqrt (+ (* c c) (* d d)))
3.0ms
(sqrt (+ (* c c) (* d d)))

series252.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
110.0ms
(/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))
95.0ms
(* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d)))))
29.0ms
(sqrt (+ (* c c) (* d d)))
19.0ms
(sqrt (+ (* c c) (* d d)))

simplify3.5s

Counts
113 → 131
Calls
113 calls:
Slowest
736.0ms
(* (* (* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ 1 (sqrt (+ (* c c) (* d d))))) (/ 1 (sqrt (+ (* c c) (* d d))))) (* (* (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d)))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))))
342.0ms
(* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d)))))
197.0ms
(- (* (* a c) (* a c)) (* (* b d) (* b d)))
189.0ms
(* (* (* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ 1 (sqrt (+ (* c c) (* d d))))) (/ 1 (sqrt (+ (* c c) (* d d))))) (/ (* (* (+ (* a c) (* b d)) (+ (* a c) (* b d))) (+ (* a c) (* b d))) (* (* (sqrt (+ (* c c) (* d d))) (sqrt (+ (* c c) (* d d)))) (sqrt (+ (* c c) (* d d))))))
181.0ms
(sqrt (+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d)))))

prune1.9s

Pruning

12 alts after pruning (11 fresh and 1 done)

Merged error: 23.3b

localize15.0ms

Local error

Found 4 expressions with local error:

31.8b
(sqrt (+ (* c c) (* d d)))
31.8b
(sqrt (+ (* c c) (* d d)))
15.8b
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
0.1b
(/ (/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d)))) (sqrt (+ (* c c) (* d d))))

rewrite34.0ms

Algorithm
rewrite-expression-head
Rules
288×times-frac
164×add-sqr-sqrt
162×add-cube-cbrt
162×*-un-lft-identity
156×sqrt-prod
27×associate-/l*
22×sqrt-div
18×associate-/r/
12×flip-+
12×flip3-+
12×associate-/r*
11×add-exp-log
11×add-cbrt-cube
div-inv
add-log-exp
div-exp
cbrt-undiv
pow1
associate-/l/
pow1/2
frac-2neg
clear-num
rem-sqrt-square
Counts
4 → 262
Calls
4 calls:
Slowest
15.0ms
(/ (/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d)))) (sqrt (+ (* c c) (* d d))))
10.0ms
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
2.0ms
(sqrt (+ (* c c) (* d d)))
2.0ms
(sqrt (+ (* c c) (* d d)))

series185.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
86.0ms
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
49.0ms
(/ (/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d)))) (sqrt (+ (* c c) (* d d))))
28.0ms
(sqrt (+ (* c c) (* d d)))
22.0ms
(sqrt (+ (* c c) (* d d)))

simplify9.7s

Counts
398 → 274
Calls
398 calls:
Slowest
261.0ms
(/ (* (* (/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d)))) (/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))) (/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))) (* (* (sqrt (+ (* c c) (* d d))) (sqrt (+ (* c c) (* d d)))) (sqrt (+ (* c c) (* d d)))))
258.0ms
(/ (/ (* (cbrt (+ (* c a) (* b d))) (cbrt (+ (* c a) (* b d)))) (* (cbrt (sqrt (+ (* c c) (* d d)))) (cbrt (sqrt (+ (* c c) (* d d)))))) 1)
252.0ms
(- (* (* c a) (* c a)) (* (* b d) (* b d)))
236.0ms
(/ (/ (* (cbrt (+ (* c a) (* b d))) (cbrt (+ (* c a) (* b d)))) (sqrt 1)) (* (cbrt (sqrt (+ (* c c) (* d d)))) (cbrt (sqrt (+ (* c c) (* d d))))))
204.0ms
(/ (/ (* (cbrt (+ (* c a) (* b d))) (cbrt (+ (* c a) (* b d)))) 1) (* (cbrt (sqrt (+ (* c c) (* d d)))) (cbrt (sqrt (+ (* c c) (* d d))))))

prune3.0s

Pruning

11 alts after pruning (10 fresh and 1 done)

Merged error: 23.3b

localize10.0ms

Local error

Found 4 expressions with local error:

31.8b
(sqrt (+ (* c c) (* d d)))
31.8b
(sqrt (+ (* c c) (* d d)))
31.8b
(sqrt (+ (* c c) (* d d)))
15.8b
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
25×add-sqr-sqrt
22×add-cube-cbrt
22×*-un-lft-identity
21×sqrt-prod
18×times-frac
sqrt-div
add-exp-log
add-cbrt-cube
associate-/r*
flip-+
flip3-+
add-log-exp
pow1
associate-/l*
pow1/2
rem-sqrt-square
associate-/l/
associate-/r/
div-inv
div-exp
frac-2neg
clear-num
cbrt-undiv
Counts
4 → 85
Calls
4 calls:
Slowest
12.0ms
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
2.0ms
(sqrt (+ (* c c) (* d d)))
2.0ms
(sqrt (+ (* c c) (* d d)))
2.0ms
(sqrt (+ (* c c) (* d d)))

series110.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
53.0ms
(/ (+ (* c a) (* b d)) (sqrt (+ (* c c) (* d d))))
20.0ms
(sqrt (+ (* c c) (* d d)))
20.0ms
(sqrt (+ (* c c) (* d d)))
18.0ms
(sqrt (+ (* c c) (* d d)))

simplify1.1s

Counts
80 → 97
Calls
80 calls:
Slowest
164.0ms
(- (* (* c a) (* c a)) (* (* b d) (* b d)))
107.0ms
(sqrt (+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d)))))
86.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))
86.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))
84.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))

prune963.0ms

Pruning

12 alts after pruning (10 fresh and 2 done)

Merged error: 23.3b

regimes268.0ms

Accuracy

0% (2.6b remaining)

Error of 25.5b against oracle of 22.9b and baseline of 25.5b

bsearch2.0ms

end0.0ms

sample1.1s

Algorithm
intervals