Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  High precision doubles
      (Rafael Gustavo da Cunha Pereira Pinto)
   2.  if True than let... (Bernhard Lehnert)
   3. Re:  if True than let... (Andrew Wagner)
   4. Re:  if True than let... (John Melesky)
   5.  Re: if True than let... (Gracjan Polak)
   6. Re:  if True than let... (Bernhard Lehnert)
   7. Re:  if True than let... (Daniel Fischer)
   8. Re:  High precision doubles (a...@spamcop.net)
   9.  on (Ivan Uemlianin)


----------------------------------------------------------------------

Message: 1
Date: Thu, 25 Jun 2009 10:38:44 -0300
From: Rafael Gustavo da Cunha Pereira Pinto
        <rafaelgcpp.li...@gmail.com>
Subject: Re: [Haskell-beginners] High precision doubles
To: beginners@haskell.org
Message-ID:
        <351ff25e0906250638l549aaf1y3de0b980f8468...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

oops:

Relative exit condition (valid only when dealing with non-zero values)

abs ((xold-xnew)/xnew) <epsilon



On Thu, Jun 25, 2009 at 10:24, Rafael Gustavo da Cunha Pereira Pinto <
rafaelgcpp.li...@gmail.com> wrote:

> I am reading this and still don't understand what is the question. You
> should never operate two floating point numbers expecting to result zero.
> Period.
>
> Floating point numbers are intrinsically imprecise. Every time you write an
> interactive process with floating points in the exit conditions, you should
> use some tolerance, either relative or absolute.
>
> Absolute exit condition:
>
> abs (xnew - xold) < epsilon
>
> Relative exit condition (valid only when dealing with non-zero values)
>
> abs ((xold+xnew)/xnew) <epsilon
>
>
> If you cannot apply this, then either:
>
> 1) You are dealing with VERY small values, close to the minimal precision
> (2.2250738585072014e-308, on 64-bit doubles),
>
> 2) You are dealing with small and big numbers, differing by 37 orders of
> magnitude amongst them, when the small number will be set to 0
>
> To solve this you should:
>
> for 1) Scale your numbers... double, multiply by 1024, whatever, as long as
> they separate from the minimal precision. It is like putting your maze under
> a HUGE microscope!
>
> for 2) Addition in situations as this one is like adding a pinch of salt on
> the ocean. For multiplications, try using Log-domain operations... That
> might work... Praying might work as well...
>
>
>
> Where epsilon is
>
> On Thu, Jun 25, 2009 at 09:17, Daniel Fischer <daniel.is.fisc...@web.de>wrote:
>
>> Am Donnerstag 25 Juni 2009 04:14:19 schrieb Sean Bartell:
>> > > When adding a new node/hex to the graph/maze, I pick an existing node
>> and
>> > > get all of its neighbour co-ordinates, filtering out co-ordinates that
>> > > represent nodes already present in the graph. The problem is that, due
>> to
>> > > floating point errors, these co-ordinates are not be exact. If hex A
>> has
>> > > the co-ordinate for hex B in its list of adjacent hexes, hex B would
>> not
>> > > necessarily have the co-ordinate for hex A in its own list. Things get
>> > > mismatched quickly.
>> >
>> > You won't be able to get it working easily with floating-point numbers.
>> > Ideally, you would use integers for the code you're describing, then
>> scale
>> > them to the proper floating-point values later.
>>
>> Say the hexagons have side length 2, the centre of one is at (0,0) and one
>> of its vertices
>> at (2,0).
>> Then the centre of any hexagon has coordinates (3*k,m*sqrt 3), for some
>> integers k, m and
>> any vertex has coordinates (i,j*sqrt 3) for integers i, j. So in this
>> case, he could work
>> with floating point values; using a large tolerance, he could build a
>> gigantic grid before
>> having false results.
>>
>> But of course, it is much better to use (k,m), resp. (i,j), as coordinates
>> and translate
>> that to floating point only for drawing.
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
>
> --
> Rafael Gustavo da Cunha Pereira Pinto
> Electronic Engineer, MSc.
>



-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090625/3f274a5e/attachment-0001.html

