Sylvester's sequence

From Rosetta Code
Task
Sylvester's sequence
You are encouraged to solve this task according to the task description, using any language you may know.
This page uses content from Wikipedia. The original article was at Sylvester's sequence. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)


In number theory, Sylvester's sequence is an integer sequence in which each term of the sequence is the product of the previous terms, plus one.

Its values grow doubly exponentially, and the sum of its reciprocals forms a series of unit fractions that converges to 1 more rapidly than any other series of unit fractions with the same number of terms.

Further, the sum of the first k terms of the infinite series of reciprocals provides the closest possible underestimate of 1 by any k-term Egyptian fraction.


Task
  • Write a routine (function, procedure, generator, whatever) to calculate Sylvester's sequence.
  • Use that routine to show the values of the first 10 elements in the sequence.
  • Show the sum of the reciprocals of the first 10 elements on the sequence, ideally as an exact fraction.


Related tasks


See also


11l

Translation of: Nim
F sylverster(lim)
   V result = [BigInt(2)]
   L 2..lim
      result.append(product(result) + 1)
   R result

V l = sylverster(10)
print(‘First 10 terms of the Sylvester sequence:’)
L(item) l
   print(item)

V s = 0.0
L(item) l
   s += 1 / Float(item)
print("\nSum of the reciprocals of the first 10 terms: #.17".format(s))
Output:
First 10 terms of the Sylvester sequence:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of the first 10 terms: 0.99999999999999982

ALGOL 68

Works with: ALGOL 68G version Any - tested with release 2.8.3.win32

Uses Algol 68G's LONG LONG INT and LONG LONG REAL which have specifiable precision. The sum of the reciprocals in the output has been manually edited to replace a large number of nines with ... to reduce the width.

BEGIN # calculate elements of Sylvestor's Sequence                         #
    PR precision 200 PR # set the number of digits for LONG LONG modes     #
    # returns an array set to the forst n elements of Sylvestor's Sequence #
    #    starting from 2, the elements are the product of the previous     #
    #                     elements plus 1                                  #
    OP SYLVESTOR = ( INT n )[]LONG LONG INT:
       BEGIN
           [ 1 : n ]LONG LONG INT result;
           LONG LONG INT product := 2;
           result[ 1 ] := 2;
           FOR i FROM 2 TO n DO
               result[ i ] := product + 1;
               product *:= result[ i ]
           OD;
           result
       END;
    # find the first 10 elements of Sylvestor's Seuence #
    []LONG LONG INT seq = SYLVESTOR 10;
    # show the sequence and sum the reciprocals #
    LONG LONG REAL reciprocal sum := 0;
    FOR i FROM LWB seq TO UPB seq DO
        print( ( whole( seq[ i ], 0 ), newline ) );
        reciprocal sum +:= 1 / seq[ i ]
    OD;
    print( ( "Sum of reciprocals: ", reciprocal sum, newline ) )
END
Output:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
Sum of reciprocals: +9.99999999999999999999999999999999999999999...999999999999999999999999999964e  -1

Arturo

sylvester: function [lim][
    result: new [2]
    loop 2..lim 'x [
        'result ++ inc fold result .seed:1 [a b][a * b]
    ]
    return result
]
lst: sylvester 10

print "First 10 terms of the Sylvester sequence:"
print lst
print ""

