caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] How to simplify an arithmetic expression ?
Date: Wed, 5 Oct 2011 23:31:20 +0200	[thread overview]
Message-ID: <CAPFanBG+FQGauE8ydJWgEnk=kHsv31LAuVDHDcRb50SjFeP-Ew@mail.gmail.com> (raw)
In-Reply-To: <87zkhfpogp.fsf@frosties.localnet>

On Wed, Oct 5, 2011 at 3:17 PM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
> (1*Y)? That certainly isn't optimal.

The inefficiency is in the code translating the semantic value back
into the expression type, not in the evaluation code.
Feel free to add the few lines needed to spot that corner case and
behave accordingly, as I did for the initialization of the sum (to
avoid "+ 0" everywhere).
Note that this doesn't stop the simplification to be involutive, so
still a valid simplification/normalization; whether the normal form
actually respects our sense of "optimality" is a different question.

On Wed, Oct 5, 2011 at 3:17 PM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
> Gabriel Scherer <gabriel.scherer@gmail.com> writes:
>
>>> Below is a quick tentative implementation of NbE, on a slightly
>>> restricted expression type (I removed the not-so-interesting Minus
>>> nodes).
>>
>> Sorry, I forgot to give a small example of what the implementation
>> does. Really the obvious thing, but it may not be so obvious just
>> looking at the code.
>> Here is an example of (X*2+Y)*(3+(Y*2+Z)) being 'rewritten' to
>> (1*Y)*Z+((2*Y)*Y+(3*Y+((2*X)*Z+((4*X)*Y+6*X)))).
>
> (1*Y)? That certainly isn't optimal.
>
> MfG
>        Goswin
>


  reply	other threads:[~2011-10-05 21:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-02 11:51 Diego Olivier Fernandez Pons
2011-10-02 14:08 ` Gabriel Scherer
2011-10-02 15:09   ` Ernesto Posse
2011-10-02 16:32     ` Xavier Leroy
2011-10-02 16:48       ` Gabriel Scherer
2011-10-02 17:07         ` Gabriel Scherer
2011-10-05 13:17           ` Goswin von Brederlow
2011-10-05 21:31             ` Gabriel Scherer [this message]
2011-10-02 16:56 ` Xavier Clerc
2011-10-05 13:09 ` Goswin von Brederlow

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='CAPFanBG+FQGauE8ydJWgEnk=kHsv31LAuVDHDcRb50SjFeP-Ew@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    /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).