Average Error: 1.7 → 0.2
Time: 20.9s
Precision: 64
Internal Precision: 128
\[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.3295382770734683 \cdot 10^{+54} \lor \neg \left(x \le 6.379273375108504 \cdot 10^{-54}\right):\\ \;\;\;\;\left|\frac{4 + x}{y} - \frac{x}{\frac{y}{z}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{\left(4 + x\right) - 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 < -2.3295382770734683e+54 or 6.379273375108504e-54 < x

    1. Initial program 0.4

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

      \[\leadsto \left|\frac{\color{blue}{1 \cdot \left(x + 4\right)}}{y} - \frac{x}{y} \cdot z\right|\]
    4. Applied associate-/l*0.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-cbrt1.1

      \[\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.1

      \[\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.4

      \[\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.4

      \[\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/0.3

      \[\leadsto \left|\left(\frac{4 + x}{y} - \color{blue}{\frac{z}{y} \cdot x}\right) + 0\right|\]
    12. Applied add-sqr-sqrt30.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-diff30.8

      \[\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. Simplified0.3

      \[\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. Simplified0.3

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

    if -2.3295382770734683e+54 < x < 6.379273375108504e-54

    1. Initial program 2.6

      \[\left|\frac{x + 4}{y} - \frac{x}{y} \cdot z\right|\]
    2. Using strategy rm
    3. Applied associate-*l/0.2

      \[\leadsto \left|\frac{x + 4}{y} - \color{blue}{\frac{x \cdot z}{y}}\right|\]
    4. Applied sub-div0.2

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

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

Reproduce

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

Details

Time bar (total: 20.1s)Debug log

sample58.0ms

Algorithm
intervals
Results
313×(pre true 80)
313×(body real 80)

simplify28.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
28.0ms
(fabs (- (/ (+ x 4) y) (* (/ x y) z)))

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 1.7b

localize28.0ms

Local error

Found 3 expressions with local error:

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

rewrite15.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
div-inv
prod-diff
associate-*l*
fma-neg
associate-/l*
log1p-expm1-u
add-exp-log
associate-*l/
add-cbrt-cube
pow1
expm1-log1p-u
associate-/l/
sub-div
flip--
flip-+
frac-sub
*-commutative
diff-log
flip3--
flip3-+
frac-2neg
sub-neg
clear-num
Counts
3 → 56
Calls
3 calls:
Slowest
7.0ms
(- (/ (+ x 4) y) (* (/ x y) z))
4.0ms
(/ (+ x 4) y)
3.0ms
(* (/ x y) z)

series92.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
43.0ms
(- (/ (+ x 4) y) (* (/ x y) z))
24.0ms
(* (/ x y) z)
24.0ms
(/ (+ x 4) y)

simplify1.5s

Counts
31 → 65
Calls
31 calls:
Slowest
396.0ms
(fma (* (cbrt (/ (+ x 4) y)) (cbrt (/ (+ x 4) y))) (cbrt (/ (+ x 4) y)) (- (* z (/ x y))))
206.0ms
(fma (+ x 4) (/ 1 y) (- (* z (/ x y))))
146.0ms
(- (* (+ x 4) y) (* y (* x z)))
95.0ms
(- (+ (/ x y) (* 4 (/ 1 y))) (/ (* x z) y))
90.0ms
(- (+ (/ x y) (* 4 (/ 1 y))) (/ (* x z) y))

prune750.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
*-un-lft-identity
associate-/r*
add-sqr-sqrt
associate-/r/
add-log-exp
div-inv
add-exp-log
prod-diff
fma-neg
pow1
log1p-expm1-u
associate-*l*
add-cbrt-cube
expm1-log1p-u
flip-+
associate-*l/
flip3-+
frac-2neg
clear-num
inv-pow
flip--
pow-flip
frac-sub
*-commutative
diff-log
flip3--
sub-neg
rec-exp
Counts
4 → 79
Calls
4 calls:
Slowest
10.0ms
(- (/ 1 (/ y (+ x 4))) (* (/ x y) z))
5.0ms
(* (/ x y) z)
2.0ms
(/ 1 (/ y (+ x 4)))
1.0ms
(/ y (+ x 4))

series98.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
42.0ms
(- (/ 1 (/ y (+ x 4))) (* (/ x y) z))
24.0ms
(/ y (+ x 4))
19.0ms
(* (/ x y) z)
13.0ms
(/ 1 (/ y (+ x 4)))

simplify3.6s

Counts
44 → 91
Calls
44 calls:
Slowest
416.0ms
(fma (sqrt (/ 1 (/ y (+ x 4)))) (sqrt (/ 1 (/ y (+ x 4)))) (- (* z (/ x y))))
378.0ms
(fma (/ 1 y) (+ x 4) (- (* z (/ x y))))
329.0ms
(- (+ (* 1/64 (* (pow x 2) y)) (* 1/4 y)) (* 1/16 (* x y)))
294.0ms
(fma 1 (/ 1 (/ y (+ x 4))) (- (* z (/ x y))))
292.0ms
(- (+ (/ y x) (* 16 (/ y (pow x 3)))) (* 4 (/ y (pow x 2))))

prune936.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.0b

localize30.0ms

Local error

Found 3 expressions with local error:

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

rewrite13.0ms

Algorithm
rewrite-expression-head
Rules
20×prod-diff
17×*-un-lft-identity
17×add-sqr-sqrt
15×add-cube-cbrt
13×div-inv
add-log-exp
associate-/r/
fma-neg
associate-/r*
associate-/l*
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
associate-/l/
frac-2neg
clear-num
difference-of-squares
distribute-lft-out--
flip--
flip-+
frac-sub
diff-log
flip3--
flip3-+
sub-neg
Counts
3 → 75
Calls
3 calls:
Slowest
9.0ms
(- (/ (+ 4 x) y) (/ z (/ y x)))
3.0ms
(/ (+ 4 x) y)
0.0ms
(/ z (/ y x))

series62.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
25.0ms
(- (/ (+ 4 x) y) (/ z (/ y x)))
21.0ms
(/ z (/ y x))
16.0ms
(/ (+ 4 x) y)

simplify4.7s

Counts
66 → 84
Calls
66 calls:
Slowest
240.0ms
(fma 1 (/ (+ 4 x) y) (- (* (/ 1 (/ y x)) z)))
236.0ms
(fma (+ 4 x) (/ 1 y) (- (* x (/ z y))))
234.0ms
(fma (sqrt (/ (+ 4 x) y)) (sqrt (/ (+ 4 x) y)) (- (* (/ 1 (/ y x)) z)))
212.0ms
(fma (- (/ 1 (/ y x))) z (* (/ 1 (/ y x)) z))
205.0ms
(fma (+ 4 x) (/ 1 y) (- (* (/ z (/ y x)) 1)))

prune807.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0b

localize31.0ms

Local error

Found 3 expressions with local error:

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

rewrite16.0ms

Algorithm
rewrite-expression-head
Rules
20×prod-diff
17×*-un-lft-identity
17×add-sqr-sqrt
15×add-cube-cbrt
13×div-inv
add-log-exp
associate-/r/
fma-neg
associate-/r*
associate-/l*
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
associate-/l/
frac-2neg
clear-num
difference-of-squares
distribute-lft-out--
flip--
flip-+
frac-sub
diff-log
flip3--
flip3-+
sub-neg
Counts
3 → 75
Calls
3 calls:
Slowest
12.0ms
(- (/ (+ x 4) y) (/ x (/ y z)))
2.0ms
(/ (+ x 4) y)
1.0ms
(/ x (/ y z))

series70.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
42.0ms
(- (/ (+ x 4) y) (/ x (/ y z)))
15.0ms
(/ x (/ y z))
14.0ms
(/ (+ x 4) y)

simplify4.7s

Counts
66 → 84
Calls
66 calls:
Slowest
276.0ms
(fma 1 (/ (+ x 4) y) (- (* (/ 1 (/ y z)) x)))
230.0ms
(fma (+ x 4) (/ 1 y) (- (* (/ x (/ y z)) 1)))
220.0ms
(fma (* (cbrt (/ (+ x 4) y)) (cbrt (/ (+ x 4) y))) (cbrt (/ (+ x 4) y)) (- (* (/ 1 (/ y z)) x)))
219.0ms
(fma (sqrt (/ (+ x 4) y)) (sqrt (/ (+ x 4) y)) (- (* (/ 1 (/ y z)) x)))
206.0ms
(fma (+ x 4) (/ 1 y) (- (* (sqrt (/ x (/ y z))) (sqrt (/ x (/ y z))))))

prune703.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0b

regimes130.0ms

Accuracy

88.8% (0.2b remaining)

Error of 0.2b against oracle of 0.0b and baseline of 1.8b

bsearch147.0ms

end0.0ms

sample1.5s

Algorithm
intervals
Results
10087×(pre true 80)
10087×(body real 80)