Average Error: 26.1 → 26.0
Time: 15.7s
Precision: 64
Internal Precision: 128
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 3.052453129606842 \cdot 10^{+67}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d \cdot d + c \cdot c}} \cdot \left(a \cdot c + b \cdot d\right)}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

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

Original26.1
Target0.5
Herbie26.0
\[\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. Split input into 2 regimes
  2. if d < 3.052453129606842e+67

    1. Initial program 23.0

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification23.0

      \[\leadsto \frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt23.0

      \[\leadsto \frac{b \cdot d + a \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    5. Applied associate-/r*22.9

      \[\leadsto \color{blue}{\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Using strategy rm
    7. Applied div-inv23.0

      \[\leadsto \frac{\color{blue}{\left(b \cdot d + a \cdot c\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]

    if 3.052453129606842e+67 < d

    1. Initial program 37.9

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Initial simplification37.9

      \[\leadsto \frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt37.9

      \[\leadsto \frac{b \cdot d + a \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    5. Applied associate-/r*37.9

      \[\leadsto \color{blue}{\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Using strategy rm
    7. Applied div-inv37.9

      \[\leadsto \frac{\color{blue}{\left(b \cdot d + a \cdot c\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    8. Taylor expanded around inf 37.8

      \[\leadsto \frac{\color{blue}{b}}{\sqrt{c \cdot c + d \cdot d}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 3.052453129606842 \cdot 10^{+67}:\\ \;\;\;\;\frac{\frac{1}{\sqrt{d \cdot d + c \cdot c}} \cdot \left(a \cdot c + b \cdot d\right)}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

Reproduce

herbie shell --seed 2018365 
(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: 12.1s)Debug log

start90.0ms

Algorithm
intervals

setup28.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 24.9b

localize39.0ms

Local error

Found 2 expressions with local error:

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

rewrite24.0ms

Algorithm
rewrite-expression-head
Counts
2 → 42
Calls

2 calls. Slowest were:

19.0ms
(/ (+ (* b d) (* a c)) (+ (* c c) (* d d)))
4.0ms
(+ (* b d) (* a c))

series140.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

97.0ms
(/ (+ (* b d) (* a c)) (+ (* c c) (* d d)))
42.0ms
(+ (* b d) (* a c))

simplify889.0ms

Counts
36 → 48
Calls

36 calls. Slowest were:

240.0ms
(- (* (* b d) (* b d)) (* (* a c) (* a c)))
166.0ms
(+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d))))
134.0ms
(/ (* (* (+ (* b d) (* a c)) (+ (* b d) (* a c))) (+ (* b d) (* a c))) (* (* (+ (* c c) (* d d)) (+ (* c c) (* d d))) (+ (* c c) (* d d))))

prune549.0ms

Pruning

9 alts after pruning (8 fresh and 1 done)

Merged error: 24.4b

localize16.0ms

Local error

Found 4 expressions with local error:

29.3b
(sqrt (+ (* c c) (* d d)))
29.3b
(sqrt (+ (* c c) (* d d)))
16.5b
(/ (+ (* b d) (* a c)) (sqrt (+ (* c c) (* d d))))
0.5b
(+ (* b d) (* a c))

rewrite32.0ms

Algorithm
rewrite-expression-head
Counts
4 → 82
Calls

4 calls. Slowest were:

19.0ms
(/ (+ (* b d) (* a c)) (sqrt (+ (* c c) (* d d))))
4.0ms
(+ (* b d) (* a c))
4.0ms
(sqrt (+ (* c c) (* d d)))

series204.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

105.0ms
(/ (+ (* b d) (* a c)) (sqrt (+ (* c c) (* d d))))
36.0ms
(+ (* b d) (* a c))
31.0ms
(sqrt (+ (* c c) (* d d)))
31.0ms
(sqrt (+ (* c c) (* d d)))

simplify1.6s

Counts
75 → 94
Calls

75 calls. Slowest were:

271.0ms
(- (* (* b d) (* b d)) (* (* a c) (* a c)))
176.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))
169.0ms
(sqrt (+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d)))))

prune1.3s

Pruning

10 alts after pruning (9 fresh and 1 done)

Merged error: 22.3b

localize18.0ms

Local error

Found 4 expressions with local error:

29.3b
(sqrt (+ (* c c) (* d d)))
29.3b
(sqrt (+ (* c c) (* d d)))
16.6b
(/ (sqrt (+ (* c c) (* d d))) (+ (* b d) (* a c)))
0.5b
(+ (* b d) (* a c))

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 82
Calls

4 calls. Slowest were:

13.0ms
(/ (sqrt (+ (* c c) (* d d))) (+ (* b d) (* a c)))
4.0ms
(+ (* b d) (* a c))
4.0ms
(sqrt (+ (* c c) (* d d)))

series165.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

72.0ms
(/ (sqrt (+ (* c c) (* d d))) (+ (* b d) (* a c)))
36.0ms
(sqrt (+ (* c c) (* d d)))
31.0ms
(sqrt (+ (* c c) (* d d)))
24.0ms
(+ (* b d) (* a c))

simplify1.4s

Counts
75 → 94
Calls

75 calls. Slowest were:

354.0ms
(+ (* (* b d) (* b d)) (- (* (* a c) (* a c)) (* (* b d) (* a c))))
157.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))
140.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))

prune1.6s

Pruning

10 alts after pruning (8 fresh and 2 done)

Merged error: 22.3b

localize9.0ms

Local error

Found 4 expressions with local error:

29.3b
(sqrt (+ (* c c) (* d d)))
29.3b
(sqrt (+ (* c c) (* d d)))
16.7b
(* (+ (* b d) (* a c)) (/ 1 (sqrt (+ (* c c) (* d d)))))
0.5b
(+ (* b d) (* a c))

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
4 → 66
Calls

4 calls. Slowest were:

6.0ms
(* (+ (* b d) (* a c)) (/ 1 (sqrt (+ (* c c) (* d d)))))
4.0ms
(sqrt (+ (* c c) (* d d)))
2.0ms
(+ (* b d) (* a c))

series136.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

73.0ms
(* (+ (* b d) (* a c)) (/ 1 (sqrt (+ (* c c) (* d d)))))
24.0ms
(+ (* b d) (* a c))
19.0ms
(sqrt (+ (* c c) (* d d)))
19.0ms
(sqrt (+ (* c c) (* d d)))

simplify2.2s

Counts
45 → 78
Calls

45 calls. Slowest were:

419.0ms
(* (- (* (* b d) (* b d)) (* (* a c) (* a c))) 1)
355.0ms
(* (+ (pow (* b d) 3) (pow (* a c) 3)) 1)
182.0ms
(* (+ (pow (* b d) 3) (pow (* a c) 3)) (/ 1 (sqrt (+ (* c c) (* d d)))))

prune1.1s

Pruning

10 alts after pruning (7 fresh and 3 done)

Merged error: 22.3b

regimes331.0ms

Accuracy

1.2% (2.7b remaining)

Error of 26.0b against oracle of 23.4b and baseline of 26.1b

bsearch81.0ms