Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calculate the sum of all values in the stack

210 views
Skip to first unread message

franfar

unread,
Jun 25, 2008, 4:03:22 AM6/25/08
to
Hi to all,

I'd like to know if there's some trick to calculate the sum of all the
existing values of the stack so I can avoid the use of the plus key
all the time (sometimes I need to calculate the sum of twenty or more
values - integers most of the time - ). Do I need to write a program
to do that? If that were de case, would you mind to write it down for
me?

Really, thank you very much,

Francesc

Raymond Del Tondo

unread,
Jun 25, 2008, 4:08:36 AM6/25/08
to
Hi,

DEPTH ->LIST
DUP LIST->
1 SWAP
START
+
NEXT


HTH

Raymond


"franfar" <fra...@gmail.com> schrieb im Newsbeitrag
news:86ce8c0e-9ada-4c0d...@k30g2000hse.googlegroups.com...

franfar

unread,
Jun 25, 2008, 4:16:38 AM6/25/08
to
Thank you very much Raimond

Best regards,

Francesc

reth

unread,
Jun 25, 2008, 5:38:30 AM6/25/08
to
On Jun 25, 6:08 pm, "Raymond Del Tondo" <Ih8...@nowhere.com> wrote:
> Hi,
>
> DEPTH ->LIST
> DUP LIST->
> 1 SWAP
> START
> +
> NEXT
>
> HTH
>
> Raymond
>
> "franfar" <fran...@gmail.com> schrieb im Newsbeitragnews:86ce8c0e-9ada-4c0d...@k30g2000hse.googlegroups.com...

>
> > Hi to all,
>
> > I'd like to know if there's some trick to calculate the sum of all the
> > existing values of the stack so I can avoid the use of the plus key
> > all the time (sometimes I need to calculate the sum of twenty or more
> > values - integers most of the time - ). Do I need to write a program
> > to do that? If that were de case, would you mind to write it down for
> > me?
>
> > Really, thank you very much,
>
> > Francesc

Raymond, you are joking aren't you, what about <<DEPTH ->LIST
sigmaLIST ???
cheers,
reth

Dueño de Monte

unread,
Jun 25, 2008, 8:40:57 AM6/25/08
to

> Raymond, you are joking aren't you, what about <<DEPTH ->LIST
> sigmaLIST ???
> cheers,
> reth

I like that !

Can you have some other statistics in the same way ? (Average,
variance, sum of squares, etc )

Can stack be a sigmaDATA set to do it ?.

Thanks.

Daniel

Raymond Del Tondo

unread,
Jun 25, 2008, 7:20:06 PM6/25/08
to
"reth" <re...@abv.bg> schrieb im Newsbeitrag
news:674e2e8b-280d-4212...@s21g2000prm.googlegroups.com...

> On Jun 25, 6:08 pm, "Raymond Del Tondo" <Ih8...@nowhere.com> wrote:
> [..]

> Raymond, you are joking aren't you, what about <<DEPTH ->LIST
> sigmaLIST ???
> cheers,
> reth
>
Hi reth,

yes, that's more elegant, of course.

Actually I never used sigmaLIST, so I didn't have that in mind;-)

However to get the same result as my discrete code,
with the stack contents retained,
it would look like this UserRPL snippet:
DEPTH ->LIST DUP LIST-> 1 + ROLL sigmaLIST

Not very memory-efficient, as most of the list manipulation functions.

In SysRPL, this could have been solved by the following snippet:
DEPTH {}N DUP >R INNERCOMP DROP R> 'EvalNoCK: sigmaLIST


Cheers

Raymond


Virgil

unread,
Jun 26, 2008, 4:00:03 AM6/26/08
to
In article <g3suel$7ps$02$1...@news.t-online.com>,

"Raymond Del Tondo" <Ih8...@nowhere.com> wrote:

> Hi,
>
> DEPTH ->LIST
> DUP LIST->
> 1 SWAP
> START
> +
> NEXT

Better is

\<< DEPTH \->LIST 0 + \GSLIST \>>

where \<<, and \>> are the program delimiters,
\-> is the right arrow symbol and
\GS is the upper case Greek 's', or sigma, symbol.

The only purpose of the " 0 + " is to allow you to use the program on an
empty stack without getting an error message. And that sum will , of
course, be 0.

