caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Radu Grigore <radugrigore@gmail.com>
To: skaller@users.sourceforge.net
Cc: Stefan Monnier <monnier@iro.umontreal.ca>,
	caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: paralell assignment problem
Date: Wed, 9 Feb 2005 13:19:15 +0200	[thread overview]
Message-ID: <7f8e92aa05020903191f26af4e@mail.gmail.com> (raw)
In-Reply-To: <7f8e92aa050209014322b561e@mail.gmail.com>

On Wed, 9 Feb 2005 11:43:34 +0200, Radu Grigore <radugrigore@gmail.com> wrote:

> 1. hold the original value of a variable
> 2. hold the result of an expression and write it later to the destination
> 
> Point (1) requires one extra assignment, while point (2) requires two
> extra assignments. The effect is however the same: one of the
> variable's value can be computed as soon as desired. Therefore we will
> only use (1). [NOTE that your approach used (2) and hence is clearly
> sub-optimal].

One more mistake. Both approaches introduce _one_ extra assignment and
the algorithm described subsequently is independent on the choice of
(1) or (2).

For the problem:
a = b+c
b = c
c = a+b

The algorithm says: introduce a temporary for c, and the order is c, a, b.
With choice (1) the solution is the one I already wrote. With choice (2) it is:

// compute temporaries
t = a+b

// compute c, a, b (skip c because we have temporary, this is what I missed)
a = b+c
b = c

// use temporaries
c = t

... for a total of 4 assignments (same as with choice 1). This is
better than the 5 assignments given by your algorithm and it does NOT
depend on breaking the rule about using temporaries only to save
results of expressions (but not initial values).

-- 
regards,
 radu
http://rgrig.idilis.ro/


  reply	other threads:[~2005-02-09 11:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-08  3:07 skaller
2005-02-08 14:34 ` Stefan Monnier
2005-02-08 16:02   ` [Caml-list] " skaller
2005-02-08 18:20     ` Stefan Monnier
2005-02-08 17:08   ` skaller
2005-02-08 18:33     ` Radu Grigore
2005-02-09  7:48       ` Radu Grigore
2005-02-09 10:11         ` skaller
2005-02-09  9:43       ` Radu Grigore
2005-02-09 11:19         ` Radu Grigore [this message]
2005-02-09 11:34         ` Pascal Zimmer
2005-02-09 13:53           ` skaller
2005-02-08 16:03 ` [Caml-list] " Florian Hars
2005-02-08 17:38   ` skaller
2005-02-08 16:29 ` Marcin 'Qrczak' Kowalczyk
2005-02-08 17:55   ` skaller
2005-02-08 18:32     ` Marcin 'Qrczak' Kowalczyk

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=7f8e92aa05020903191f26af4e@mail.gmail.com \
    --to=radugrigore@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=monnier@iro.umontreal.ca \
    --cc=skaller@users.sourceforge.net \
    /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.
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 NNTP newsgroup(s).