------------------------------

Message: 2
Date: Thu, 25 Jun 2009 22:12:08 +0200
From: Bernhard Lehnert <b.lehn...@gmx.de>
Subject: [Haskell-beginners] if True than let...
To: beginners@haskell.org
Message-ID: <1245960728.6635.60.ca...@sol>
Content-Type: text/plain

Hi,

I'm sorry because I am absolutely sure, this is bloody obvious to the
knowing. Being a total beginner I'm stuck. In the main = do part I
wrote:

1:     if a == True then putStrLn "Yes!" else putStrLn "No."
2:     if a == True then let b = "+" else let b = "-"

Line #1 works perfectly well. 
Read line #2 as pseudocode and you'll see what I want to do. Read it in
ghci and it produces 
     "  parse error on input `='    "

I tried 'case of' but it doesn't work either. 

What am I doing wrong?
Thank you for any help,

Bernhard







------------------------------

Message: 3
Date: Thu, 25 Jun 2009 16:22:19 -0400
From: Andrew Wagner <wagner.and...@gmail.com>
Subject: Re: [Haskell-beginners] if True than let...
To: Bernhard Lehnert <b.lehn...@gmx.de>
Cc: beginners@haskell.org
Message-ID:
        <b8a8636e0906251322t411319cav3dd642e7e5552...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Try this: let b = if a == True then "+" else "-" in ...

On Thu, Jun 25, 2009 at 4:12 PM, Bernhard Lehnert <b.lehn...@gmx.de> wrote:

> Hi,
>
> I'm sorry because I am absolutely sure, this is bloody obvious to the
> knowing. Being a total beginner I'm stuck. In the main = do part I
> wrote:
>
> 1:     if a == True then putStrLn "Yes!" else putStrLn "No."
> 2:     if a == True then let b = "+" else let b = "-"
>
> Line #1 works perfectly well.
> Read line #2 as pseudocode and you'll see what I want to do. Read it in
> ghci and it produces
>     "  parse error on input `='    "
>
> I tried 'case of' but it doesn't work either.
>
> What am I doing wrong?
> Thank you for any help,
>
> Bernhard
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090625/d8143aa9/attachment-0001.html

------------------------------

Message: 4
Date: Thu, 25 Jun 2009 13:24:53 -0700
From: John Melesky <l...@phaedrusdeinus.org>
Subject: Re: [Haskell-beginners] if True than let...
To: Bernhard Lehnert <b.lehn...@gmx.de>
Cc: beginners@haskell.org
Message-ID: <7ddeb33f-d7f3-4d36-bb16-bbe1c70af...@phaedrusdeinus.org>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

On Jun 25, 2009, at 1:12 PM, Bernhard Lehnert wrote:
> 1:     if a == True then putStrLn "Yes!" else putStrLn "No."
> 2:     if a == True then let b = "+" else let b = "-"

You can try:

let b = if a == True then "+" else "-"

Also, whenever you find yourself testing 'x == True' or 'x == False',  
you can reduce that to 'x' and 'not x' respectively, so you go down to:

let b = if a then "+" else "-"

Hope that helps.

-johnnnnnnn



------------------------------

Message: 5
Date: Thu, 25 Jun 2009 20:24:30 +0000 (UTC)
From: Gracjan Polak <gracjanpo...@gmail.com>
Subject: [Haskell-beginners] Re: if True than let...
To: beginners@haskell.org
Message-ID: <loom.20090625t202338-...@post.gmane.org>
Content-Type: text/plain; charset=us-ascii

Andrew Wagner <wagner.andrew <at> gmail.com> writes:
> Try this: let b = if a == True then "+" else "-" in ...

Or like this:

main = do
    let b = if True then "a" else "b"
    putStrLn b

-- 
Gracjan




------------------------------

Message: 6
Date: Thu, 25 Jun 2009 22:37:58 +0200
From: Bernhard Lehnert <b.lehn...@gmx.de>
Subject: Re: [Haskell-beginners] if True than let...
To: beginners@haskell.org
Message-ID: <1245962278.6635.64.ca...@sol>
Content-Type: text/plain


> Since ifs are an expression in haskell, they return a value,

All right, that explains it. Today I learned to think of that
expression thing even in do blocks. Thank you to everyone!

Cheers,
Bernhard



------------------------------

Message: 7
Date: Thu, 25 Jun 2009 22:40:34 +0200
From: Daniel Fischer <daniel.is.fisc...@web.de>
Subject: Re: [Haskell-beginners] if True than let...
To: beginners@haskell.org
Message-ID: <200906252240.34576.daniel.is.fisc...@web.de>
Content-Type: text/plain;  charset="iso-8859-15"

Am Donnerstag 25 Juni 2009 22:12:08 schrieb Bernhard Lehnert:
> Hi,
>
> I'm sorry because I am absolutely sure, this is bloody obvious to the
> knowing. Being a total beginner I'm stuck. In the main = do part I
> wrote:
>
> 1:     if a == True then putStrLn "Yes!" else putStrLn "No."
> 2:     if a == True then let b = "+" else let b = "-"
>
> Line #1 works perfectly well.
> Read line #2 as pseudocode and you'll see what I want to do. Read it in
> ghci and it produces
>      "  parse error on input `='    "
>
> I tried 'case of' but it doesn't work either.
>
> What am I doing wrong?
> Thank you for any help,
>
> Bernhard
>

let b = "+"

is not a complete expression, thus cannot be a branch of 'if'. It should give a 
parse 
error on 'else' (and my ghci does).
But (putStrLn "Yes!") is a complete expression, so can be used as a branch of 
an if-
expression.

You probably want to bind the name b to a value depending on a somewhere in 
main's do-
block?

That would be achieved so:

let b = if a then "+" else "-"

b can then be used in following statements.

Outside of a do-block, you would have to write

let b = if a then "+" else "-" in someExpression

HTH,
Daniel


------------------------------

Message: 8
Date: Fri, 26 Jun 2009 03:00:48 -0400
From: a...@spamcop.net
Subject: Re: [Haskell-beginners] High precision doubles
To: beginners@haskell.org
Message-ID: <20090626030048.1jtcgrli8gowwwg8-...@webmail.spamcop.net>
Content-Type: text/plain;       charset=ISO-8859-1;     DelSp="Yes";
        format="flowed"

G'day all.

Quoting Rafael Gustavo da Cunha Pereira Pinto <rafaelgcpp.li...@gmail.com>:

> I am reading this and still don't understand what is the question. You
> should never operate two floating point numbers expecting to result zero.
> Period.

WARNING: Advanced material follows.

A 32-bit integer fits losslessly in the mantissa of a Double.  Any of
the basic integer operations which work correctly on 32-bit integers
must also work correctly when that integer is stored in a Double.  You
are allowed to assume this.

Cheers,
Andrew Bromage


------------------------------

Message: 9
Date: Fri, 26 Jun 2009 10:20:49 +0100
From: Ivan Uemlianin <i...@llaisdy.com>
Subject: [Haskell-beginners] on
To: beginners@haskell.org
Message-ID: <4a4492f1.2020...@llaisdy.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Dear All

During some recent discussion about different ways of sorting a list by 
some comparison function, one of the methods suggested was like this:

    sortByFunc = sortBy (compare `on` func)

Now, I can imagine how this works, and I don't want to discuss the 
efficiency of this implementation (I imagine it's not "Schwartzian", for 
example;).  I know what the backticks do (allow infix use of a function).

My question is: what is "on"? 

I'm afraid I haven't been able to find anything about this, no doubt 
because of all the false positives coming up in searches.  Please could 
someone tell me its official title, or where I could find it in the docs?

Thanks and best wishes

Ivan


-- 
============================================================
Ivan A. Uemlianin
Speech Technology Research and Development

                    i...@llaisdy.com
                     www.llaisdy.com
                         llaisdy.wordpress.com
                     www.linkedin.com/in/ivanuemlianin

    "Froh, froh! Wie seine Sonnen, seine Sonnen fliegen"
                     (Schiller, Beethoven)
============================================================



------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 12, Issue 13
*****************************************

Reply via email to