Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Caution: breathing may be hazardous to your health.


comp / comp.lang.python / Lengthy numbers

SubjectAuthor
* Lengthy numbersGilmeh Serda
+* Re: Lengthy numbers (Posting On Python-List Prohibited)Lawrence D'Oliveiro
|`* Re: Lengthy numbers (Posting On Python-List Prohibited)Gilmeh Serda
| `- Re: Lengthy numbers (Posting On Python-List Prohibited)Lawrence D'Oliveiro
`* Re: Lengthy numbersOscar Benjamin
 +* Re: Lengthy numbersStefan Ram
 |`* Re: Lengthy numbersPaul Rubin
 | `- Re: Lengthy numbersStefan Ram
 `- Re: Lengthy numbersPaul Rubin

1
Subject: Lengthy numbers
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Sat, 21 Dec 2024 11:49 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!2.eu.feeder.erje.net!feeder.erje.net!feeder2.feed.ams11.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx01.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Lengthy numbers
Newsgroups: comp.lang.python
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.161 (Chasiv Yar; 7e6f2f6)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 34
Message-ID: <eXx9P.64901$o72.28550@fx01.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sat, 21 Dec 2024 11:49:30 GMT
X-Received-Bytes: 2053
View all headers

Was just playing with numbers and stumbled on something I've never seen
before.

>>> 9**9**2
196627050475552913618075908526912116283103450944214766927315415537966391196809

>>> 9**9**3
439328503696464329829774782657072712058010308177126710621676697750466344744764
029773301412612482563729435064854354299095570379503452515853238520182740967398
746503532324400000659505126023955913142968176998364877699089666171297275956245
407453033190168644894850576346492691458695174281789557994923607783461486426448
617667076393901104477324982631297641034277093818692823488603426279473674368943
609268871793467206677285688478458498235002859256706389043030847945506577080623
430066283504397583789044245429585982964571774605868466160379567432725704121260
940939343217905975847365096315872153240969882363435363449775254393010368267343
970426230801390250903399147001650831878665172798468587509747439118815689

>>> 9**9**4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Exceeds the limit (4300 digits) for integer string conversion;
use sys.set_int_max_str_digits() to increase the limit

Explanation:
https://discuss.python.org/t/int-str-conversions-broken-in-latest-python-bugfix-releases/18889

Though, it would have been funnier had it been 4400...

--
Gilmeh

The best definition of a gentleman is a man who can play the accordion --
but doesn't. -- Tom Crichton

