For fixed vectors in a finite-dimensional Euclidean space, define
The gradient and Hessian matrix of are
To derive the first identity, differentiate each exponential function and divide the sum of its gradients by . For the second, differentiating a normalized weight gives . Thus , where the weighted covariance matrix is the sum in the displayed Hessian matrix. Differentiating completes the calculation.
The weighted covariance matrix is positive semidefinite, so . Also as . Therefore and share a unique global minimizer, characterized by . The weights place that minimizer in the convex hull of the centres.
For stable numerical evaluation, subtract the largest exponent before computing the normalized weights. This is the log-sum-exp principle and avoids floating-point overflow without changing the gradient. A naive iteration need not converge: in one dimension, centres give with derivative at its unique fixed point. A Newton root-finding iteration or a suitable Quasi-Newton method instead uses the positive curvature of .
Equivalence partitioning divides the input domain into classes expected to exercise the same relevant behavior, then chooses representatives and boundary cases from each class. It is a way to select tests, not a proof that every member of a class must behave identically in a faulty implementation.
Useful classes for this parser include integer-only inputs, a leading point, a trailing point, and digits on both sides; all-zero inputs and inputs containing ones; leading or trailing zeroes; one-digit and longer blocks; and large integer or tiny fractional magnitudes near floating-point rounding, floating-point overflow and floating-point underflow boundaries. For instance, compare '1', '1.', '.1', '1.1', '0001.1000', and digit strings just beyond the exact integer precision of Double. Empty digit blocks have the zero convention used above. If a surrounding validator rejects an entirely empty representation or a bare point, test those as separate invalid-format classes. Unexpected digits and multiple points are likewise validator tests, since the conversion fragments assume well-formed input. Include representatives with independently calculated positional values, rather than relying only on inverse conversion.
Let the committed model be amounts and an exchange rate , with invariant . Editing pounds keeps the rate and computes euros; editing euros keeps the rate and computes pounds; editing the rate keeps pounds and computes euros. A usable rate must be strictly positive, and every accepted floating-point number and derived result must be finite. Negative amounts are allowed. Rejecting invalid text preserves the last committed model.
Insert the following members inside the supplied MainFrame, after the three fields have been initialized. Its existing layout can remain as written:
private var p = 10.0
private var e = 11.5
private var r = 1.15
private var refreshing = false

private def finite(x: Double): Boolean = !x.isNaN && !x.isInfinity

private def showModel(): Unit = {
  refreshing = true
  try {
    pounds.text = java.lang.String.format(java.util.Locale.ROOT, "%.2f", Double.box(p))
    euros.text = java.lang.String.format(java.util.Locale.ROOT, "%.2f", Double.box(e))
    rate.text = r.toString
  } finally {
    refreshing = false
  }
}

private def edit(source: TextField): Unit = {
  try {
    val v = source.text.trim.toDouble
    if (finite(v)) {
      var nextP = p
      var nextE = e
      var nextR = r
      if (source eq pounds) {
        nextP = v
        nextE = v * r
      } else if (source eq euros) {
        nextE = v
        nextP = v / r
      } else if (source eq rate) {
        nextR = v
        nextE = p * v
      }
      if (nextR > 0.0 && finite(nextP) && finite(nextE) && finite(nextR)) {
        p = nextP
        e = nextE
        r = nextR
      }
    }
  } catch {
    case _: NumberFormatException => ()
  }
  showModel()
}

listenTo(pounds, euros, rate)
reactions += {
  case EditDone(source) if !refreshing => edit(source)
}
The invariant is interpreted with the usual floating-point rounding in multiplication and division. All candidate values are calculated before committing any of them, so invalid text, zero/negative rates, NaN, infinity and floating-point overflow leave the old model intact. The committed r remains positive, so euro-to-pound division is defined. Using a fixed formatting locale keeps the decimal separator compatible with toDouble. The displayed amounts are rounded to two decimal places, while the model retains their full available precision. The rate is not forcibly rounded to two places, which could otherwise turn a valid small positive rate into displayed zero.
The refreshing guard prevents synchronous derived-field notifications from recursively committing another edit. EditDone is an edit-completion event, not a request to react to every partial keystroke; pressing the field's completion action is enough to trigger the conversion. If a particular UI additionally needs live updates, it can subscribe to the appropriate text-change events with the same validation and authoritative-source policy. The supplied API and archived Scala Swing documentation suffice for the requested completion-event implementation; no unidentified practical library is required.[ref]
A practical choice is a BFGS method, using exact gradients and a line search. At dimension , its -by- inverse-Hessian matrix approximation is small, whereas forming a million rank-one contributions to the exact Hessian matrix is expensive. If , the explicit derivatives are
The positive-definite Hessian matrix and coercivity show that the objective has one global minimizer.
For numerical stability one can minimize instead, which has exactly the same minimizer. Put , , and . Then the logarithmic gradient of an exponential squared-distance sum gives
Evaluate the weights as to avoid floating-point overflow. A Quasi-Newton method step is
where is the positive-definite inverse-Hessian matrix approximation updated by BFGS, and is chosen by a line search, for example one satisfying the Wolfe conditions. Under the standard smoothness and nondegeneracy assumptions at this strongly convex minimizer, full-memory BFGS has local superlinear convergence. An exact Newton's method in optimization would have local quadratic convergence, but pays for those much more expensive exact second derivatives.[ref]
Separable integrand 2026-10-25
An integrand is separable across coordinates when it factors as . On a product domain, the Fubini theorem reduces its integral to a product of one-dimensional integrals, provided the factors are integrable; for nonnegative factors the Tonelli theorem gives the extended-value version.
A finite sum of separable terms can likewise be integrated as a finite sum of products. For example,
For fixed centres, the factors are smooth on compact intervals. Repeated one-dimensional composite Simpson's rule refinements have fourth-order discretization error, avoiding the exponential tensor-grid cost of a generic -dimensional rule. The numerical constants and possible floating-point overflow still depend on the scale of the factors; separability removes a dimension-dependent combinatorial cost, not all conditioning difficulties.