Average Error: 1.5 → 0.3
Time: 18.5s
Precision: 64
Internal Precision: 128
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.6436486530612315 \cdot 10^{+33} \lor \neg \left(x \le 5.5078194604740656 \cdot 10^{-111}\right):\\ \;\;\;\;\left|\frac{4 + x}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4 + x}{y} - \frac{z \cdot x}{y}\right|\\ \end{array}\]

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < -1.6436486530612315e+33 or 5.5078194604740656e-111 < x

    1. Initial program 0.5

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.5

      \[\leadsto \left|\frac{\color{blue}{1 \cdot \left(x + 4\right)}}{y} - \frac{x}{y} \cdot z\right|\]
    4. Applied associate-/l*0.6

      \[\leadsto \left|\color{blue}{\frac{1}{\frac{y}{x + 4}}} - \frac{x}{y} \cdot z\right|\]
    5. Using strategy rm
    6. Applied add-cube-cbrt1.3

      \[\leadsto \left|\color{blue}{\left(\sqrt[3]{\frac{1}{\frac{y}{x + 4}}} \cdot \sqrt[3]{\frac{1}{\frac{y}{x + 4}}}\right) \cdot \sqrt[3]{\frac{1}{\frac{y}{x + 4}}}} - \frac{x}{y} \cdot z\right|\]
    7. Applied prod-diff1.3

      \[\leadsto \left|\color{blue}{(\left(\sqrt[3]{\frac{1}{\frac{y}{x + 4}}} \cdot \sqrt[3]{\frac{1}{\frac{y}{x + 4}}}\right) \cdot \left(\sqrt[3]{\frac{1}{\frac{y}{x + 4}}}\right) + \left(-z \cdot \frac{x}{y}\right))_* + (\left(-z\right) \cdot \left(\frac{x}{y}\right) + \left(z \cdot \frac{x}{y}\right))_*}\right|\]
    8. Simplified0.5

      \[\leadsto \left|\color{blue}{\left(\frac{4 + x}{y} - \frac{z}{\frac{y}{x}}\right)} + (\left(-z\right) \cdot \left(\frac{x}{y}\right) + \left(z \cdot \frac{x}{y}\right))_*\right|\]
    9. Simplified0.5

      \[\leadsto \left|\left(\frac{4 + x}{y} - \frac{z}{\frac{y}{x}}\right) + \color{blue}{0}\right|\]

    if -1.6436486530612315e+33 < x < 5.5078194604740656e-111

    1. Initial program 2.4

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
    2. Using strategy rm
    3. Applied *-un-lft-identity2.4

      \[\leadsto \left|\frac{\color{blue}{1 \cdot \left(x + 4\right)}}{y} - \frac{x}{y} \cdot z\right|\]
    4. Applied associate-/l*2.5

      \[\leadsto \left|\color{blue}{\frac{1}{\frac{y}{x + 4}}} - \frac{x}{y} \cdot z\right|\]
    5. Using strategy rm
    6. Applied add-cube-cbrt3.5

      \[\leadsto \left|\color{blue}{\left(\sqrt[3]{\frac{1}{\frac{y}{x + 4}}} \cdot \sqrt[3]{\frac{1}{\frac{y}{x + 4}}}\right) \cdot \sqrt[3]{\frac{1}{\frac{y}{x + 4}}}} - \frac{x}{y} \cdot z\right|\]
    7. Applied prod-diff3.5

      \[\leadsto \left|\color{blue}{(\left(\sqrt[3]{\frac{1}{\frac{y}{x + 4}}} \cdot \sqrt[3]{\frac{1}{\frac{y}{x + 4}}}\right) \cdot \left(\sqrt[3]{\frac{1}{\frac{y}{x + 4}}}\right) + \left(-z \cdot \frac{x}{y}\right))_* + (\left(-z\right) \cdot \left(\frac{x}{y}\right) + \left(z \cdot \frac{x}{y}\right))_*}\right|\]
    8. Simplified2.6

      \[\leadsto \left|\color{blue}{\left(\frac{4 + x}{y} - \frac{z}{\frac{y}{x}}\right)} + (\left(-z\right) \cdot \left(\frac{x}{y}\right) + \left(z \cdot \frac{x}{y}\right))_*\right|\]
    9. Simplified2.6

      \[\leadsto \left|\left(\frac{4 + x}{y} - \frac{z}{\frac{y}{x}}\right) + \color{blue}{0}\right|\]
    10. Using strategy rm
    11. Applied associate-/r/5.4

      \[\leadsto \left|\left(\frac{4 + x}{y} - \color{blue}{\frac{z}{y} \cdot x}\right) + 0\right|\]
    12. Applied add-sqr-sqrt32.9

      \[\leadsto \left|\left(\color{blue}{\sqrt{\frac{4 + x}{y}} \cdot \sqrt{\frac{4 + x}{y}}} - \frac{z}{y} \cdot x\right) + 0\right|\]
    13. Applied prod-diff32.9

      \[\leadsto \left|\color{blue}{\left((\left(\sqrt{\frac{4 + x}{y}}\right) \cdot \left(\sqrt{\frac{4 + x}{y}}\right) + \left(-x \cdot \frac{z}{y}\right))_* + (\left(-x\right) \cdot \left(\frac{z}{y}\right) + \left(x \cdot \frac{z}{y}\right))_*\right)} + 0\right|\]
    14. Simplified5.4

      \[\leadsto \left|\left(\color{blue}{\left(\frac{x + 4}{y} - \frac{x}{\frac{y}{z}}\right)} + (\left(-x\right) \cdot \left(\frac{z}{y}\right) + \left(x \cdot \frac{z}{y}\right))_*\right) + 0\right|\]
    15. Simplified5.0

      \[\leadsto \left|\left(\left(\frac{x + 4}{y} - \frac{x}{\frac{y}{z}}\right) + \color{blue}{0}\right) + 0\right|\]
    16. Taylor expanded around inf 0.1

      \[\leadsto \left|\left(\left(\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right) + 0\right) + 0\right|\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.6436486530612315 \cdot 10^{+33} \lor \neg \left(x \le 5.5078194604740656 \cdot 10^{-111}\right):\\ \;\;\;\;\left|\frac{4 + x}{y} - \frac{z}{\frac{y}{x}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4 + x}{y} - \frac{z \cdot x}{y}\right|\\ \end{array}\]

