A numerical engine that computes gross salary from a target net salary using a hybrid root-finding approach.
This project solves:
net_salary(gross) = target_net
Rewritten as:
f(gross) = net_salary(gross) - target_net = 0
It combines:
- Newton–Raphson (fast convergence)
- Brent’s Method (guaranteed convergence)
- Hybrid solver (Newton + Brent)
- Adaptive bracketing
- Progressive tax model support
- Contribution caps
- High numerical precision
- Robust handling of non-linear, piecewise functions
Progressive brackets:
(0.0, 0.0)
(1000.0, 0.10)
(2000.0, 0.20)
(4000.0, 0.30)
Tax is computed cumulatively per bracket.
min(gross * SOCIAL_RATE, SOCIAL_CAP)
Constants:
SOCIAL_RATE = 0.08
SOCIAL_CAP = 500.0
net = gross - income_tax(gross) - social_contribution(gross)
Finds an interval [low, high] such that:
f(low) * f(high) < 0
Expands high exponentially if needed.
Iteration:
g_next = g - f(g) / f'(g)
Derivative approximated via central difference:
f'(x) ≈ (f(x + h) - f(x - h)) / (2h)
Used as a fast initial convergence attempt.
Fallback solver combining:
- Bisection
- Secant method
- Inverse quadratic interpolation
Guarantees convergence when a root is bracketed.
Target Net
↓
Bracketing
↓
Newton (fast path)
↓ success
Return result
↓ failure
Brent solver
↓
Return result
- Newton tolerance:
1e-6 - Brent tolerance:
1e-6 - Maximum iterations: configurable (default 100)
SolveResult:
* Converged(f64)
* NoBracket
* MaxIterations
Target Net: 2500
Estimated Gross: 3055.56
Verified Net: 2499.999999999954
- Newton: O(log n) near solution
- Brent: O(log n) guaranteed convergence
- Hybrid: typically < 20 iterations total
- Payroll systems
- Tax simulation
- Financial modeling
- Inverse pricing problems
- Embedded numerical computation
- Works with non-linear and piecewise functions
- Handles discontinuities in derivatives
- Designed for numerical stability
- No analytical inversion required