Average Error: 25.7 → 19.3
Time: 14.4s
Precision: 64
Internal Precision: 128
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} = -\infty:\\ \;\;\;\;\frac{-a}{-c}\\ \mathbf{elif}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} \le 1.8905920109414215 \cdot 10^{+242}:\\ \;\;\;\;\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{-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

Original25.7
Target0.4
Herbie19.3
\[\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 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < -inf.0 or 1.8905920109414215e+242 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))

    1. Initial program 59.2

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

      \[\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 associate-/r*59.2

      \[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    5. Taylor expanded around -inf 58.8

      \[\leadsto \frac{\color{blue}{-1 \cdot a}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Simplified58.8

      \[\leadsto \frac{\color{blue}{-a}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Taylor expanded around -inf 37.5

      \[\leadsto \frac{-a}{\color{blue}{-1 \cdot c}}\]
    8. Simplified37.5

      \[\leadsto \frac{-a}{\color{blue}{-c}}\]

    if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 1.8905920109414215e+242

    1. Initial program 11.8

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

      \[\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 associate-/r*11.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} = -\infty:\\ \;\;\;\;\frac{-a}{-c}\\ \mathbf{elif}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} \le 1.8905920109414215 \cdot 10^{+242}:\\ \;\;\;\;\frac{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{-c}\\ \end{array}\]

Reproduce

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

sample69.0ms

Algorithm
intervals

simplify8.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 27.4b

localize36.0ms

Local error

Found 2 expressions with local error:

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

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
2 → 42
Calls

2 calls. Slowest were:

17.0ms
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
2.0ms
(+ (* a c) (* b d))

series83.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

54.0ms
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
29.0ms
(+ (* a c) (* b d))

simplify727.0ms

Counts
36 → 48
Calls

36 calls. Slowest were:

185.0ms
(- (* (* a c) (* a c)) (* (* b d) (* b d)))
142.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))))
116.0ms
(+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d))))

prune470.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 27.0b

localize8.0ms

Local error

Found 4 expressions with local error:

29.1b
(sqrt (+ (* c c) (* d d)))
29.1b
(sqrt (+ (* c c) (* d d)))
19.0b
(/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))
0.2b
(+ (* a c) (* b d))

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 82
Calls

4 calls. Slowest were:

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

series162.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

84.0ms
(/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))
31.0ms
(+ (* a c) (* b d))
26.0ms
(sqrt (+ (* c c) (* d d)))
22.0ms
(sqrt (+ (* c c) (* d d)))

simplify1.2s

Counts
75 → 94
Calls

75 calls. Slowest were:

195.0ms
(- (* (* a c) (* a c)) (* (* b d) (* b d)))
133.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))
130.0ms
(sqrt (+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d)))))

prune977.0ms

Pruning

7 alts after pruning (5 fresh and 2 done)

Merged error: 22.1b

localize7.0ms

Local error

Found 4 expressions with local error:

29.1b
(sqrt (+ (* c c) (* d d)))
29.1b
(sqrt (+ (* c c) (* d d)))
19.0b
(/ (+ (* 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)))))

rewrite24.0ms

Algorithm
rewrite-expression-head
Counts
4 → 119
Calls

4 calls. Slowest were:

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

series206.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

89.0ms
(/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))
72.0ms
(* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d)))))
26.0ms
(sqrt (+ (* c c) (* d d)))
19.0ms
(sqrt (+ (* c c) (* d d)))

simplify3.7s

Counts
113 → 131
Calls

113 calls. Slowest were:

737.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))))))
316.0ms
(* (/ 1 (sqrt (+ (* c c) (* d d)))) (/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d)))))
254.0ms
(- (* (* a c) (* a c)) (* (* b d) (* b d)))

prune1.8s

Pruning

8 alts after pruning (5 fresh and 3 done)

Merged error: 22.1b

localize5.0ms

Local error

Found 2 expressions with local error:

29.1b
(sqrt (+ (* c c) (* d d)))
0.0b
(/ (- a) (sqrt (+ (* c c) (* d d))))

rewrite7.0ms

Algorithm
rewrite-expression-head
Counts
2 → 64
Calls

2 calls. Slowest were:

4.0ms
(/ (- a) (sqrt (+ (* c c) (* d d))))
2.0ms
(sqrt (+ (* c c) (* d d)))

series62.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

34.0ms
(/ (- a) (sqrt (+ (* c c) (* d d))))
28.0ms
(sqrt (+ (* c c) (* d d)))

simplify848.0ms

Counts
74 → 70
Calls

74 calls. Slowest were:

151.0ms
(sqrt (+ (* (* c c) (* c c)) (- (* (* d d) (* d d)) (* (* c c) (* d d)))))
147.0ms
(/ (* (* (- a) (- a)) (- a)) (* (* (sqrt (+ (* c c) (* d d))) (sqrt (+ (* c c) (* d d)))) (sqrt (+ (* c c) (* d d)))))
113.0ms
(sqrt (- (* (* c c) (* c c)) (* (* d d) (* d d))))

prune649.0ms

Pruning

9 alts after pruning (6 fresh and 3 done)

Merged error: 15.0b

regimes527.0ms

Accuracy

57.6% (4.7b remaining)

Error of 19.3b against oracle of 14.6b and baseline of 25.6b

bsearch6.0ms

end0.0ms

sample1.9s

Algorithm
intervals