// SPDX-License-Identifier: MIT // Generated by EML-lang Solidity backend // Source module: catenary // Source file: /home/monogate/monogate/forge/examples/catenary.eml // Functions: 1 (1 @verify-annotated) // Constants: 2 // Transcendental stubs: cosh -- override in a derived contract (see PRBMath SD59x18) // WARNING: 1 fractional Real literal(s) were rounded to int256 (e.g. 0.6108 -> 1). // For fixed-point semantics, scale your EML constants // by WAD (1e18) and override the transcendental stubs // with PRBMath SD59x18 in a derived contract. pragma solidity ^0.8.20; contract Catenary { int256 constant H_MIN = 1; int256 constant H_MAX = 20; /// @notice Formal proof: catenary_within_envelope (MachLib). Compiled from EML-lang. /// @dev Pfaffian profile: chain_order=2, cost_class=p2-d5-w2-c0, drift_risk=MEDIUM. /// @dev Gas estimate: ~7,300 gas (PRBMath SD59x18 overrides assumed; run forge gas-bench for the canonical signal). /// @param scale scale (int256) /// @param curv curv (int256) /// @param x x (int256) /// @dev ensures: (result >= H_MIN) /// @dev ensures: (result <= H_MAX) function catenary(int256 scale, int256 curv, int256 x) external pure returns (int256) { require(((scale < 0 ? -scale : scale) <= 5), "catenary: refinement violated on scale: ((scale < 0 ? -scale : scale) <= 5)"); require(((curv < 0 ? -curv : curv) <= 0 /* 0.5 rounded; see header re fixed-point */), "catenary: refinement violated on curv: ((curv < 0 ? -curv : curv) <= 0 /* 0.5 rounded; see header..."); require(((x < 0 ? -x : x) <= 4), "catenary: refinement violated on x: ((x < 0 ? -x : x) <= 4)"); int256 raw = (scale * _cosh((curv * x))); return _clamp(raw, H_MIN, H_MAX); } /// @dev clamp helper -- min(max(x, lo), hi). function _clamp(int256 x, int256 lo, int256 hi) internal pure returns (int256) { if (x < lo) return lo; if (x > hi) return hi; return x; } /// @dev cosh stub — override with a fixed-point implementation. function _cosh(int256 x) internal pure virtual returns (int256) { x; // silence unused-param warning revert("_cosh: stub — override in a derived contract (see PRBMath SD59x18.cosh)"); } }