Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Memory fault -- core...uh...um...core... Oh dammit, I forget!


devel / comp.lang.lisp / Re: recursion is silly

SubjectAuthor
* recursion is sillynone
+* Re: recursion is sillyLIT
|+* Re: recursion is sillyJulieta Shem
||+* Re: recursion is sillyLIT
|||`- Re: recursion is sillyJulieta Shem
||+- Re: recursion is sillyLIT
||+* Re: recursion is sillyJoerg Mertens
|||`- Re: recursion is sillyJulieta Shem
||`- Re: recursion is sillynone
|`* Re: recursion is sillyGeorge Neuner
| +* Re: recursion is sillyKaz Kylheku
| |`* Re: recursion is sillyGeorge Neuner
| | `* Re: recursion is sillyKaz Kylheku
| |  +* Re: recursion is sillyPaul Rubin
| |  |+* Re: recursion is sillyJulieta Shem
| |  ||`* Re: recursion is sillyPaul Rubin
| |  || `* Re: recursion is sillyJulieta Shem
| |  ||  `* Re: recursion is sillyPaul Rubin
| |  ||   `- These jumps are enjoyable (was: recursion is silly)Axel Reichert
| |  |+* Re: recursion is sillyAnton Ertl
| |  ||`* Re: recursion is sillynone
| |  || `- Re: recursion is sillyAnton Ertl
| |  |`- Re: recursion is sillynone
| |  +- Re: recursion is sillyGeorge Neuner
| |  `* Re: recursion is sillynone
| |   `* Re: recursion is sillyPaul Rubin
| |    `* Re: recursion is sillynone
| |     +* Re: recursion is sillymhx
| |     |+* Re: recursion is sillyKaz Kylheku
| |     ||+* Re: recursion is sillyKaz Kylheku
| |     |||`- Re: recursion is sillynone
| |     ||`* Re: recursion is sillynone
| |     || `* Re: recursion is sillyKaz Kylheku
| |     ||  `* Re: recursion is sillymhx
| |     ||   `* Re: recursion is sillyKaz Kylheku
| |     ||    +* Re: recursion is sillyLawrence D'Oliveiro
| |     ||    |`* Re: recursion is sillyKaz Kylheku
| |     ||    | `- Re: recursion is sillyKaz Kylheku
| |     ||    `* Re: recursion is sillymhx
| |     ||     `- Re: recursion is sillyAnton Ertl
| |     |`- Re: recursion is sillyPaul Rubin
| |     `* Re: recursion is sillyPaul Rubin
| |      `- Re: recursion is sillynone
| +- Re: recursion is sillynone
| `* Re: recursion is sillydxf
|  `- Re: recursion is sillyGeorge Neuner
+- Re: recursion is sillyJulieta Shem
+* Re: recursion is sillyPaul Rubin
|`* Re: recursion is sillyPaul Rubin
| `* Re: recursion is sillyPaul Rubin
|  +* Re: recursion is sillymhx
|  |+- Re: recursion is sillyPaul Rubin
|  |+* Re: recursion is sillyPaul Rubin
|  ||`* Re: recursion is sillynone
|  || +* Re: recursion is sillyPaul Rubin
|  || |+- Re: recursion is sillynone
|  || |`- Re: recursion is sillynone
|  || `* Re: recursion is sillymhx
|  ||  +- Re: recursion is sillynone
|  ||  `* Re: recursion is sillynone
|  ||   `* Re: recursion is sillyPaul Rubin
|  ||    `* Re: recursion is sillynone
|  ||     `* Re: recursion is sillyPaul Rubin
|  ||      `- Re: recursion is sillyLawrence D'Oliveiro
|  |`- Re: recursion is sillynone
|  `- Re: recursion is sillynone
+- Re: recursion is sillyminforth
`* Re: recursion is sillyLawrence D'Oliveiro
 `* Re: recursion is sillyJulieta Shem
  +* Re: recursion is sillyLawrence D'Oliveiro
  |`* Re: recursion is sillyJulieta Shem
  | `* Re: recursion is sillyLawrence D'Oliveiro
  |  `* Re: recursion is sillyJulieta Shem
  |   `* Re: recursion is sillyLawrence D'Oliveiro
  |    `* Re: recursion is sillyJulieta Shem
  |     `* Re: goto is sillyLawrence D'Oliveiro
  |      `- Re: goto is sillyKaz Kylheku
  `- Re: recursion is sillyPaul Rubin

Pages:1234
Re: recursion is silly

<87plynv41o.fsf@yaxenu.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17674&group=comp.lang.lisp#17674

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jshem@yaxenu.org (Julieta Shem)
Newsgroups: comp.lang.lisp
Subject: Re: recursion is silly
Date: Sat, 30 Dec 2023 17:17:07 -0300
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <87plynv41o.fsf@yaxenu.org>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<umlc7a$iq0h$6@dont-email.me> <875y0h7lae.fsf@yaxenu.org>
<umlhak$ne7o$2@dont-email.me> <87v88hx8yk.fsf@yaxenu.org>
<umnhjk$101mi$2@dont-email.me> <87tto0whs2.fsf@yaxenu.org>
<umob07$16i0g$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="e1a20affaf2c7e86c2f668799f16ba49";
logging-data="1474835"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BeFdMxawcH6BcitSe+hzZ77DTDucTy9Y="
Cancel-Lock: sha1:GpGmk88/EY/jjnvc5hGlf/fMqbQ=
sha1:C0r9dTQpbn7PGyeFv3Cr7B+QWZY=
 by: Julieta Shem - Sat, 30 Dec 2023 20:17 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:

> On Fri, 29 Dec 2023 23:22:53 -0300, Julieta Shem wrote:
>
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>>> Arbitrary gotos:
>>> -- useful/desirable? Not so.
>>
>> Very useful, very desirable.
>
> Come on ... you don’t mean you code that way, do you?

I do and, of course, I'm not the only one.

Knuth, Donald E. ``Structured programming with /go-to/ statements.''
ACM Computing Surveys (CSUR) 6.4 (1974): 261-301.

Re: goto is silly

<umpvba$1d4qp$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17675&group=comp.lang.lisp#17675

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Re: goto is silly
Date: Sat, 30 Dec 2023 20:42:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <umpvba$1d4qp$3@dont-email.me>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<umlc7a$iq0h$6@dont-email.me> <875y0h7lae.fsf@yaxenu.org>
<umlhak$ne7o$2@dont-email.me> <87v88hx8yk.fsf@yaxenu.org>
<umnhjk$101mi$2@dont-email.me> <87tto0whs2.fsf@yaxenu.org>
<umob07$16i0g$2@dont-email.me> <87plynv41o.fsf@yaxenu.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 30 Dec 2023 20:42:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c80ec37991426df62a20cfe9b4522d80";
logging-data="1479513"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VdHCiEJHF5kGAsOlUcp6q"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:JSexCHnMTTzra/3hvSJd6EZRgTo=
 by: Lawrence D'Oliv - Sat, 30 Dec 2023 20:42 UTC