Subject: Re: Lengthy numbers (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Sat, 21 Dec 2024 21:03 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Lengthy numbers (Posting On Python-List Prohibited)
Date: Sat, 21 Dec 2024 21:03:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <vk7afo$7g01$2@dont-email.me>
References: <eXx9P.64901$o72.28550@fx01.ams4>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 21 Dec 2024 22:03:53 +0100 (CET)
Injection-Info: dont-email.me; posting-host="13a42d5f937e341e3a688a49c45bb4c8";
logging-data="245761"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9eAWZnqwOtzvbwHWmCTql"
User-Agent: Pan/0.161 (Chasiv Yar; )
Cancel-Lock: sha1:8JSt11g+PanmciCaaq791eh15cs=
View all headers

On Sat, 21 Dec 2024 11:49:30 GMT, Gilmeh Serda wrote:

> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: Exceeds the limit (4300 digits) for integer string
> conversion;
> use sys.set_int_max_str_digits() to increase the limit
>
> Explanation:
> https://discuss.python.org/t/int-str-conversions-broken-in-latest-python-bugfix-releases/18889

This is a feature, not a bug. It’s to guard against an attacker
exhausting system resources (CPU) by forcing the execution of an O(N²)
operation with large N.

Subject: Re: Lengthy numbers (Posting On Python-List Prohibited)
From: Gilmeh Serda
Newsgroups: comp.lang.python
Organization: Easynews - www.easynews.com
Date: Sun, 22 Dec 2024 09:18 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.swapon.de!news.in-chemnitz.de!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx03.ams4.POSTED!not-for-mail
From: gilmeh.serda@nothing.here.invalid (Gilmeh Serda)
Subject: Re: Lengthy numbers (Posting On Python-List Prohibited)
Newsgroups: comp.lang.python
References: <eXx9P.64901$o72.28550@fx01.ams4> <vk7afo$7g01$2@dont-email.me>
MIME-Version: 1.0
x-no-archive: yes
User-Agent: Pan/0.161 (Chasiv Yar; 7e6f2f6)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Lines: 11
Message-ID: <CPQ9P.18709$M62.17538@fx03.ams4>
X-Complaints-To: abuse@easynews.com
Organization: Easynews - www.easynews.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 22 Dec 2024 09:18:26 GMT
X-Received-Bytes: 1004
View all headers

On Sat, 21 Dec 2024 21:03:52 -0000 (UTC), Lawrence D'Oliveiro wrote:

> not a bug.

Who said anything about a bug?

--
Gilmeh

Barbie says, Take quaaludes in gin and go to a disco right away! But Ken
says, WOO-WOO!! No credit at "Mr. Liquor"!!

Subject: Re: Lengthy numbers
From: Oscar Benjamin
Newsgroups: comp.lang.python
Date: Sun, 22 Dec 2024 23:32 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: oscar.j.benjamin@gmail.com (Oscar Benjamin)
Newsgroups: comp.lang.python
Subject: Re: Lengthy numbers
Date: Sun, 22 Dec 2024 23:32:30 +0000
Lines: 44
Message-ID: <mailman.14.1734910364.2912.python-list@python.org>
References: <eXx9P.64901$o72.28550@fx01.ams4>
<CAHVvXxRQBUhFxdKKUGvR8BAeCmi0p-YZvoD_xdXuusFqcDjdjQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de UObgpSVC3U+Axn4eVOWxXQR0yV3aE7Rm4frTtdjFNRlg==
Cancel-Lock: sha1:xtnJlFRLaiiAXBujzfFUfwxoaJY= sha256:xPoU0rsrGHlB81eVsjznJezibX0mvYraCXjio0MEV3s=
Return-Path: <oscar.j.benjamin@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=kCiNCd93;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'traceback': 0.04; '(most':
0.05; 'last):': 0.05; 'e.g.': 0.07; 'string': 0.07; 'sun,': 0.07;
'url-ip:184.105.99/24': 0.07; 'url-ip:184.105/16': 0.07;
'enough.': 0.09; 'int': 0.09; 'skip:x 10': 0.09;
'subject:numbers': 0.09; 'url-ip:184.105.99.75/32': 0.09;
'url:discuss': 0.09; 'valueerror:': 0.09; 'conversion': 0.16;
'cpython': 0.16; 'cpython.': 0.16; 'integer': 0.16; 'parsing':
0.16; 'reminded': 0.16; 'slow': 0.16; 'slowness': 0.16; 'wrote:':
0.16; 'problem': 0.16; 'solve': 0.19; 'to:addr:python-list': 0.20;
'issue': 0.21; 'machine': 0.22; "i've": 0.22; 'i.e.': 0.22; 'run':
0.23; '>>>': 0.28; 'etc': 0.28; 'think': 0.29; 'before.': 0.31;
'dec': 0.31; 'message-id:@mail.gmail.com': 0.31; "doesn't": 0.32;
'"",': 0.32; '(as': 0.32; 'concern': 0.32; 'python-list': 0.32;
'but': 0.32; 'header:In-Reply-To:1': 0.34; 'received:google.com':
0.34; 'same': 0.34; 'from:addr:gmail.com': 0.34; 'computer.':
0.35; 'possibly': 0.36; 'people': 0.36; 'using': 0.37; 'hard':
0.37; 'file': 0.38; 'use': 0.39; 'something': 0.40; 'want': 0.40;
'likely': 0.61; 'seen': 0.62; 'come': 0.62; 'security': 0.64;
'your': 0.64; 'becomes': 0.64; 'mainly': 0.64; 'numbers': 0.67;
'playing': 0.69; 'url:t': 0.73; '....': 0.76; 'stumbled': 0.76;
'quick': 0.77; 'dangerous': 0.81; 'motivated': 0.84; 'oscar':
0.84; 'type.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1734910361; x=1735515161; darn=python.org;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=ES63BYC3cWlELxCHvKqK6HWzfEgSvS9Ums3g8dN5W3c=;
b=kCiNCd93U2j7Gkjvb9e4st80lOKUsdyh7mt0MyRgkWYG8VJht8KzjbVAqf/Hi6wHu0
HQG7sR3/MoKr2wbPUS3w0Ev/k/HokMfH1L+VgjcyviA03dIRLhl4DChzLsWY7o1AP+ln
G4Q7x6xFfFwDoGteH1JSuAfBZuzUvcnLiA62JweonNixzJs3l+VnjRl7jICLTwod0C88
X7FNtoD50CK4fAcD7h4XmF3JNgnP4bJSKC/AtDRq5kHAYYN3PUl5nL4rEWrX2t5P531x
qTaS4DzS3CdUzSb17zB3Ek3u3zHa0sjLiXj46GsgwCi5wCqSSMJFfXmVw0wGpst6Q6sU
/52A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1734910361; x=1735515161;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=ES63BYC3cWlELxCHvKqK6HWzfEgSvS9Ums3g8dN5W3c=;
b=U/QmQl8Fl9biYfOrF1B8gBFfR60FYgPdYK3wuSaWGQtsbSzv1ZpXpjkryoxLFaRsSb
8cSBfrxeYpzHHH5O5SJY8+yFx5bEpylkqxAbCH1VLowNPQHbNIJnLzcV5xAXqa3f0EMQ
2Z9xLh4gphDchiw6zKCcxqGr1ImMpSsHTaUfc4YmA2xqKe1TvOll8jYt4aJfUDfsTLD5
dE4dF+InFj8VLogXYtzWnY33JXAwzJSPWcKuhlyKvk3J7N0dJDoYdpjGcGy3nWvHsrGz
qvfe/Hn2hDqRLryaupWmWcjc6NyxLKI4Jl0IrBQg0s57LV8Bwk0mi2lVQ3DWr0RzJ7hD
QWCA==
X-Gm-Message-State: AOJu0Yw7UPmz7U1DDR4WNYA8A+J1TzswlH5cXPmxRSZZbhXK2OldySLI
/LAplhxoxu4T0BoZ8cTW9X5PJv/v28jhlJjIinwU0wU0mMcmp9Pe4SKBXauLhvuwLCjy3nRaf/R
vuw8/O2p/hz58M22leoieFRvbqty+mXwV
X-Gm-Gg: ASbGncu09McW94J3WmgDv7gWMR0SNWuJt0enxUELk0g/u+z80QGCTv4126Ua+XMnWIR
bFvQwAH5z8ksAMgsLe271wEVRjyxBcqPxi9xwBwxOFdBHTnfXCXmxmaWL/SR9fJ+cPjeFcGhD
X-Google-Smtp-Source: AGHT+IEVaUW4KSTQ9UD8jxcDHcMvTbd6hsRIaMQWpf4D0saZIoGgZiC1dSZiE23TjhplFjDUt4ei3AUXAfifAStsZPM=
X-Received: by 2002:a05:6870:9c88:b0:29e:27b6:bea5 with SMTP id
586e51a60fabf-2a7fb1af4cemr5957772fac.25.1734910361480; Sun, 22 Dec 2024
15:32:41 -0800 (PST)
In-Reply-To: <eXx9P.64901$o72.28550@fx01.ams4>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAHVvXxRQBUhFxdKKUGvR8BAeCmi0p-YZvoD_xdXuusFqcDjdjQ@mail.gmail.com>
X-Mailman-Original-References: <eXx9P.64901$o72.28550@fx01.ams4>
View all headers

On Sun, 22 Dec 2024 at 19:17, Gilmeh Serda via Python-list
<python-list@python.org> wrote:
>
> Was just playing with numbers and stumbled on something I've never seen
> before.
....
>
> >>> 9**9**4
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ValueError: Exceeds the limit (4300 digits) for integer string conversion;
> use sys.set_int_max_str_digits() to increase the limit
>
> Explanation:
> https://discuss.python.org/t/int-str-conversions-broken-in-latest-python-bugfix-releases/18889

I think that the original security concern was mainly motivated by the
string to int direction i.e. calling int(s) for a possibly large
string s (possibly from an untrusted source) might be slow with
CPython. To solve that problem conversions from string->int and
int->string were disallowed. Now that more time has passed it becomes
clearer that disabling int->string conversion is more likely to be the
thing that people bump into as a result of this limitation (as you
just did). I find it harder to see what the security problem is in
that direction but I don't think this will be changed.

CPython has an implementation of arbitrarily large integers but an
important part of it is hobbled. If you do want to work with such
large integers then I recommend using either gmpy2's gmpy2.mpz type or
python-flint's flint.fmpz type.

At the same time it is not hard to run into slowness with integers
e.g. 10**10**10 but that won't come up in string parsing if not using
eval. Not a likely security issue but I am suddenly reminded of this
dangerous snippet:

x = [0]; x.extend(iter(x))

If you want to test it then make sure to save your work etc and be
prepared to hard reset the computer. On this machine Ctrl-C doesn't
work for this but Ctrl-\ does if you do it quick enough.

--
Oscar

Subject: Re: Lengthy numbers
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Mon, 23 Dec 2024 08:02 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Lengthy numbers
Date: 23 Dec 2024 08:02:08 GMT
Organization: Stefan Ram
Lines: 30
Expires: 1 Jan 2026 11:59:58 GMT
Message-ID: <extend-20241223090009@ram.dialup.fu-berlin.de>
References: <eXx9P.64901$o72.28550@fx01.ams4> <mailman.14.1734910364.2912.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de fIDjdGhIKBrS7ygw9Ijh0gV9PGSbprUWRexjWDkhEnoFM5
Cancel-Lock: sha1:YV22kRBYR4fzBx4UI9Nvs5GmZhs= sha256:uvNAXuMbZDNoVYg0AmPFPeEh3Ra8myKXK0rLwfuv+2M=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote or quoted:
>x = [0]; x.extend(iter(x))

Yo, that's a gnarly piece of Python code!

This code whips up an infinite list, but in a pretty slick way.

Here's the lowdown:

- First off, we're cooking up a list x with just one ingredient: 0

- Then we're using extend() to pile more stuff onto x

- The mind-bender is what we're extending with: iter(x)

iter(x) spins up an iterator from the list x. When we extend x
with this iterator, it starts tossing the elements of x back into
itself. But here's the kicker: as x grows, the iterator keeps
chugging along, creating an endless loop.

So in theory, this would crank out an infinite list that looks like
[0, 0, 0, 0, ...]. In the real world, though, if you try to print or
use this list, your program will probably freeze up faster than the
405 at rush hour.

It's a pretty clever (and kind of diabolical) way to create an
infinite data structure. Just watch out using something like
this in actual code - it could cause some serious brain freeze!

Subject: Re: Lengthy numbers
From: Paul Rubin
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Mon, 23 Dec 2024 23:03 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.python
Subject: Re: Lengthy numbers
Date: Mon, 23 Dec 2024 15:03:01 -0800
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <875xna9f4q.fsf@nightsong.com>
References: <eXx9P.64901$o72.28550@fx01.ams4>
<CAHVvXxRQBUhFxdKKUGvR8BAeCmi0p-YZvoD_xdXuusFqcDjdjQ@mail.gmail.com>
<mailman.14.1734910364.2912.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 24 Dec 2024 00:03:02 +0100 (CET)
Injection-Info: dont-email.me; posting-host="0ec77f02b40872df5202021528adc871";
logging-data="1506899"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UpRTVd8j0qq00lP3QQ7ew"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:dBEMqFVrbMq3Cw9BVdGmRXmHexY=
sha1:uqi3rybdM+EhGlIzdmT/iGMx5JI=
View all headers

Oscar Benjamin <oscar.j.benjamin@gmail.com> writes:
> To solve that problem conversions from string->int and
> int->string were disallowed.

The obvious conversion algorithms use quadratic time but it seems to me
that O(n log n) is doable with some careful programming. For example,
people have computed pi to billions or trillions of decimal places.

I believe GMP uses the Toom-Cook algorithm for multiplication once the
numbers are big enough. I don't know whether that is also used for
decimal conversions.

Page 14 of http://maths-people.anu.edu.au/~brent/pd/rpb032.pdf discusses
base conversion. That link is from a stackexchange thread that I found
with web search.

Subject: Re: Lengthy numbers (Posting On Python-List Prohibited)
From: Lawrence D'Oliv
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Mon, 23 Dec 2024 23:06 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.python
Subject: Re: Lengthy numbers (Posting On Python-List Prohibited)
Date: Mon, 23 Dec 2024 23:06:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <vkcqd8$1e6nt$1@dont-email.me>
References: <eXx9P.64901$o72.28550@fx01.ams4> <vk7afo$7g01$2@dont-email.me>
<CPQ9P.18709$M62.17538@fx03.ams4>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 24 Dec 2024 00:06:17 +0100 (CET)
Injection-Info: dont-email.me; posting-host="edef36f048484e23e2423422291f3974";
logging-data="1514237"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19drZskml8zfeYyKDhO1Vg9"
User-Agent: Pan/0.161 (Chasiv Yar; )
Cancel-Lock: sha1:yATZL214Kbo9rtGZ60LjSa5X5Y8=
View all headers

On Sun, 22 Dec 2024 09:18:26 GMT, Gilmeh Serda wrote:

> On Sat, 21 Dec 2024 21:03:52 -0000 (UTC), Lawrence D'Oliveiro wrote:
>
>> This is a feature, not a bug.
>
> Who said anything about a bug?

Not sure what this is relevant to, but ... you tell me.

Subject: Re: Lengthy numbers
From: Paul Rubin
Newsgroups: comp.lang.python
Organization: A noiseless patient Spider
Date: Mon, 23 Dec 2024 23:38 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.python
Subject: Re: Lengthy numbers
Date: Mon, 23 Dec 2024 15:38:13 -0800
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <871pxy9di2.fsf@nightsong.com>
References: <eXx9P.64901$o72.28550@fx01.ams4>
<mailman.14.1734910364.2912.python-list@python.org>
<extend-20241223090009@ram.dialup.fu-berlin.de>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Tue, 24 Dec 2024 00:38:19 +0100 (CET)
Injection-Info: dont-email.me; posting-host="0ec77f02b40872df5202021528adc871";
logging-data="1527689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/U6NkNhLK5pY12iw9v4n4s"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:ai7ePeHug8IL6mwyca7VcFgb/Ic=
sha1:wUf/NMpJBjlSYOkk5Bodv+ZKxuE=
View all headers

ram@zedat.fu-berlin.de (Stefan Ram) writes:
> So in theory, this would crank out an infinite list that looks like
> [0, 0, 0, 0, ...]. In the real world, though, if you try to print or
> use this list, your program will probably freeze up faster than the
> 405 at rush hour.

The freeze-up happens as soon as you create the list. Unfortunately
iterators don't have anything like .extend so I don't see a way to
create recursive ones like that, short of writing more verbose code
using yield. In Haskell it is straightforward:

fibonacci = 0 : 1 : zipWith (+) (tail fibonacci)

main = print (take 10 fibonacci)

should print [0,1,1,2,3,5,8,13,21,34].

Subject: Re: Lengthy numbers
From: Stefan Ram
Newsgroups: comp.lang.python
Organization: Stefan Ram
Date: Tue, 24 Dec 2024 12:26 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Lengthy numbers
Date: 24 Dec 2024 12:26:26 GMT
Organization: Stefan Ram
Lines: 13
Expires: 1 Jan 2026 11:59:58 GMT
Message-ID: <list-20241224132559@ram.dialup.fu-berlin.de>
References: <eXx9P.64901$o72.28550@fx01.ams4> <mailman.14.1734910364.2912.python-list@python.org> <extend-20241223090009@ram.dialup.fu-berlin.de> <871pxy9di2.fsf@nightsong.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de AyMJFWgMjSH5/6Mqg2AN+wvtkwpPwUDmjTLqwyxUwOJS2s
Cancel-Lock: sha1:iFsmBfcknpPtSLF7wMdwrZwvojk= sha256:3cI2aOp3mCOnmG281SyDBjMj05vZgOzqh02Wy7ZtHT8=
X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
View all headers

Paul Rubin <no.email@nospam.invalid> wrote or quoted:
>ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>So in theory, this would crank out an infinite list that looks like
>>[0, 0, 0, 0, ...]. In the real world, though, if you try to print or
>>use this list, your program will probably freeze up faster than the
>>405 at rush hour.
>The freeze-up happens as soon as you create the list.

I'm stoked you caught that! You hit the nail on the head -
that resource-hogging calculation goes down when the expression's
evaluated. No need to "print or use this list" to see it happen.

1

rocksolid light 0.9.8
clearnet tor