## martedì 29 dicembre 2009

Verlet integration algorithm written in 3 minutes

-- Verlet integration

projOneTwo ( a, b, c , d ,e ) = ( a, b)

nextStepInt (_ ,_ , 0 ,_ ,_ ) = []
nextStepInt ( xt ,vt , n , acc , h ) =
let
atph = acc . ( xt + ) $h vtph = vt + atph * h * 0.5 xtph = xt + h * vt + 0.5 * acc xt * h^2 in ( xtph, vtph , n-1 , acc , h ) : nextStepInt ( xtph, vtph , n-1 , acc , h ) timeInt ( xt ,vt , n , acc , h ) = map ( projOneTwo )$ nextStepInt ( xt ,vt , n , acc , h )

example ( spring ) :
timeInt (0 , 1 , 10000 , (\x -> 0.1 * ( - x ) ) , 0.2 )

## giovedì 24 dicembre 2009

### my delicious

now i'm in delicious: http://delicious.com/koteth

## martedì 8 dicembre 2009

Is only a fixed-point iteration over this function:

lgs x r = r * x * exp(- x )

### Dollar $operator in Haskell Do you know what is$ operator in Haskell?
$means simply , 'apply the left function at the right value'. f$ x := f x

it seems really trivial, isn't it ?
But, for example in this kind of situation, is really usefull:

zipWith ( $) ( cycle [ \x -> div (x + 1) 2 , \x -> div x 2 ] ) [1..] here you have a infinite list of function: a = cycle [ \x -> div (x + 1) 2 , \x -> div x 2 ] ( ie: [\x -> div (x + 1) 2 , \x -> div x 2 , \x -> div (x + 1) 2 , \x -> div x 2, ... ] ) and you want to apply every element of the list at the element at the same index in the second list: b = [1..] zipWith, for every index i takes the element a(i) of the left list and b(i) of the right list and execute what is requested inside the parentheses. In this situation is specified$ so:

