Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ML Problem Set 1 #1

Open
YLGH opened this issue Nov 2, 2014 · 0 comments
Open

ML Problem Set 1 #1

YLGH opened this issue Nov 2, 2014 · 0 comments

Comments

@YLGH
Copy link
Owner

YLGH commented Nov 2, 2014

fun area (x,y) = x*y/2.0;

area(3.0,4.0);

1.0 - 0.9 - 0.1;

fun rootplus (a,b,c) = (~b + Math.sqrt(b_b-4.0_a_c))/(2.0_a);

fun eval(a,b,c,x: real) = a_x_x + b*x + c;

val x1 = rootplus(1.0,121.0,11.0);

eval(1.0,121.0,11.0, x1);

val x2 = rootplus(1.22,3.34,2.28);

eval(1.22,3.34,2.28, x2);

fun fact n =
if n = 0 then 1
else n * fact(n-1);

fact(6);

fun interfact (n,total) =
if n = 0 then total
else interfact(n-1, total*n);

interfact(6,1);
(fact(~6);)
(interfact(~6,1);)
(continued)
fun even(n) =
n mod 2 = 0;

fun power2(x,n) =
if n = 1 then x
else if even(n) then power2(x_x,n div 2)
else x_power2(x*x, n div 2): real;

1.0/power2(2.0,2);

fun sumt(n) =
if n = 1 then 1.0
else 1.0/power2(2.0, n-1) + sumt(n-1);

sumt(1);

fun sum2t(x,n) =
if n = 0 then x
else x + sum2t(x/2.0, n-1);

sum2t(2.0, 50);

fun eapprox(n) =
if n = 1 then 1.0
else 1.0/(real(fact(n-1))) + eapprox(n-1); (* ask about more efficient*)

eapprox(10);

fun exp(z,n) =
if n = 0 then 1.0
else power2(z, n-1)/(real(fact(n-1))) + exp(z, n-1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant