g | x | w | all
Bytes Lang Time Link
063APLNARS250723T135900ZRosario
110Python 3230822T055305ZRhaixer
007Pyt240505T141924ZKip the
047GAWK230822T100214ZMarius_C
009Japt v2.0a0 x231101T102610ZShaggy
4332Wolfram Language Mathematica230822T081615Z138 Aspe
4838Pari/GP230822T063419Z138 Aspe
020sclin230822T153441ZMama Fun
007Husk230822T132848ZDominic
4375Vyxal s230822T051811Zlyxal
056JavaScript ES6230822T095540ZArnauld
007Thunno 2 +230822T063934ZThe Thon
nanRuby rprime230822T083917ZG B
032Charcoal230822T082212ZNeil
127Excel230822T060610ZJos Wool
071Python230822T054332Zbsoelch
041Raku230822T080248ZSean
00505AB1E230822T075224ZKevin Cr
069Desmos230822T073004ZAiden Ch
035Factor + math.primes math.unicode230822T062804Zchunes
066Python 3230822T061543Zxnor

APL(NARS), 63 chars

r←f w;j
w+←1⋄r←⍬⋄j←w÷w
→3×⍳w≤0⋄j←1πj⋄r,←j⋄w-←1⋄→2
r←+/2{⍺÷⍵}/r

//8+15+27+13= 63 If the input is a rational or big float "v", the output is a rational, if the input is float the output is a float.

    f 3x
208r105 
  f 3
1.980952381
  f 7
5.122912588
  f 185
179.1897451
  f 185x      
47752148506472867074638763838344811754955279237362380323460936336224283840376019837825788
  08644660355428679348283266958544172716221681797357847578096268781718236396122190592
  72221718819558098038143436234124173850168099116519092309146927965885314796198028165
  42774045718728603327915977708384371271480484970717073697504033148775214336339953864
  14758567792291033680198127968054539321736033209795196804723888951997341145221866183
  936637544019198370699032428211686155281139619642036r2664892930881166271482866959666
  54714656604183482917950495618298572067762686515928942320813893151097659932181197909
  52088310711340165562346919693142105436178412616910243993889870315190322853164714150
  83367576874197592494003887711107064408842143573929306097378545964636245380168828046
  20546522158807976979978615658815800867141043294274946174853915067303211860210164183
  52855233501699608715735469759081421130149548060687058734585470049027535356177084511
  745793717898532350701335 

Python 3, 131 112 110 bytes

-19 thanks to bsoelch
-2 due to a missed golf

lambda n:sum(x[k]/x[k+1]for k in range(n))
x=[i for i in range(2,7920)if not[i%j for j in range(2,i)if i%j<1]]

Try it online!

Old explanation:

lambda n:                                # lambda with an argument
x:=[i for i in range(2,7920)if not[i%j for j in range(2,i)if not i%j]][:n+1]
# prime getter till 1000. 7919 is 1000th prime, slice until n+1
sum(x[k]/x[k+1]for k in range(len(x)-1)) # sum it up
[1]                                      # and return the latter

Pyt, 7 bytes

⁺řᵽᵮʁ/Ʃ

Try it online!

⁺              implicit input; increment
 ř             řangify (1...n+1)
  ᵽ            get the kth ᵽrime number
   ᵮ           convert to ᵮloat
    ʁ/         ʁeduce the array by division (each element divided by the next)
      Ʃ        Ʃum; implicit print

GAWK, 49 47 bytes

func f(n){t=0;for(i=1;i<=n;)t+=$i/$++i;print t}

Try it online!

This one implies that the input file is an infinite list of prime number. The function is still taking an integer n as argument.

As mentionned by @Olivier Dulac, this script need to run using gawk or other awk variant that support having multiple digits fields.

He also suggested a variant that could work with Unix Shell, that would be 61 bytes, and would take as input file an infinite list of prime number, with one number per record :

# HEADER
BEGIN{OFMT = "%.6f"} # Get precision set up
#HEADER

{a[NR]=$0}func f(n){t=0;for(i=1;i<=n;)t+=a[i]/a[++i];print t}

