Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #53408

Re: Question on exponentiation

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Richmond <dnomhcir@gmx.com>
Newsgroups comp.lang.forth
Subject Re: Question on exponentiation
Date Sun, 18 Dec 2016 18:07:24 +0000
Organization Frantic
Lines 34
Message-ID <85d1gp2js3.fsf@example.com> (permalink)
References <o35791$99j$1@dont-email.me> <o35s9m$ssa$1@cherry.spenarnc.xs4all.nl> <o35s5g$vnu$1@dont-email.me>
NNTP-Posting-Host PvntusSwr4q7vyFfAigJOw.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Complaints-To abuse@aioe.org
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)
X-Notice Filtered by postfilter v. 0.8.2
Cancel-Lock sha1:1RcZ/0KEn8Ws7IfD4fe8fcXW+js=
Xref csiph.com comp.lang.forth:53408

Show key headers only | View raw


Ron Aaron <rambamist@gmail.com> writes:

> On 12/18/2016 13:35, Albert van der Horst wrote:
>> In article <o35791$99j$1@dont-email.me>,
>> Ron Aaron  <rambamist@gmail.com> wrote:
>>> One of my users complained that in 8th, "-2 2 ^" gives "4" while python
>>> (and google's calculator, etc) gives "-4".
>>>
>>> I maintain that "-2 2 ^" is equivalent to "-2 -2 *" and therefore must
>>> be "4".  But clearly there are programs (and authors thereof) which
>>> disagree.
>>>
>>> Can anyone shed light on why python gives the answer it does, and
>>> whether or not I'm just crazy to expect -2 2 ^ to give the answer 4 ?
>> 
>> Python can't calculate "-2 2 ^", maybe "-2**2" . By having ** bind thighter
>> than -, the result ensues.
>
> Yes, exactly.  "**" binds tighter than monadic "-" in Python.  You must
> use parentheses to get the result I would expect naively.
>
>> Of course your result is correct. Furthermore the Python decision is
>> dubious, it doesn't agree with the best thought language ever, Algol68.
>> There the rule is:  All monadic operators bind more tightly then
>> dyadic operators.
>
> Interesting about Algol68; never had occasion to look at it, though I
> was (, a long time ago) familiar with PL/1.
>
> I think this simply illustrates a prime advantage of the "Forth way",
> e.g. that there are no precedence rules and items are evaluated in the
> order they appear.

I think python is correct. In mathematics -x² is not the same as (-x)².

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Question on exponentiation Ron Aaron <rambamist@gmail.com> - 2016-12-18 07:37 +0200
  Re: Question on exponentiation Julian Fondren <julian.fondren@gmail.com> - 2016-12-17 21:45 -0800
    Re: Question on exponentiation Ron Aaron <rambamist@gmail.com> - 2016-12-18 07:46 +0200
  Re: Question on exponentiation albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-18 12:35 +0100
    Re: Question on exponentiation Ron Aaron <rambamist@gmail.com> - 2016-12-18 13:33 +0200
      Re: Question on exponentiation Richmond <dnomhcir@gmx.com> - 2016-12-18 18:07 +0000
        Re: Question on exponentiation albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-12-19 14:00 +0100
      Re: Question on exponentiation rickman <gnuarm@gmail.com> - 2016-12-18 15:45 -0500
      Re: Question on exponentiation Paul Rubin <no.email@nospam.invalid> - 2016-12-18 14:26 -0800
        Re: Question on exponentiation rickman <gnuarm@gmail.com> - 2016-12-18 17:43 -0500
          Re: Question on exponentiation Paul Rubin <no.email@nospam.invalid> - 2016-12-18 14:53 -0800
            Re: Question on exponentiation rickman <gnuarm@gmail.com> - 2016-12-18 19:12 -0500
              Re: Question on exponentiation Julian Fondren <julian.fondren@gmail.com> - 2016-12-18 16:56 -0800
          Re: Question on exponentiation Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-12-19 02:52 -0600
  Re: Question on exponentiation john <anon@example.com> - 2016-12-18 12:21 +0000
  Re: Question on exponentiation Cecil Bayona <cbayona@cbayona.com> - 2016-12-18 12:14 -0600
    Re: Question on exponentiation rickman <gnuarm@gmail.com> - 2016-12-18 15:48 -0500

csiph-web