unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Christian Schlauer <cs-muelleimer-rubbish.bin@arcor.de>
To: emacs-devel@gnu.org
Subject: Re: Calc: `*' binds more strongly than `/'
Date: Thu, 26 Apr 2007 23:07:45 +0200	[thread overview]
Message-ID: <f0r48r$9sv$2@sea.gmane.org> (raw)
In-Reply-To: 87d51sqinn.fsf@gmail.com

Jay Belanger <jay.p.belanger@gmail.com> writes:

> Christian Schlauer <cs-muelleimer-rubbish.bin@arcor.de> writes:

[...]

>> I did some more `research', and a*b/c*d is not bad form, and it is a
>> properly written expression, see Wikipedia. Let me cite from
>> <http://en.wikipedia.org/wiki/Order_of_operations#Examples_from_arithmetic>:
>
> As I said, there are rules for interpreting the above expressions.  
> I also said that avoiding the parentheses is bad form; note that the
> wikipedia article also says:
>
>   Proper use of parentheses and other grouping symbols
>
>   When restricted to using a straight text editor, parentheses (or
>   more generally "grouping symbols") must be used generously to make
>   up for the lack of graphics, like square root symbols. Here are some
>   rules for doing so: 
>
>   1) Whenever there is a fraction formed with a slash, put the
>   numerator (the number on top of the fraction) in one set of
>   parentheses, and the denominator (the number on the bottom of the
>   fraction) in another set of parentheses. This is not required for
>   fractions formed with underlines: 
>     y = (x+1)/(x+2)
>   ...
>   5) An exception to the rules requiring parentheses applies when only
>   one character is present. While correct either way, it is more
>   readable if parentheses around a single character are omitted: 
>
>     y = (3)/(x) or y = 3/x
>
>     y = (3)/(2x) or y = 3/(2x)

I saw those examples, too, but didn't read the text of that section,
as all examples there use `+', and then of course one needs
parentheses -- otherwise it is *really* wrong. But the last line I
cite from you is exactly what Calc is ignoring and what I `complain'
about:

y = 3/(2x)

So despite the `juxtaposition operator' (I had to check what this
means, <http://en.wiktionary.org/wiki/juxtaposition> says "An absence
of multiplication symbols, `ab' instead of `a times b'"), they suggest
to write the denominator with parentheses to bind the `x' to `2'.
Let's ignore for a moment the `juxtaposition operator' and use `*': in
the current Calc you can write `y = 3/2*x' when what you want Calc to
do is `y = 3/(2*x)', and *that* is really not what I'd expect from
mathematics software after reading the Wikipedia article -- because
according to what you cite above from Wikipedia, the `x' in `y =
3/2*x' does definitely not belong to the denominator. But in Calc, it
does. :-(

If you want, let Calc interpret `y = 3/2x' as `y = 3/(2x)', in order
to let the `juxtaposition operator' have precedence -- but `y = 3/2*x'
should _never_ be treated in that way.

>> So besides Excel, Gnumeric, MATLAB, all pocket calculators, Wikipedia
>> agrees with me, too.
>
> Well, wikipedia also says
>
>   Calculators
>
>   Different calculators follow different orders of operations.
>
> and gives several examples.

But these examples refer to only two cases:

1) Cheaper calculators without a stack work left to right without any
   priority given to different operators, for example giving

   1+2*3=9

   while more sophisticated calculators will use a more standard
   priority, for example giving

   1+2*3=7.

2) Two different TI models that differ in the interpretation of a^b^c:
   one sees it as (a^b)^c, the other as a^(b^c).

That the TI models differ concerning a^b^c is unfortunate, but on the
basis of this Wikipedia article I still say that

- all pocket calculators _that consider the order of operators_ treat
  / and * as equal and evaluate from left to right in the absence of
  parentheses and