# FOOTER
END{
    f(3)
    f(185)
    f(564)
    f(849)
    f(999)
}
# FOOTER

AWK, 120 111 109 bytes

{for(a[n=1]=2;t=j=n<1e3;a[++n]=m)for(m=a[n]+(i=1);++i<m;)i=m%i<1?2+0*m++:i;for(;j<$0;)t+=a[++j]/a[1+j];$1=t}1

Try it online!

This one work with just n as input. It only supplies 999 pair of prime number, but if you change 1e3 with 1e4 it will supplies 9999, it will just get 10 time longer for each lines.

Japt v2.0a0 -x, 9 bytes

_j}jUÄ ä÷

Try it

Wolfram Language (Mathematica), 43 32 bytes

Saved 11 bytes thanks to the comment of @Roman


N@Sum[Prime@i/Prime[i+1],{i,#}]&

Try it online!

Pari/GP, 48 38 bytes

Saved 10 bytes thanks to the comment of @alephalpha


f(n)=sum(k=1,n,prime(k)/prime(k+1))*1.

Try it online!

sclin, 20 bytes

$P"1dp"Q / rev tk +/

Try it here!

For testing purposes:

999 ; 20N>d
$P"1dp"Q / rev tk +/

NOTE: the default representation is a rational number, but 20N>d converts the representation to decimal for convenience.

Explanation

Prettified code:

$P 1.dp Q / rev tk +/

Assuming input n:

Husk, 8 7 bytes

Σ↑Ẋ`/İp

Try it online!

Σ↑Ẋ`/İp
  Ẋ      # map over adjacent pairs of values
   `/    #   flipped division: x ÷ y
     İp  # apply this to the infinite list of primes
 ↑       # then take the first arg1 values
Σ        # and sum them

Vyxal s, 35 bitsv2, 4.375 bytes

ʀǎ¨p/

Try it Online!

Works for any n >= 1 (even bigger than 1000). The flag is for display purposes.

Explained

ʀǎ¨p/­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁣​‎‏​⁢⁠⁡‌­
ʀǎ     # ‎⁡First n prime numbers
  ¨p/  # ‎⁢With every overlapping pair reduced by divison
# ‎⁣Automatically sum
💎

Created with the help of Luminespire.

JavaScript (ES6), 56 bytes

n=>(g=(p,d=k++)=>k%d--?g(p,d):d?g(p):n--&&p/k+g(k))(k=2)

Try it online!

Thunno 2 +, 7 bytes

ÆpDḣỊØ.

Try it online!

2 flags -> 1 flag thanks to Neil

Explanation

ÆpDḣỊØ.  # Implicit input
Æp       # First (input + 1) primes
  Dḣ     # Push a copy without the first item
    Ị    # Reciprocal of each
     Ø.  # Dot product of the two lists
         # Implicit output

Ruby -rprime, 42+6 = 48 bytes

->n{k=0;Prime.take(n+1).sum{|x|k*1.0/k=x}}

Try it online!

Charcoal, 32 bytes

Nθ→→W¬›Lυθ¿⬤υ﹪ⅈκ⊞υⅈM→IΣEΦυκ∕§υκι

Try it online! Link is to verbose version of code. Explanation:

Nθ→→W¬›Lυθ¿⬤υ﹪ⅈκ⊞υⅈM→

Input n and generate the first n+1 primes using the same method as for my answer to Number of bits needed to represent the product of the first primes.

IΣEΦυκ∕§υκι

Divide each prime by its successor and output the sum.

30 bytes using the newer version of Charcoal on ATO:

Nθ→→W¬›Lυθ¿⬤υ﹪ⅈκ⊞υⅈM→IΣ×υ∕¹Φυκ

Attempt This Online! Link is to verbose version of code. Explanation: Takes the dot product of the primes with the reciprocals of the odd primes.

Excel, 127 bytes

=LET(
    a,ROW(1:7327),
    b,FILTER(a,MMULT(N(MOD(a,TOROW(a))=0),a^0)=2),
    SUM(EXP(MMULT(LN(INDEX(b,SEQUENCE(A1)+{0,1})^{1,-1}),{1;1})))
)

Input in cell A1. Fails for A1>932.

Explanation

ROW(1:7327)
# Vertical array of integers 1 to 7327

TOROW(a) 
# Transpose the above

MOD(a,TOROW(a)) 
# 2D array of all those integers modulo all those integers

MOD(a,TOROW(a))=0) 
# Which of these is equal to 0

N(MOD(a,TOROW(a))=0) 
# Convert Booleans to ones and zeroes

a^0 
# Vertical array of size 7327, each entry unity

MMULT(N(MOD(a,TOROW(a))=0),a^0) 
# Matrix multiplication of the above arrays

MMULT(N(MOD(a,TOROW(a))=0),a^0)=2 
# Which of these is equal to 2, i.e. only divisors are unity and itself

FILTER(a,MMULT(N(MOD(a,TOROW(a))=0),a^0)=2) 
# Filter array of integers accordingly, i.e. list of primes <=7327

SEQUENCE(A1) 
# Vertical array from 1 to value in cell A1

SEQUENCE(A1)+{0,1} 
# Additional column added to above with values offset by 1

INDEX(b,SEQUENCE(A1)+{0,1}) 
# Index list of primes with these indices

INDEX(b,SEQUENCE(A1)+{0,1})^{1,-1} 
# Reciprocate the last entry in each pair with unity

LN(INDEX(b,SEQUENCE(A1)+{0,1})^{1,-1}) 
# Take the natural logarithm

MMULT(LN(INDEX(b,SEQUENCE(A1)+{0,1})^{1,-1}),{1;1}) 
# Matrix multiplication for pairwise summation

EXP(MMULT(LN(INDEX(b,SEQUENCE(A1)+{0,1})^{1,-1}),{1;1})) 
# Take the natural exponentiation

SUM(EXP(MMULT(LN(INDEX(b,SEQUENCE(A1)+{0,1})^{1,-1}),{1;1}))) 
# Sum all entries

Python, 71 bytes

lambda n:sum(p(k+1)/p(k+2)for k in range(n))
from sympy import*
p=prime

Attempt This Online!

Explanation

prime computes the n-th prime

Python, 105 bytes

longer but faster

lambda n:sum(a/b for(a,b)in i.pairwise(i.islice(sympy.primerange(4**n),n+1)))
import sympy,itertools as i

Attempt This Online!

Explanation

Uses the fact that the n+1-st prime is less than 4n+1 to obtain a list of the first n+1 primes from the list of the primes less than n (sympy.primerange).

pairwise groups the elements in adjacent pairs

Raku, 41 bytes

[\+] {.(2)Z/.(3)}({grep &is-prime,$_..*})

Try it online!

This is an expression for the infinite sequence of partial sums.

05AB1E, 6 5 bytes

ÝØü/O

Try it online or verify all test cases.

Explanation:

Ý      # Push a list in the range [0, (implicit) input]
 Ø     # Convert each to their 0-based n'th prime
  ü    # For each overlapping pair of values:
   /   #  Divide them
    O  # Them sum all these decimal values together
       # (which is output implicitly as result)

Desmos, 69 bytes

L=[2...7920]
P=L[∏_{d=3}^Lmod(L,d-1)>0]
f(k)=∑_{n=1}^kP[n]/P[n+1]

Try It On Desmos!

Try It On Desmos! - Prettified

Probably golfable but this is the best I could think of for now.

Factor + math.primes math.unicode, 35 bytes

[ 1 + nprimes 2 clump unzip v/ Σ ]

Try it online!

         ! 3
1        ! 3 1
+        ! 4
nprimes  ! { 2 3 5 7 }
2        ! { 2 3 5 7 } 2
clump    ! { { 2 3 } { 3 5 } { 5 7 } }
unzip    ! { 2 3 5 } { 3 5 7 }
v/       ! { 2/3 3/5 5/7 }
Σ        ! 1+103/105

Python 3, 66 bytes

f=lambda n,p=3,P=4,d=2:n and P%p*d/p+f(n-P%p,p+1,P*p*p,[d,p][P%p])

Try it online!

The Wilson's Theorem generator strikes again. Similar to the template for the first n primes here, but also stores the previous prime as d and keeps the running sum of the ratios.