User:Coderjoe/Sandbox2: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1:
=={{header|OzPerl}}==
<lang perl>use Math::Complex ':trig';
To be executed in the REPL.
 
sub compose {
<lang oz>declare
my ($f, $g) = @_;
end
sub {
$f -> ($g -> (@_));
};
};
 
my $cube = sub { $_[0] ** (3) };
fun {Compose F G}
my $croot = funsub { $_[0] ** (1/3) X};
{F {G X}}
end
end
 
my @flist1 = ( \&Math::Complex::sin, \&Math::Complex::cos, $cube );
fun {Cube X} X*X*X end
my @flist2 = ( \&asin, \&acos, $croot );
 
print join "\n", map {
fun {CubeRoot X} {Number.pow X 1.0/3.0} end
compose($flist1[$_], $flist2[$_]) -> (0.5)
} 0..2;</lang>
 
=={{header|PARI/GPPerl 6}}==
in
{{works with|PARI/GPRakudo|22011.4.2 and above06}}
 
<lang perl6>sub compose (&g, &f) { return { g f $^x } }
for
F in [Float.sin Float.cos Cube]
I in [Float.asin Float.acos CubeRoot]
do
{Show {{Compose I F} 0.5}}
end
</lang>
 
my $x = *.sin;
=={{header|PARI/GP}}==
my $xi = *.asin;
{{works with|PARI/GP|2.4.2 and above}}
my $y = *.cos;
<lang parigp>compose(f,g)={
my $yi = *.acos;
x -> f(g(x))
my $z = * ** 3;
};
my $zi = * ** (1/3);
 
do
fcf()={
my @functions = $x, $y, $z;
my(A,B);
my @inverses = $xi, $yi, $zi;
A=[x->sin(x), x->cos(x), x->x^2];
B=[x->asin(x), x->acos(x), x->sqrt(x)];
for @functions Z @inverses { say compose($^g, $^f)(.5) }</lang>
for(i=1,#A,
Output:
print(compose(A[i],B[i])(.5))
<pre>0.5
)
0.5
};</lang>
0.5</pre>
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>
Anonymous user