[Question]
  [
Write a program to calculate the first 500 digits of pi, meeting the rules below:
* It must be less than 500 characters in length.
* It cannot include "pi", "math.pi" or similar pi constants, nor may it call a library function to calculate pi.
* It may not use the digits "3", "1" and "4" consecutively.
* It must execute in a reasonable time (under 1 minute) on a modern computer.
The shortest program wins.
  
[Answer]
## Golfscript - 29 chars
```
6666,-2%{2+.2/@*\/9)499?2*+}*
```
I will post analysis later
[Answer]
# Mathematica (34 chars): (without "cheating" with trig)
`N[2Integrate[[1-x^2]^.5,-1,1],500]`
So, to explain the magic here:  
`Integrate[function, lower, upper]` gives you the area under the curve "function" from "lower" to "upper". In this case, that function is `[1-x^2]^.5`, which is a formula that describes the top half of a circle with radius 1. Because the circle has a radius of 1, it does not exist for values of x lower than -1 or higher than 1. Therefore, we are finding the area of half of a circle. When we multiply by 2, then we get the area inside of a circle of radius 1, which is equal to pi.
[Answer]
# Python (83 chars)
```
P=0
B=10**500
i=1666
while i:d=2*i+1;P=(P*i%B+(P*i/B+3*i)%d*B)/d;i-=1
print'3.%d'%P
```
[Answer]
## Python3 136
Uses [Madhava's](http://en.wikipedia.org/wiki/Madhava_of_Sangamagrama#The_value_of_.CF.80_.28pi.29)  formula.
```
from decimal import *
D=Decimal
getcontext().prec=600
p=D(3).sqrt()*sum(D(2-k%2*4)/3**k/(2*k+1)for k in range(1100))
print(str(p)[:502])
```
## Python3 164
Uses [this](http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula) formula.
```
from decimal import *
D=Decimal
getcontext().prec=600
p=sum(D(1)/16**k*(D(4)/(8*k+1)-D(2)/(8*k+4)-D(1)/(8*k+5)-D(1)/(8*k+6))for k in range(411))
print(str(p)[:502])
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~28~~ ~~25~~ 24 bytes
```
i*!500İ⁰ΣG*2mṠ/o!İ1→ḣ□70
```
[Try it online!](https://tio.run/##AS0A0v9odXNr//9pKiE1MDDEsOKBsM6jRyoybeG5oC9vIcSwMeKGkuG4o@KWoTcw//8 "Husk – Try It Online")
Calculates the value of pi as a rational number using the first 5000 terms of the infinite series `2 + 1/3*(2 + 2/5*(2 + 3/7*(2 + 4/9*(2 + ...))))`, and then extracts the first 500 digits.
The code to calculate the value of pi from a specified number of terms is only 13 bytes (`ΣG*2mṠ/o!İ1→ḣ`):
```
ΣG*2mṠ/o!İ1→ḣ
Σ                       # the sum of
 G*2                    # the cumulative product, starting at 2, of
    m                   # mapping the following function to all terms of 
            ḣ           # series from 1 to ... (whatever number is specified)
     Ṡ/                 # divide by x
       o!  →            # element at index -1
         İ1             # of series of odd numbers
```
Unfortunately, we then need to waste 3 bytes specifying the number of terms to use:
```
□70                     # 70^2 = 4900
```
And then 8 more bytes converting the rational number (expressed as a fraction) into its digits in decimal form:
```
i*!500İ⁰            
i                       # integer value of
 *                      # multiplying by 
  !500                  # 500th element of
      İ⁰                # series of powers of 10
```
[Answer]
# Java 10, ~~208~~ ~~207~~ ~~206~~ ~~193~~ ~~176~~ 155 bytes
```
n->{var t=java.math.BigInteger.TEN.pow(499).shiftLeft(1);var p=t;for(int i=1656;i>0;)p=t.add(p.multiply(t.valueOf(i)).divide(t.valueOf(i-~i--)));return p;}
```
-14 bytes thanks to *@ceilingcat*.  
-17 bytes thanks to *@jeJe*.  
[Try it online.](https://tio.run/##bZAxa8MwEIX3/IobpcFHA20gCGcIdCi06ZDSpXRQbdk5V5aFfFIJwf3rrkwzdOhycPfeg@9dp5MuuvpzrqweR3jS5C4rAHJsQqMrA4dlBeiyD3vNJ9xT@5DV1gSoxOtANSSpsmda5TGyZqrgAA5KmF2xuyQdgMv/4vhyf0A/fInb7VbieKKGH03DYi3VEvIlq2YIIqMAlevN3UbR7kbJfEdd18JjHy2Tt2fBmLSN5rkRJCXWlKg2f4/FNxWFlFIFwzE48Gqa1YLr44fNuFfqtJTp8wfEkQO59u0dtPytfzyPbHocIqPPElsnHFbCRWvltf00/wA)
**Or as full program (203 bytes):**
```
interface M{static void main(String[]a){var t=java.math.BigInteger.TEN.pow(499).shiftLeft(1);var p=t;for(int i=1656;i>0;)p=t.add(p.multiply(t.valueOf(i)).divide(t.valueOf(i-~i--)));System.out.print(p);}}
```
[Try it online.](https://tio.run/##Tc49iwIxEMbxr5IyU@ygcCdIWAvB4kDvCu3EYjDJ7qz7ErKzOUT0q@/lOts//HiehhIVjb3NM/fioqerU4fHKCR8VWlgqzriXh8lcl@dLwSPRFFJ2WSHHUmNW66@Mq1cxNPuG8Pwqz/Wa8CxZi9750UvwfyjUIrxQ9R5SHG5XH2uDG8WBnJHslYH7KZWOLR3LZiondyP1wyAlhNb9x6LFxcFAJjjfRTX4TAJhvxQdADzfM7zHw)
[Answer]
## Mathematica (17 bytes)
```
N[ArcCos[-1],500]
```
[Proof of validity](http://www.wolframalpha.com/input/?i=N%5BArcCos%5B-1%5D,%20500%5D%20==%20N%5BPi,%20500%5D&t=ff3tb01).
[Answer]
## PARI/GP, 14
```
\p500
acos(-1)
```
You can avoid trig by replacing the second line with
```
gamma(.5)^2
```
or
```
(6*zeta(2))^.5
```
or
```
psi(3/4)-psi(1/4)
```
or
```
4*intnum(x=0,1,(1-x^2)^.5)
```
or
```
sumalt(k=2,(-1)^k/(2*k-3))*4
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 21
```
u+/*GHhyHy^T500r^3T1Z
```
Uses this algorithm:
`pi = 2 + 1/3*(2 + 2/5*(2 + 3/7*(2 + 4/9*(2 + ...))))` found in the comments of the Golfscript answer.
[Answer]
# [Raku](https://raku.org/), 44 bytes
```
(2.FatRat,{++$*$_/(2*++$+1)}...*)[^1658].sum
```
[Try it online!](https://tio.run/##K0gtyjH7X5xY@V/DSM8tsSQosUSnWltbRUslXl/DSAvI0jbUrNXT09PSjI4zNDO1iNUrLs39DySSikuKNAx0FEwNjDT/AwA "Perl 6 – Try It Online")
A search for a series that quickly converges to pi led to [this](https://math.stackexchange.com/a/14116/16422) Math StackExchange answer, which I implemented in Raku. The series consists of FatRats, which is Raku's unlimited-precision rational number type. A little calculation and trial and error showed that 1,658 terms are sufficient to obtain 500 decimal places of accuracy.
[Answer]
# Fortran, ~~154~~ 144 bytes
Mangled the [rosetta code](https://rosettacode.org/wiki/Pi#Fortran) solution. Saved lots of bytes using implicit integers `i j k l m n`, `print` instead of `write`, and shuffling things around.
[Try it online!](https://tio.run/##NY3NCoQgFEb3PcXsUtPJW7hJ7nIW8xgDWZg/DRLh2ztJzObjcDjwLXs60ieKdbmhFBsPs5o0TScZRyUpDjojvJTeUOp5f0QEDhIqeqwFBy6gCZjZSTztLPPaYujJwLwAqqvEICz7CxPneW8c2j7rb7ruWvJWT0VbvnXuerHCsXxXdUv5AQ)
~~[154 bytes](https://tio.run/##NY3LDoMgFAX3fkV3BYQqGjaSu@yin9EENFd5NNQY/p5i2m5OJpNJzhzTnp5BLPMXSsGw28UmbtDb8MYYyDiqnk7TAYPOIO9Kr9A3Jl4CSC57qSs6OCMuuZCNh8wO4miLzGkE35GBOSGpPiV4gewvbDAmNhtgl/Ur1eMreaibole@tlt9QbGx/KvqlvIB)~~
```
integer::v(3350)=2;x=1E5;j=0;do n=1,101;do l=3350,1,-1
m=x*v(l)+i*l;i=m/(2*l-1);v(l)=m-i*(2*l-1);enddo
k=i/x;print'(I5.5)',j+k;j=i-k*x;enddo;end
```
[Answer]
## bc -l (22 = 5 command line + 17 program)
```
scale=500
4*a(1)
```
[Answer]
# Mathematica - 50
```
½ = 1/2; 2/Times @@ FixedPointList[(½ + ½ #)^½~N~500 &, ½^½]
```
[Answer]
# Axiom, 80 bytes
```
digits(503);v:=1./sqrt(3);6*reduce(+,[(-1)^k*v^(2*k+1)/(2*k+1)for k in 0..2000])
```
for reference <https://tuts4you.com/download.php?view.452>;
it would be an approssimation to 6\*arctg(1/sqrt(3))=%pi and it would use serie expansion for arctg
```
  3.1415926535 8979323846 2643383279 5028841971 6939937510 5820974944 592307816
  4 0628620899 8628034825 3421170679 8214808651 3282306647 0938446095 505822317
  2 5359408128 4811174502 8410270193 8521105559 6446229489 5493038196 442881097
  5 6659334461 2847564823 3786783165 2712019091 4564856692 3460348610 454326648
  2 1339360726 0249141273 7245870066 0631558817 4881520920 9628292540 917153643
  6 7892590360 0113305305 4882046652 1384146951 9415116094 3305727036 575959195
  3 0921861173 8193261179 3105118548 0744623799 6274956735 1885752724 891227938
  1 8301194913 01
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 20 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
₄°·D.ΓN>*N·3+÷}O+₄;£
```
Port of [my Java answer](https://codegolf.stackexchange.com/a/213932/52210) (with the `503` replaced with `1000` - anything \$\geq503\$ is fine to output the first 500 digits accurately with this approach).
[Try it online](https://tio.run/##yy9OTMpM/f//UVPLoQ2HtrvonZvsZ6fld2i7sfbh7bX@2kBx60OL//8HAA) or [verify it's equal to the first 500 digits of PI using the builtin `žs`](https://tio.run/##yy9OTMpM/f//UVPLoQ2HtrvonZvsZ6fld2i7sfbh7bX@2kBx60OLbbmO7iuGML1suZQci1IVSjJSKxVSC0sTc@wVlOwDlfLyFSpTi5WUiw@v0Pn/HwA).
**Explanation:**
```
₄°              # Push 10**1000
  ·             # Double it to 2e1000
   D            # Duplicate it
    .Γ          # Loop until the result no longer changes,
                # collecting all intermediate results
                # (excluding the initial value unfortunately)
      N>        #  Push the 0-based loop-index, and increase it by 1 to make it 1-based
        *       #  Multiply this 1-based index to the current value
         N·     #  Push the 0-based index again, and double it
           3+   #  Add 3 to it
             ÷  #  Integer-divide the (index+1)*value by this (2*index+3)
     }O         # After the cumulative fixed-point loop: sum all values in the list
       +        # Add the 2e1000 we've duplicated, which wasn't included in the list
        ₄;      # Push 1000, and halve it to 500
          £     # Leave the first 500 digits of what we've calculated
                # (after which it is output implicitly as result)
```
[Answer]
# APL (NARS2000), 20 bytes
```
{2+⍵×⍺÷1+⍨2×⍺}/⍳7e3x
```
I haven't been able to test this, but [here's](https://tio.run/##SyzI0U2pTMzJT////1Hf1ICAR20TDC24gEy3IBDTyML8//9qI@1HvVsPT3/Uu@vwdkMge4URmFOr/6h3s3mqMQA) a version in Dyalog APL. The only difference between them is the suffix "x", which is used for rational numbers in NARS2000 but is not available in Dyalog (or other variants available online, as far as I know).
It's based on the `pi = 2 + 1/3*(2 + 2/5*(2 + 3/7*(2 + 4/9*(2 + ...))))` formula in the comments under the accepted Golfscript answer.
[Answer]
# [Scala 3](https://www.scala-lang.org/), ~~96~~ 84 bytes
A port of [@Kevin Cruijssen's Java 10 answer](https://codegolf.stackexchange.com/a/213932/110802) in Scala.
Saved 12 bytes thanks to @ceilingcat
---
Golfed version. [Attempt This Online!](https://ato.pxeger.com/run?1=LY7BagIxGITv-xSDp2RlbWNb0V0jKL300FNrLyIluu6SEpMQfxVZfJJevLSXPpFv04gyh4GZYfi-fzdLZdTD36yVWbdXwbbmZ-YWX6sl4VVpiyZJgJ0ysDn7cLqUo4muXyxxSPxsqcr65_dPOWouE5LXjol73vFuzx4HA552i50K8JKKygXoYQbRe-qBHAQWh0ygdJe27VN9x7qpbgte-OPt-xkoVxXWEYWpUG9yjENQh9kbBW3rOc8xtZoiSxMxAR9TMpZFbY3hPIbH5PZ1Ol39Hw)
```
_=>{val t=BigInt(10).pow(499)*2;var p=t;for i<- 1656 to 1 by-1 do p=t+p*i/(2*i+1);p}
```
Ungolfed version. [Attempt This Online!](https://ato.pxeger.com/run?1=PVDLTsMwELznK0Y92aCUhkdFo6YSXCoOcEH0UlXIpGlY5DqR6zZCqF_CpRe48Av8SP-GdWLhg63ZnZn17Of3JldaXfzMe7GpGmVNb3GcVi9vRe5wr8jgI4oAZxU5PDAAn2WxQi52KWYVLWWKWyrvjOPW3nN3SsOkTM6-tm4VXx9_8YxsErS-65AFjUgGsl9XjbgcjSTGYySBZFEzyf0jYpQMr4ZtoXklXUAQJhjI4Buci7XXneOEFafBDZ0XY1FzI0wmibOWLwOJEGdBsW_v2icKGaZRF3vNKxHKlpsUN9aq9_mjs2TKBW_hyZAP1n2n5qrTRph-LsxWaynb9QS7w6F7_wA)
```
_ => {
  val t = BigInt(10).pow(499) << 1
  var p = t
  var i = 1656
  while (i > 0) {
    val temp = 2 * i + 1
    p = t + (p * BigInt(i) / temp)
    i -= 1
  }
  p
}
```
[Answer]
# APL(NARS), 213 chars
```
r2fs←{⎕ct←0⋄k←≢b←⍕⌊⍵×10x*a←⍺⋄k-←s←'¯'=↑b⋄c←{s:'¯'⋄''}⋄m←s↓b⋄0≥k-⍺:c,'0.',((⍺-k)⍴'0'),m⋄c,((k-⍺)↑m),'.',(k-⍺)↓m}
r←P w;i;d;e;k
r←i←0x⋄e←÷10x*w
k←1+8×i⋄d←(+/4 2 1 1÷k,-k+3..5)×÷16*i⋄→3×⍳e>∣d⋄r+←d⋄i+←1⋄→2
{⍵r2fs P⍵}500
```
111+13+15+59+2+13=213
`p r2fs w`, return a string of the rational number in w seen as float with p digits afther the point.
`P p`, would return a rational number enough to be traslated from `r2fs` to a float string with p digits of precision.
Test (the last digit is always not rounded)- output:
```
  3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066
  470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337
  867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153
  643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799
  6274956735188575272489122793818301194912
```
]