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

Error

Bits error versus wj

Bits error versus x

Target

Original13.8
Target13.2
Herbie0.3
\[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 < 8.218026681193705e-05

    1. Initial program 13.5

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

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

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

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

      \[\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))_*}\]
    7. Simplified0.3

      \[\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 8.218026681193705e-05 < wj

    1. Initial program 25.7

      \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\]
    2. Using strategy rm
    3. Applied div-sub25.7

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

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

      \[\leadsto \left(wj - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \color{blue}{\frac{x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity25.6

      \[\leadsto \left(wj - \frac{wj \cdot e^{wj}}{\color{blue}{1 \cdot \left(e^{wj} + wj \cdot e^{wj}\right)}}\right) + \frac{x}{(wj \cdot \left(e^{wj}\right) + \left(e^{wj}\right))_*}\]
    8. Applied times-frac25.6

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

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

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

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

Reproduce

herbie shell --seed 2019008 +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: 19.3s)Debug log

sample254.0ms

Algorithm
intervals

simplify142.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune22.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 16.3b

localize31.0ms

Local error

Found 4 expressions with local error:

6.0b
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
1.5b
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
0.0b
(* wj (exp wj))
0.0b
(* wj (exp wj))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
4 → 82
Calls

4 calls. Slowest were:

9.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
1.0ms
(* wj (exp wj))
1.0ms
(* wj (exp wj))

series149.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

56.0ms
(- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj)))))
52.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
25.0ms
(* wj (exp wj))
16.0ms
(* wj (exp wj))

simplify3.4s

Counts
63 → 94
Calls

63 calls. Slowest were:

671.0ms
(/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))
379.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
314.0ms
(+ (* (exp wj) (exp wj)) (- (* (* wj (exp wj)) (* wj (exp wj))) (* (exp wj) (* wj (exp wj)))))

prune852.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.4b

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:

prune18.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.4b

localize35.0ms

Local error

Found 4 expressions with local error:

6.7b
(- wj (/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj)))))
1.5b
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
0.0b
(/ x (fma wj (exp wj) (exp wj)))
0.0b
(* wj (exp wj))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
4 → 68
Calls

4 calls. Slowest were:

13.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
2.0ms
(* wj (exp wj))
1.0ms
(- wj (/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj)))))

series208.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

84.0ms
(/ x (fma wj (exp wj) (exp wj)))
60.0ms
(- wj (/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj)))))
46.0ms
(/ (* wj (exp wj)) (+ (exp wj) (* wj (exp wj))))
19.0ms
(* wj (exp wj))

simplify1.7s

Counts
37 → 80
Calls

37 calls. Slowest were:

358.0ms
(- (+ x (* 5/2 (* x (pow wj 2)))) (* 2 (* x wj)))
326.0ms
(+ (* (exp wj) (exp wj)) (- (* (* wj (exp wj)) (* wj (exp wj))) (* (exp wj) (* wj (exp wj)))))
136.0ms
(/ (* (* (* wj (exp wj)) (* wj (exp wj))) (* wj (exp wj))) (* (* (+ (exp wj) (* wj (exp wj))) (+ (exp wj) (* wj (exp wj)))) (+ (exp wj) (* wj (exp wj)))))

prune782.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.1b

localize15.0ms

Local error

Found 4 expressions with local error:

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

rewrite5.0ms

Algorithm
rewrite-expression-head
Counts
4 → 53
Calls

4 calls. Slowest were:

4.0ms
(+ (fma (- 1 wj) (* wj wj) (pow wj 4)) (/ x (fma wj (exp wj) (exp wj))))
0.0ms
(/ x (fma wj (exp wj) (exp wj)))
0.0ms
(fma (- 1 wj) (* wj wj) (pow wj 4))

series149.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

57.0ms
(+ (fma (- 1 wj) (* wj wj) (pow wj 4)) (/ x (fma wj (exp wj) (exp wj))))
57.0ms
(/ x (fma wj (exp wj) (exp wj)))
21.0ms
(fma wj (exp wj) (exp wj))
13.0ms
(fma (- 1 wj) (* wj wj) (pow wj 4))

simplify1.7s

Counts
20 → 65
Calls

20 calls. Slowest were:

413.0ms
(- (+ x (* 5/2 (* x (pow wj 2)))) (* 2 (* x wj)))
311.0ms
(* (exp (fma (- 1 wj) (* wj wj) (pow wj 4))) (exp (/ x (fma wj (exp wj) (exp wj)))))
256.0ms
(+ (fma (- 1 wj) (* wj wj) (pow wj 4)) (/ x (fma wj (exp wj) (exp wj))))

prune768.0ms

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.1b

regimes104.0ms

Accuracy

79.6% (0.2b remaining)

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

bsearch54.0ms

end0.0ms

sample8.8s

Algorithm
intervals