- the behaviour of pocket calculators starts to differ with
  expressions like a^b^c, which some evaluate left-to-right, as they
  do with other operators, while others (the better ones, IMO -- Calc
  included, see (info "(calc)Algebraic Tutorial"): `2^3^4' is
  equivalent to `2^(3^4)') evaluate this from right-to-left.

> For those that really don't like parentheses, an option to allow the
> user to decide for themselves the relative precedence of * and / in
> Calc will be added, of course.

That sounds good, but what will be the default? I really think that
the Wikipedia article has more than enough evidence against Calc's
current behaviour.

Regards,

Christian

  parent reply	other threads:[~2007-04-26 21:07 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-14 11:57 Calc: `*' binds more strongly than `/' Christian Schlauer
2007-04-14 15:09 ` Jay Belanger
2007-04-15 19:21   ` Chong Yidong
2007-04-15 20:05     ` Stefan Monnier
2007-04-17 12:47       ` Randal L. Schwartz
2007-04-17 18:03         ` Stefan Monnier
2007-04-18  8:44           ` Kim F. Storm
2007-04-18 19:27             ` Stefan Monnier
2007-04-18 20:02               ` Davis Herring
2007-04-18 20:16                 ` David Kastrup
2007-04-18 21:43                   ` Davis Herring
2007-04-19 16:10                 ` Stefan Monnier
2007-04-20 11:13                   ` Randal L. Schwartz
2007-04-20 13:40                     ` Stefan Monnier
2007-04-20 14:07                       ` Jay Belanger
2007-04-22  1:31                         ` Miles Bader
2007-04-22 10:19                           ` Christian Schlauer
2007-04-22 10:23                         ` Christian Schlauer
2007-04-22 19:47                           ` Jay Belanger
2007-04-23 10:46                           ` Jason Rumney
2007-04-23 13:03                             ` Kim F. Storm
2007-04-23 15:54                               ` Jay Belanger
2007-04-25 19:56                                 ` Christian Schlauer
2007-04-25 20:54                                   ` Jay Belanger
2007-04-26  3:35                                     ` Stefan Monnier
2007-04-26  4:06                                       ` Jay Belanger
2007-04-26 14:11                                         ` Stefan Monnier
2007-04-26 21:07                                           ` Christian Schlauer
2007-04-26 15:07                                         ` Davis Herring
2007-04-26 16:01                                           ` Stefan Monnier
2007-04-26 18:32                                             ` Luc Teirlinck
2007-04-26 21:29                                               ` Christian Schlauer
2007-04-26 23:17                                                 ` Luc Teirlinck
2007-04-26 21:07                                     ` Christian Schlauer [this message]
2007-04-27  1:27                                       ` Jay Belanger
2007-04-26 17:47                                   ` Davis Herring
2007-06-20 15:23                         ` Jay Belanger
2007-06-20 16:02                           ` Kim F. Storm
2007-06-20 17:13                             ` Jay Belanger
2007-06-20 17:29                             ` Luc Teirlinck
2007-06-20 17:54                               ` Jay Belanger
2007-06-20 19:14                                 ` Kim F. Storm
2007-06-20 19:28                                 ` Luc Teirlinck
2007-06-20 20:18                                   ` Jay Belanger
2007-04-17 18:54         ` Jay Belanger
2007-04-18 21:55           ` Christian Schlauer
2007-04-19  2:58             ` Daniel Brockman
2007-04-22 10:27               ` Christian Schlauer
2007-04-26 16:00                 ` Daniel Brockman
2007-04-19 15:16           ` Drew Adams
2007-04-19 17:05             ` David Kastrup
2007-04-19 17:18               ` Drew Adams
2007-04-19 17:33                 ` David Kastrup
2007-04-16 15:38     ` Richard Stallman
2007-04-17 12:47 ` Randal L. Schwartz
2007-04-18 21:29   ` Christian Schlauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='f0r48r$9sv$2@sea.gmane.org' \
    --to=cs-muelleimer-rubbish.bin@arcor.de \
    --cc=cs-usenet@arcor.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).