My F# article on dotNetMania 73

dnm73

For the first time I decided to do some propaganda about an article of mine that was published in the Spanish magazine called dotNetMania. As far as I know this magazine is the oldest one that is on spanish dedicated only to .NET and I can ensure every month delivers a range of interesting articles topics in wide used .NET technologies. I have said first time because the editors already gave me the honor to participate twice in the past, this time however it means a bit more for me as it features an F# solution to bind together lessons from algebra ith the functional programming paradigm. The translated title of the work is “Functional representation of numerical matrixs”, as it suggests the articles introduces a functional abstraction of the concept of a numerical matrix, wich in turns mean that it is possible to represent a matrix whitout using not a single array, the alternative I propose is via functions…

If you find the subject of the article interesting you can check the the project behind the article on this codeplex site. Currently I use Codeplex as a frontend while the source is hosted on GitHub. The project also includes a customization of the F# Interactive to start playing with the new data type.

Also if you are capable of reading spanish I encourage the reader to visit the magazine site and subcribe to it.  One of the benefits of being a subscriber is that from time to time a hands-on-labs books written by experts are included that targets .NET

Just for finnish I left you a few examples about how you can build some easy matrix objects via a function:


    let empty m n = 
        requires (m = 0 || n = 0) MATRIX_EMPTYCREATION_BADDIMENSIONS
        new FMatrix(m,n, fun (i,j) -> failwith MATRIX_EMPTY )

    let identity m =
        requires (m >= 0) MATRIX_IDENTITYCREATION_BADDIMENSIONS
        if m = 0 then
           empty 0 0
        else
            new FMatrix(m,m, fun (i,j) -> if i = j then 1.0 else 0.0)

    let diagonal m v =
        requires (m > 0) MATRIX_CUSTOMCREATION_BADDIMENSIONS
        new FMatrix(m,m, fun (i,j) -> if i = j then v else 0.0)

    let zero m n =
        requires (m > 0 && n > 0) MATRIX_CUSTOMCREATION_BADDIMENSIONS
        new FMatrix(m,n, fun (i,j) -> 0.0)

    let scalar m n value =
        requires (m > 0 && n > 0) MATRIX_CUSTOMCREATION_BADDIMENSIONS
        new FMatrix(m,n, fun (i,j) -> value)

    let hilbert m n =
        requires (m > 0 && n > 0) MATRIX_CUSTOMCREATION_BADDIMENSIONS
        let newGen = (fun (i,j) -> 1.0 / (float(i) + float(j) - 1.0))
        new FMatrix(m,n,newGen)

    let upperTriangular m n v =
        requires (m > 0 && n > 0) MATRIX_CUSTOMCREATION_BADDIMENSIONS
        let newGen = (fun (i,j) -> if float(i) > float(j) then 0.0 else v)
        new FMatrix(m,n,newGen)

    let lowerTriangular m n v =
        requires (m > 0 && n > 0) MATRIX_CUSTOMCREATION_BADDIMENSIONS
        let newGen = (fun (i,j) -> if float(i) < float(j) then 0.0 else v)
        new FMatrix(m,n,newGen) 

hope you like it

-horacio

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s