Average Error: 1.6 → 0.1
Time: 10.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.305821992521901 \cdot 10^{-26} \lor \neg \left(x \le 5.613510658928969 \cdot 10^{-09}\right):\\ \;\;\;\;\left|\left(\frac{4}{y} + \frac{x}{y}\right) - \frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{4}{y} + \left(\frac{x}{y} - \frac{x \cdot z}{y}\right)\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.305821992521901e-26 or 5.613510658928969e-09 < x

    1. Initial program 0.1

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
    2. Taylor expanded around 0 0.1

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

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

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

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

    if -1.305821992521901e-26 < x < 5.613510658928969e-09

    1. Initial program 2.8

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
    2. Taylor expanded around 0 2.8

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

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

      \[\leadsto \left|\color{blue}{\left(\frac{x}{y} + 4 \cdot \frac{1}{y}\right) - \frac{x \cdot z}{y}}\right|\]
    5. Simplified5.2

      \[\leadsto \left|\color{blue}{\left(\frac{x}{y} + \frac{4}{y}\right) - \frac{x}{\frac{y}{z}}}\right|\]
    6. Using strategy rm
    7. Applied *-un-lft-identity5.2

      \[\leadsto \left|\left(\frac{x}{y} + \frac{4}{y}\right) - \color{blue}{1 \cdot \frac{x}{\frac{y}{z}}}\right|\]
    8. Applied *-un-lft-identity5.2

      \[\leadsto \left|\left(\frac{x}{y} + \color{blue}{1 \cdot \frac{4}{y}}\right) - 1 \cdot \frac{x}{\frac{y}{z}}\right|\]
    9. Applied *-un-lft-identity5.2

      \[\leadsto \left|\left(\color{blue}{1 \cdot \frac{x}{y}} + 1 \cdot \frac{4}{y}\right) - 1 \cdot \frac{x}{\frac{y}{z}}\right|\]
    10. Applied distribute-lft-out5.2

      \[\leadsto \left|\color{blue}{1 \cdot \left(\frac{x}{y} + \frac{4}{y}\right)} - 1 \cdot \frac{x}{\frac{y}{z}}\right|\]
    11. Applied distribute-lft-out--5.2

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

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

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

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

Reproduce

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

Details

Time bar (total: 10.1s)Debug log

sample49.0ms

Algorithm
intervals

simplify40.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 2.0b

localize16.0ms

Local error

Found 3 expressions with local error:

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

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
3 → 42
Calls

3 calls. Slowest were:

7.0ms
(- (/ (+ x 4) y) (* (/ x y) z))
4.0ms
(/ (+ x 4) y)
3.0ms
(* (/ x y) z)

series89.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

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

simplify477.0ms

Counts
20 → 51
Calls

20 calls. Slowest were:

96.0ms
(- (* (+ x 4) y) (* y (* x z)))
81.0ms
(- (+ (/ x y) (* 4 (/ 1 y))) (/ (* x z) y))
78.0ms
(- (+ (/ x y) (* 4 (/ 1 y))) (/ (* x z) y))

prune541.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize24.0ms

Local error

Found 3 expressions with local error:

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

rewrite30.0ms

Algorithm
rewrite-expression-head
Counts
3 → 44
Calls

3 calls. Slowest were:

22.0ms
(- (+ (/ x y) (/ 4 y)) (* (/ x y) z))
4.0ms
(* (/ x y) z)
3.0ms
(+ (/ x y) (/ 4 y))

series67.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

34.0ms
(- (+ (/ x y) (/ 4 y)) (* (/ x y) z))
18.0ms
(* (/ x y) z)
15.0ms
(+ (/ x y) (/ 4 y))

simplify1.5s

Counts
27 → 53
Calls

27 calls. Slowest were:

345.0ms
(- (* (+ (pow (/ x y) 3) (pow (/ 4 y) 3)) y) (* (+ (* (/ x y) (/ x y)) (- (* (/ 4 y) (/ 4 y)) (* (/ x y) (/ 4 y)))) (* x z)))
283.0ms
(- (* (+ (* x y) (* y 4)) y) (* (* y y) (* x z)))
192.0ms
(* (+ (* (/ x y) (/ x y)) (- (* (/ 4 y) (/ 4 y)) (* (/ x y) (/ 4 y)))) y)

prune508.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.0b

localize10.0ms

Local error

Found 3 expressions with local error:

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

rewrite23.0ms

Algorithm
rewrite-expression-head
Counts
3 → 49
Calls

3 calls. Slowest were:

19.0ms
(- (+ (/ x y) (/ 4 y)) (/ x (/ y z)))
3.0ms
(+ (/ x y) (/ 4 y))
0.0ms
(/ x (/ y z))

series72.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

29.0ms
(- (+ (/ x y) (/ 4 y)) (/ x (/ y z)))
27.0ms
(/ x (/ y z))
16.0ms
(+ (/ x y) (/ 4 y))

simplify1.6s

Counts
32 → 58
Calls

32 calls. Slowest were:

243.0ms
(- (* (+ (* x y) (* y 4)) (/ y z)) (* (* y y) x))
242.0ms
(- (* (- (* (/ x y) (/ x y)) (* (/ 4 y) (/ 4 y))) (/ y z)) (* (- (/ x y) (/ 4 y)) x))
217.0ms
(- (* (+ (pow (/ x y) 3) (pow (/ 4 y) 3)) (/ y z)) (* (+ (* (/ x y) (/ x y)) (- (* (/ 4 y) (/ 4 y)) (* (/ x y) (/ 4 y)))) x))

prune511.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.0b

localize12.0ms

Local error

Found 2 expressions with local error:

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

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
2 → 39
Calls

2 calls. Slowest were:

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

series58.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

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

simplify2.4s

Counts
32 → 45
Calls

32 calls. Slowest were:

393.0ms
(* (* (+ (* 1 1) (+ (* z z) (* 1 z))) y) y)
271.0ms
(* (* (* (- 1 z) (- 1 z)) (- 1 z)) (* (* (/ x y) (/ x y)) (/ x y)))
214.0ms
(* (- (* 1 1) (* z z)) (/ x y))

prune401.0ms

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.0b

regimes193.0ms

Accuracy

94.4% (0.1b remaining)

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

bsearch176.0ms

end0.0ms

sample1.3s

Algorithm
intervals