Skip to content

[RFC]: Develop C implementations for base special mathematical functions #148

Closed
@iraandrushko

Description

@iraandrushko

Full name

Iryna Andrushko

University status

Yes

University name

Ivan Franko National University of Lviv

University program

Applied Mathematics and Informatics

Expected graduation

December 2025

Short biography

I hold a Bachelor’s degree in Applied Mathematics and am currently pursuing a Master’s degree in Applied Mathematics at Lviv National University of Ivan Franko. During my studies, I have written mathematical research papers focusing on linear algebra, computational methods, and numerical analysis. I also developed several university projects in both C and JavaScript, primarily for solving practical tasks arising from computational mathematics courses. My interests include high-performance computing, advanced numerical methods, and integrating theoretical mathematics with real-world software solutions.

Timezone

Eastern European Standard Time (EEST), UTC+3

Contact details

[email protected]

Platform

Windows

Editor

I prefer VSCode because it offers an excellent balance of features and usability. It has a rich ecosystem of extensions—such as IntelliSense for auto-completion, built-in Git integration, and powerful debugging tools—and robust support for multiple languages.

Programming experience

I have gained experience with multiple programming languages including Python, C++, C#, JavaScript, C. During my studies at university, I worked on various programming projects that combined both practical application and theoretical problem solving. For example, I contributed to a project for our university cafeteria that streamlined both online and offline payment systems. The project also included the implementation of a delivery service, with a well-defined role-based task distribution system that coordinated between kitchen staff, delivery personnel, and administrative teams to ensure smooth order processing and timely deliveries. This experience allowed me to design and develop end-to-end solutions.

JavaScript experience

I have some experience with JavaScript, particularly in developing front-end applications using React. For instance, in the university cafeteria project, I developed a React-based user interface that streamlined order processing and payment management. My favorite feature of JavaScript is its flexibility and rich ecosystem, which enables rapid prototyping and the use of modern libraries like React for building dynamic user interfaces. On the other hand, my least favorite aspect is the sometimes unpredictable behavior of type coercion, which can lead to subtle bugs if not managed carefully.

Node.js experience

I have foundational experience with Node.js, including setting up development environments, managing packages via npm, and building server-side applications. Although my work outside of stdlib has mainly involved npm packages and client-side JavaScript, contributing to stdlib has given me the opportunity to explore Node APIs more deeply and enhance my understanding through thorough documentation.

C/Fortran experience

I studied the fundamentals of C as part of my parallel computing course, where I gained a solid understanding of procedural programming, memory management, and low-level system concepts. Through that course, I also became proficient with multithreading and parallel programming in C, which involved working with threads, synchronization primitives, and optimizing performance for concurrent operations.

Interest in stdlib

I'm drawn to stdlib because I love JavaScript for its flexibility and ease of use, and I believe it should offer a broader range of capabilities—especially in mathematics. While Python currently dominates the field with its extensive scientific libraries, stdlib is bridging that gap by providing a modular collection of specialized packages. This approach not only prevents unnecessary bundle bloat but also enables powerful, NumPy-like operations directly in the browser. As I deepen my understanding of statistics and machine learning, I'm thrilled by the potential of expanding JavaScript's math capabilities through stdlib.

Version control

Yes

Contributions to stdlib

C implementation for frechet/logpdf
fix JavaScript lint error

stdlib showcase

This showcase contains a university assignment project that demonstrates linear regression analysis using synthetic data. The project is built with Node.js and Express on the server side, leverages stdlib for generating random data and performing statistical computations (e.g., computing means and dot products), and uses Chart.js on the client side to visualize the measured data along with the estimated regression line.
Linear Regression Analysis

Goals

What do I hope to achieve?
I plan to port a comprehensive suite of special mathematical functions (e.g., Bessel, Gamma, Beta, Error functions, etc.) from JavaScript to C within the stdlib-js/stdlib project. My goal is to create well-tested, high-performance C implementations that can be bundled as Node.js native addons, allowing significantly faster computation, especially for array-based (ndarray) operations. Ultimately, this work will help stdlib move closer to numerical libraries like NumPy or SciPy in terms of performance and functionality.