a(i) $b(i ) := a(i) ( b(i) ) the result must be the following: [ 1 ,1 , 2, 2 , 3 ,3 ... and so on. ### Prime Numbers in haskell well, do you want to know how to find 'prime numbers' in a quick and dirty way using Haskell ? try this! import Data.List nubBy ( \x y -> mod y x == 0 ) [2..] Haskell is so easy and charming... ( ps: if you want to speed up a little bit: nubBy ( \x y -> ( x*x-1 <= y ) && ( mod y x == 0 ) ) [2..] ) ## giovedì 20 agosto 2009 ### re: Mandelbrot Set in Haskell import Data.Complex conv p=(\n->".,:;|!([$O0*%#@?"!!(n-1))(ceiling (p*8)::Int)
gr=map(\y->[(x:+y)|x<-[-2,-1.97..0.7]])[-1.2,-1.13..1.2]
--px w=magnitude(foldl1(\z c ->z^2 +c)(replicate 10 w))
px w=(magnitude.last.take 10.takeWhile(\r->(magnitude r )<6).iterate(\z->z^2+w))w
image=map((map(\el->case(px el<2)of{true->conv(px el);_->' '})))gr
main=mapM_ putStrLn image

better...

import Data.Complex
gr = map(\y-> [( x:+y )|x<-[-3,-2.95..1]])[-2,-1.9..2]
px (a:+b) = magnitude(foldl (\z c ->z^2+c) 0 (take 10([((a*x):+b)|x<-[1,1..]])))
image = map((map(\el->case(px el<2)of{true->'*';_ ->'-'})))gr
main = mapM_ putStrLn ( (map(\el->show el) )image )

A first interpretation ( a little bit unsatisfactory ) of the Mandelbrot set in Haskell

## martedì 18 agosto 2009

The core of numbers post in Haskell:

idens p q x = case ( rem ( x ^ 2 ) p ) of { 1 -> 1 ; _ -> 0 }
numList p x = map ( idens p x ) ( map ( x * ) [ 1..( p-1 ) ] )
matIde p = map ( numList p ) [ 1..(p-1) ]

## domenica 16 agosto 2009

### The Path of St. Augustine

Here you can find info about "Il Cammino di Sant'Agostino ( The Path of St. Augustine )" in Italy.

### Quinta da Regaleira

( Mystic Cristina )

## domenica 19 luglio 2009

### Mandelbrot in Rebol

And this is my interpretation of Mandelbrot fractal using Rebol:

This language allow to write a gui using few rows of code.
There is still a problem with zoom functionality ( I hope to fix it soon ).

## domenica 12 luglio 2009

### Latent Semantic Indexing ( LSI )

LSI is a simple but powerful indexing and retrieval method that is able to identify patterns in the relationships between the terms and concepts contained in a text corpus.
The mathematics of LSI easy to understand cause is based entirely on vector and matrix algebra.
I'll post soon some code ( if someone needs code, my mail is always open ).

## sabato 11 luglio 2009

### Peano in Js

You Can find Here 'peano', my interpretation of Peano Curve in jQuery ( javascript ) using canvas ( if you insist to use iexplorer you must download also exCanvas.pack.js to see something ).
To see this image you need only the last jQuery js library and a browser...
Ah, you also need to rename the file with 'HTML' as extension.

### Metamorphosis ( Music animation )

http://vimeo.com/1747316?pg=embed&sec=1747316

## lunedì 6 luglio 2009

### context-free art

A little piece of context-free art:

circles.cfdg
startshape trails
background {b -1}
rule trail {
trail{
sat 0.001
a -0.001
r 0.4
y 0.5
s 0.999y 0.5
}
SQUARE{s 1}
}
rule trail 0.001 {
trail{flip 90} ring{x 5}
}
rule trails {
140*{r 120}trail{b 1 sat 0 h 100}
}
rule ring {
120*{r 5}SQUARE{s 4 0.5 y 6 h 100}
}


### Rebol Search File

Another little Rebol program:

rebTest.r
REBOL [Title: "Ricerca"]mainWin: layout [banner green "Ricerca Parola" box brick 580x2text "Parola da cercare"infi1: field infi2: field ""text "nome file"selFile: text-list data read %. [infi2/data: valueinfi2/text: valueshow infi2] button "Ricerca"  [fil1: to-file infi2/datatext: read fil1outOne: copy ""while [ text: find text infi1/data ] [   formattedStuff:  reduce [ " ( " index?  text  " ) " copy/part text  10  ]append outOne "^/ ( indice ) riga:   "append outOne form formattedStufftext: next text]tuno/text: form outOne show tuno]at 260x70tuno: area 340x300 acrosstext "Risultato"]windowHelp: layout [backcolor linenh2 "Help Window"text 300 { Inserisci la parola da ricercare e il nome del file...}button "Chiudimi" [ unview/only windowHelp ]]windowHelp/offset: mainWin/offset + (mainWin/size * 1x0) + 10x0view/new mainWinview/new windowHelpdo-events

### 'Text Categorization with SVM

A really nice pdf about 'Text Categorization with Support Vector Machines' ( from University of Dortmund ) :

http://www.cs.cornell.edu/People/tj/publications/joachims_97b.pdf

REBOL [Title: "Numbers Test"]ena: 121positions: []dimPal: 3unitar: func [ ele enne ][ either (( (ele // enne) == 1 ) or (( ele // enne) == (enne - 1)))[ 1  ] ["-"] ]evaluateUni: func [ en ] [for j 1 en 1[ st: copy ""for i 1 en 1[append st unitar i * j ensr: square-root enif ( unitar i * j en ) == 1  [ append positions ( as-pair i j  ) * 350 / en + 23x23 ]]]positions]evaluateUni enarefre: does[positions: copy []evaluateUni enapis: copy []posi: copy positionsforeach p posi[ insert tail pis  reduce[ 'fill-pen 160.209.215.100 'circle p dimPal ]  ]out: form ( length? positions ) / 2 == ( ena - 1 )insert tail pis reduce [  'text 230x5 join "numero primo: "   out ]scrn/effect/draw: copy []append scrn/effect/draw pisshow scrn]refreNoEval: does[pis: copy []posi: copy positionsforeach p posi[ insert tail pis  reduce[ 'fill-pen 160.209.215.100 'circle p dimPal ]  ]out: form ( length? positions ) / 2 == ( ena - 1 )insert tail pis reduce [  'text 230x5 join "numero primo: "   out ]scrn/effect/draw: copy []append scrn/effect/draw pisshow scrn]lay: layout [scrn: box 400x400 black effect [draw [ text "unit" ]rotate 50gradmul 180.180.210 180.60.255]slider 200x16 ena / 300 [ena: to-integer value * 300inpNum/data: form enainpNum/text: form enashow inpNumrefre]inpNum: field form ena [print to-integer inpNum/textena: to-integer inpNum/text ]at 330x460btn "Change"  [refre]slider 100x15 dimPal / 10 [dimPal: to-integer  value    * 10refreNoEval]]view lay