Beauzeau

unread,
Jun 26, 2008, 1:23:11 PM6/26/08
to
On Jun 25, 7:20 pm, "Raymond Del Tondo" <Ih8...@nowhere.com> wrote:

Question: What is the difference between UserRPL and SysRPL ???

I did a search on the manual, and per the manual UserRPL is the
program language enclosed by << >> ; I did a search on SysRPL (Find
function) and nothing came up ??? There must be some difference.. ?

Thanks.

Andreas Möller

unread,
Jun 26, 2008, 1:57:13 PM6/26/08
to
Hello,

> Question: What is the difference between
> UserRPL and SysRPL ???

UserRPL is a subset of SysRPL.

The difference is that each UserRPL contains check-code for argument
validation which leads to a significant speed penalty as *each*
UserRPL checks for valid arguments.
The advantage is that is almost impossible to crash the calculator
while using UserRPL.

SysRPL usually does not contain any error checking so the programmer
is responsible that his program will not fail. If it fails the result
will be a warmstart (in the less severe errors) or a complete memory
wipe out.

Below SysRPL is Saturn assembly which is the fastest (in the Saturn
world, in the ARM based machines ARM assembly is way faster than
Saturn assembly as the Saturn processors is emulated in this machines)
but here you have to do *everything* by youself since your are working
outside of the operating system.

Do a search on SysRPL in this newsgroup and more answers will show up
then you can read.

HTH,
Andreas
http://www.software49g.gmxhome.de

John H Meyers

unread,
Jun 28, 2008, 5:30:43 PM6/28/08
to
On Wed, 25 Jun 2008 04:38:30 -0500, reth wrote:

> what about \<< DEPTH \->LIST \GSLIST \>> ???

Try it with a stack depth of either zero or one ;-)

Whatever program you use, an additional thought
is to return the NEGative of the actual sum,
with an identifying "tag" (e.g. NEG "-Sum" \->TAG)

You can then keep any number of independent sums on the stack,
simulating one of those long forgotten "paperless printer" calcs,
because each independent "section,"
consisting of some values followed by the negative sum,
totals zero, and thus does not affect subsequent sections.

This can go slightly awry if the sets of values
have many significant digits, and also
widely differ in exponent range (powers of 10),
where a "small" roundoff error in an earlier "section" can then
start off a new "section" with a relatively large "imbalance,"
but it will generally work fine for everyday accounting.

If you want to be able to insert non-numeric items
(e.g. heading strings like "Gas" "Food" etc. for your expense report)
then also have your program bypass non-numerics while summing.

E.g. here's a complete program for all HP48/49/50,
accepting any stack,
permitting multiple independent sums on the same stack:

\<< 0 DEPTH 1. SWAP FOR i i PICK DTAG
{ 0. 28. } OVER TYPE POS { + } { DROP } IFTE
NEXT NEG "-Sum" \->TAG \>> '\GSSTK' STO

This handles empty and 1-item stacks, too.

---

"Texas Instruments Paperless Printer" (1987-1996+)
http://www.datamath.org/Desktop/PaperlessPrinter.htm
http://www.datamath.org/Desktop/ti-5038.htm
http://www.datamath.org/Desktop/ti-5028.htm

[r->] [OFF]

reth

unread,
Jun 28, 2008, 6:35:55 PM6/28/08
to

the original post defines pretty clearly what's needed:
"...trick to calculate the sum of all the existing values of the stack
so I can avoid the use of the plus key all the time..."
and the short answer is what I sugested; all the rest is an
overkill ;)
So, how many times does one have to hit the plus key to get the sum of
zero or one values? :)
cheers,
reth

John H Meyers

unread,
Jun 30, 2008, 4:11:21 PM6/30/08
to
On Sat, 28 Jun 2008 17:35:55 -0500, reth wrote:

> the original post defines pretty clearly what's needed...


> all the rest is an overkill ;)

Most people have low initial expectations,
and can make do with any old calculator;
the entire HP line is "overkill,"
giving more capability, often appreciated
by those who didn't even know that they could get more.

If you object to seeing "added value,"
read a more dumbed down newsgroup ;)

-[ ]-

reth

unread,
Jul 1, 2008, 4:00:23 AM7/1/08
to

"the entire HP line is "overkill," I like that :)
cheers,
reth

0 new messages