Detailed Description of the Proposed Work:

  1. Function-by-Function Porting: Migrate existing JS implementations to C by leveraging well-known numerical methods and polynomials (e.g., Lanczos for Gamma, rational approximations for Bessel, etc.).
  2. Native Addons for Node.js: Integrate these C implementations into stdlib’s Node.js addons, providing a seamless fallback to JS in environments where native addons are unavailable.
  3. Testing and Benchmarking: For each function, add unit tests covering edge cases (NaNs, infinities, domain errors) and compare numerical accuracy against the existing JS versions or other high-precision references. Establish micro-benchmarks to measure performance gains.
  4. Documentation and Integration: Update code and user documentation, ensure consistent APIs, handle domain restrictions, and provide a cohesive developer experience within stdlib’s build system.

Why this project?

  • Performance Enthusiasm: I am excited by the prospect of offering near “C-level” speeds to JavaScript developers. Integrating native C math routines into Node.js can unlock new possibilities for scientific computing on a popular platform.
  • Bridging JS and Scientific Computing: I am passionate about making advanced numerical methods accessible to the JavaScript community. Porting these functions empowers data scientists and engineers who prefer JS to run heavier computations efficiently without switching languages.
  • Learning and Contribution: This project combines my interests in numerical methods, systems programming, and open-source collaboration.

Qualifications

  • C and Systems Programming Experience: I have built native modules in C for Node.js in previous projects and am comfortable with compiler toolchains, memory management, and debugging at the systems level.
  • Mathematical Foundations: I have taken courses covering advanced calculus, numerical methods, and statistics. I am also familiar with the references typically used (Cephes, Boost, OpenLibm) and know how to verify correctness and handle edge cases.
  • JavaScript and Node.js Expertise: I have contributed to JS libraries before, understand asynchronous workflows, and have experience writing robust unit tests.
  • Open-Source Familiarity: I have contributed fixes and enhancements to open-source projects, which has taught me how to follow contributor guidelines, write clear documentation.

Prior art

  • Cephes, msun, OpenLibm: Most of the special functions we intend to port have existing C implementations in well-known numerical libraries like Cephes, FreeBSD’s msun, or OpenLibm. They typically use polynomial/rational approximations, asymptotic expansions, and reflection formulas (for Gamma, etc.).
  • Boost: The Boost C++ Libraries provide highly accurate implementations of these functions, often referencing the same formulas used by Cephes.
  • NumPy/SciPy: Python’s scientific stack relies on underlying C/C++/Fortran routines for these functions.

Commitment

  • I plan to contribute part-time, dedicating approximately 20 hours per week over the 12-week Google Summer of Code (GSoC) period.
  • During GSoC: Each week, I will follow the implementation plan, write tests, and ensure thorough benchmarks. If any short vacations arise, I will communicate in advance and ensure my weekly milestones remain on track.
  • After GSoC: I intend to remain involved post-GSoC by helping maintain and refine these C implementations, responding to issues, and potentially adding new functions as needed.

Schedule

  • Week 1 – Inverse Hyperbolic Functions & Advanced Trig Helpers

    • Key Functions: acoshf, acothf, acschf, asechf, asinhf, atanhf, and atan2f
    • Focus: Port logarithmic-based formulas and handle domain/edge cases.
  • Week 2 – Bessel Functions & Bernoulli Numbers

    • Key Functions: besselj1f, bessely0f, bessely1, bessely1f; bernoullif
    • Focus: Port polynomial/rational approximations from Cephes/OpenLibm; implement Bernoulli numbers using an algorithm (e.g., Akiyama–Tanigawa) for n ≤ 20.
  • Week 3 – Beta Functions (Complete Beta)

    • Key Functions: betaf, betalnf
    • Focus: Implement complete Beta via B(x,y) = exp(gammaln(x)+gammaln(y)-gammaln(x+y)); verify symmetry and edge cases.
  • Week 4 – Incomplete Beta Functions

    • Key Functions: betainc, betaincf (optionally betaincinv, betaincinvf)
    • Focus: Implement regularized incomplete beta using a continued fraction or series approach; handle symmetry Iₓ(a,b) = 1 – I₁₋ₓ(b,a).
  • Week 5 – Gamma Functions (Part I)

    • Key Functions: gammaf, gamma-delta-ratiof, gamma-lanczos-sumf, gamma-lanczos-sum-expg-scaledf; begin gamma1pm1f, gammasgnf
    • Focus: Port a Lanczos-based Gamma algorithm with reflection; implement supporting functions.
  • Week 6 – Gamma Functions (Part II) & Factorials

    • Key Functions: gammalnf, gammainc, gammaincf, gammaincinv, gammaincinvf; factorialf, factorial2f, factoriallnf; binomcoeff, binomcoeflnf
    • Focus: Extend Gamma suite with log-Gamma and incomplete Gamma; implement factorials and binomial coefficients robustly.
  • Week 7 – Exponential & Logarithmic Functions

    • Key Functions: expf, exp10f, exp2f, expitf, expm1f, expm1relf; log10f, log1mexpf, log1pf, log1pexpf, log1pmxf, log2f, logaddexpf, logitf, xlog1pyf
    • Focus: Port the full exp/log suite with careful attention to numerical stability for small values.
  • Week 8 – Combinatorial Functions & Numeric Sequences

    • Key Functions: fibonacci-indexf, lucasf, tribonaccif, nonfibonaccif; falling-factorialf, rising-factorial, rising-factorialf
    • Focus: Implement iterative and closed-form algorithms with safeguards for overflow.
  • Week 9 – Fresnel Integrals & Spence’s Function

    • Key Functions: fresnelf, fresnelcf, fresnelsf; spencef
    • Focus: Port series and asymptotic expansions from Cephes for Fresnel integrals; implement Spence’s function via polynomial approximations.
  • Week 10 – Advanced Special Functions: Zeta, Eta, and Polygamma

    • Key Functions: riemann-zetaf, dirichlet-etaf; polygamma, polygammaf, trigammaf
    • Focus: Implement ζ(s) for s ≥ 1 (and η(s) via η(s) = (1 - 2^(1-s)) ζ(s)); focus on trigamma for polygamma.
  • Week 11 – Remaining Miscellaneous & Complex Utilities

    • Key Functions: boxcoxf, boxcox1pf, boxcox1pinvf, boxcoxinvf; complex utilities (ccisf, cinvf, cflipsignf, cidentityf, covercosf, coversinf, cphasef, cpolarf); rounding and miscellaneous functions (round10f, round2f, roundbf, roundnf, roundsd, roundsdf, minmaxf, minmaxabsf, modff, wrapf, etc.)
    • Focus: Implement all remaining functions ensuring consistency with JS behavior.
  • Week 12 – Final Integration, Benchmarking & Documentation

    • Focus: Comprehensive testing, performance benchmarking, and documentation updates.
    • Tasks:
      • Run the full test suite to verify accuracy (within acceptable ULP tolerances).
      • Compile a benchmark report comparing C vs. JS implementations.
      • Update documentation and finalize the GSoC report.
  • Final Week

    • Will be wrapping up any pending tasks or functions, and along with that, also will be working on any additional things if required by the mentors

Related issues

Project description
List of base special math functions

Checklist

  • I have read and understood the Code of Conduct.
  • I have read and understood the application materials found in this repository.
  • I understand that plagiarism will not be tolerated, and I have authored this application in my own words.
  • I have read and understood the patch requirement which is necessary for my application to be considered for acceptance.
  • I have read and understood the stdlib showcase requirement which is necessary for my application to be considered for acceptance.
  • The issue name begins with [RFC]: and succinctly describes your proposal.
  • I understand that, in order to apply to be a GSoC contributor, I must submit my final application to https://summerofcode.withgoogle.com/ before the submission deadline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    20252025 GSoC proposal.received feedbackA proposal which has received feedback.rfcProject proposal.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions