HP 50g Double factorial
|
01-27-2024, 05:51 PM
Post: #21
|
|||
|
|||
RE: HP 50g Double factorial
Hello David,
Thank you very much for your insight. ListExt is installed on my 50G(s), but I'm not very familiar with it. Following your advice, I did a new and very short program (for n ≥ 0), which weights now 46 bytes instead of 135! << { 2 − } { 1 > } LWHL 1 + @ To insert the missing 1 in the list. LPROD >> … "et voilà" as (some) English speakers say (sometimes). 0 returns 1 1 returns 1 2 returns 2 3 returns 3 4 returns 8 5 returns 15 … 14 yields 645 120 15 yields 2 027 025 etc. ListExt, what a great tool! Best regards Bruno Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G |
|||
01-27-2024, 09:33 PM
Post: #22
|
|||
|
|||
RE: HP 50g Double factorial
(01-27-2024 05:51 PM)FLISZT Wrote: << In this case, you don't actually need the "1 +" after the LWHL command, since multiplying by 1 has no impact on the final result. It doesn't hurt anything for it to be there, of course. But it's not needed. Note that this method isn't particularly good with large n, since it requires enough free memory for the entire list of multiplicands to be created en masse, and also the program essentially has to iterate the large list twice behind the scenes (once when building, then a second time for computing the product). John Keith's example covers most everything you could want here, and is much more efficient. I just wanted to point out the use of LWHL and LPROD in this context, which shortens the code significantly. As is frequently the case, though, large lists take lots of memory and can be slow to process. |
|||
01-28-2024, 01:47 AM
Post: #23
|
|||
|
|||
RE: HP 50g Double factorial
(01-27-2024 09:33 PM)DavidM Wrote: In this case, you don't actually need the "1 +" after the LWHL command, since multiplying by 1 has no impact on the final result. It doesn't hurt anything for it to be there, of course. But it's not needed. It's so obvious! I just noticed the LHWD instruction then immediately dove into the ListExt documentation, not noticing that you'd already given the full solution (41 bytes). « Où avais-je la tête ? » … literally: "Where did I have the head? " (01-27-2024 09:33 PM)DavidM Wrote: Note that this method isn't particularly good with large n, since it requires enough free memory for the entire list of multiplicands to be created en masse, and also the program essentially has to iterate the large list twice behind the scenes (once when building, then a second time for computing the product). Yes, indeed. But for me, it was just an exercise, I don't need to calculate double factorials. Anyway, I'll take a look at John Keith's example. Many thanks! Bruno Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G |
|||
01-28-2024, 02:51 PM
Post: #24
|
|||
|
|||
RE: HP 50g Double factorial
(01-28-2024 01:47 AM)FLISZT Wrote: ...But for me, it was just an exercise, I don't need to calculate double factorials. That goes doubly for me (pun partially intended). I believe the last time I wrote some calculator-based code for something that I actually needed was somewhere around 2010. Everything else has been for amusement or personal edification. |
|||
01-28-2024, 07:07 PM
Post: #25
|
|||
|
|||
RE: HP 50g Double factorial
(01-28-2024 02:51 PM)DavidM Wrote:(01-28-2024 01:47 AM)FLISZT Wrote: ...But for me, it was just an exercise, I don't need to calculate double factorials. Got it! Same here: apart from my TI-57 and 15C, I've bought my other calculators for neither school nor professional purposes. As for my first calculator (Sanyo CZ-0124), it was a gift from my paternal grandfather, a few days before Christmas (my grandmother had just died in mid-December) and I was in junior high school and still very young! It was not a (RPN) CZ-2901 (was it ever sold in France?), however, my calculator had/has in a wondeful key: X⇆Y Bruno Sanyo CZ-0124 ⋅ TI-57 ⋅ HP-15C ⋅ Canon X-07 + XP-140 Monitor Card ⋅ HP-41CX ⋅ HP-28S ⋅ HP-50G ⋅ HP-50G |
|||
01-28-2024, 08:48 PM
(This post was last modified: 01-28-2024 10:22 PM by John Keith.)
Post: #26
|
|||
|
|||
RE: HP 50g Double factorial
(01-27-2024 09:33 PM)DavidM Wrote: … Another nice use for ListExt is to produce lists of double factorials. The following program will return a list of the first n odd double factorials (A001147) given n on the stack. Changing the first 1 into a 2 will return the even double factorials (A000165) instead. The second 1 can be removed if the 0th term is not required. Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)