Reproduce

herbie shell --seed 2019008 +o rules:numerics
(FPCore (x y z)
  :name "fabs fraction 1"
  (fabs (- (/ (+ x 4) y) (* (/ x y) z))))

Details

Time bar (total: 18.1s)Debug log

sample82.0ms

Algorithm
intervals

simplify33.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

33.0ms
(fabs (- (/ (+ x 4) y) (* (/ x y) z)))

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 1.5b

localize17.0ms

Local error

Found 3 expressions with local error:

4.0b
(* (/ x y) z)
0.0b
(- (/ (+ x 4) y) (* (/ x y) z))
0.0b
(/ (+ x 4) y)

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
3 → 56
Calls

3 calls. Slowest were:

9.0ms
(* (/ x y) z)
7.0ms
(- (/ (+ x 4) y) (* (/ x y) z))
2.0ms
(/ (+ x 4) y)

series53.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

25.0ms
(- (/ (+ x 4) y) (* (/ x y) z))
14.0ms
(* (/ x y) z)
14.0ms
(/ (+ x 4) y)

simplify1.1s

Counts
31 → 65
Calls

31 calls. Slowest were:

223.0ms
(fma (+ x 4) (/ 1 y) (- (* z (/ x y))))
136.0ms
(- (* (+ x 4) y) (* y (* x z)))
118.0ms
(- (+ (/ x y) (* 4 (/ 1 y))) (/ (* x z) y))

prune675.0ms

Pruning

5 alts after pruning (5 fresh and 0 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 4 expressions with local error:

4.0b
(* (/ x y) z)
0.1b
(/ 1 (/ y (+ x 4)))
0.0b
(- (/ 1 (/ y (+ x 4))) (* (/ x y) z))
0.0b
(/ y (+ x 4))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
4 → 79
Calls

4 calls. Slowest were:

6.0ms
(- (/ 1 (/ y (+ x 4))) (* (/ x y) z))
4.0ms
(* (/ x y) z)
1.0ms
(/ 1 (/ y (+ x 4)))

series75.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

27.0ms
(- (/ 1 (/ y (+ x 4))) (* (/ x y) z))
19.0ms
(/ y (+ x 4))
15.0ms
(/ 1 (/ y (+ x 4)))
14.0ms
(* (/ x y) z)

simplify3.8s

Counts
44 → 91
Calls

44 calls. Slowest were:

733.0ms
(fma (/ 1 y) (+ x 4) (- (* z (/ x y))))
373.0ms
(fma (sqrt (/ 1 (/ y (+ x 4)))) (sqrt (/ 1 (/ y (+ x 4)))) (- (* z (/ x y))))
355.0ms
(- (+ (/ y x) (* 16 (/ y (pow x 3)))) (* 4 (/ y (pow x 2))))

prune1.1s

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 0b

localize35.0ms

Local error

Found 3 expressions with local error:

4.4b
(/ z (/ y x))
0.0b
(- (/ (+ 4 x) y) (/ z (/ y x)))
0.0b
(/ (+ 4 x) y)

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
3 → 75
Calls

3 calls. Slowest were:

16.0ms
(- (/ (+ 4 x) y) (/ z (/ y x)))
2.0ms
(/ (+ 4 x) y)
1.0ms
(/ z (/ y x))

series68.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

33.0ms
(- (/ (+ 4 x) y) (/ z (/ y x)))
22.0ms
(/ (+ 4 x) y)
13.0ms
(/ z (/ y x))

simplify4.5s

Counts
66 → 84
Calls

66 calls. Slowest were:

255.0ms
(fma (+ 4 x) (/ 1 y) (- (* x (/ z y))))
234.0ms
(fma 1 (/ (+ 4 x) y) (- (* (/ 1 (/ y x)) z)))
220.0ms
(fma (- (/ 1 (/ y x))) z (* (/ 1 (/ y x)) z))

prune558.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 0b

localize14.0ms

Local error

Found 3 expressions with local error:

7.6b
(/ x (/ y z))
0.0b
(- (/ (+ x 4) y) (/ x (/ y z)))
0.0b
(/ (+ x 4) y)

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
3 → 75
Calls

3 calls. Slowest were:

6.0ms
(- (/ (+ x 4) y) (/ x (/ y z)))
2.0ms
(/ (+ x 4) y)
0.0ms
(/ x (/ y z))

series65.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

35.0ms
(- (/ (+ x 4) y) (/ x (/ y z)))
16.0ms
(/ (+ x 4) y)
13.0ms
(/ x (/ y z))

simplify3.8s

Counts
66 → 84
Calls

66 calls. Slowest were:

262.0ms
(fma 1 (/ (+ x 4) y) (- (* (/ 1 (/ y z)) x)))
213.0ms
(fma (+ x 4) (/ 1 y) (- (* (/ x (/ y z)) 1)))
213.0ms
(fma (+ x 4) (/ 1 y) (- (* z (/ x y))))

prune698.0ms

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0b

regimes124.0ms

Accuracy

81.4% (0.3b remaining)

Error of 0.3b against oracle of 0.0b and baseline of 1.6b

bsearch106.0ms

end0.0ms

sample1.1s

Algorithm
intervals