Phase 12: Element-Wise Transcendental Functions
Context
Section titled “Context”MTL5 Phases 1-11 are complete (61 tests passing). MTL5 currently has only 4 element-wise math operations (abs, sqrt, conj, negate), while MTL4 has 18+. Phase 12 adds the full set of transcendental and special functions needed for scientific computing — signal processing, control theory, neural networks, physics simulations. All 27 functions follow the exact same pattern as the existing abs.hpp/sqrt.hpp, making this highly mechanical.
Also fixes an inconsistency: sqrt.hpp, conj.hpp, negate.hpp are missing matrix overloads.
Canonical Patterns
Section titled “Canonical Patterns”Operation (from include/mtl/operation/abs.hpp): template <Vector V> auto func(const V& v) + template <Matrix M> auto func(const M& m), using ADL-friendly using std::func; inside loop body.
Scalar functor (from include/mtl/functor/scalar/sqrt.hpp): struct with result_type, static apply(), operator().
27 Functions in 4 Groups
Section titled “27 Functions in 4 Groups”Group A — Exponential/Logarithmic (7)
Section titled “Group A — Exponential/Logarithmic (7)”exp, log, exp2, log2, log10, cbrt, pow (binary: scalar exponent)
Group B — Trigonometric (6)
Section titled “Group B — Trigonometric (6)”sin, cos, tan, asin, acos, atan
Group C — Hyperbolic (6)
Section titled “Group C — Hyperbolic (6)”sinh, cosh, tanh, asinh, acosh, atanh
Group D — Rounding & Special (8)
Section titled “Group D — Rounding & Special (8)”ceil, floor, round, signum (custom), erf, erfc, real, imag
Special Cases
Section titled “Special Cases”pow— Binary:pow(v, exponent)withScalarconstrained exponentsignum— Manual:(x>0)?1:(x<0)?-1:0real/imag— Returnmagnitude_t<T>, useconstexpr iffor real vs complex dispatcherf/erfc— Real types only (no complexstd::erf)
Files to Create (61 new files)
Section titled “Files to Create (61 new files)”Operation headers (28 in include/mtl/operation/)
Section titled “Operation headers (28 in include/mtl/operation/)”- 27 individual:
exp.hpp,log.hpp,exp2.hpp,log2.hpp,log10.hpp,cbrt.hpp,pow.hpp,sin.hpp,cos.hpp,tan.hpp,asin.hpp,acos.hpp,atan.hpp,sinh.hpp,cosh.hpp,tanh.hpp,asinh.hpp,acosh.hpp,atanh.hpp,ceil.hpp,floor.hpp,round.hpp,signum.hpp,erf.hpp,erfc.hpp,real.hpp,imag.hpp - 1 umbrella:
transcendental.hpp
Scalar functors (27 in include/mtl/functor/scalar/)
Section titled “Scalar functors (27 in include/mtl/functor/scalar/)”Same 27 names as individual operations above.
Tests (4 in tests/unit/operation/)
Section titled “Tests (4 in tests/unit/operation/)”test_transcendental_exp_log.cpp— exp, log, exp2, log2, log10, cbrt, pow (known values, vector+matrix)test_transcendental_trig.cpp— sin, cos, tan, asin, acos, atan +sin²+cos²=1identitytest_transcendental_hyp.cpp— sinh, cosh, tanh, asinh, acosh, atanh +cosh²-sinh²=1identitytest_transcendental_special.cpp— ceil, floor, round, signum, erf, erfc, real, imag
Examples (2 in examples/)
Section titled “Examples (2 in examples/)”phase12a_signal_processing.cpp— Sine wave generation, exponential decay, phase angles, discretizationphase12b_activation_functions.cpp— Sigmoid, tanh, softmax, GELU from transcendental building blocks
Files to Modify (4)
Section titled “Files to Modify (4)”include/mtl/operation/sqrt.hpp— Add matrix overloadinclude/mtl/operation/conj.hpp— Add matrix overloadinclude/mtl/operation/negate.hpp— Add matrix overloadinclude/mtl/mtl.hpp— Add includes for all new operation + functor headers
Implementation Order
Section titled “Implementation Order”- Fix
sqrt.hpp,conj.hpp,negate.hpp(add matrix overloads) - Group A: 7 operations + 7 functors + test
- Group B: 6 operations + 6 functors + test
- Group C: 6 operations + 6 functors + test
- Group D: 8 operations + 8 functors + test
transcendental.hppumbrella + updatemtl.hpp- Examples 12a + 12b
- Full build + full test suite
Cross-Platform Notes
Section titled “Cross-Platform Notes”- ALL
<cmath>standard functions only — no POSIX/GNU extensions exp10excluded (GNU extension)std::numbers::pi/std::numbers::efor constants (C++20), neverM_PI/M_Esignummanually implemented
Verification
Section titled “Verification”cd /home/stillwater/dev/stillwater/clones/mtl5cmake -B build && cmake --build build -j$(nproc) && ctest --test-dir build