{"version":3,"file":"monotonicity-BdebFOtv.mjs","names":[],"sources":["../../src/monotonicity/monotonicity.ts"],"sourcesContent":["/**\n * Classification of a function's monotonicity on an interval.\n *\n * Encoded as a 2-bit sign-coverage bitmask of the function's derivative:\n *   - bit 0 (`Increasing`) — derivative takes positive values\n *   - bit 1 (`Decreasing`) — derivative takes negative values\n *\n * The four states fall out of the encoding:\n *\n *   | value | name         | derivative on the interval        |\n *   |-------|--------------|-----------------------------------|\n *   |   `0` | `Constant`   | ≡ 0                               |\n *   |   `1` | `Increasing` | ≥ 0, with at least one `> 0`      |\n *   |   `2` | `Decreasing` | ≤ 0, with at least one `< 0`      |\n *   |   `3` | `None`       | crosses zero                      |\n *\n * The numeric encoding is principled, not arbitrary: the bitwise OR of two\n * adjacent subintervals' classifications gives the classification of their\n * union, which lets monotonicity be computed by recursive subdivision\n * without any custom combine logic.\n *\n * @since 2.0.0\n */\nexport type Monotonicity = 0 | 1 | 2 | 3\n\n/**\n * Subset of {@link Monotonicity} excluding the indeterminate `None` state.\n * Returned by classifiers operating on functions whose derivative cannot\n * change sign on the interval (e.g. linear polynomials, whose derivative is\n * constant).\n *\n * @since 2.0.0\n */\nexport type GuaranteedMonotonicity = 0 | 1 | 2\n\n/**\n * Derivative is identically zero on the interval. The function is constant.\n *\n * @since 2.0.0\n */\nexport const Constant = 0 as const\n\n/**\n * Derivative is non-negative on the interval with at least one strictly\n * positive sample. The function is strictly increasing.\n *\n * @since 2.0.0\n */\nexport const Increasing = 1 as const\n\n/**\n * Derivative is non-positive on the interval with at least one strictly\n * negative sample. The function is strictly decreasing.\n *\n * @since 2.0.0\n */\nexport const Decreasing = 2 as const\n\n/**\n * Derivative crosses zero on the interval. The function has at least one\n * interior extremum and is not monotonic in either direction.\n *\n * @since 2.0.0\n */\nexport const None = 3 as const\n\n/**\n * Type-narrowing predicate: refines a `Monotonicity` to `Increasing |\n * Decreasing` — the strict cases that admit a unique inverse.\n *\n * @param m - The monotonicity classification.\n * @returns `true` when `m` is `Increasing` or `Decreasing`.\n * @since 2.0.0\n */\nexport const isStrict = (m: Monotonicity): m is 1 | 2 => m === Increasing || m === Decreasing\n\n/**\n * Classifies the monotonicity of a function given its values at two interval\n * endpoints, when the function is known a priori to be monotonic on the\n * spanning interval (e.g. a linear polynomial).\n *\n * @param s0 - The function value at the start of the interval.\n * @param s1 - The function value at the end of the interval.\n * @returns The classification — `Increasing`, `Decreasing`, or `Constant`.\n * @since 2.0.0\n */\nexport const fromComparison = (s0: number, s1: number): GuaranteedMonotonicity =>\n  s0 < s1 ? Increasing : s0 > s1 ? Decreasing : Constant\n"],"mappings":";;;;;;;;;;;;;;;;;;AA0EA,MAAa,YAAY,MAAgC,MAAA,KAAoB,MAAA;;;;;;;;;;;AAY7E,MAAa,kBAAkB,IAAY,OACzC,KAAK,KAAA,IAAkB,KAAK,KAAA,IAAA"}