home.social

#sagemath — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #sagemath, aggregated by home.social.

  1. #CodeGolf #SageMath #OEIS

    Okay, I admit it: I was code golfing today.

    The subject was Bernoulli numbers. Many clever and incredibly complex algorithms have been devised to calculate them for large arguments and resulting in implementations so arcane that they leave mere mortals in the dust.

    That’s why I was surprised to find for Bernoulli number with an even index an one-liner for SageMath.

    Here it is—84 bytes is the benchmark now; who can beat that? [Naturally, simply calling the built-in function isn't allowed.]

    B=lambda n:matrix(2*n,lambda r,c:(c<r+2)*binomial(r+2,r-c+2)).det()/factorial(2*n+1)

    sagecell.sagemath.org/?q=sucdxd

  2. #CodeGolf #SageMath #OEIS

    Okay, I admit it: I was code golfing today.

    The subject was Bernoulli numbers. Many clever and incredibly complex algorithms have been devised to calculate them for large arguments and resulting in implementations so arcane that they leave mere mortals in the dust.

    That’s why I was surprised to find for Bernoulli number with an even index an one-liner for SageMath.

    Here it is—84 bytes is the benchmark now; who can beat that? [Naturally, simply calling the built-in function isn't allowed.]

    B=lambda n:matrix(2*n,lambda r,c:(c<r+2)*binomial(r+2,r-c+2)).det()/factorial(2*n+1)

    sagecell.sagemath.org/?q=sucdxd

  3. #CodeGolf #SageMath #OEIS

    Okay, I admit it: I was code golfing today.

    The subject was Bernoulli numbers. Many clever and incredibly complex algorithms have been devised to calculate them for large arguments and resulting in implementations so arcane that they leave mere mortals in the dust.

    That’s why I was surprised to find for Bernoulli number with an even index an one-liner for SageMath.

    Here it is—84 bytes is the benchmark now; who can beat that? [Naturally, simply calling the built-in function isn't allowed.]

    B=lambda n:matrix(2*n,lambda r,c:(c<r+2)*binomial(r+2,r-c+2)).det()/factorial(2*n+1)

    sagecell.sagemath.org/?q=sucdxd

  4. #CodeGolf #SageMath #OEIS

    Okay, I admit it: I was code golfing today.

    The subject was Bernoulli numbers. Many clever and incredibly complex algorithms have been devised to calculate them for large arguments and resulting in implementations so arcane that they leave mere mortals in the dust.

    That’s why I was surprised to find for Bernoulli number with an even index an one-liner for SageMath.

    Here it is—84 bytes is the benchmark now; who can beat that? [Naturally, simply calling the built-in function isn't allowed.]

    B=lambda n:matrix(2*n,lambda r,c:(c<r+2)*binomial(r+2,r-c+2)).det()/factorial(2*n+1)

    sagecell.sagemath.org/?q=sucdxd