User:Coderjoe/Sandbox2: Difference between revisions

From Rosetta Code
Content added Content deleted
(begin testing for busted geshi language)
 
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
<lang ActionScript>function compose(f:Function, g:Function):Function {
<lang parigp>compose(f,g)={
return function(x:Number) {return f(g(x));};
x -> f(g(x))
}
};
var functions:Array = [Math.cos, Math.tan, function(x:Number){return x*x;}];
var inverse:Array = [Math.acos, Math.atan, function(x:Number){return Math.sqrt(x);}];


fcf()={
function test() {
my(A,B);
for (var i:uint = 0; i < functions.length; i++) {
A=[x->sin(x), x->cos(x), x->x^2];
trace(compose(functions[i], inverse[i])(0.5));
B=[x->asin(x), x->acos(x), x->sqrt(x)];
}
for(i=1,#A,
}</lang>
print(compose(A[i],B[i])(.5))
)
};</lang>
Usage note: In Pari/GP 2.4.3 the vectors can be written as
<lang parigp> A=[sin, cos, x->x^2];
B=[asin, acos, x->sqrt(x)];</lang>

Latest revision as of 20:38, 16 July 2011

<lang parigp>compose(f,g)={

 x -> f(g(x))

};

fcf()={

 my(A,B);
 A=[x->sin(x), x->cos(x), x->x^2];
 B=[x->asin(x), x->acos(x), x->sqrt(x)];
 for(i=1,#A,
   print(compose(A[i],B[i])(.5))
 )

};</lang> Usage note: In Pari/GP 2.4.3 the vectors can be written as <lang parigp> A=[sin, cos, x->x^2];

 B=[asin, acos, x->sqrt(x)];</lang>