Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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.  Quickcheck: pushing element onto stack   increases stack size
      (PATRICK BROWNE)
   2. Re:  Quickcheck: pushing element onto stack increases stack
      size (David McBride)
   3. Re:  Quickcheck: pushing element onto stack increases stack
      size (PATRICK BROWNE)
   4.  Runge-Kutta and vectors (mike h)


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

Message: 1
Date: Thu, 11 May 2017 20:38:59 +0100
From: PATRICK BROWNE <patrick.bro...@dit.ie>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Quickcheck: pushing element onto stack
        increases stack size
Message-ID:
        <cagflrkfxmavbqbwqwmi81uadkpglkwfornnaak-aykshapp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,
I am trying to use Quickcheck to check that pushing an element increases
the size of a stack.
Something like:
prop_size2 x s = (size (Push x s)) > (size s)

Is this possible? Below is my effort using an empty stack.
Thanks in advance,
Pat


module Stack (empty, push, pop, top, isEmpty) where
import Test.QuickCheck

data Stack a = Empty | Push a (Stack a) deriving  Show

empty :: Stack a
empty = Empty

push :: a -> Stack a -> Stack a
push x ss = Push x ss

pop :: Stack a -> Stack a
pop Empty = error "pop emptyStack"
pop (Push x ss) = ss

top :: Stack a -> a
top Empty = error "top emptyStack"
top (Push x ss) = x

isEmpty :: Stack a -> Bool
isEmpty Empty = True
isEmpty (Push x ss) = False


size :: (Stack a) -> Int
size Empty = 0
size (Push x ss) = succ (size ss)


prop_size x  = (size (Push x Empty)) > (size Empty)

-- 


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170511/64f3d46e/attachment-0001.html>

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

Message: 2
Date: Thu, 11 May 2017 16:00:57 -0400
From: David McBride <toa...@gmail.com>
To: patrick.bro...@dit.ie,  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Quickcheck: pushing element onto
        stack increases stack size
Message-ID:
        <can+tr42capno62-g7sgfwu7wfy1ceyk3l1shcm-t2mzv-jd...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

First you need a way to generate an arbitrary stack.  Here's a simple
method that just gives you a 50% chance at each level of generating an
extra layer.

instance Arbitrary a => Arbitrary (Stack a) where
  arbitrary = oneof [return Empty, Push <$> arbitrary <*> arbitrary ]

prop_size_succeeds x s = size (Push x s) > size s
prop_size_fails x s = size s > size Empty

>quickCheck prop_size_fails
*** Failed! Falsifiable (after 6 tests):
()
Empty


On Thu, May 11, 2017 at 3:38 PM, PATRICK BROWNE <patrick.bro...@dit.ie> wrote:
> Hi,
> I am trying to use Quickcheck to check that pushing an element increases the
> size of a stack.
> Something like:
> prop_size2 x s = (size (Push x s)) > (size s)
>
> Is this possible? Below is my effort using an empty stack.
> Thanks in advance,
> Pat
>
>
> module Stack (empty, push, pop, top, isEmpty) where
> import Test.QuickCheck
>
> data Stack a = Empty | Push a (Stack a) deriving  Show
>
> empty :: Stack a
> empty = Empty
>
> push :: a -> Stack a -> Stack a
> push x ss = Push x ss
>
> pop :: Stack a -> Stack a
> pop Empty = error "pop emptyStack"
> pop (Push x ss) = ss
>
> top :: Stack a -> a
> top Empty = error "top emptyStack"
> top (Push x ss) = x
>
> isEmpty :: Stack a -> Bool
> isEmpty Empty = True
> isEmpty (Push x ss) = False
>
>
> size :: (Stack a) -> Int
> size Empty = 0
> size (Push x ss) = succ (size ss)
>
>
> prop_size x  = (size (Push x Empty)) > (size Empty)
>
> This email originated from DIT. If you received this email in error, please
> delete it from your system. Please note that if you are not the named
> addressee, disclosing, copying, distributing or taking any action based on
> the contents of this email or attachments is prohibited. www.dit.ie
>
> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí
> earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an
> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon
> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa ríomhphost
> nó sna hiatáin seo. www.dit.ie
>
> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to
> Grangegorman
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


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

Message: 3
Date: Thu, 11 May 2017 22:55:55 +0100
From: PATRICK BROWNE <patrick.bro...@dit.ie>
To: David McBride <toa...@gmail.com>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Quickcheck: pushing element onto
        stack increases stack size
Message-ID:
        <CAGFLrKfBf=aXq-z+Nqhn=x83bjgvq68qbqr4xaqcuwx7f84...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

David,
Thanks for the help.
Much appreciated,
Pat

On 11 May 2017 at 21:00, David McBride <toa...@gmail.com> wrote:

> First you need a way to generate an arbitrary stack.  Here's a simple
> method that just gives you a 50% chance at each level of generating an
> extra layer.
>
> instance Arbitrary a => Arbitrary (Stack a) where
>   arbitrary = oneof [return Empty, Push <$> arbitrary <*> arbitrary ]
>
> prop_size_succeeds x s = size (Push x s) > size s
> prop_size_fails x s = size s > size Empty
>
> >quickCheck prop_size_fails
> *** Failed! Falsifiable (after 6 tests):
> ()
> Empty
>
>
> On Thu, May 11, 2017 at 3:38 PM, PATRICK BROWNE <patrick.bro...@dit.ie>
> wrote:
> > Hi,
> > I am trying to use Quickcheck to check that pushing an element increases
> the
> > size of a stack.
> > Something like:
> > prop_size2 x s = (size (Push x s)) > (size s)
> >
> > Is this possible? Below is my effort using an empty stack.
> > Thanks in advance,
> > Pat
> >
> >
> > module Stack (empty, push, pop, top, isEmpty) where
> > import Test.QuickCheck
> >
> > data Stack a = Empty | Push a (Stack a) deriving  Show
> >
> > empty :: Stack a
> > empty = Empty
> >
> > push :: a -> Stack a -> Stack a
> > push x ss = Push x ss
> >
> > pop :: Stack a -> Stack a
> > pop Empty = error "pop emptyStack"
> > pop (Push x ss) = ss
> >
> > top :: Stack a -> a
> > top Empty = error "top emptyStack"
> > top (Push x ss) = x
> >
> > isEmpty :: Stack a -> Bool
> > isEmpty Empty = True
> > isEmpty (Push x ss) = False
> >
> >
> > size :: (Stack a) -> Int
> > size Empty = 0
> > size (Push x ss) = succ (size ss)
> >
> >
> > prop_size x  = (size (Push x Empty)) > (size Empty)
> >
> > This email originated from DIT. If you received this email in error,
> please
> > delete it from your system. Please note that if you are not the named
> > addressee, disclosing, copying, distributing or taking any action based
> on
> > the contents of this email or attachments is prohibited. www.dit.ie
> >
> > Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí
> > earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an
> > seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon
> > dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa
> ríomhphost
> > nó sna hiatáin seo. www.dit.ie
> >
> > Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to
> > Grangegorman
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners@haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >
>

-- 


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20170511/71506976/attachment-0001.html>

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

Message: 4
Date: Fri, 12 May 2017 08:49:12 +0100
From: mike h <mike_k_hough...@yahoo.co.uk>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Runge-Kutta and vectors
Message-ID: <41c956b2-13a1-4471-885e-08b59a597...@yahoo.co.uk>
Content-Type: text/plain; charset=utf-8


Having looked at 'Learn Physics by Programming in Haskell’ I became quite 
wobbly with excitement! :)

So I took and implemented some of their ideas. My University level maths is 
around 40 years old and so I struggled
with some of the later things - but it's slowly coming back!

(I have a copy at 
https://github.com/banditpig/vectors/blob/master/LearnPhysics.pdf)

So I have

type Scalar = Double
type XYZ = (Scalar, Scalar, Scalar)
newtype Vector = V { xyz :: XYZ} 

and set of vector  operations

(^+^) :: Vector -> Vector -> Vector
(^-^) :: Vector -> Vector -> Vector
(*^) :: Scalar -> Vector -> Vector
(^*) :: Vector -> Scalar -> Vector
(^/) :: Vector -> Scalar  -> Vector
(>.<) :: Vector -> Vector -> Scalar -- dot 
(><) :: Vector -> Vector -> Vector  -- cross
etc

I then have 

type Time = Double
type Displacement = Vector
type Velocity = Vector

type State = (Time, Displacement, Velocity) 


eulerStep :: (State -> Vector) -> Double -> State -> State
eulerStep f dt st@(t, r, v) = (t', r', v') where
    t' = t + dt             
    r' = r ^+^  v ^* dt      
    v' = v ^+^  f st ^* dt   

and so for a given acceleration function, time step and start state a solution  
is given by

solution :: (State -> Vector) -> Double -> State -> [State]
solution a dt  = iterate (eulerStep a dt)

What I'm trying to do is replace the Euler method of solving with the 
Rung-Kutta method.
I'm really struggling in seeing how the Rung-Kutta examples I've seen are 
implemented using vectors.

How should I progress? Any advice would be welcome! (I really want to implement 
it using the types I have rather than using an external library )


Many Thanks

Mike









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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 107, Issue 9
*****************************************

Reply via email to