On Sat, 30 Dec 2023 17:17:07 -0300, Julieta Shem wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> On Fri, 29 Dec 2023 23:22:53 -0300, Julieta Shem wrote:
>>
>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>
>>>> Arbitrary gotos:
>>>> -- useful/desirable? Not so.
>>>
>>> Very useful, very desirable.
>>
>> Come on ... you don’t mean you code that way, do you?
>
> I do and, of course, I'm not the only one.
>
> Knuth, Donald E. ``Structured programming with /go-to/ statements.''
> ACM Computing Surveys (CSUR) 6.4 (1974): 261-301.

Frankly, I don’t know how realistic his examples were: all I can say is,
dynamic memory allocation was a lot less common in his day.

Here’s my exposition on goto-free programming, and why it’s such a good
idea: <https://gitlab.com/ldo/a_structured_discipline_of_programming/>.

Re: goto is silly

<20231230214626.443@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17677&group=comp.lang.lisp#17677

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: goto is silly
Date: Sun, 31 Dec 2023 06:41:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <20231230214626.443@kylheku.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<umlc7a$iq0h$6@dont-email.me> <875y0h7lae.fsf@yaxenu.org>
<umlhak$ne7o$2@dont-email.me> <87v88hx8yk.fsf@yaxenu.org>
<umnhjk$101mi$2@dont-email.me> <87tto0whs2.fsf@yaxenu.org>
<umob07$16i0g$2@dont-email.me> <87plynv41o.fsf@yaxenu.org>
<umpvba$1d4qp$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 31 Dec 2023 06:41:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dc5f0f430fe1b4bd6cdf246437f21a94";
logging-data="1745130"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6ks5u8OZe7hhMw+8XDqICky+dtysyko8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:U3ewP/iAkIL9Q+rFB2z5fnz62gE=
 by: Kaz Kylheku - Sun, 31 Dec 2023 06:41 UTC

On 2023-12-30, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Sat, 30 Dec 2023 17:17:07 -0300, Julieta Shem wrote:
>
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>>> On Fri, 29 Dec 2023 23:22:53 -0300, Julieta Shem wrote:
>>>
>>>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>>>
>>>>> Arbitrary gotos:
>>>>> -- useful/desirable? Not so.
>>>>
>>>> Very useful, very desirable.
>>>
>>> Come on ... you don’t mean you code that way, do you?
>>
>> I do and, of course, I'm not the only one.
>>
>> Knuth, Donald E. ``Structured programming with /go-to/ statements.''
>> ACM Computing Surveys (CSUR) 6.4 (1974): 261-301.
>
> Frankly, I don’t know how realistic his examples were: all I can say is,
> dynamic memory allocation was a lot less common in his day.
>
> Here’s my exposition on goto-free programming, and why it’s such a good
> idea: <https://gitlab.com/ldo/a_structured_discipline_of_programming/>.

There is a fundamental difference between goto and using control
structures. Control structures nest, and so they avoid producing
program control flow graphs that have certain undesirable properties,
which is not guaranteed with goto.

For instance control structures will not produce a graph that is
analogous to what we get from this:

if (condition_a) {
// ...
label:
statement;
// ...
}

if (condition_b) {
// ...
goto label;
}

The feature here is that we have a backwards branch, but it's not
exactly an ordinary backwards branch. A backwards branch normally goes
back to a node which was necessarily visited on the way to the branch.

The branch above goes to a node which is not necessarily reached
on the way to the goto. In fact, statement may be executing for
the first time when the "goto label" branch is taken.

If you banish gotos, you can guarantee to your compiler back-end
that you don't have these kinds of branches in the program graph.
All the backwards branches to to program nodes that dominate
the branch points. (Meaning that the branch points are not reachable in
the forward direction without traversing those backwards target points.)

The Red Dragon Book discusses this (1988 edition).

I think these kinds of odd backward gotos will also tend to
make the logic harder to follow.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: recursion is silly

<nnd$4e0464a2$72397d2b@98ccb8d7c74a6c64>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17681&group=comp.lang.lisp#17681

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <20231228140434.720@kylheku.com> <87le9e7wq8.fsf@nightsong.com> <2023Dec30.084142@mips.complang.tuwien.ac.at>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$4e0464a2$72397d2b@98ccb8d7c74a6c64>
Organization: KPN B.V.
Date: Sun, 31 Dec 2023 11:56:35 +0100
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe005.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 24
Injection-Date: Sun, 31 Dec 2023 11:56:35 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1573
 by: none - Sun, 31 Dec 2023 10:56 UTC

In article <2023Dec30.084142@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>
>\ SORTM (best-performing)
>: sort2 ( al ah -- )
> begin
> over cell+ over u< while
> partition recurse
> repeat
> 2drop ;

I hate it if one uses U< in comparing numbers that hapenns
to be positive.
Are you really expecting the index straddles the boundary e.g
9223372036854775807 and 9223372036854775809

<SNIP>
>- anton
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<2023Dec31.170120@mips.complang.tuwien.ac.at>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17682&group=comp.lang.lisp#17682

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Followup: comp.lang.forth
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Followup-To: comp.lang.forth
Date: Sun, 31 Dec 2023 16:01:20 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 29
Message-ID: <2023Dec31.170120@mips.complang.tuwien.ac.at>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <20231228140434.720@kylheku.com> <87le9e7wq8.fsf@nightsong.com> <2023Dec30.084142@mips.complang.tuwien.ac.at> <nnd$4e0464a2$72397d2b@98ccb8d7c74a6c64>
Injection-Info: dont-email.me; posting-host="75f5bb5dda2a929d77fc4b84ba0fd077";
logging-data="1876813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195yVy+oE751Fhvw29sNUN7"
Cancel-Lock: sha1:6b7snkj478XQ9RKocUlKpxPPypE=
X-newsreader: xrn 10.11
 by: Anton Ertl - Sun, 31 Dec 2023 16:01 UTC

albert@cherry.(none) (albert) writes:
>In article <2023Dec30.084142@mips.complang.tuwien.ac.at>,
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>>
>>\ SORTM (best-performing)
>>: sort2 ( al ah -- )
>> begin
>> over cell+ over u< while
>> partition recurse
>> repeat
>> 2drop ;
>
>I hate it if one uses U< in comparing numbers that hapenns
>to be positive.

