all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Roland Winkler" <winkler@gnu.org>
To: jay.p.belanger@gmail.com
Cc: 10554@debbugs.gnu.org
Subject: bug#10554: 24.0.92; No units specified (dimensionless quantities in Emacs Calc)
Date: Sat, 21 Jan 2012 03:24:42 -0600	[thread overview]
Message-ID: <20250.33882.89017.12372@gargle.gargle.HOWL> (raw)
In-Reply-To: <87r4yt9b6g.fsf@gmail.com>

On Fri Jan 20 2012 Jay Belanger wrote:
> >     - if the old expression has units that cancel completely (e.g.,
> >       as in my orginal bug report) or it has a unit like "alpha",
> >       one can specify "1" as the new unit and the unit conversion
> >       returns a plain number.
> 
> If the "error if the units don't match" option is chosen, I would think
> this would naturally be the default.  If partial conversions are
> allowed, I don't think "1" as a unit should trigger an error, but I
> think it should still be a no-op.

If the old expression was "7 in / m" and the new unit is "1", this
should be converted to 0.178, 

- This is already the answer we get from calc-simplify-units.

- For an explicitly defined new trivial unit "one" (see below),
  conversion of "7 in / m" to "one" already gives "0.178 one".

  (A purist might even argue that something like "0.178 one" should
  be the answer to be returned by calc-simplify-units.)

So this is all quite consistent.

This has nothing to do with the value of a new user option
calc-need-matching-units.

> >       (Yes, I am irritated if calc-convert-units asks me about the
> >       old unit if there is just a plain number on the stack. So
> >       backward compatibility would probably require a variable such
> >       as calc-treat-numbers-as-dimensional, bound to nil by
> >       default.)
> 
> An option might be reasonable, with the current behavior the default.
> But this would only be useful when changing a number to a dimensionless
> quantity, like alpha, it seems.

No, I don't see a need to further distiguish here, see below my
discussion of an explicitly defined trivial unit "one". If the old
expression is just a plain number, Calc should do the same thing it
is doing currently if the old expression is given the unit "one"
instead. In that sense, I am essentially requesting that these cases
should be handled more consistently.

> > (2) The old expression is not dimensionless such as "7 m", the new
> >     unit is "1". Here I suggest that partial conversion means to
> >     return the old expression without any unit conversion.
> 
> Basically the current behavior (without the error).  But with the "need 
> matching units", this should give an error.

Exactly.

> > (3) The old expression is a dimensionless number, the requested new
> >     unit is something like "m":
> >
> >     Here I suggest to just return the old expression unmodified
> 
> Unless the "need matching units" option is chosen, in which case this
> would give an error.

Exactly.

Everything I am suggesting here is consistent / equivalent with the
existing behavior of Calc for complete or partial conversion of
units, independent of the value of a new user option
calc-need-matching-units, in the following way:

We can define a trivial unit

(add-to-list 'math-additional-units '(one "1" "One"))

So every plain, dimensionless number in Calc can be converted to
ones. "7" becomes "7 one", in much the same way "7" becomes "960
alpha". Then the exisiting Calc code is already properly converting
"7 one" to other units, both completely or partially. Likewise,
"one" can be choosen as a new unit of an expression with whatever
units.

So I suggest:

  Calc should interpret dimensionless numbers such as "7" equivalent
  to "7 one" without the need to explicitly make this trivial
  conversion in either direction.

  In other words, "one" becomes an "invisible" unit for dimensionless
  numbers.

That means:

- If Calc finds a dimensionless number "7" on the stack, for unit
  conversions it gets interpreted as "7 one"

- The string "1" should consistently become a valid short-hand
  notation for specifying the invisible unit "one" when calling
  something like calc-convert-units.

If such a behavior gets implemented it immediately covers the cases
(1) - (3) in my previous email including all their subcases. 

- There is no ambiguity in this concept.

- It is fully consistent with Calc's current treatment of an explcit
  definition of the trivial unit "one".

All this has nothing to do with what value is chosen for a user
option calc-need-matching-units. Just use again the behavior one may
expect in either case for an explicitly defined unit "one".

As discussed already, backward compatibility will require a user
variable calc-treat-numbers-as-dimensional, bound to nil by default.
There might be other situations where the requested treatment of
dimensionless numbers implies a deviation from the current behavior
so that this might require another user option.

However all in all, these changes will make the treatment of units
more consistent within Calc and also more consistent with how units
are used elsewhere. (Though I have a physicist's perspective, I hope
that engineers and other disciplines will not disagree here.)

Roland





  reply	other threads:[~2012-01-21  9:24 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-19  5:24 bug#10554: 24.0.92; No units specified (dimensionless quantities in Emacs Calc) Roland Winkler
2012-01-19 21:45 ` Jay Belanger
2012-01-19 22:33   ` Roland Winkler
2012-01-20  4:53     ` Jay Belanger
2012-01-20  8:34       ` Roland Winkler
2012-01-20 16:48         ` Jay Belanger
2012-01-20 17:55           ` Roland Winkler
2012-01-20 19:10             ` Jay Belanger
2012-01-20 20:30               ` Roland Winkler
2012-01-20 20:54                 ` Jay Belanger
2012-01-20 22:10                   ` Roland Winkler
2012-01-21  0:00                     ` Jay Belanger
2012-01-21  9:24                       ` Roland Winkler [this message]
2012-01-21 14:45                         ` Jay Belanger
2012-01-21 15:12                           ` Roland Winkler
2012-01-21 15:28                             ` Jay Belanger
2012-01-21 15:42                         ` Jay Belanger
2012-01-21 16:03                           ` Roland Winkler
2012-01-20 20:36               ` Roland Winkler
2012-01-21  4:21 ` Jay Belanger

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

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

  git send-email \
    --in-reply-to=20250.33882.89017.12372@gargle.gargle.HOWL \
    --to=winkler@gnu.org \
    --cc=10554@debbugs.gnu.org \
    --cc=jay.p.belanger@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.