fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Inequalities, Bounds, and Constraints

Install and import#

bash
npm install fintech-algorithms
ts
import { inequalitiesBoundsAndConstraints } from "fintech-algorithms/foundations/mathematical-language-and-quantitative-reasoning/inequalities-bounds-and-constraints";

Signature#

inequalitiesBoundsAndConstraints(input)

Tests a candidate number against a lower and upper bound, reporting whether it is admissible, what it becomes once clamped into range, and how far outside the range it sits.

Parameters#

NameTypeNotes
inputD00InputA plain object. Every F01 topic first reads values, which must be a non-empty array of finite numbers, and validates it before any per-topic branch runs. This topic then reads candidate, lower and upper, each coerced with Number; values is demanded but not used by this calculation.

Returns#

{ withinBounds: boolean; clamped: number; distanceToFeasible: number }

withinBounds is true when the candidate lies inside the closed interval, bounds included. clamped is the candidate pulled to the nearest bound when it is outside. distanceToFeasible is how far it must move to become admissible, and is 0 when it already is.

Errors#

  • When input is not a plain object — throws TypeError
  • When values is missing, empty, or not an array — throws RangeError
  • When values contains a value that is not a finite number — throws RangeError
  • When lower is greater than upper — throws RangeError

Complexity: time O(n), space O(n).

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

input
{
  "values": [1, 2, 3, 4, 5],
  "startingCash": 1000,
  "inflows": 250,
  "outflows": 120,
  "slope": 2,
  "intercept": 1,
  "part": 25,
  "whole": 200,
  "elapsed": 5,
  "old": 4.5,
  "new": 4.75,
  "base": 16,
  "exponent": 0.5,
  "a": 2
}

Showing 14 of 28 fields.

Call#

inequalitiesBoundsAndConstraints(input)

Returns#

object with 2 fields: withinBounds, clamped

{
  "withinBounds": false,
  "clamped": 10
}

Diagrams#

Inequalities, Bounds, and Constraints — concept anatomy
Inequalities, Bounds, and Constraints — lesson map
Inequalities, Bounds, and Constraints — mistake contrast

Calculation flow#

Inequalities, Bounds, and Constraints — four-part map
flowchart LR
    A["Name the input"] --> B["Apply: committed + new spend ≤ limit, so new spend ≤ limit - committed"]
    B --> C["Check units and boundary"]
    C --> D["Explain the output"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

  • NIST/SEMATECH e-Handbook of Statistical Methods — NIST/SEMATECH
  • Author-derived and synthetic boundary

The rest of the Mathematical Language and Quantitative Reasoning family#