What makes you think that this code compares numbers with U<? It
actually compares two addresses, and I certainly don't want my sorting
programs to fail when the sorted array straddles the addresses
2147483647 and 2147483648 on a 32-bit system. Note that an "a" prefix
typically does not indicate a signed number.

Followups set to comp.lang.forth

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023

Re: recursion is silly

<nnd$6f8d4fb1$5509f70d@46490c8c7354685d>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17697&group=comp.lang.lisp#17697

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <20231227150908.647@kylheku.com> <1gjroi9kbq8vss6r8nond3s0nj6p0ob6t0@4ax.com> <20231228140434.720@kylheku.com>
Subject: Re: recursion is silly
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$6f8d4fb1$5509f70d@46490c8c7354685d>
Organization: KPN B.V.
Date: Mon, 01 Jan 2024 14:01:10 +0100
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!tr2.iad1.usenetexpress.com!feeder.usenetexpress.com!tr1.eu1.usenetexpress.com!2001:67c:174:101:2:67:202:4.MISMATCH!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 68
Injection-Date: Mon, 01 Jan 2024 14:01:10 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: none - Mon, 1 Jan 2024 13:01 UTC

In article <20231228140434.720@kylheku.com>,
Kaz Kylheku <433-929-6894@kylheku.com> wrote:
>On 2023-12-28, George Neuner <gneuner2@comcast.net> wrote:
>> On Wed, 27 Dec 2023 23:12:07 -0000 (UTC), Kaz Kylheku
>><433-929-6894@kylheku.com> wrote:
>>
>>>On 2023-12-27, George Neuner <gneuner2@comcast.net> wrote:
>>>> On Wed, 27 Dec 2023 15:57:48 +0000, zbigniew2011@gmail.com (LIT)
>>>> wrote:
>>>>
>>>>>> Recursion is silly (if you can avoid it).
>>>>>
>>>>>Not really.
>>>>>
>>>>>Recursion is elegant — but actually isn't any
>>>>>more efficient than iteration, and of course
>>>>>it requires stack space.
>>>>
>>>> Not necessarily. Scheme compilers actually are *required* to turn
>>>> self recursion into a loop (except in the case of a supported "debug"
>>>> mode).
>>>
>>>Careful there: not all self-recursion is tail recursion!
>>
>> Oops, you're right. I should have said Scheme is required to turn
>> *tail-recursion* into a loop.
>>
>> However, it is true that any recursion can be turned into a loop, and
>
>Can it, by an algorithm? That's a theoretical question that's above my pay grade.
>
>(Or, well, below; if I were a CS academic, I'd make less.)
>
>It doesn't seem obvious to me. Consider a graph traversal (like garbage
>collection marking). When you visit N pointers of a graph node, only the
>last visit can be a tail call. The first N-1 have to return to that
>node.
>
>There is a mildly famous (in some circles) pointer-reversal trick that
>has been used to implement a stackless traversal for garbage collection.
>But it's not a simple code transformation; it mutates the nodes in order
>to, effectively, create a return stack within the graph itself.
>
>That could not possibly be a valid automatic compiler optimization.

Note that in the example that started this threat (the count change
program) there was a double recursion, that cannot be handled
readily with a tail recursion optimisation.
On the other hand the alternative algorithm was easier to understand
even to lispers who are thoroughly familiar with recursion.
It runs fast without the need for external optimisation like a
memoization.

And may I stress it:
This is my home brew compiler. It is a couple of thousand lines in
assembler. The compiler is built by a single call to the fasm
assembler, that takes less that 10 mS. No external library.
Two nested loops, that is all. As small as the original algorithm.

>
>--
>TXRg ProgramminLanguage: http://nongnu.org/txr
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<nnd$73ad9123$7ab61b92@df5419c2445928f2>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17698&group=comp.lang.lisp#17698

  copy link   Newsgroups: comp.lang.lisp
Newsgroups: comp.lang.lisp
Subject: Re: recursion is silly
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <7443e54dc76553fbe54bdb46baa721bf@news.novabbs.com> <87a5pveeit.fsf@yaxenu.org>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$73ad9123$7ab61b92@df5419c2445928f2>
Organization: KPN B.V.
Date: Mon, 01 Jan 2024 15:40:13 +0100
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 36
Injection-Date: Mon, 01 Jan 2024 15:40:13 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1966
 by: none - Mon, 1 Jan 2024 14:40 UTC

In article <87a5pveeit.fsf@yaxenu.org>, Julieta Shem <jshem@yaxenu.org> wrote:
>zbigniew2011@gmail.com (LIT) writes:
>
>>> Recursion is silly (if you can avoid it).
>>
>> Not really.
>>
>> Recursion is elegant — but actually isn't any
>> more efficient than iteration, and of course
>> it requires stack space.
>>
>> And yes, most of the time (or always?) there
>> does exist iterative counterpart solution
>
>What do you mean iterative? For instance, Gerald Sussman and Harold
>Abelson classify as `iterative' the procedure
>
> (def (f n [acc 1])
> (if (= n 1)
> 1
> (f (dec n) (* acc n)))),
>
>which is self-referential.

That is pretty insane. It is however the prerogative of a math book,
that you are allowed to define whatever terms as soon as you include
the definitions. The reader should be aware that the term may
not be in universal use.

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<nnd$6a9a3264$3d0c8364@6e9f90d04f28c6ef>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17699&group=comp.lang.lisp#17699

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <8af29958c24b1596a65d3d7f927f6211@news.novabbs.com> <nnd$3aa91e3a$4f77b356@ea42f28632e84cdd> <87jzowirtb.fsf@nightsong.com>
Subject: Re: recursion is silly
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$6a9a3264$3d0c8364@6e9f90d04f28c6ef>
Organization: KPN B.V.
Date: Mon, 01 Jan 2024 15:45:59 +0100
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe005.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 33
Injection-Date: Mon, 01 Jan 2024 15:45:59 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2083
 by: none - Mon, 1 Jan 2024 14:45 UTC

In article <87jzowirtb.fsf@nightsong.com>,
Paul Rubin <no.email@nospam.invalid> wrote:
>albert@cherry.(none) (albert) writes:
>> Rubin's program also can be run with an older version of Guile (2.0.13).
>> My guess is that Rubin made a fresh start each time
>
>Yes, I re-ran the program for each value, to get the timing.
>
>> with the mysterious ?singleton call.
>
>singleton? just checks whether a list has exactly one element. It is
>used to detect the case where only one coin is available to make change
>with. In that case, there are either 0 ways or 1 way to make change,
>depending on whether the coin denomination divides the amount to be
>changed.

Next guess.
With
(set! cc (memoize cc))
you overwrite the `cc to henceforth to use the memoizer.

