Average Error: 13.9 → 0.2
Time: 24.2s
Precision: 64
Internal Precision: 128
\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
\[\begin{array}{l} \mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 4.904870601809956 \cdot 10^{-10}:\\ \;\;\;\;(\left(1 - wj\right) \cdot \left(wj \cdot wj\right) + \left({wj}^{4}\right))_* - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\ \mathbf{else}:\\ \;\;\;\;wj - \left(wj - \frac{x}{e^{wj}}\right) \cdot \frac{1}{wj + 1}\\ \end{array}\]

Error

Bits error versus wj

Bits error versus x

Target

Original13.9
Target13.3
Herbie0.2
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)\]

Derivation

  1. Split input into 2 regimes
  2. if (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))) < 4.904870601809956e-10

    1. Initial program 18.0

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied distribute-rgt1-in18.0

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity18.0

      \[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{\left(wj + 1\right) \cdot e^{wj}}\]
    5. Applied times-frac18.0

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Simplified18.0

      \[\leadsto wj - \frac{1}{wj + 1} \cdot \color{blue}{\left(wj - \frac{x}{e^{wj}}\right)}\]
    7. Using strategy rm
    8. Applied sub-neg18.0

      \[\leadsto wj - \frac{1}{wj + 1} \cdot \color{blue}{\left(wj + \left(-\frac{x}{e^{wj}}\right)\right)}\]
    9. Applied distribute-rgt-in18.0

      \[\leadsto wj - \color{blue}{\left(wj \cdot \frac{1}{wj + 1} + \left(-\frac{x}{e^{wj}}\right) \cdot \frac{1}{wj + 1}\right)}\]
    10. Applied associate--r+9.5

      \[\leadsto \color{blue}{\left(wj - wj \cdot \frac{1}{wj + 1}\right) - \left(-\frac{x}{e^{wj}}\right) \cdot \frac{1}{wj + 1}}\]
    11. Simplified9.5

      \[\leadsto \left(wj - wj \cdot \frac{1}{wj + 1}\right) - \color{blue}{\frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\]
    12. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\left(\left({wj}^{2} + {wj}^{4}\right) - {wj}^{3}\right)} - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\]
    13. Simplified0.2

      \[\leadsto \color{blue}{(\left(1 - wj\right) \cdot \left(wj \cdot wj\right) + \left({wj}^{4}\right))_*} - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\]

    if 4.904870601809956e-10 < (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

    1. Initial program 2.5

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied distribute-rgt1-in2.5

      \[\leadsto wj - \frac{wj \cdot e^{wj} - x}{\color{blue}{\left(wj + 1\right) \cdot e^{wj}}}\]
    4. Applied *-un-lft-identity2.5

      \[\leadsto wj - \frac{\color{blue}{1 \cdot \left(wj \cdot e^{wj} - x\right)}}{\left(wj + 1\right) \cdot e^{wj}}\]
    5. Applied times-frac2.5

      \[\leadsto wj - \color{blue}{\frac{1}{wj + 1} \cdot \frac{wj \cdot e^{wj} - x}{e^{wj}}}\]
    6. Simplified0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \le 4.904870601809956 \cdot 10^{-10}:\\ \;\;\;\;(\left(1 - wj\right) \cdot \left(wj \cdot wj\right) + \left({wj}^{4}\right))_* - \frac{-x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\\ \mathbf{else}:\\ \;\;\;\;wj - \left(wj - \frac{x}{e^{wj}}\right) \cdot \frac{1}{wj + 1}\\ \end{array}\]

Reproduce

herbie shell --seed 2019004 +o rules:numerics
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"

  :herbie-target
  (- wj (- (/ wj (+ wj 1)) (/ x (+ (exp wj) (* wj (exp wj))))))

  (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))

Details

Time bar (total: 23.6s)Debug log

sample232.0ms

Algorithm
intervals

simplify178.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

178.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))

prune9.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 13.0b

localize19.0ms

Local error

Found 4 expressions with local error:

4.9b
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
0.8b
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
0.0b
(+ (exp wj) (* wj (exp wj)))
0.0b
(* wj (exp wj))

rewrite31.0ms

Algorithm
rewrite-expression-head
Counts
4 → 87
Calls

4 calls. Slowest were:

19.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
7.0ms
(+ (exp wj) (* wj (exp wj)))
2.0ms
(* wj (exp wj))

series186.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

86.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
53.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
27.0ms
(* wj (exp wj))
19.0ms
(+ (exp wj) (* wj (exp wj)))

simplify3.3s

Counts
66 → 99
Calls

66 calls. Slowest were:

525.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
436.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
350.0ms
(+ (* (exp wj) (exp wj)) (- (* (* wj (exp wj)) (* wj (exp wj))) (* (exp wj) (* wj (exp wj)))))

prune999.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.2b

localize15.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune16.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.2b

localize31.0ms

Local error

Found 4 expressions with local error:

4.9b
(- wj (* (/ 1 (+ wj 1)) (- wj (/ x (exp wj)))))
0.0b
(* (/ 1 (+ wj 1)) (- wj (/ x (exp wj))))
0.0b
(/ 1 (+ wj 1))
0.0b
(/ x (exp wj))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 84
Calls

4 calls. Slowest were:

15.0ms
(* (/ 1 (+ wj 1)) (- wj (/ x (exp wj))))
2.0ms
(- wj (* (/ 1 (+ wj 1)) (- wj (/ x (exp wj)))))
2.0ms
(/ 1 (+ wj 1))

series144.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

50.0ms
(- wj (* (/ 1 (+ wj 1)) (- wj (/ x (exp wj)))))
48.0ms
(* (/ 1 (+ wj 1)) (- wj (/ x (exp wj))))
36.0ms
(/ x (exp wj))
11.0ms
(/ 1 (+ wj 1))

simplify5.4s

Counts
47 → 96
Calls

47 calls. Slowest were:

631.0ms
(* (* (* (/ 1 (+ wj 1)) (/ 1 (+ wj 1))) (/ 1 (+ wj 1))) (* (* (- wj (/ x (exp wj))) (- wj (/ x (exp wj)))) (- wj (/ x (exp wj)))))
545.0ms
(* (+ wj 1) (+ (* wj wj) (+ (* (/ x (exp wj)) (/ x (exp wj))) (* wj (/ x (exp wj))))))
459.0ms
(* 1 (- (pow wj 3) (pow (/ x (exp wj)) 3)))

prune838.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.2b

localize31.0ms

Local error

Found 4 expressions with local error:

4.8b
(- wj (* wj (/ 1 (+ wj 1))))
0.0b
(* wj (/ 1 (+ wj 1)))
0.0b
(fma wj (exp wj) (exp wj))
0.0b
(/ (- x) (fma wj (exp wj) (exp wj)))

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 76
Calls

4 calls. Slowest were:

6.0ms
(/ (- x) (fma wj (exp wj) (exp wj)))
2.0ms
(* wj (/ 1 (+ wj 1)))
1.0ms
(- wj (* wj (/ 1 (+ wj 1))))

series122.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

68.0ms
(/ (- x) (fma wj (exp wj) (exp wj)))
28.0ms
(fma wj (exp wj) (exp wj))
16.0ms
(- wj (* wj (/ 1 (+ wj 1))))
9.0ms
(* wj (/ 1 (+ wj 1)))

simplify1.9s

Counts
53 → 88
Calls

53 calls. Slowest were:

491.0ms
(- (* 2 (* x wj)) (+ x (* 5/2 (* x (pow wj 2)))))
425.0ms
(/ (* (* (- x) (- x)) (- x)) (* (* (fma wj (exp wj) (exp wj)) (fma wj (exp wj) (exp wj))) (fma wj (exp wj) (exp wj))))
63.0ms
(- (/ x (* (exp wj) (pow wj 2))) (+ (/ x (* (exp wj) wj)) (/ x (* (exp wj) (pow wj 3)))))

prune1.1s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.1b

regimes179.0ms

Accuracy

87.6% (0.1b remaining)

Error of 0.2b against oracle of 0.1b and baseline of 1.1b

bsearch10.0ms

end0.0ms

sample8.8s

Algorithm
intervals