Advanced Math Library for C

Hello There!

In this post I will share a C library I created: Advanced Math Library, or libamath. This is a C library that centralizes some of my mathematical implementations, focusing on performance and multithreading.

libamath includes algorithms s…


This content originally appeared on DEV Community and was authored by Aria Diniz

Hello There!

In this post I will share a C library I created: Advanced Math Library, or libamath. This is a C library that centralizes some of my mathematical implementations, focusing on performance and multithreading.

libamath includes algorithms such as Kendall Correlation, Genetic Algorithms for optimization, Fourier Transforms, and various statistical calculations like mean, median, and standard deviation. I'm also planning to add support for BigInt factorial, which will offer higher precision for Poisson Distribution and other advanced calculations. Many of these functions are optimized with multithread support to handle intensive computational tasks.

Here are some examples of how you can use libamath:

  1. Kendall Correlation:
double data1[] = {1.0, 2.0, 3.0};
double data2[] = {3.0, 2.0, 1.0};
double tau = amath_kcorr(data1, data2, 3);
printf("Kendall's Tau: %f\n", tau);
  1. Genetic Algorithm:
void *fitness_function(Individuals *individuals) {
  // Define fitness logic
  return NULL;
}
Individuals *pop = amath_generate_individuals(100, 0.05, 0.001, 0.25, 4, 0.0, 1.0);
for (int i = 0; i < 1000; i++) {
  amath_fit(pop, fitness_function);
  amath_mutate(pop);
  amath_reproduce(pop);
}
amath_destroy_individuals(pop);
  1. Discrete Fourier Transform (DFT):
double complex data[] = {1.0, 2.0, 3.0, 4.0};
amath_dft(data, 4, 2); // Perform DFT using 2 threads
  1. Mean:
double data[] = {1.0, 2.0, 3.0};
double mean_value = amath_mean(data, 3);
printf("Mean: %f\n", mean_value);

For those familiar with my previous repositories, libamath brings together both the Kendall Correlation (now with performance improvements) and the Genetic Algorithm implementations into one place. This will make it easier to expand and manage the tools over time.

In my free time, I intend to add even more features, including:

  • Variance Calculation: Handy alongside the standard deviation.
  • Covariance: To measure how two datasets vary together.
  • Linear Regression: To model relationships between variables.
  • Binomial Distribution: A great complement to the Poisson distribution.
  • Gamma Distribution: Another versatile probability distribution.

This is something I built some time ago, since I often use these functions in my work, and I decided to share it in case anyone else finds it useful.

You can check out the project and contribute here: https://github.com/ariasdiniz/advanced_math_lib

As always, suggestions and feedback are very welcome!


This content originally appeared on DEV Community and was authored by Aria Diniz


Print Share Comment Cite Upload Translate Updates
APA

Aria Diniz | Sciencx (2024-10-20T22:12:05+00:00) Advanced Math Library for C. Retrieved from https://www.scien.cx/2024/10/20/advanced-math-library-for-c/

MLA
" » Advanced Math Library for C." Aria Diniz | Sciencx - Sunday October 20, 2024, https://www.scien.cx/2024/10/20/advanced-math-library-for-c/
HARVARD
Aria Diniz | Sciencx Sunday October 20, 2024 » Advanced Math Library for C., viewed ,<https://www.scien.cx/2024/10/20/advanced-math-library-for-c/>
VANCOUVER
Aria Diniz | Sciencx - » Advanced Math Library for C. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/20/advanced-math-library-for-c/
CHICAGO
" » Advanced Math Library for C." Aria Diniz | Sciencx - Accessed . https://www.scien.cx/2024/10/20/advanced-math-library-for-c/
IEEE
" » Advanced Math Library for C." Aria Diniz | Sciencx [Online]. Available: https://www.scien.cx/2024/10/20/advanced-math-library-for-c/. [Accessed: ]
rf:citation
» Advanced Math Library for C | Aria Diniz | Sciencx | https://www.scien.cx/2024/10/20/advanced-math-library-for-c/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.