?

Average Accuracy: 78.4% → 99.9%
Time: 17.9s
Precision: binary64
Cost: 7104

?

\[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
\[\frac{\frac{x}{e^{wj}} + wj \cdot wj}{wj + 1} \]
(FPCore (wj x)
 :precision binary64
 (- wj (/ (- (* wj (exp wj)) x) (+ (exp wj) (* wj (exp wj))))))
(FPCore (wj x) :precision binary64 (/ (+ (/ x (exp wj)) (* wj wj)) (+ wj 1.0)))
double code(double wj, double x) {
	return wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
}
double code(double wj, double x) {
	return ((x / exp(wj)) + (wj * wj)) / (wj + 1.0);
}
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))))
end function
real(8) function code(wj, x)
    real(8), intent (in) :: wj
    real(8), intent (in) :: x
    code = ((x / exp(wj)) + (wj * wj)) / (wj + 1.0d0)
end function
public static double code(double wj, double x) {
	return wj - (((wj * Math.exp(wj)) - x) / (Math.exp(wj) + (wj * Math.exp(wj))));
}
public static double code(double wj, double x) {
	return ((x / Math.exp(wj)) + (wj * wj)) / (wj + 1.0);
}
def code(wj, x):
	return wj - (((wj * math.exp(wj)) - x) / (math.exp(wj) + (wj * math.exp(wj))))
def code(wj, x):
	return ((x / math.exp(wj)) + (wj * wj)) / (wj + 1.0)
function code(wj, x)
	return Float64(wj - Float64(Float64(Float64(wj * exp(wj)) - x) / Float64(exp(wj) + Float64(wj * exp(wj)))))
end
function code(wj, x)
	return Float64(Float64(Float64(x / exp(wj)) + Float64(wj * wj)) / Float64(wj + 1.0))
end
function tmp = code(wj, x)
	tmp = wj - (((wj * exp(wj)) - x) / (exp(wj) + (wj * exp(wj))));
end
function tmp = code(wj, x)
	tmp = ((x / exp(wj)) + (wj * wj)) / (wj + 1.0);
end
code[wj_, x_] := N[(wj - N[(N[(N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision] / N[(N[Exp[wj], $MachinePrecision] + N[(wj * N[Exp[wj], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[wj_, x_] := N[(N[(N[(x / N[Exp[wj], $MachinePrecision]), $MachinePrecision] + N[(wj * wj), $MachinePrecision]), $MachinePrecision] / N[(wj + 1.0), $MachinePrecision]), $MachinePrecision]
wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}
\frac{\frac{x}{e^{wj}} + wj \cdot wj}{wj + 1}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original78.4%
Target79.5%
Herbie99.9%
\[wj - \left(\frac{wj}{wj + 1} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right) \]

Derivation?

  1. Initial program 78.4%

    \[wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]
  2. Simplified79.5%

    \[\leadsto \color{blue}{wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
    Proof

    [Start]78.4

    \[ wj - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \]

    sub-neg [=>]78.4

    \[ \color{blue}{wj + \left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

    neg-mul-1 [=>]78.4

    \[ wj + \color{blue}{-1 \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}} \]

    *-commutative [=>]78.4

    \[ wj + \color{blue}{\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}} \cdot -1} \]

    *-commutative [<=]78.4

    \[ wj + \color{blue}{-1 \cdot \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}} \]

    neg-mul-1 [<=]78.4

    \[ wj + \color{blue}{\left(-\frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

    neg-sub0 [=>]78.4

    \[ wj + \color{blue}{\left(0 - \frac{wj \cdot e^{wj} - x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

    div-sub [=>]78.4

    \[ wj + \left(0 - \color{blue}{\left(\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}} - \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]

    associate--r- [=>]78.4

    \[ wj + \color{blue}{\left(\left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right) + \frac{x}{e^{wj} + wj \cdot e^{wj}}\right)} \]

    +-commutative [=>]78.4

    \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \left(0 - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)\right)} \]

    sub0-neg [=>]78.4

    \[ wj + \left(\frac{x}{e^{wj} + wj \cdot e^{wj}} + \color{blue}{\left(-\frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)}\right) \]

    sub-neg [<=]78.4

    \[ wj + \color{blue}{\left(\frac{x}{e^{wj} + wj \cdot e^{wj}} - \frac{wj \cdot e^{wj}}{e^{wj} + wj \cdot e^{wj}}\right)} \]
  3. Applied egg-rr55.7%

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

    [Start]79.5

    \[ wj + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    expm1-log1p-u [=>]79.0

    \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(wj\right)\right)} + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    log1p-def [<=]75.8

    \[ \mathsf{expm1}\left(\color{blue}{\log \left(1 + wj\right)}\right) + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    +-commutative [<=]75.8

    \[ \mathsf{expm1}\left(\log \color{blue}{\left(wj + 1\right)}\right) + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    expm1-udef [=>]75.8

    \[ \color{blue}{\left(e^{\log \left(wj + 1\right)} - 1\right)} + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    add-exp-log [<=]76.4

    \[ \left(\color{blue}{\left(wj + 1\right)} - 1\right) + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    associate-+l- [=>]55.7

    \[ \color{blue}{\left(wj + 1\right) - \left(1 - \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\right)} \]
  4. Simplified76.4%

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

    [Start]55.7

    \[ \left(wj + 1\right) - \left(1 - \frac{\frac{x}{e^{wj}} - wj}{wj + 1}\right) \]

    associate--r- [=>]76.4

    \[ \color{blue}{\left(\left(wj + 1\right) - 1\right) + \frac{\frac{x}{e^{wj}} - wj}{wj + 1}} \]
  5. Applied egg-rr78.2%

    \[\leadsto \color{blue}{\frac{wj \cdot wj}{wj}} + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]
    Proof

    [Start]76.4

    \[ \left(\left(wj + 1\right) - 1\right) + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    associate--l+ [=>]79.5

    \[ \color{blue}{\left(wj + \left(1 - 1\right)\right)} + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    metadata-eval [=>]79.5

    \[ \left(wj + \color{blue}{0}\right) + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    metadata-eval [<=]79.5

    \[ \left(wj + \color{blue}{\log 1}\right) + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    flip-+ [=>]78.2

    \[ \color{blue}{\frac{wj \cdot wj - \log 1 \cdot \log 1}{wj - \log 1}} + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]
  6. Applied egg-rr79.5%

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

    [Start]78.2

    \[ \frac{wj \cdot wj}{wj} + \frac{\frac{x}{e^{wj}} - wj}{wj + 1} \]

    +-commutative [=>]78.2

    \[ \color{blue}{\frac{\frac{x}{e^{wj}} - wj}{wj + 1} + \frac{wj \cdot wj}{wj}} \]

    associate-/l* [=>]79.5

    \[ \frac{\frac{x}{e^{wj}} - wj}{wj + 1} + \color{blue}{\frac{wj}{\frac{wj}{wj}}} \]

    *-inverses [=>]79.5

    \[ \frac{\frac{x}{e^{wj}} - wj}{wj + 1} + \frac{wj}{\color{blue}{1}} \]

    frac-add [=>]79.5

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

    *-commutative [<=]79.5

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

    *-un-lft-identity [<=]79.5

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

    *-commutative [<=]79.5

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

    distribute-rgt-in [=>]79.5

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

    *-un-lft-identity [<=]79.5

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

    +-commutative [<=]79.5

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

    *-commutative [<=]79.5

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

    *-un-lft-identity [<=]79.5

    \[ \frac{\left(\frac{x}{e^{wj}} - wj\right) + \left(wj + wj \cdot wj\right)}{\color{blue}{wj + 1}} \]
  7. Simplified99.9%

    \[\leadsto \color{blue}{\frac{\frac{x}{e^{wj}} + wj \cdot wj}{wj + 1}} \]
    Proof

    [Start]79.5

    \[ \frac{\left(\frac{x}{e^{wj}} - wj\right) + \left(wj + wj \cdot wj\right)}{wj + 1} \]

    sub-neg [=>]79.5

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

    associate-+l+ [=>]89.4

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

    +-commutative [=>]89.4

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

    distribute-rgt1-in [=>]89.4

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

    neg-mul-1 [=>]89.4

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

    distribute-rgt-in [<=]89.4

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

    associate-+l+ [=>]99.9

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

    metadata-eval [=>]99.9

    \[ \frac{\frac{x}{e^{wj}} + wj \cdot \left(wj + \color{blue}{0}\right)}{wj + 1} \]

    +-commutative [<=]99.9

    \[ \frac{\frac{x}{e^{wj}} + wj \cdot \color{blue}{\left(0 + wj\right)}}{wj + 1} \]

    +-lft-identity [=>]99.9

    \[ \frac{\frac{x}{e^{wj}} + wj \cdot \color{blue}{wj}}{wj + 1} \]
  8. Final simplification99.9%

    \[\leadsto \frac{\frac{x}{e^{wj}} + wj \cdot wj}{wj + 1} \]

Alternatives

Alternative 1
Accuracy83.4%
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -1.05 \cdot 10^{-180}:\\ \;\;\;\;\frac{x - x \cdot wj}{wj + 1}\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-307}:\\ \;\;\;\;\frac{wj}{1 + \frac{1}{wj}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(\frac{1}{wj + 1} - \frac{wj}{wj + 1}\right)\\ \end{array} \]
Alternative 2
Accuracy83.4%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -9.4 \cdot 10^{-181} \lor \neg \left(x \leq 4.4 \cdot 10^{-308}\right):\\ \;\;\;\;\frac{x - x \cdot wj}{wj + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{wj}{1 + \frac{1}{wj}}\\ \end{array} \]
Alternative 3
Accuracy98.4%
Cost832
\[\frac{wj \cdot wj + \left(x - x \cdot wj\right)}{wj + 1} \]
Alternative 4
Accuracy82.9%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{-180} \lor \neg \left(x \leq 6.8 \cdot 10^{-307}\right):\\ \;\;\;\;x + \left(x \cdot wj\right) \cdot -2\\ \mathbf{else}:\\ \;\;\;\;wj \cdot wj\\ \end{array} \]
Alternative 5
Accuracy83.3%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.52 \cdot 10^{-180} \lor \neg \left(x \leq 5.8 \cdot 10^{-307}\right):\\ \;\;\;\;x + \left(x \cdot wj\right) \cdot -2\\ \mathbf{else}:\\ \;\;\;\;\frac{wj}{1 + \frac{1}{wj}}\\ \end{array} \]
Alternative 6
Accuracy82.4%
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -8.8 \cdot 10^{-181}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{-308}:\\ \;\;\;\;wj \cdot wj\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Accuracy4.5%
Cost64
\[wj \]
Alternative 8
Accuracy85.0%
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (wj x)
  :name "Jmat.Real.lambertw, newton loop step"
  :precision binary64

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

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