Giter VIP home page Giter VIP logo

leibniz-formula-benchmark's People

Contributors

shnarazk avatar

Watchers

 avatar  avatar  avatar

leibniz-formula-benchmark's Issues

Add me: Koka

import std/num/float64

pub fun main()
  println("The " ++ (4.0 * pi(0, 0.0)).show)

fun pi(n: int, sum : float64): pure float64
  if 100_000_000 < n
  then sum
  else
    val n4 = n.float64 * 4.0;
    pi(n + 1, sum + 2.0 / ((n4 + 1.0) * (n4 + 3.0)))
nix$ time .koka/v3.0.4/cc-drelease/pi
The 3.1415926445762157
.koka/v3.0.4/cc-drelease/pi  0.08s user 0.00s system 96% cpu 0.089 total

Pharo

PiFinder class>>#runTo: pairs

	| denominator currSum tmp |
	denominator := -1.
	currSum := 0.0.
	pairs timesRepeat: [
		denominator := denominator + 4.
		tmp := denominator asFloat.
		currSum := currSum + (2.0 / (tmp * (tmp - 2.0))) ].
	^ 4.0 * currSum

Add me: Factor

  • 2024-02-09
    golfed
USING: kernel math ;
IN: leibniz

: lpi ( num-of-pairs: integer -- pi )
  0.0 0 rot
  [ [ 4.0 * [ 3.0 + ] [ 1.0 + ] bi * 2.0 swap / + ] keep 1 + ] times
  drop 4 *
;
  • 2023-12-12
USING: kernel math ;
IN: Leibniz

: calcpi ( -- pi index )
    0.0 0
    [
        dup [ 4.0 * [ 3.0 + ] [ 1.0 + ] bi * 2.0 swap / + ] dip
      1 +
     dup 100000000 <
    ] loop
    [ 4 * ] dip
    ! drop
    ;

100M pairs => 0.137 sec. on 2.3GHz dual core Core i5 😲

Add me: Lean4

def leibniz (n : Nat) (sum : Float) : Float :=
  match n with
  | 0 => sum + 8.0 / 3.0
  | succ n' => let k := (n * 4).toFloat; leibniz n' (sum + 8.0 / ((k + 1.0) * (k + 3.0)))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.