sumRep: round sum map lst => [1 // &]

print "Sum of the reciprocals of the first 10 items:"
print sumRep
Output:
First 10 terms of the Sylvester sequence:
2 3 7 43 1807 3263443 10650056950807 113423713055421844361000443 12864938683278671740537145998360961546653259485195807 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 

Sum of the reciprocals of the first 10 items:
1.0

AWK

# syntax: GAWK --bignum -f SYLVESTERS_SEQUENCE.AWK
BEGIN {
    start = 1
    stop = 10
    for (i=start; i<=stop; i++) {
      sylvester = (i == 1) ? 2 : sylvester*sylvester-sylvester+1
      printf("%2d: %d\n",i,sylvester)
      sum += 1 / sylvester
    }
    printf("\nSylvester sequence %d-%d: sum of reciprocals %30.28f\n",start,stop,sum)
    exit(0)
}
Output:
 1: 2
 2: 3
 3: 7
 4: 43
 5: 1807
 6: 3263443
 7: 10650056950807
 8: 113423713055421844361000443
 9: 12864938683278671740537145998360961546653259485195807
10: 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sylvester sequence 1-10: sum of reciprocals 0.9999999999999998889776975375

BASIC

BASIC256

Works with: True BASIC
Works with: Chipmunk Basic
Translation of: FreeBASIC
PRINT "10 primeros términos de la sucesión de sylvester:"
PRINT

LET suma = 0
FOR i = 1 to 10
    IF i = 1 then
       LET sylvester = 2
    ELSE
       LET sylvester = sylvester*sylvester-sylvester+1
    END IF
    PRINT i; ": "; sylvester
    LET suma = suma + 1 / sylvester
NEXT i

PRINT
PRINT "suma de sus recíprocos: "; suma
END


FreeBASIC

precisión estándar

Dim As Double sylvester, suma = 0

Print "10 primeros t‚rminos de la sucesi¢n de Sylvester:"

For i As Byte = 1 To 10
    sylvester = Iif(i=1, 2, sylvester*sylvester-sylvester+1)
    Print Using "##: &"; i; sylvester
    suma += 1 / sylvester
Next i

Print !"\nSuma de sus rec¡procos:"; suma
Sleep
Output:
10 primeros términos de la sucesión de Sylvester:
 1: 2
 2: 3
 3: 7
 4: 43
 5: 1807
 6: 3263443
 7: 10650056950807
 8: 1.134237130554218E+26
 9: 1.286493868327867E+52
10: 1.6550664732452E+104

Suma de sus recíprocos: 0.9999999999999999

PureBasic

Translation of: FreeBASIC
OpenConsole()
PrintN("10 primeros términos de la sucesión de Sylvester:")

suma.d = 0
For i.i = 1 To 10
  If i = 1 
    sylvester.d = 2 
  Else 
    sylvester.d = sylvester*sylvester-sylvester+1
  EndIf
  PrintN(Str(i) + ": " + StrD(sylvester))
  suma = suma + 1 / sylvester
Next i

Print(#CRLF$ + "Suma de sus recíprocos: " + StrD(suma))
Input()
CloseConsole()
End

Yabasic

Translation of: FreeBASIC
print "10 primeros términos de la sucesión de Sylvester:"

suma = 0
for i = 1 to 10
    if i=1 then sylvester = 2 else sylvester = sylvester*sylvester-sylvester+1 : fi
	print i using("##"), ": ", sylvester
    suma = suma + 1 / sylvester
next i

print "\nSuma de sus rec¡procos: ", suma
end

C#

Translation of: Go
using System;
using System.Collections.Generic;
using System.Numerics;

public class SylvesterSequence
{
    public static void Main(string[] args)
    {
        BigInteger one = BigInteger.One;
        BigInteger two = new BigInteger(2);
        List<BigInteger> sylvester = new List<BigInteger> { two };
        BigInteger prod = two;
        int count = 1;

        while (count < 10)
        {
            BigInteger next = BigInteger.Add(prod, one);
            sylvester.Add(next);
            count++;
            prod *= next;
        }

        Console.WriteLine("The first 10 terms in the Sylvester sequence are:");
        foreach (var term in sylvester)
        {
            Console.WriteLine(term);
        }

        // Assuming a BigRational implementation or a workaround for the sum of reciprocals
        BigInteger denominator = BigInteger.One;
        foreach (var term in sylvester)
        {
            denominator = BigInteger.Multiply(denominator, term);
        }

        BigInteger numerator = BigInteger.Zero;
        foreach (var term in sylvester)
        {
            numerator += denominator / term;
        }

        // Assuming you have a way to convert this to a decimal representation
        Console.WriteLine("\nThe sum of their reciprocals as a rational number is:");
        Console.WriteLine($"{numerator}/{denominator}");

        // For the decimal representation, you might need to perform the division to a fixed number of decimal places
        // This is a simplified approach and may not directly achieve 211 decimal places accurately
        Console.WriteLine("\nThe sum of their reciprocals as a decimal number (to 211 places) is:");
        Console.WriteLine(DecimalDivide(numerator, denominator, 210));
    }

    private static string DecimalDivide(BigInteger numerator, BigInteger denominator, int decimalPlaces)
    {
        // This is a basic implementation and might not be accurate for very large numbers or very high precision requirements
        BigInteger quotient = BigInteger.Divide(numerator * BigInteger.Pow(10, decimalPlaces + 1), denominator);
        string quotientStr = quotient.ToString();
        string result = quotientStr.Substring(0, quotientStr.Length - decimalPlaces) + "." + quotientStr.Substring(quotientStr.Length - decimalPlaces);
        return result;
    }
}
Output:
The first 10 terms in the Sylvester sequence are:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

The sum of their reciprocals as a rational number is:
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

The sum of their reciprocals as a decimal number (to 211 places) is:
9.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999634


C++

Library: Boost
#include <iomanip>
#include <iostream>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using integer = boost::multiprecision::cpp_int;
using rational = boost::rational<integer>;

integer sylvester_next(const integer& n) {
    return n * n - n + 1;
}

int main() {
    std::cout << "First 10 elements in Sylvester's sequence:\n";
    integer term = 2;
    rational sum = 0;
    for (int i = 1; i <= 10; ++i) {
        std::cout << std::setw(2) << i << ": " << term << '\n';
        sum += rational(1, term);
        term = sylvester_next(term);
    }
    std::cout << "Sum of reciprocals: " << sum << '\n';
}
Output:
First 10 elements in Sylvester's sequence:
 1: 2
 2: 3
 3: 7
 4: 43
 5: 1807
 6: 3263443
 7: 10650056950807
 8: 113423713055421844361000443
 9: 12864938683278671740537145998360961546653259485195807
10: 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
Sum of reciprocals: 27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

EasyLang

numfmt 8 0
for i = 1 to 10
   if i = 1
      sylv = 2
   else
      sylv = sylv * sylv - sylv + 1
   .
   print sylv
   sum += 1 / sylv
.
print ""
print sum

F#

// Sylvester's sequence: Nigel Galloway. June 7th., 2021
let S10=Seq.unfold(fun(n,g)->printfn "*%A %A" n g; Some(n,(n*g+1I,n*g) ) )(2I,1I)|>Seq.take 10|>List.ofSeq
S10|>List.iteri(fun n g->printfn "%2d -> %A" (n+1) g)
let n,g=S10|>List.fold(fun(n,g) i->(n*i+g,g*i))(0I,1I) in printfn "\nThe sum of the reciprocals of S10 is \n%A/\n%A" n g
Output:
 1 -> 2
 2 -> 3
 3 -> 7
 4 -> 43
 5 -> 1807
 6 -> 3263443
 7 -> 10650056950807
 8 -> 113423713055421844361000443
 9 -> 12864938683278671740537145998360961546653259485195807
10 -> 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

The sum of the reciprocals of S10 is
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Factor

Note that if the previous element of the sequence is x, the next element is x2-x+1.

Works with: Factor version 0.99 2021-02-05
USING: io kernel lists lists.lazy math prettyprint ;

: lsylvester ( -- list ) 2 [ dup sq swap - 1 + ] lfrom-by ;

"First 10 elements of Sylvester's sequence:" print
10 lsylvester ltake dup [ . ] leach nl

"Sum of the reciprocals of first 10 elements:" print
0 [ recip + ] foldl .
Output:
First 10 elements of Sylvester's sequence:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of first 10 elements:
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Or, in other words, the sum is 2739245…3920805/2739245…3920806.

Fermat

Array syl[10];
syl[1]:=2;
for i=2 to 10 do syl[i]:=1+Prod<n=1,i-1>[syl[n]] od;
!![syl];
srec:=Sigma<i=1,10>[1/syl[i]];
!!srec;
Output:

syl[1] := 2
syl[2] := 3
syl[3] := 7
syl[4] := 43
syl[5] := 1807
syl[6] := 3263443
syl[7] := 10650056950807
syl[8] := 113423713055421844361000443
syl[9] := 12864938683278671740537145998360961546653259485195807
syl[10] := 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

2739245030860303142341023429167468628119436436758091462794736794160869202622699363433211840458243863492954873728399236975 `
8487974306317730580753883429460344956410077034761330476016739454649828385541500213920805 / 273924503086030314234102342916746 `
862811943643675809146279473679416086920262269936343321184045824386349295487372839923697584879743063177305807538834294603 `
44956410077034761330476016739454649828385541500213920806

Go

Translation of: Wren
package main

import (
    "fmt"
    "math/big"
)

func main() {
    one := big.NewInt(1)
    two := big.NewInt(2)
    next := new(big.Int)
    sylvester := []*big.Int{two}
    prod := new(big.Int).Set(two)
    count := 1
    for count < 10 {
        next.Add(prod, one)
        sylvester = append(sylvester, new(big.Int).Set(next))
        count++
        prod.Mul(prod, next)
    }
    fmt.Println("The first 10 terms in the Sylvester sequence are:")
    for i := 0; i < 10; i++ {
        fmt.Println(sylvester[i])
    }

    sumRecip := new(big.Rat)
    for _, s := range sylvester {
        sumRecip.Add(sumRecip, new(big.Rat).SetFrac(one, s))
    }
    fmt.Println("\nThe sum of their reciprocals as a rational number is:")
    fmt.Println(sumRecip)
    fmt.Println("\nThe sum of their reciprocals as a decimal number (to 211 places) is:")
    fmt.Println(sumRecip.FloatString(211))
}
Output:
The first 10 terms in the Sylvester sequence are:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

The sum of their reciprocals as a rational number is:
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

The sum of their reciprocals as a decimal number (to 211 places) is:
0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999635

Haskell

sylvester :: [Integer]
sylvester = map s [0 ..]
  where
    s 0 = 2
    s n = succ $ foldr ((*) . s) 1 [0 .. pred n]

main :: IO ()
main = do
  putStrLn "First 10 elements of Sylvester's sequence:"
  putStr $ unlines $ map show $ take 10 sylvester

  putStr "\nSum of reciprocals by sum over map: "
  print $ sum $ map ((1 /) . fromInteger) $ take 10 sylvester

  putStr "Sum of reciprocals by fold: "
  print $ foldr ((+) . (1 /) . fromInteger) 0 $ take 10 sylvester
Output:
First 10 elements of Sylvester's sequence:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of reciprocals by sum over map: 0.9999999999999999
Sum of reciprocals by fold: 1.0

Simpler way of generating sequence:

sylvester :: [Integer]
sylvester = iterate (\x -> x * (x-1) + 1) 2

or applicatively:

sylvester :: [Integer]
sylvester = iterate (succ . ((*) <*> pred)) 2

J

J uses r instead of / to display rationals

   2 ('Sum of reciprocals: ' , ":@:(+/))@:%@:([ echo&>)@:((, 1x + */)@[&_~) 9
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
Sum of reciprocals: 27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805r27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

jq

# Generate the sylvester integers:
def sylvester:
  foreach range(0; infinite) as $i ({prev: 1, product: 1};
    .product *= .prev
    | .prev = .product + 1;
    .prev);

Left padding:

def lpad($len; $fill): tostring | ($len - length) as $l | ($fill * $l)[:$l] + .;
def lpad($len): lpad($len; " ");
def lpad: lpad(4);

The task:

[limit(10; sylvester)]
| "First 10 Sylvester numbers:",
  (range(0;10) as $i | "\($i+1|lpad) => \(.[$i])"),
  "",
  "Sum of reciprocals of first 10 is approximately: \(map( 1/ .) | add)"
Output:

For integer precision, we will use `gojq`, the "go" implementation of jq.

First 10 Sylvester numbers:
   1 => 2
   2 => 3
   3 => 7
   4 => 43
   5 => 1807
   6 => 3263443
   7 => 10650056950807
   8 => 113423713055421844361000443
   9 => 12864938683278671740537145998360961546653259485195807
  10 => 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of reciprocals of first 10 is approximately: 0.9999999999999999

Julia

sylvester(n) = (n == 1) ? big"2" : prod(sylvester, 1:n-1) + big"1"

foreach(n -> println(rpad(n, 3), " =>  ", sylvester(n)), 1:10)

println("Sum of reciprocals of first 10: ", sum(big"1.0" / sylvester(n) for n in 1:10))
Output:
1   =>  2
2   =>  3
3   =>  7
4   =>  43
5   =>  1807
6   =>  3263443
7   =>  10650056950807
8   =>  113423713055421844361000443
9   =>  12864938683278671740537145998360961546653259485195807
10  =>  165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of reciprocals of first 10: 0.9999999999999999999999999999999999999999999999999999999999999999999999999999914

Mathematica/Wolfram Language

Rest[Nest[Append[#, (Times @@ #) + 1] &, {1}, 10]]
N[Total[1/%], 250]
Output:
{2,3,7,43,1807,3263443,10650056950807,113423713055421844361000443,12864938683278671740537145998360961546653259485195807,165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443}
0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996349359079841301329356159748234615361531272

Maxima

sylvester[n]:= if n=0 then sylvester[n]:2 else sylvester[n-1]^2-sylvester[n-1]+1$

/* Test cases */
makelist(sylvester[i],i,0,9);

apply("+",1/%);
Output:
[2,3,7,43,1807,3263443,10650056950807,113423713055421844361000443,12864938683278671740537145998360961546653259485195807,165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443]

27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Nim

Library: bignum
import sequtils
import bignum

proc sylverster(lim: Positive): seq[Int] =
  result.add(newInt(2))
  for _ in 2..lim:
    result.add result.foldl(a * b) + 1

let list = sylverster(10)
echo "First 10 terms of the Sylvester sequence:"
for item in list: echo item

var sum = newRat()
for item in list: sum += newRat(1, item)
echo "\nSum of the reciprocals of the first 10 terms: ", sum.toFloat
Output:
First 10 terms of the Sylvester sequence:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of the first 10 terms: 0.9999999999999999

PARI/GP

S=vector(10)
S[1]=2
for(i=2, 10, S[i]=prod(n=1,i-1,S[n])+1)
print(S)
print(sum(i=1,10,1/S[i]))
Output:
[2, 3, 7, 43, 1807, 3263443, 10650056950807, 113423713055421844361000443, 12864938683278671740537145998360961546653259485195807, 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443]

27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Pascal

Works with: Free Pascal

Free Pascal console program, using the library IntXLib4Pascal for arbitrarily large integers. I couldn't get the library to work with Delphi 7; it's said to work with Delphi 2010 and above.

program SylvesterSeq;

{$mode objfpc}{$H+}

uses SysUtils,
     UIntX; // in the library IntX4Pascal
(*
As noted in the Wikipedia article "Sylvester's sequence", we have
    1/2 + 1/3 + ... + 1/s[j-1] = (s[j] - 2)/(s[j] - 1),
so that instead of summing the reciprocals explicitly we can just
calculate an extra term.
*)
var
  s : UIntX.TIntX; // arbitrarily large integer
  i : integer;
begin
  s := 1;
  for i := 0 to 9 do begin
    inc(s);
    WriteLn( SysUtils.Format( 's[%d] = %s', [i, s.ToString]));
    s := s*(s - 1);
  end;
  WriteLn( 'Sum of reciprocals =');
  WriteLn( (s - 1).ToString);
  WriteLn( '/'); // on a separate line for clarity
  WriteLn( s.ToString);
end.
Output:
s[0] = 2
s[1] = 3
s[2] = 7
s[3] = 43
s[4] = 1807
s[5] = 3263443
s[6] = 10650056950807
s[7] = 113423713055421844361000443
s[8] = 12864938683278671740537145998360961546653259485195807
s[9] = 1655066473245199641984681954444391800175131527063774978418513887665358686
39572406808911988131737645185443
Sum of reciprocals =
27392450308603031423410234291674686281194364367580914627947367941608692026226993
63433211840458243863492954873728399236975848797430631773058075388342946034495641
0077034761330476016739454649828385541500213920805
/
27392450308603031423410234291674686281194364367580914627947367941608692026226993
63433211840458243863492954873728399236975848797430631773058075388342946034495641
0077034761330476016739454649828385541500213920806

Perl

use strict;
use warnings;
use feature 'say';
use List::Util 'reduce';
use Math::AnyNum ':overload';
local $Math::AnyNum::PREC = 845;

my(@S,$sum);
push @S, 1 + reduce { $a * $b } @S for 0..10;
shift @S;
$sum += 1/$_ for @S;

say "First 10 elements of Sylvester's sequence: @S";
say "\nSum of the reciprocals of first 10 elements: " . float $sum;
Output:
First 10 elements of Sylvester's sequence: 2 3 7 43 1807 3263443 10650056950807 113423713055421844361000443 12864938683278671740537145998360961546653259485195807 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of first 10 elements: 0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999635

Phix

standard precision

atom n, rn = 0,
     lim = power(2,iff(machine_bits()=32?53:64))
for i=1 to 10 do
    n = iff(i=1?2:n*n-n+1)
    printf(1,iff(n<=lim?"%d: %d\n":"%d: %g\n"),{i,n})
    rn += 1/n
end for
printf(1,"sum of reciprocals: %g\n",{rn})
Output:
1: 2
2: 3
3: 7
4: 43
5: 1807
6: 3263443
7: 10650056950807
8: 1.13424e+26
9: 1.2865e+52
10: 1.65507e+104
sum of reciprocals: 1

mpfr version

Note the (minimal) precision settings of 698 and 211 were found by trial and error (ie larger values gain nothing but smaller ones lose accuracy).

with javascript_semantics
requires("1.0.0") -- (mpfr_set_default_prec[ision] has been renamed)
                  -- (and mpfr_sprintf() replaced with mpfr_get_fixed())
include mpfr.e
mpz n = mpz_init(2), nm1 = mpz_init()
mpfr_set_default_precision(720)
mpfr {rn, tmp} = mpfr_inits(2)
for i=1 to 10 do
    if i>1 then
        mpz_sub_ui(nm1,n,1)
        mpz_mul(n,nm1,n)
        mpz_add_ui(n,n,1)
    end if
    printf(1,"%d: %s\n",{i,mpz_get_str(n)})
    mpfr_set_z(tmp,n)
    mpfr_si_div(tmp,1,tmp)
    mpfr_add(rn,rn,tmp)
end for
printf(1,"sum of reciprocals: %s\n",{shorten(mpfr_get_fixed(rn,211))})
Output:
1: 2
2: 3
3: 7
4: 43
5: 1807
6: 3263443
7: 10650056950807
8: 113423713055421844361000443
9: 12864938683278671740537145998360961546653259485195807
10: 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
sum of reciprocals: 0.999999999999999999...99999999999999999635 (213 digits)

PL/M

As the original 8080 PL/M only has unsigned 8 and 16 bit items, this Uses code from the PL/M Long Multiplication sample routines.
It doesn't calculate the reciprocal sum as 8080 PL/M has no floating point...
This sample can be compiled with the original 8080 PL/M compiler and run under CP/M (or an emulator or clone).

100H: /* CALCULATE ELEMENTS OF SYLVESTOR'S SEQUENCE                          */

   BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL                      */
      DECLARE FN BYTE, ARG ADDRESS;
      GOTO 5;
   END BDOS;
   PRINT$CHAR:   PROCEDURE( C ); DECLARE C BYTE;    CALL BDOS( 2, C ); END;
   PRINT$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
   DECLARE PRINT$NL LITERALLY 'PRINT$STRING( .( 0DH, 0AH, ''$'' ) )';

   DECLARE LONG$INTEGER  LITERALLY '(201)BYTE';
   DECLARE DIGIT$BASE    LITERALLY '10';

   /* PRINTS A LONG INTEGER                                                  */
   PRINT$LONG$INTEGER: PROCEDURE( N$PTR );
      DECLARE N$PTR ADDRESS;
      DECLARE N BASED N$PTR LONG$INTEGER;
      DECLARE ( D, F ) BYTE;
      F = N( 0 );
      DO D = 1 TO N( 0 );
         CALL PRINT$CHAR( N( F ) + '0' );
         F = F - 1;
      END;
   END PRINT$LONG$INTEGER;
   /* IMPLEMENTS LONG MULTIPLICATION, C IS SET TO A * B                      */
   /*     C CAN BE THE SAME LONG$INTEGER AS A OR B                           */
   LONG$MULTIPLY: PROCEDURE( A$PTR, B$PTR, C$PTR );
      DECLARE ( A$PTR, B$PTR, C$PTR ) ADDRESS;
      DECLARE ( A BASED A$PTR, B BASED B$PTR, C BASED C$PTR ) LONG$INTEGER;
      DECLARE MRESULT LONG$INTEGER;
      DECLARE RPOS    BYTE;

      /* MULTIPLIES THE LONG INTEGER IN B BY THE INTEGER A, THE RESULT       */
      /*     IS ADDED TO C, STARTING FROM DIGIT START                        */
      /*     OVERFLOW IS IGNORED                                             */
      MULTIPLY$ELEMENT: PROCEDURE( A, B$PTR, C$PTR, START );
         DECLARE ( B$PTR, C$PTR )                 ADDRESS;
         DECLARE ( A, START )                     BYTE;
         DECLARE ( B BASED B$PTR, C BASED C$PTR ) LONG$INTEGER;
         DECLARE ( CDIGIT, D$CARRY, BPOS, CPOS )  BYTE;
         D$CARRY = 0;
         CPOS    = START;
         DO BPOS = 1 TO B( 0 );
            CDIGIT = C( CPOS ) + ( A * B( BPOS ) ) + D$CARRY;
            IF CDIGIT < DIGIT$BASE THEN D$CARRY = 0;
            ELSE DO;
               /* HAVE DIGITS TO CARRY                                       */
               D$CARRY = CDIGIT  /  DIGIT$BASE;
               CDIGIT  = CDIGIT MOD DIGIT$BASE;
            END;
            C( CPOS ) = CDIGIT;
            CPOS = CPOS + 1;
         END;
         C( CPOS ) = D$CARRY;
         /* REMOVE LEADING ZEROS BUT IF THE NUMBER IS 0, KEEP THE FINAL 0    */
         DO WHILE( CPOS > 1 AND C( CPOS ) = 0 );
            CPOS = CPOS - 1;
         END;
         C( 0 ) = CPOS;
      END MULTIPLY$ELEMENT ;

      /* THE RESULT WILL BE COMPUTED IN MRESULT, ALLOWING A OR B TO BE C     */
      DO RPOS = 1 TO LAST( MRESULT ); MRESULT( RPOS ) = 0; END;
      /* MULTIPLY BY EACH DIGIT AND ADD TO THE RESULT                        */
      DO RPOS = 1 TO A( 0 );
         IF A( RPOS ) <> 0 THEN DO;
            CALL MULTIPLY$ELEMENT( A( RPOS ), B$PTR, .MRESULT, RPOS );
         END;
      END;
      /* RETURN THE RESULT IN C                                              */
      DO RPOS = 0 TO MRESULT( 0 ); C( RPOS ) = MRESULT( RPOS ); END;
   END;
   /* ADDS THE INTEGER A TO THE LONG$INTEGER N                               */
   ADD$BYTE$TO$LONG$INTEGER: PROCEDURE( A, N$PTR );
      DECLARE A BYTE, N$PTR ADDRESS;
      DECLARE N BASED N$PTR LONG$INTEGER;
      DECLARE ( D, D$CARRY, DIGIT ) BYTE;
      D       = 1;
      D$CARRY = A;
      DO WHILE( D$CARRY > 0 );
         DIGIT = N( D ) + D$CARRY;
         IF DIGIT < DIGIT$BASE THEN DO;
            N( D )  = DIGIT;
            D$CARRY = 0;
            END;
         ELSE DO;
             D$CARRY = DIGIT  /  DIGIT$BASE;
             N( D )  = DIGIT MOD DIGIT$BASE;
             D       = D + 1;
             IF D > N( 0 ) THEN DO;
                /* THE NUMBER NOW HAS AN EXTRA DIGIT                         */
                N( 0 )  = D;
                N( D )  = D$CARRY;
                D$CARRY = 0;
             END;
         END;
      END;
   END ADD$BYTE$TO$LONG$INTEGER;
   /* FIND THE FIRST 10 ELEMENTS OF SYLVESTOR'S SEQUENCE                     */
   DECLARE ( SEQ$ELEMENT, PRODUCT ) LONG$INTEGER;
   DECLARE ( I, D )                 BYTE;
   DO D = 2 TO LAST( PRODUCT     ); PRODUCT(     D ) = 0; END;
   DO D = 2 TO LAST( SEQ$ELEMENT ); SEQ$ELEMENT( D ) = 0; END;
   SEQ$ELEMENT( 0 ) = 1; /* THE FIRST SEQUENCE ELEMENT HAS 1 DIGIT...        */
   SEQ$ELEMENT( 1 ) = 2; /* WHICH IS 2                                       */
   PRODUCT(     0 ) = 1;
   PRODUCT(     1 ) = 2;
   CALL PRINT$LONG$INTEGER( .SEQ$ELEMENT );     /* SHOW ELEMENT 1            */
   CALL PRINT$NL;
   DO I = 2 TO 9;
      DO D = 0 TO PRODUCT( 0 ); SEQ$ELEMENT( D ) = PRODUCT( D ); END;
      CALL ADD$BYTE$TO$LONG$INTEGER( 1, .SEQ$ELEMENT );
      CALL PRINT$LONG$INTEGER( .SEQ$ELEMENT );
      CALL LONG$MULTIPLY( .SEQ$ELEMENT, .PRODUCT, .PRODUCT );
      CALL PRINT$NL;
   END;
   /* THE FINAL ELEMENT IS THE PRODUCT PLUS 1                                */
   CALL ADD$BYTE$TO$LONG$INTEGER( 1, .PRODUCT );
   CALL PRINT$LONG$INTEGER( .PRODUCT );
   CALL PRINT$NL;
EOF
Output:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Prolog

Works with: SWI Prolog
sylvesters_sequence(N, S, R):-
    sylvesters_sequence(N, S, 2, R, 0).

sylvesters_sequence(0, [X], X, R, S):-
    !,
    R is S + 1 rdiv X.
sylvesters_sequence(N, [X|Xs], X, R, S):-
    Y is X * X - X + 1,
    M is N - 1,
    T is S + 1 rdiv X,
    sylvesters_sequence(M, Xs, Y, R, T).

main:-
    sylvesters_sequence(9, Sequence, Sum),
    writeln('First 10 elements in Sylvester\'s sequence:'),
    forall(member(S, Sequence), writef('%t\n', [S])),
    N is numerator(Sum),
    D is denominator(Sum),
    writef('\nSum of reciprocals: %t / %t\n', [N, D]).
Output:
First 10 elements in Sylvester's sequence:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of reciprocals: 27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805 / 27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Python

'''Sylvester's sequence'''

from functools import reduce
from itertools import count, islice


# sylvester :: [Int]
def sylvester():
    '''Non-finite stream of the terms
       of Sylvester's sequence.
       (OEIS A000058)
    '''
    def go(n):
        return 1 + reduce(
            lambda a, x: a * go(x),
            range(0, n),
            1
        ) if 0 != n else 2

    return map(go, count(0))


# ------------------------- TEST -------------------------
# main :: IO ()
def main():
    '''First terms, and sum of reciprocals.'''

    print("First 10 terms of OEIS A000058:")
    xs = list(islice(sylvester(), 10))
    print('\n'.join([
        str(x) for x in xs
    ]))

    print("\nSum of the reciprocals of the first 10 terms:")
    print(
        reduce(lambda a, x: a + 1 / x, xs, 0)
    )


# MAIN ---
if __name__ == '__main__':
    main()
Output:
First 10 terms of OEIS A000058:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of the first 10 terms:
0.9999999999999999


Or as an iteration:

'''Sylvester's sequence'''

from functools import reduce
from itertools import islice

# sylvester :: [Int]
def sylvester():
    '''A non finite sequence of the terms of OEIS A000058
    '''
    return iterate(
        lambda x: x * (x - 1) + 1
    )(2)


# ------------------------- TEST -------------------------
# main :: IO ()
def main():
    '''First terms, and sum of reciprocals.'''

    print("First 10 terms of OEIS A000058:")
    xs = list(islice(sylvester(), 10))
    print('\n'.join([
        str(x) for x in xs
    ]))

    print("\nSum of the reciprocals of the first 10 terms:")
    print(
        reduce(lambda a, x: a + 1 / x, xs, 0)
    )

# ----------------------- GENERIC ------------------------

# iterate :: (a -> a) -> a -> Gen [a]
def iterate(f):
    '''An infinite list of repeated
       applications of f to x.
    '''
    def go(x):
        v = x
        while True:
            yield v
            v = f(v)
    return go


# MAIN ---
if __name__ == '__main__':
    main()
Output:
First 10 terms of OEIS A000058:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of the first 10 terms:
0.9999999999999999

Quackery

[ $ "bigrat.qky" loadfile ] now! 

' [ 2 ] 9 times [ dup -1 peek dup 2 ** swap - 1+ join ]

dup witheach [ echo cr ] cr

0 n->v rot witheach [ n->v 1/v v+ ] 222 point$ echo$
Output:

The first 222 digits after the decimal point are shown for the sum of reciprocals.

2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

0.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999963493590798413

Raku

my @S = {1 + [*] @S[^($++)]} … *;

put 'First 10 elements of Sylvester\'s sequence: ', @S[^10];

say "\nSum of the reciprocals of first 10 elements: ", sum @S[^10].map: { FatRat.new: 1, $_ };
Output:
First 10 elements of Sylvester's sequence: 2 3 7 43 1807 3263443 10650056950807 113423713055421844361000443 12864938683278671740537145998360961546653259485195807 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of first 10 elements: 0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999635

REXX

/*REXX pgm finds N terms of the Sylvester's sequence & the sum of the their reciprocals.*/
parse arg n .                                    /*obtain optional argument from the CL.*/
if n=='' | n==","  then n= 10                    /*Not specified?  Then use the default.*/
numeric digits max(9, 2**(n-7) * 13 + 1)         /*calculate how many dec. digs we need.*/
@.0= 2                                           /*the value of the 1st Sylvester number*/
$= 0
        do j=0  for n;      jm= j - 1            /*calculate the Sylvester sequence.    */
        if j>0  then @.j= @.jm**2 - @.jm + 1     /*calculate  a  Sylvester sequence num.*/
        say 'Sylvester('j") ──► "   @.j          /*display the Sylvester index & number.*/
        $= $   +   1 / @.j                       /*add its reciprocal to the recip. sum.*/
        end   /*j*/
say                                              /*stick a fork in it,  we're all done. */
numeric digits digits() - 1
say 'sum of the first '   n   " reciprocals using"   digits()   'decimal digits: '   $ / 1
output   when using the default inputs:
Sylvester(0) ──►  2
Sylvester(1) ──►  3
Sylvester(2) ──►  7
Sylvester(3) ──►  43
Sylvester(4) ──►  1807
Sylvester(5) ──►  3263443
Sylvester(6) ──►  10650056950807
Sylvester(7) ──►  113423713055421844361000443
Sylvester(8) ──►  12864938683278671740537145998360961546653259485195807
Sylvester(9) ──►  165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

sum of the first  10  reciprocals using 104 decimal digits:  1

RPL

Works with: HP version 49
≪ { 2 3 } 
   DO
     DUP ΠLIST 1 + + 
   UNTIL DUP2 SIZE == END
   NIP
≫ 'SYLV' STO 
10 SYLV
DUP INV ∑LIST EXPAND
Output:
2: { 2 3 7 43 1807 3263443 10650056950807 113423713055421844361000443 12864938683278671740537145998360961546653259485195807 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443 }
1: 27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805 /
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Ruby

def sylvester(n) = (1..n).reduce(2){|a| a*a - a + 1 }
  
(0..9).each {|n| puts "#{n}: #{sylvester n}"  }
puts "
Sum of reciprocals of first 10 terms:
#{(0..9).sum{|n| 1.0r / sylvester(n)}.to_f }"
Output:
0: 2
1: 3
2: 7
3: 43
4: 1807
5: 3263443
6: 10650056950807
7: 113423713055421844361000443
8: 12864938683278671740537145998360961546653259485195807
9: 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of reciprocals of first 10 terms:
1.0

Scheme

(define sylvester
  (lambda (x)
    (if (= x 1)
      2
      (let ((n (sylvester (- x 1)))) (- (* n n) n -1)))))
(define list (map sylvester '(1 2 3 4 5 6 7 8 9 10)))
(print list)
(newline)
(print (apply + (map / list)))
Output:
(2 3 7 43 1807 3263443 10650056950807 113423713055421844361000443 12864938683278671740537145998360961546653259485195807 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443)
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Seed7

$ include "seed7_05.s7i";
  include "bigint.s7i";
  include "bigrat.s7i";

const func bigInteger: nextSylvester (in bigInteger: prev) is
  return prev * prev - prev + 1_;

const proc: main is func
  local
    var bigInteger: number is 2_;
    var bigRational: reciprocalSum is 0_ / 1_;
    var integer: n is 0;
  begin
    writeln("First 10 elements of Sylvester's sequence:");
    for n range 1 to 10 do
      writeln(number);
      reciprocalSum +:= 1_ / number;
      number := nextSylvester(number);
    end for;
    writeln("\nSum of the reciprocals of the first 10 elements:");
    writeln(reciprocalSum digits 210);
  end func;
Output:
First 10 elements of Sylvester's sequence:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of the reciprocals of the first 10 elements:
0.999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999963

Sidef

func sylvester_sequence(n) {
    1..n -> reduce({|a| a*(a-1) + 1 }, 2)
}

say "First 10 terms in Sylvester's sequence:"
10.of(sylvester_sequence).each_kv{|k,v| '%2s: %s' % (k,v) -> say }

say "\nSum of reciprocals of first 10 terms: "
say 10.of(sylvester_sequence).sum {|n| 1/n }.as_dec(230)
Output:
First 10 terms in Sylvester's sequence:
 0: 2
 1: 3
 2: 7
 3: 43
 4: 1807
 5: 3263443
 6: 10650056950807
 7: 113423713055421844361000443
 8: 12864938683278671740537145998360961546653259485195807
 9: 165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

Sum of reciprocals of first 10 terms: 
0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996349359079841301329356

Swift

Using mkrd's BigNumber library.

import BigNumber

func sylvester(n: Int) -> BInt {
  var a = BInt(2)

  for _ in 0..<n {
    a = a * a - a + 1
  }

  return a
}

var sum = BDouble(0)

for n in 0..<10 {
  let syl = sylvester(n: n)
  sum += BDouble(1) / BDouble(syl)
  print(syl)
}

print("Sum of the reciprocals of first ten in sequence: \(sum)")
Output:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443
Sum of the reciprocals of first ten in sequence: 27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

Verilog

module main;
  integer i;
  real suma, num;

  initial begin
    $display("10 primeros términos de la sucesión de sylvester:");
    $display("");

    suma = 0;
    num = 0;
    for(i=1; i<=10; i=i+1) begin
        if (i==1) num = 2;
        else      num = num * num - num + 1;
    
        $display(i, ": ", num);
        suma = suma + 1 / num;
    end

    $display("");
    $display("suma de sus recíprocos: ", suma);
    $finish ;
  end
endmodule
Output:
10 primeros términos de la sucesión de sylvester:

          1: 2.00000
          2: 3.00000
          3: 7.00000
          4: 43.0000
          5: 1807.00
          6: 3.26344e+06
          7: 1.06501e+13
          8: 1.13424e+26
          9: 1.28649e+52
         10: 1.65507e+104

suma de sus recíprocos: 1.00000


Wren

Library: Wren-big
import "./big" for BigInt, BigRat

var sylvester = [BigInt.two]
var prod = BigInt.two
var count = 1
while (true) {
    var next = prod + 1
    sylvester.add(next)
    count = count + 1
    if (count == 10) break
    prod = prod * next
}
System.print("The first 10 terms in the Sylvester sequence are:")
System.print(sylvester.join("\n"))

var sumRecip = sylvester.reduce(BigRat.zero) { |acc, s| acc + BigRat.new(1, s) }
System.print("\nThe sum of their reciprocals as a rational number is:")
System.print (sumRecip)
System.print("\nThe sum of their reciprocals as a decimal number (to 211 places) is:")
System.print(sumRecip.toDecimal(211))
Output:
The first 10 terms in the Sylvester sequence are:
2
3
7
43
1807
3263443
10650056950807
113423713055421844361000443
12864938683278671740537145998360961546653259485195807
165506647324519964198468195444439180017513152706377497841851388766535868639572406808911988131737645185443

The sum of their reciprocals as a rational number is:
27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920805/27392450308603031423410234291674686281194364367580914627947367941608692026226993634332118404582438634929548737283992369758487974306317730580753883429460344956410077034761330476016739454649828385541500213920806

The sum of their reciprocals as a decimal number (to 211 places) is:
0.9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999635