Blog

Bird Flocking on GPU - CUDA

Bird Flocking Simulation Bird flocking is an extremely interesting natural phenomenon that have been widely studied as witnessed by the number of papers in literature). I will present here a work on aggregate motion of large number of boids in a virtual environment with the presence of predators using CUDA as computational framework. Collective motion or flocking appears at different fields and scales in nature and several mathematical tools have been developed for analyzing such motions organism are threaten as particles in Brownian motion combined with attraction/repulsion forces Differential equation models Agent based models. The model presented here is based on a work of Reynolds (1987)… Read More »Bird Flocking on GPU - CUDA

C/C++ - Byte to Number Conversion

Byte Number Conversion For a project I'm working on these days I was forced to convert raw byte to several numerical values ( to and from binary format). Bytes are represented in C/C++ as  unsigned char, and std::string are often used as byte buffer as well as old well known raw arrays. I wrote a simple struct that relieve the pain in performing such conversions. It exposes two functions: fromBytes and toBytes.fromBytes takes an additional boolean parameter that takes care of different endianness. Usage is very simple: let's say for instance you have the following 8 bytes into an unsigned long long 00:00:00:00:00:00:00:5E this will output… Read More »C/C++ - Byte to Number Conversion

Music Meeting in Ediburgh

A great experience, that I hope will became an joyful habit, took place last week when a colleague of mine at the Department of Engineering at University of Edinburgh (Kino) told me about a meeting among the researchers/musicians of the university. I was invited to play some music, and I obviously accepted! It was great to meet new smart people and musician from all over the world and share with them delicious food and wine. There were several instrument involved in the performances such as viola, violin, cello and voice. Here two (very) short videos from my performance:   The following was played to fulfill a special request… Read More »Music Meeting in Ediburgh

Largest Prime Number

Largest Prime Number Recently a team at the University of Central Missouri, headed by Curtis Cooper has announced, via press release from the Mersenne organization to have discovered a new largest prime. The number have more than 22M digits, to be precise. It's so large that writing 4 digits per centimeter one would be able to cover the entire distance between Edinburgh and Glasgow! Here the full http://www.filedropper.com/largestprimenumber number. The following is an Haskell micro-script for computing and writing the number to a file (using Haskell because it's lazy input/output allows to write big files to disk without any concern about memory). Compile using using :… Read More »Largest Prime Number

Programming Question - Integer Parity

Programming Question: Given an integer, compute its parity(easy) The parity of an integer is true iff number of set bits (1) is odd, false otherwise. Example: has 5 set bits and hence its parity is true.   Solutions:

Programming Question - Compute GCD

Programming Question: Compute the Greatest Common Divisor of two integers (easy) This question is divided in two parts: you will first asked to write a function that computes the  GCD withouth any space/time constraints. The second part will be more challenching, asking for not using multiplication or division or addition. Part1: write a function that takes two integers as input and returns their gcd using the famous Euclidean algorithm. Part 2: compute the Greatest Common Divisor of two integers without using multiplication addition or division operators (easy) Solutions:

Yet Another one on Fibonacci serie - Knuth multiplication

Fibonacci serie - Knuth multiplication - Java

Leonardo Fibonacci,the Italian mathematician (from Pisa, 1170, one of the most important mathematician of all time) invented the famous serie defined recursively as follows:

    \[F(n) = F(n-1) + F(n-2)\]

    \[F(0) = 0\]

    \[F(1) = 1\]

We all know that as programmers once in life (at least) we will write some piece of code to compute the n_{th} element of the serie. Recursive implementation is straightforward but inefficient, due to the exponential number of recursive calls, that make "hard" to compute numbers bigger that 40. It is very easy to come up with some iterative or memoised implementation, that lowers the complexity to O(n) and allows to efficently compute "any" number of the serie.
In this post we will derive an implementation (JAVA) that have complexity O(log_2(n))1)using results from Knuth, Fibonacci multiplication,1988.Read More »Yet Another one on Fibonacci serie - Knuth multiplication

References   [ + ]

1. using results from Knuth, Fibonacci multiplication,1988

Haskell - Sudoku Solver - List Monad

Haskell Sudoku Solver - List Monad In this article we will write a Sudoku solver in Haskell using the expressive and powerful List Monad to enumerate the solutions trasparently. I assume that the reader has a general understanding of monads (if not read http://www.idryman.org/blog/2014/01/23/yet-another-monad-tutorial/) Su Doku means literally  number place is the name of a popular puzzle game that a special case of the old Latin Square (invented by Leonard Euler). Latin Square force each symbol to appear once in each row and column. In addition to these contraint Sudoku force each symbol to apper one in each sub-matrix. In the general case Sudoku is… Read More »Haskell - Sudoku Solver - List Monad