Images, snippets, snapshots, math

View Gabriele Lami's profile on LinkedIn

lunedì 29 settembre 2008

xml viewer in Scala

This is a snapshot of a program thought to show an xml

The xml source for this tree is here
The idea is to create a graphical editor for xml and processDefiniton
of Jbpm.
Soon I'll post some code ...

venerdì 26 settembre 2008

Haar wavelet transform in Scala

This is my first try to write a wavelet(ondine in Italian) transform in Scala.
Naturally i've choose Haar wavelet transform, the simplest!
This is the core of the transformation:

def waveletCalc( values: List[Double] ):List[List[Double]]=
haarCalc( values , List( ) ).reverse

def haarCalc( vals: List[Double], cc: List[List[Double]] )
:List[List[Double]] =
vals.length / 2 match {
case 1 => cc ::: List( List((vals(0) - vals(1) ) / 2 ) ,
List(( vals(0) + vals(1) ) / 2 ))
case _ => haarCalc( vals.indices.dropRight(vals.length/2)
.map(_*2).map(el=>(vals(el) + vals(el+1))/2),
cc ::: List( vals.indices.dropRight(
(vals (el) - vals(el + 1))/2)))

The algorithm is recursive and returns as a result a list of lists.
This arrangement is the most convenient since a base of wavelets has two indexes.
Soon i'll try to post the complete class with the inverse transform and a brief
description on this particular wavelets transform.
I strongly recommend to copy and paste the code in an editor to read it better...
you can find a more complete code here

mercoledì 24 settembre 2008

Algebraic group

Today I started to write a class in Scala to represent a group (in the mathematical sense).
To test closure, i.e.:

the code I wrote is:

def closure( ): Boolean =
el => elements.forall(
el2 => elements.exists(
el2.*(el, this).name == ) ) )

'elements' is the list of all group elements and and each element has a different 'name'.
The following piece of code is the product of two elements.

  el2.*(el, this)

the * operator is defined as follows:

def *( b : groupElement ,group: genericGroup ) : groupElement

the code is not optimized, but it is amazing how, in this language,
we can write a test like this in a way so simple!
this is only a snippet of the entire code...
I hope to post the complete code soon

a Snapshot of my new Jung-Scala project

This is a snapshot from my first try to use
Jung (Java Universal Network/Graph Framework)
in a Scala project

lunedì 22 settembre 2008

Fast Fourier transform

Fast Fourier transform in Scala

domenica 7 settembre 2008

little scala snippet

def showRow(arra: Array[int], molt: int, mod: int ,unitari : boolean ):Array[int] = {
val a2 = s => ( s * molt ) % mod )

if ( unitari )
println ( s => if ( s == 1 s == ( mod -1 ) ) 1 else 0 ).toString )
println( a2.toString )

def shoMatr( mod: int , unitari : boolean ) {

println( if ( unitari ) "elementi unitari" else "tabella moltiplicativa" )

val array = new Array[int]( mod - 1 ) s => s + 1 )

array.foreach( p => showRow( array , ( array indexOf p ) + 1 , mod , unitari ) )