That means that the second calculation of the same results
is immediate and that larger results benefit from the
smaller results that are calculated before them.
True?

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<87v88amgc8.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17715&group=comp.lang.lisp#17715

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Wed, 03 Jan 2024 10:17:43 -0800
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <87v88amgc8.fsf@nightsong.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<8af29958c24b1596a65d3d7f927f6211@news.novabbs.com>
<nnd$3aa91e3a$4f77b356@ea42f28632e84cdd>
<87jzowirtb.fsf@nightsong.com>
<nnd$6a9a3264$3d0c8364@6e9f90d04f28c6ef>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="683b36643af16cd74f5304cb9e325f28";
logging-data="3465797"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BOA6xnWZZN/07g09cxqGB"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:zgh6K0AwZrGPOsyxmGY9ZxKzyXg=
sha1:Rvt34MS6Y0TC0ZpQWEegEF/uNpY=
 by: Paul Rubin - Wed, 3 Jan 2024 18:17 UTC

albert@cherry.(none) (albert) writes:
> you overwrite the `cc to henceforth to use the memoizer.
>
> That means that the second calculation of the same results
> is immediate and that larger results benefit from the
> smaller results that are calculated before them.
> True?

Yes, that is exactly right, sorry about the slow response. The Python
equivalent (untested) is:

def memoize(f):
def m(*args):
if args in memo: return memo[args]
memo[args] = f(*args)
return memo[args]
return m

@memoize
def cc(n, coins): ...

There is an aspect of the Scheme version that confuses me slightly but I
will ask some Scheme experts (I'm not one myself).

Re: recursion is silly

<un4bam$3a3ir$3@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17716&group=comp.lang.lisp#17716

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Re: recursion is silly
Date: Wed, 3 Jan 2024 19:08:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <un4bam$3a3ir$3@dont-email.me>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<8af29958c24b1596a65d3d7f927f6211@news.novabbs.com>
<nnd$3aa91e3a$4f77b356@ea42f28632e84cdd> <87jzowirtb.fsf@nightsong.com>
<nnd$6a9a3264$3d0c8364@6e9f90d04f28c6ef> <87v88amgc8.fsf@nightsong.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 3 Jan 2024 19:08:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d2829472fbd4038bd394ae124011a4c8";
logging-data="3477083"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lV1VhqzVYFsrWPhorjHMw"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:OYsCCJNSvgp7mD9wQ4YtkwI4m1g=
 by: Lawrence D'Oliv - Wed, 3 Jan 2024 19:08 UTC

On Wed, 03 Jan 2024 10:17:43 -0800, Paul Rubin wrote:

> The Python equivalent (untested) is:

Fixed missing definition of “memo” variable:

def memoize(f) :

memo = {}

def m(*args) :
if args not in memo :
memo[args] = f(*args)
#end if
return memo[args]
#end m

#begin memoize
return m
#end memoize

Of course this still doesn’t work with keyword args ...

Re: recursion is silly

<87ttnu54qa.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17724&group=comp.lang.lisp#17724

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Wed, 03 Jan 2024 16:20:29 -0800
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <87ttnu54qa.fsf@nightsong.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<20231227150908.647@kylheku.com>
<1gjroi9kbq8vss6r8nond3s0nj6p0ob6t0@4ax.com>
<20231228140434.720@kylheku.com>
<nnd$6f8d4fb1$5509f70d@46490c8c7354685d>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="91a630b595e6e5bef44e319b69d624fa";
logging-data="3559033"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MtTiA367H9jcvLgA5aEfu"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:PHgcFDl5m1wwGAVlslgB59dzO5E=
sha1:SJxmo0kc4tM5OamX3y/arEPpqlc=
 by: Paul Rubin - Thu, 4 Jan 2024 00:20 UTC

albert@cherry.(none) (albert) writes:
> On the other hand the alternative algorithm was easier to understand
> even to lispers who are thoroughly familiar with recursion.
> It runs fast without the need for external optimisation like a
> memoization.

I don't think I examined it, but is that the one that iteratively fills
the lookup table before doing the requested value?

I found in the memoizing Scheme version, after computing (cc 1000000),
the memo table held 670004 entries, which is much less than the 5
million that would be used by precomputing all the earlier entries.

When I removed the optimization (I originally hadn't thought of it as
one) of quickly checking divisibility when only one coin denomination
was available, the table size went up to 2470005 entries, still half
of what it would have been from precomputing everything.

Re: recursion is silly

<nnd$4b6f18cf$1a843abd@36af38f06eabba0f>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17730&group=comp.lang.lisp#17730

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <20231228140434.720@kylheku.com> <nnd$6f8d4fb1$5509f70d@46490c8c7354685d> <87ttnu54qa.fsf@nightsong.com>
Subject: Re: recursion is silly
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
Organization: KPN B.V.
Date: Thu, 04 Jan 2024 10:52:28 +0100
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe005.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 38
Injection-Date: Thu, 04 Jan 2024 10:52:28 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2681
 by: none - Thu, 4 Jan 2024 09:52 UTC

In article <87ttnu54qa.fsf@nightsong.com>,
Paul Rubin <no.email@nospam.invalid> wrote:
>albert@cherry.(none) (albert) writes:
>> On the other hand the alternative algorithm was easier to understand
>> even to lispers who are thoroughly familiar with recursion.
>> It runs fast without the need for external optimisation like a
>> memoization.
>
>I don't think I examined it, but is that the one that iteratively fills
>the lookup table before doing the requested value?
>
>I found in the memoizing Scheme version, after computing (cc 1000000),
>the memo table held 670004 entries, which is much less than the 5
>million that would be used by precomputing all the earlier entries.
>
>When I removed the optimization (I originally hadn't thought of it as
>one) of quickly checking divisibility when only one coin denomination
>was available, the table size went up to 2470005 entries, still half
>of what it would have been from precomputing everything.

Once you do memoization in Scheme, it is important that you mention
the order of nominations (increasing or decreasing).
The minimum should be N/50 + N/25 + N/10 + N/5 + N as far a I can see.
(In the order of increasion nominations)
I can't understand that there can be less that a million entries, unless ..
Can the memoization "see" that once cc(N-5,5) is known,
cc(N-4,5) = cc(N-5,5), up till (cc(N-1,5) (which are zero till now
in the iterative version),
and that cc(N,5) becomes cc(N,4)+cc(N-5,5) . That is chill.
(The iterative version also saves some 50% of the time going 50 -> 1)

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17732&group=comp.lang.lisp#17732

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!.POSTED!not-for-mail
From: mhx@iae.nl (mhx)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Thu, 4 Jan 2024 11:58:58 +0000
Organization: novaBBS
Message-ID: <62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <20231228140434.720@kylheku.com> <nnd$6f8d4fb1$5509f70d@46490c8c7354685d> <87ttnu54qa.fsf@nightsong.com> <nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="2237290"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$ejKDtyUh9ASDFxDh6z0cXuZDReJcE8mXYIEEgmQmVg7wr67CMJUdS
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Posting-User: 463cbf1a76c808942982a163321348c75477c065
 by: mhx - Thu, 4 Jan 2024 11:58 UTC

> Can the memoization "see" that once cc(N-5,5) is known,
> cc(N-4,5) = cc(N-5,5), up till (cc(N-1,5) (which are zero till now
[..]

I never used naive memoization much because the table size becomes
impractical for real-world problems. If it is known how to compress
N-dim tables (in hopefully a simple way), I'd be very interested
to know how it is done (even when N=1).

-marcel

Re: recursion is silly

<20240104101004.858@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17734&group=comp.lang.lisp#17734

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Thu, 4 Jan 2024 18:45:30 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 115
Message-ID: <20240104101004.858@kylheku.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<20231228140434.720@kylheku.com> <nnd$6f8d4fb1$5509f70d@46490c8c7354685d>
<87ttnu54qa.fsf@nightsong.com> <nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
Injection-Date: Thu, 4 Jan 2024 18:45:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e86d7ed55a4386262bd5785b65adb8f4";
logging-data="3952492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1850JJ9qrL4uOzZfDIYiBs92d1tUne+0vc="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:lesecW9UKBnTKJqjNmHeHNjjcuw=
 by: Kaz Kylheku - Thu, 4 Jan 2024 18:45 UTC

On 2024-01-04, mhx <mhx@iae.nl> wrote:
>> Can the memoization "see" that once cc(N-5,5) is known,
>> cc(N-4,5) = cc(N-5,5), up till (cc(N-1,5) (which are zero till now
> [..]
>
> I never used naive memoization much because the table size becomes
> impractical for real-world problems. If it is known how to compress
> N-dim tables (in hopefully a simple way), I'd be very interested
> to know how it is done (even when N=1).

In some cases, eviction may be possible (i.e. caching).

If we consider memoized Fibonacci, once it has calculated fib(7),
it's not going to have to calculate fib(5) again. That value could
be evacuated from the table. In fact, I suspect that a LRU table
with only several entries would serve.

This is easily confirmed code-wise, using TXR Lisp:

$ txr -i fib.tl
Read-eval-disagree-downvote-insult treadmill initialized! Enter an expression:
1> (compile 'fib-rec)
#<vm fun: 2 param>
2> (pprof (fib 200))
malloc bytes: 74356
gc heap bytes: 66272
total: 140628
milliseconds: 2
453973694165307953197296969697410619233826
3> (trace fib-rec)
nil
4> (fib 8)
(fib-rec (8 #(nil nil nil))
(fib-rec (6 #(nil nil nil))
(fib-rec (4 #(nil nil nil))
(fib-rec (2 #(nil nil nil))
(fib-rec (0 #(nil nil nil))
1)
(fib-rec (1 #(nil nil nil))
1)
2)
(fib-rec (3 #((2 . 2) nil nil))
(fib-rec (1 #((2 . 2) nil nil))
1)
(fib-rec (2 #((2 . 2) nil nil))
2)
3)
5)
(fib-rec (5 #((4 . 5) (3 . 3) (2 . 2)))
(fib-rec (3 #((4 . 5) (3 . 3) (2 . 2)))
3)
(fib-rec (4 #((4 . 5) (3 . 3) (2 . 2)))
5)
8)
13)
(fib-rec (7 #((6 . 13) (5 . 8) (4 . 5)))
(fib-rec (5 #((6 . 13) (5 . 8) (4 . 5)))
8)
(fib-rec (6 #((6 . 13) (5 . 8) (4 . 5)))
13)
21)
34)
34

Calculating (fib 200) is instantaneous. The trace shows
that the caching with a three element table is sufficient;
E.g. once (fib-rec 5) is calculated, the second time
it is encountered, it no longer recurses to (fib-rec 3)
and (fib-rec 4); it just returns 8.

This is the code in fib.tl:

(defun fib-rec (n table)
(or (if (meq n 0 1) 1)
(cdr [find n table : car])
(flow (+ (fib-rec (ppred n) table)
(fib-rec (pred n) table))
(let f)
(cons n)
(set [(nrot table -1) 0])
(ret f))))

(defun fib (n)
(fib-rec n (vector 3)))

The auxiliary table parameter always holds the same 3 element
vector object throughout the recursion. The vector holds
cons pairs of the form (cons n (fib n)), thus mapping Fibonacci
indices to values.

Whenever there is a table miss, the nrot function is used to
rotate the table entries down, and the new value is placed
in the first element, [table 0].

In fact, a two element table is sufficient; if we change
the (vector 3) to (vector 2), the performance is not affected.

Moreover, it deosn't matter whether the recursive step is
(+ (fib-rec (ppred n) table) (fib-rec (pred n) table)) or
(+ (fib-rec (pred n) table) (fib-rec (ppred n) table));
a two-element cache is sufficient. (TXR Lisp is strictly
evaluated, left-to-right, like Common Lisp, so if we
vary the order of the arguments to +, we can control the
order in which the recursive calls take place.)

In conclusion, while memoized Fibonacci is great textbook
example for illustrating the power of memoization,
it woudl behoove the textbooks to also add the observation
that it still works with a two-slot LRU cache.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: recursion is silly

<87plyh53mf.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17735&group=comp.lang.lisp#17735

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Thu, 04 Jan 2024 10:56:40 -0800
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <87plyh53mf.fsf@nightsong.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<20231228140434.720@kylheku.com>
<nnd$6f8d4fb1$5509f70d@46490c8c7354685d>
<87ttnu54qa.fsf@nightsong.com>
<nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="91a630b595e6e5bef44e319b69d624fa";
logging-data="3955253"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hgriCbbYteiKfusXLLxBY"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:wbRXCFC63Fzt4mD5dkk7h36pMUc=
sha1:Z5/bGz0RZYxuVd5zcsGisFpX9Ws=
 by: Paul Rubin - Thu, 4 Jan 2024 18:56 UTC

mhx@iae.nl (mhx) writes:
> If it is known how to compress N-dim tables (in hopefully a simple
> way), I'd be very interested to know how it is done (even when N=1).

In the Scheme code I posted, the "coordinate list" is used as a hash key.

Re: recursion is silly

<20240104114837.742@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17736&group=comp.lang.lisp#17736

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Thu, 4 Jan 2024 19:49:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <20240104114837.742@kylheku.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<20231228140434.720@kylheku.com> <nnd$6f8d4fb1$5509f70d@46490c8c7354685d>
<87ttnu54qa.fsf@nightsong.com> <nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
<20240104101004.858@kylheku.com>
Injection-Date: Thu, 4 Jan 2024 19:49:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e86d7ed55a4386262bd5785b65adb8f4";
logging-data="3970097"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bxwYDywQUk4KHhqC3FFO1FSl2xMT1Xds="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Guqm3nrj80IouKpDMHtclvQES6U=
 by: Kaz Kylheku - Thu, 4 Jan 2024 19:49 UTC

On 2024-01-04, Kaz Kylheku <433-929-6894@kylheku.com> wrote:
> In conclusion, while memoized Fibonacci is great textbook
> example for illustrating the power of memoization,
> it woudl behoove the textbooks to also add the observation
> that it still works with a two-slot LRU cache.

However, due to the function activation frames, memory
use is still O(n).

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: recursion is silly

<87le946bga.fsf@nightsong.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17737&group=comp.lang.lisp#17737

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: no.email@nospam.invalid (Paul Rubin)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Thu, 04 Jan 2024 13:22:13 -0800
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <87le946bga.fsf@nightsong.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<20231228140434.720@kylheku.com>
<nnd$6f8d4fb1$5509f70d@46490c8c7354685d>
<87ttnu54qa.fsf@nightsong.com>
<nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="91a630b595e6e5bef44e319b69d624fa";
logging-data="3994129"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/LYhG9h2bSEdNux9NgA86G"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:4QWlkpHnfNjABBtp0awVBNsvvfw=
sha1:qcHZY9gjEMpPGzICl2i3jPA7Pog=
 by: Paul Rubin - Thu, 4 Jan 2024 21:22 UTC

albert@cherry.(none) (albert) writes:
> Can the memoization "see" that once cc(N-5,5) is known,
> cc(N-4,5) = cc(N-5,5), up till (cc(N-1,5) (which are zero till now
> in the iterative version),

I'm not sure what you mean by that. The memoization scheme proceeds
recursively until it reaches a place where it knows how to get a
numerical answer. Then it computes and remembers that answer, so it can
use it the next time the calculation gets there.

> and that cc(N,5) becomes cc(N,4)+cc(N-5,5) . That is chill.

Yes that is right.

> (The iterative version also saves some 50% of the time going 50 -> 1)

I don't think I understand your iterative algorithm, but I think there
is one that actually doesn't have to remember the calculation results
all the way back to the beginning. It only has to remember the last 100
(or whatever the size of the largest coin is), and similarly for the
other coin sizes. I'll see if I can code that.

Re: recursion is silly

<nnd$7d0e6362$6714e6de@046c865c6f32b5ed>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17744&group=comp.lang.lisp#17744

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <87ttnu54qa.fsf@nightsong.com> <nnd$4b6f18cf$1a843abd@36af38f06eabba0f> <87le946bga.fsf@nightsong.com>
Subject: Re: recursion is silly
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$7d0e6362$6714e6de@046c865c6f32b5ed>
Organization: KPN B.V.
Date: Fri, 05 Jan 2024 13:27:43 +0100
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 34
Injection-Date: Fri, 05 Jan 2024 13:27:43 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 2267
 by: none - Fri, 5 Jan 2024 12:27 UTC

In article <87le946bga.fsf@nightsong.com>,
Paul Rubin <no.email@nospam.invalid> wrote:
>albert@cherry.(none) (albert) writes:
>> Can the memoization "see" that once cc(N-5,5) is known,
>> cc(N-4,5) = cc(N-5,5), up till (cc(N-1,5) (which are zero till now
>> in the iterative version),
>
>I'm not sure what you mean by that. The memoization scheme proceeds
>recursively until it reaches a place where it knows how to get a
>numerical answer. Then it computes and remembers that answer, so it can
>use it the next time the calculation gets there.
>
>> and that cc(N,5) becomes cc(N,4)+cc(N-5,5) . That is chill.
>
>Yes that is right.
>
>> (The iterative version also saves some 50% of the time going 50 -> 1)
>
>I don't think I understand your iterative algorithm, but I think there
>is one that actually doesn't have to remember the calculation results
>all the way back to the beginning. It only has to remember the last 100
>(or whatever the size of the largest coin is), and similarly for the
>other coin sizes. I'll see if I can code that.

I thought of that too, and it doesn't work. Something inherent of
two way recursion.

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<nnd$7561b49c$43c6a88e@a8960ed47cc85118>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17745&group=comp.lang.lisp#17745

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <nnd$4b6f18cf$1a843abd@36af38f06eabba0f> <62ce04af2582b47ac60b4a504694156f@news.novabbs.com> <20240104101004.858@kylheku.com>
Subject: Re: recursion is silly
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$7561b49c$43c6a88e@a8960ed47cc85118>
Organization: KPN B.V.
Date: Fri, 05 Jan 2024 13:37:25 +0100
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!peer03.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe005.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 133
Injection-Date: Fri, 05 Jan 2024 13:37:25 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 5219
 by: none - Fri, 5 Jan 2024 12:37 UTC

In article <20240104101004.858@kylheku.com>,
Kaz Kylheku <433-929-6894@kylheku.com> wrote:
>On 2024-01-04, mhx <mhx@iae.nl> wrote:
>>> Can the memoization "see" that once cc(N-5,5) is known,
>>> cc(N-4,5) = cc(N-5,5), up till (cc(N-1,5) (which are zero till now
>> [..]
>>
>> I never used naive memoization much because the table size becomes
>> impractical for real-world problems. If it is known how to compress
>> N-dim tables (in hopefully a simple way), I'd be very interested
>> to know how it is done (even when N=1).
>
>In some cases, eviction may be possible (i.e. caching).
>
>If we consider memoized Fibonacci, once it has calculated fib(7),
>it's not going to have to calculate fib(5) again. That value could
>be evacuated from the table. In fact, I suspect that a LRU table
>with only several entries would serve.
>
>This is easily confirmed code-wise, using TXR Lisp:
>
>$ txr -i fib.tl
>Read-eval-disagree-downvote-insult treadmill initialized! Enter an expression:
>1> (compile 'fib-rec)
>#<vm fun: 2 param>
>2> (pprof (fib 200))
>malloc bytes: 74356
>gc heap bytes: 66272
>total: 140628
>milliseconds: 2
>453973694165307953197296969697410619233826
>3> (trace fib-rec)
>nil
>4> (fib 8)
>(fib-rec (8 #(nil nil nil))
> (fib-rec (6 #(nil nil nil))
> (fib-rec (4 #(nil nil nil))
> (fib-rec (2 #(nil nil nil))
> (fib-rec (0 #(nil nil nil))
> 1)
> (fib-rec (1 #(nil nil nil))
> 1)
> 2)
> (fib-rec (3 #((2 . 2) nil nil))
> (fib-rec (1 #((2 . 2) nil nil))
> 1)
> (fib-rec (2 #((2 . 2) nil nil))
> 2)
> 3)
> 5)
> (fib-rec (5 #((4 . 5) (3 . 3) (2 . 2)))
> (fib-rec (3 #((4 . 5) (3 . 3) (2 . 2)))
> 3)
> (fib-rec (4 #((4 . 5) (3 . 3) (2 . 2)))
> 5)
> 8)
> 13)
> (fib-rec (7 #((6 . 13) (5 . 8) (4 . 5)))
> (fib-rec (5 #((6 . 13) (5 . 8) (4 . 5)))
> 8)
> (fib-rec (6 #((6 . 13) (5 . 8) (4 . 5)))
> 13)
> 21)
> 34)
>34
>
>Calculating (fib 200) is instantaneous. The trace shows
>that the caching with a three element table is sufficient;
>E.g. once (fib-rec 5) is calculated, the second time
>it is encountered, it no longer recurses to (fib-rec 3)
>and (fib-rec 4); it just returns 8.
>
>This is the code in fib.tl:
>
>(defun fib-rec (n table)
> (or (if (meq n 0 1) 1)
> (cdr [find n table : car])
> (flow (+ (fib-rec (ppred n) table)
> (fib-rec (pred n) table))
> (let f)
> (cons n)
> (set [(nrot table -1) 0])
> (ret f))))
>
>(defun fib (n)
> (fib-rec n (vector 3)))
>
>The auxiliary table parameter always holds the same 3 element
>vector object throughout the recursion. The vector holds
>cons pairs of the form (cons n (fib n)), thus mapping Fibonacci
>indices to values.
>
>Whenever there is a table miss, the nrot function is used to
>rotate the table entries down, and the new value is placed
>in the first element, [table 0].
>
>In fact, a two element table is sufficient; if we change
>the (vector 3) to (vector 2), the performance is not affected.
>
>Moreover, it deosn't matter whether the recursive step is
>(+ (fib-rec (ppred n) table) (fib-rec (pred n) table)) or
>(+ (fib-rec (pred n) table) (fib-rec (ppred n) table));
>a two-element cache is sufficient. (TXR Lisp is strictly
>evaluated, left-to-right, like Common Lisp, so if we
>vary the order of the arguments to +, we can control the
>order in which the recursive calls take place.)
>
>In conclusion, while memoized Fibonacci is great textbook
>example for illustrating the power of memoization,
>it woudl behoove the textbooks to also add the observation
>that it still works with a two-slot LRU cache.
+1

You have managed to arrive at this iterative version, that keeps
track of only two values.
: FIB
>R 0 1
R> 0 ?DO SWAP OVER + 1 +LOOP
DROP
;

(Interested to see this coded in lisp. )

>
>Mastodon: @Kazinator@mstdn.ca

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<nnd$76aec35d$18a0a930@a8960ed47cc85118>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17746&group=comp.lang.lisp#17746

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <62ce04af2582b47ac60b4a504694156f@news.novabbs.com> <20240104101004.858@kylheku.com> <20240104114837.742@kylheku.com>
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: albert@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$76aec35d$18a0a930@a8960ed47cc85118>
Organization: KPN B.V.
Date: Fri, 05 Jan 2024 13:42:58 +0100
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe006.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 28
Injection-Date: Fri, 05 Jan 2024 13:42:58 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 1937
 by: none - Fri, 5 Jan 2024 12:42 UTC

In article <20240104114837.742@kylheku.com>,
Kaz Kylheku <433-929-6894@kylheku.com> wrote:
>On 2024-01-04, Kaz Kylheku <433-929-6894@kylheku.com> wrote:
>> In conclusion, while memoized Fibonacci is great textbook
>> example for illustrating the power of memoization,
>> it woudl behoove the textbooks to also add the observation
>> that it still works with a two-slot LRU cache.
>
>However, due to the function activation frames, memory
>use is still O(n).

In the coins example I did not use memoization per se, but
rather a reverse memoization. Please check that the memory
usage with the Forth example for FIB, is O(1), also with
reverse memoization.
[I had success with this technique in several of the 400 problems
of projecteuler.net that I solved.]
>
>--
>Mastodon: @Kazinator@mstdn.ca

Groetjes Albert
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

Re: recursion is silly

<20240105104414.216@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17754&group=comp.lang.lisp#17754

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Fri, 5 Jan 2024 18:53:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <20240105104414.216@kylheku.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
<20240104101004.858@kylheku.com> <nnd$7561b49c$43c6a88e@a8960ed47cc85118>
Injection-Date: Fri, 5 Jan 2024 18:53:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="624dae6c469856f06c49a782a2b1407e";
logging-data="275916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZvuVAtxaPbibRQKumUKVd6FINacKz0QI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:2O+PX4Vri9J2/HkDQc5cu8UkL+0=
 by: Kaz Kylheku - Fri, 5 Jan 2024 18:53 UTC

On 2024-01-05, albert@cherry.(none) (albert) <albert@cherry> wrote:
> You have managed to arrive at this iterative version, that keeps
> track of only two values.

Well, yes; that is understood and where the intution comes from for why
Memoization implicitly reduces the exponential explosion in Fibonacci.
It must be effectively iterating on the recurrence in the
straightforward way, since it takes linear time.

The recurrence relation implies a two-element state; I guessed at
a cache size of three items as a fudge factor; when that
was debugged, I reduced to two.

Sometimes, the Fibonacci recurrence is expressed as a matrix
multiplication on a state vector [a b]

[1 1][a] => [a + b]
[1 0][b] [ a ]

a receives the sum of a + b, while b receives the prior value of a.

Raising this matrix to an arbitrary integer power is how we arrive
at the closed form solution.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: recursion is silly

<44ad19ee75efa3982019aea1a6fc0b8f@news.novabbs.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17755&group=comp.lang.lisp#17755

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!.POSTED!not-for-mail
From: mhx@iae.nl (mhx)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Fri, 5 Jan 2024 19:44:27 +0000
Organization: novaBBS
Message-ID: <44ad19ee75efa3982019aea1a6fc0b8f@news.novabbs.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c> <nnd$4b6f18cf$1a843abd@36af38f06eabba0f> <62ce04af2582b47ac60b4a504694156f@news.novabbs.com> <20240104101004.858@kylheku.com> <nnd$7561b49c$43c6a88e@a8960ed47cc85118> <20240105104414.216@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="2400834"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$ufb2CsWwcEaZhjok2hOXvuw5kZEuLtoLQHf3i0nyHWW5yQAixhSX2
X-Rslight-Posting-User: 463cbf1a76c808942982a163321348c75477c065
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: mhx - Fri, 5 Jan 2024 19:44 UTC

Kaz Kylheku wrote:

> Sometimes, the Fibonacci recurrence is expressed as a matrix
> multiplication on a state vector [a b]

> [1 1][a] => [a + b]
> [1 0][b] [ a ]

> a receives the sum of a + b, while b receives the prior value of a.

> Raising this matrix to an arbitrary integer power is how we arrive
> at the closed form solution.

Really nice! I'll keep this general idea in a safe place.

-marcel

Re: recursion is silly

<20240105131349.9@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17756&group=comp.lang.lisp#17756

  copy link   Newsgroups: comp.lang.forth comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.forth,comp.lang.lisp
Subject: Re: recursion is silly
Date: Fri, 5 Jan 2024 21:24:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <20240105131349.9@kylheku.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
<20240104101004.858@kylheku.com> <nnd$7561b49c$43c6a88e@a8960ed47cc85118>
<20240105104414.216@kylheku.com>
<44ad19ee75efa3982019aea1a6fc0b8f@news.novabbs.com>
Injection-Date: Fri, 5 Jan 2024 21:24:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="624dae6c469856f06c49a782a2b1407e";
logging-data="321273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+mqe0t9dHDUp/8yTYKozs9LEmz5XgfG3w="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:H1fFuVhzyXPBR9nDs4ncba81np0=
 by: Kaz Kylheku - Fri, 5 Jan 2024 21:24 UTC

On 2024-01-05, mhx <mhx@iae.nl> wrote:
> Kaz Kylheku wrote:
>
>> Sometimes, the Fibonacci recurrence is expressed as a matrix
>> multiplication on a state vector [a b]
>
>> [1 1][a] => [a + b]
>> [1 0][b] [ a ]
>
>> a receives the sum of a + b, while b receives the prior value of a.
>
>> Raising this matrix to an arbitrary integer power is how we arrive
>> at the closed form solution.
>
> Really nice! I'll keep this general idea in a safe place.

You don't have to; it's found in textbooks.

Using linear algebra techniques found in introductory texts, you can do
this this:

n
[1 1]
[1 0]

The details escape me, much like a departing youthful appearance, but
basically we can factor it into a form

n
U X V

where U, X, V are all 2x2 matrices. The middle one X is special
in that it is diagonal (consisting of a diagonal trace of eigenvalues).
A diagonal matrix is easy to exponentiate.

Something like that.

That gives us that closed form formula for Fibonacci with those
square roots of five in it.

Closely relating to the Golden Ratio! Which is (/ (+ 1 (sqrt 5)) 2).
The ratio of successive values of the Fibonacci numbers approaches
the golden ratio.

1> (/ (fib 50) (fib 49))
1.61803398874989

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: recursion is silly

<un9tr9$9uq6$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17758&group=comp.lang.lisp#17758

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Re: recursion is silly
Date: Fri, 5 Jan 2024 21:54:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <un9tr9$9uq6$2@dont-email.me>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
<20240104101004.858@kylheku.com> <nnd$7561b49c$43c6a88e@a8960ed47cc85118>
<20240105104414.216@kylheku.com>
<44ad19ee75efa3982019aea1a6fc0b8f@news.novabbs.com>
<20240105131349.9@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 5 Jan 2024 21:54:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e86eefbb5c47a726a6c35183164fc57f";
logging-data="326470"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pKBOc02Ga7wd7OjX6fkUA"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:9owsYgYhzgpSsIopXlNRivLu5zc=
 by: Lawrence D'Oliv - Fri, 5 Jan 2024 21:54 UTC

On Fri, 5 Jan 2024 21:24:00 -0000 (UTC), Kaz Kylheku wrote:

> The ratio of successive values of the Fibonacci numbers approaches the
> golden ratio.

The golden ratio is also obtained by just about the simplest of all
continued fractions:

1
1 + -------------
1
1 + ---------
1
1 + -----
...

Re: recursion is silly

<20240105140957.434@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17760&group=comp.lang.lisp#17760

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-6894@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: recursion is silly
Date: Fri, 5 Jan 2024 22:36:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <20240105140957.434@kylheku.com>
References: <nnd$6660ae2b$78615640@f2c7e8d01681877c>
<nnd$4b6f18cf$1a843abd@36af38f06eabba0f>
<62ce04af2582b47ac60b4a504694156f@news.novabbs.com>
<20240104101004.858@kylheku.com> <nnd$7561b49c$43c6a88e@a8960ed47cc85118>
<20240105104414.216@kylheku.com>
<44ad19ee75efa3982019aea1a6fc0b8f@news.novabbs.com>
<20240105131349.9@kylheku.com> <un9tr9$9uq6$2@dont-email.me>
Injection-Date: Fri, 5 Jan 2024 22:36:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="624dae6c469856f06c49a782a2b1407e";
logging-data="338841"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+d0bGywn/xelSq16Y2byOdRSmJA97QRT8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:eOT/R6nDQks0GjZDhX0jBZqhnes=
 by: Kaz Kylheku - Fri, 5 Jan 2024 22:36 UTC

On 2024-01-05, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Fri, 5 Jan 2024 21:24:00 -0000 (UTC), Kaz Kylheku wrote:
>
>> The ratio of successive values of the Fibonacci numbers approaches the
>> golden ratio.
>
> The golden ratio is also obtained by just about the simplest of all
> continued fractions:
>
> 1
> 1 + -------------
> 1
> 1 + ---------
> 1
> 1 + -----
> ...

That's recursive, like a Droste image, and so we can rewrite it
self-referentially:

R = 1 + 1/R

R^2 = R + 1

R^2 - R - 1 = 0

Then solve for R using the quadratic formula:

1 +/- sqrt(5)
R = -------------
2

One of the solutions is negative, which we can reject. A continued
fraction with only positive constants and addition cannot have
a limit that is negatively valued.

---

Puzzle:

Could we use this information somehow to neatly build an amplifier whose
closed-loop gain is the Golden Ratio, using only resistors that have
integer-valued resistances in Ohms?

I might post this to the Electronics Stack Exchange.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.


devel / comp.lang.lisp / Re: recursion is silly

Pages:1234
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor