Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to add new functions to stdlib_math module #365

Open
aman-godara opened this issue Mar 27, 2021 · 3 comments
Open

Proposal to add new functions to stdlib_math module #365

aman-godara opened this issue Mar 27, 2021 · 3 comments
Labels
idea Proposition of an idea and opening an issue to discuss it topic: mathematics linear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ...

Comments

@aman-godara
Copy link
Member

aman-godara commented Mar 27, 2021

About: This issue concerns with proposing new functions to stdlib_math module.

I am working on building a new module sdlib_math for fortran. As the name suggests this module aims to provide general purpose mathematical functions. I wanted to know about some of the functions that people are requesting so that we can add them to this module. One of the proposed function was clip(Issue #319).

I propose to add some other functions like gcd, lcm, etc. to this library, if they don't already exist. So I decided to take review from the community regarding this. Please propose functions that you would like to have in stdlib_math module, so that fortran community can have discussions on them and start adding to the codebase.

Some resources:
Numpy Math
Matlab Discrete Math
Python Math module
Java Math

@aman-godara aman-godara changed the title Proposal to add new functions to add to stdlib_math.f90 file Proposal to add new functions to stdlib_math.f90 file Mar 27, 2021
@aman-godara aman-godara changed the title Proposal to add new functions to stdlib_math.f90 file Proposal to add new functions to stdlib_math module Mar 27, 2021
@awvwgk awvwgk added idea Proposition of an idea and opening an issue to discuss it topic: mathematics linear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ... labels Mar 27, 2021
@Beliavsky
Copy link

Maybe a function to determine if an integer is prime and a subroutine for prime factorization?

@milancurcic
Copy link
Member

This issue was mentioned in the Youtube video by Conor Hoekstra (@codereport) who compared 16 languages in an implementation of a simple problem (finding the gcd).

https://www.youtube.com/watch?v=UVUjnzpQKUo

Unfortunately, I think Fortran was the only language in the video that doesn't have gcd() either built into the language or standard library. We can easily improve this by implementing it in stdlib_math.

Here's a simple implementation using Euclid's method, adapted from (https://pages.mtu.edu/~shene/COURSES/cs201/NOTES/chap04/gcd.html):

  elemental integer function gcd(x, y)
    integer, intent(in) :: x, y
    integer :: a, b, c
    a = x
    b = y

    ! Swap a and b if a < b
    if (a < b) then 
      c = a
      a = b
      b = c
    end if

    ! Iterate until remainder is zero
    do
      c = mod(a, b)    
      if (c == 0) exit 
      a = b
      b = c
    end do

    gcd = b
  end function gcd

I think gcd() would be a good first issue for new contributors.

@milancurcic
Copy link
Member

@FortranFan posted a similar implementation here: j3-fortran/fortran_proposals#221 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea Proposition of an idea and opening an issue to discuss it topic: mathematics linear algebra, sparse matrices, special functions, FFT, random numbers, statistics, ...
Projects
None yet
Development

No branches or pull requests

4 participants