
map_fst ((z 4).(4)));;
Jugez par vous même : exception Overflow;;
let zmax=30000;;
let rec fact = fun
| 0 -> 1
| 4 -> 24
| n ->
let r=n*fact (n-1) in
if r>zmax then raise Overflow
else r;;
let srt (x,xs) =
if x<0 then (-1,"")
else (
let f=sqrt (float_of_int x) in
let i=int_of_float f in
if x=i*i then (i,"V("^xs^")")
else if x=(i+1)*(i+1) then (i+1,"V("^xs^")")
else (-1,"")
);;
let rec pw x = fun
| 0 -> 1
| n -> let h=n/2 and s=x*x in
if s>zmax && h>0 then s
else (
let r=pw s h in
if n=2*h then r else r*x
);;
let cat = fun
| (_,"") l -> l
| x l -> x::l;;
let rec fus = fun
| [] l -> l
| m (a::l) when fst a=fst (hd m) && string_length(snd a)>=string_length(snd (hd m)) -> fus m l
| m (a::l) when fst a<fst (hd m) -> a::fus m l
| l m -> fus m l;;
let rec half = fun
| (a::b::l) -> a::half l
| l -> l;;
let rec zsort=fun
| [] -> []
| [a] -> [a]
| l -> fus(zsort(half(l)))(zsort(half(tl l)));;
let rec fp f (a:(int*string)list) =
let b=f a in
if a=b then a
else fp f b;;
let rec psi=fun
| [] -> []
| (a::r) ->
let rec u = fun
| [] -> []
| (a::l) ->
let j=(try (fact (fst a),"("^snd a^")!") with _->(-1,"")) in
let g=(try if fst a=0 then raise Overflow else (fact (fst a-1),"G("^snd a^")") with _->(-1,"")) in
let k=srt a in
zsort (cat a (cat g (cat j (cat k (u l))))) in
zsort ((fp u [a])@r);;
(*trace "fp";;*)
let append a b =
zsort (a@b);;
let rec restrict = fun
| [] -> []
| ((x,t) as u::r) -> if x>=0 && x<=zmax then u::restrict r else restrict r;;
let rec crossmap f x = fun
| [] -> []
| (y::r) -> append (restrict (map (fun t->f t y) x)) (crossmap f x r);;
let rec z=fun
| 1 -> [|[];psi [(4,"4")]|]
| n ->
let h=z (n-1) in
let s0=make_string n `4` in
let c=ref [(int_of_string s0,s0)] in
for p=1 to n-1 do
let q=n-p in
c:=append (crossmap (fun (x,xs) (y,ys)->(x+y,"("^xs^")+("^ys^")")) h.(p) h.(q)) !c;
c:=append (crossmap (fun (x,xs) (y,ys)->(x-y,"("^xs^")-("^ys^")")) h.(p) h.(q)) !c;
c:=append (crossmap (fun (x,xs) (y,ys)->(x*y,"("^xs^")*("^ys^")")) h.(p) h.(q)) !c;
c:=append (crossmap (fun (x,xs) (y,ys)->if y=0 || (x mod y)<>0 then (-1,"")
else (x/y,"("^xs^")/("^ys^")")) h.(p) h.(q)) !c;
c:=append (crossmap (fun (x,xs) (y,ys)->(pw x y,"("^xs^")^("^ys^")")) h.(p) h.(q)) !c;
done;
let ret=make_vect (n+1) [] in
for i=0 to n-1 do
ret.(i)<-h.(i)
done;
ret.(n) <- psi !c;
ret;;
let map_fst = map fst;;
let rec iset = fun
| 0 -> []
| n -> (iset (n-1))@[n];;
subtract (iset 100) (