module Main:
  with "hash.rml"
  datatype tmp   =  V of real list array
                 |  Vec of real list array * real list array  
  relation main: string list => ()

  type intHash = (int, string) Hash.hash
end
 
(* our AST *)
val ast = [[1.0],[2.0],[3.0]]

relation loop =
     rule int_lt(i, max) => true & 
	 int_add(i, 1) => i' &
	 int_real(i') => r &
	 RML.array_update(vli, i', [r]) => vli &
	 array_nth(vli, i) => l &
	 RML.debug_print("\nset:", l) &
	 apply(vli) &
	 loop(i', max, vli)
	 --------------------------------
	 loop(i, max, vli) 
	 
    rule int_ge(i,max) => true
	------------------------------
	loop(i, max, _)
end


relation apply=
   rule let li = [10.0]  & 
        let lli = ast &
        array_vector(arr) => vec &
        array_create(10, li) => vli' &
        list_array(lli) => vli &
        let li_new = [3.0] &
        let k = vli &
        array_setnth(vli', 1, li_new) => vli' &
        array_setnth(vli, 1, li_new) => vli &
        array_setnth(vli', 2, li_new) => vli' &
        array_update(vli', 5, li_new) => vli' &
        array_setnth(vli, 2, li_new) => vli &
        array_add(vli', li_new) => vli' &
        let l = vli' &
        let z = Vec(k, l)
        ------------------------------------
        apply(arr)
end

relation main: string list => () =

(*
   rule int_div(4, 3) => res1 &
        int_div(-4,3) => res2 &
        int_string(res1) => s1 &
        int_string(res2) => s2 &
        print "\ndiv(4,3)=" & print s1 &
        print "\ndiv(-4,3)=" & print s2 &
        print "\n"
        ---------------------------------------
        main (_)
*)

   rule 
(*
        let v = 1 & 
        let v1 = v &
        let v = 2 &
        let v2 = v & 
        let v = 3 &
        v = 3 &
        int_add(v, 1) => v &
        let x = 2 &
        int_mod(7, 5) => res1 &
        int_mod(13,5) => res2 &
        int_mod(10,5) => res3 &
        int_mod(-7,5) => res4 &
        int_mod(7,-5) => res5 &
        real_mod(2.0,0.9) => res6 &
        real_mod(-2.0,0.9) => res7 &
        real_mod(2.0,-0.9) => res8 &
        int_string(res1) => s1 &
        int_string(res2) => s2 &
        int_string(res3) => s3 &
        int_string(res4) => s4 &
        int_string(res5) => s5 &
        real_string(res6) => s6 &
        real_string(res7) => s7 &
        real_string(res8) => s8 &
        print "\nmod(7,5)=" & print s1 &
        print "\nmod(13,5)=" & print s2 &
        print "\nmod(10,5)=" & print s3 &
        print "\nmod(-7,5)=" & print s4 &
        print "\nmod(7,-5)=" & print s5 &
        print "\nmod(2,0.9)=" & print s6 &
        print "\nmod(-2,0.9)=" & print s7 &
        print "\nmod(2,-0.9)=" & print s8 &
        print "\n"
*)

	print("1e-006:") &
	realString(1e-006) => s1 & print(s1) &
	print("\n") &
	print("1.2e-006:") & 
	realString(1.2e-006) => s2 & print(s2) & 
	print("\n") &
	print("1.1e+006:") & 
	realString(1.1e-006) => s2 & print(s2) & 
	print("\n") &
	print("7.00008266325159e-011:") & 
	realString(7.00008266325159e-011) => s2 & print(s2) & 
	print("\n")
        ---------------------------------------
        main (_)



end
