(* The Zelus compiler, version 2.2-dev (2025-06-16-15:24) *) open Common open Ztypes open Solvers let g = 9.81 let y0 = 50. let y'0 = 0. type ('g , 'f , 'e , 'd , 'c , 'b , 'a) _ball = { mutable major_50 : 'g ; mutable h_60 : 'f ; mutable h_58 : 'e ; mutable i_56 : 'd ; mutable x_55 : 'c ; mutable y'_52 : 'b ; mutable y_51 : 'a } let ball (cstate_74:Ztypes.cstate) = let ball_alloc _ = cstate_74.cmax <- (+) cstate_74.cmax 2 ; cstate_74.zmax <- (+) cstate_74.zmax 1; { major_50 = false ; h_60 = 42. ; h_58 = (42.:float) ; i_56 = (false:bool) ; x_55 = { zin = false; zout = 1. } ; y'_52 = { pos = 42.; der = 0. } ; y_51 = { pos = 42.; der = 0. } } in let ball_step self ((_time_49:float) , ()) = ((let (cindex_75:int) = cstate_74.cindex in let cpos_77 = ref (cindex_75:int) in let (zindex_76:int) = cstate_74.zindex in let zpos_78 = ref (zindex_76:int) in cstate_74.cindex <- (+) cstate_74.cindex 2 ; cstate_74.zindex <- (+) cstate_74.zindex 1 ; self.major_50 <- cstate_74.major ; (if cstate_74.major then for i_1 = cindex_75 to 1 do Zls.set cstate_74.dvec i_1 0. done else ((self.y'_52.pos <- Zls.get cstate_74.cvec !cpos_77 ; cpos_77 := (+) !cpos_77 1) ; (self.y_51.pos <- Zls.get cstate_74.cvec !cpos_77 ; cpos_77 := (+) !cpos_77 1))) ; (let (result_79:float) = let h_59 = ref (infinity:float) in let encore_57 = ref (false:bool) in (if self.i_56 then self.y'_52.pos <- y'0) ; (let (l_54:float) = self.y'_52.pos in begin match self.x_55.zin with | true -> encore_57 := true ; self.y'_52.pos <- ( *. ) (-0.8) l_54 | _ -> () end; self.h_58 <- (if !encore_57 then 0. else infinity) ; h_59 := min !h_59 self.h_58 ; self.h_60 <- !h_59 ; (if self.i_56 then self.y_51.pos <- y0) ; self.i_56 <- false ; self.x_55.zout <- (~-.) self.y_51.pos ; self.y'_52.der <- (~-.) g ; self.y_51.der <- self.y'_52.pos ; self.y_51.pos) in cstate_74.horizon <- min cstate_74.horizon self.h_60 ; cpos_77 := cindex_75 ; (if cstate_74.major then (((Zls.set cstate_74.cvec !cpos_77 self.y'_52.pos ; cpos_77 := (+) !cpos_77 1) ; (Zls.set cstate_74.cvec !cpos_77 self.y_51.pos ; cpos_77 := (+) !cpos_77 1)) ; ((self.x_55.zin <- false))) else (((self.x_55.zin <- Zls.get_zin cstate_74.zinvec !zpos_78 ; zpos_78 := (+) !zpos_78 1)) ; zpos_78 := zindex_76 ; ((Zls.set cstate_74.zoutvec !zpos_78 self.x_55.zout ; zpos_78 := (+) !zpos_78 1)) ; ((Zls.set cstate_74.dvec !cpos_77 self.y'_52.der ; cpos_77 := (+) !cpos_77 1) ; (Zls.set cstate_74.dvec !cpos_77 self.y_51.der ; cpos_77 := (+) !cpos_77 1)))) ; Bigarray.(Array1.of_array Float64 c_layout [| result_79 |])))) in let ball_reset self = (self.i_56 <- true:unit) in Node { alloc = ball_alloc; step = ball_step ; reset = ball_reset } type ('f , 'e , 'd , 'c , 'b , 'a) _main = { mutable i_73 : 'f ; mutable major_62 : 'e ; mutable h_72 : 'd ; mutable i_70 : 'c ; mutable h_68 : 'b ; mutable t_63 : 'a } let main (cstate_80:Ztypes.cstate) = let Node { alloc = i_73_alloc; step = i_73_step ; reset = i_73_reset } = ball cstate_80 in let main_alloc _ = cstate_80.cmax <- (+) cstate_80.cmax 1; { major_62 = false ; h_72 = 42. ; i_70 = (false:bool) ; h_68 = (42.:float) ; t_63 = { pos = 42.; der = 0. }; i_73 = i_73_alloc () (* continuous *) } in let main_step self ((time_61:float) , ()) = ((let (cindex_81:int) = cstate_80.cindex in let cpos_83 = ref (cindex_81:int) in cstate_80.cindex <- (+) cstate_80.cindex 1 ; self.major_62 <- cstate_80.major ; (if cstate_80.major then for i_1 = cindex_81 to 0 do Zls.set cstate_80.dvec i_1 0. done else ((self.t_63.pos <- Zls.get cstate_80.cvec !cpos_83 ; cpos_83 := (+) !cpos_83 1))) ; (let (result_85) = let h_71 = ref (infinity:float) in (if self.i_70 then self.h_68 <- (+.) time_61 0.) ; (let (z_69:bool) = (&&) self.major_62 ((>=) time_61 self.h_68) in self.h_68 <- (if z_69 then (+.) self.h_68 0.01 else self.h_68) ; h_71 := min !h_71 self.h_68 ; self.h_72 <- !h_71 ; self.i_70 <- false ; self.t_63.der <- 1. ; (let (y_64:float) = (i_73_step self.i_73 (time_61 , ())).{0} in (begin match z_69 with | true -> Printf.printf "%.10e\t%.10e\n" self.t_63.pos y_64 | _ -> () end) ; Bigarray.(Array1.create Float64 c_layout 0))) in cstate_80.horizon <- min cstate_80.horizon self.h_72 ; cpos_83 := cindex_81 ; (if cstate_80.major then (((Zls.set cstate_80.cvec !cpos_83 self.t_63.pos ; cpos_83 := (+) !cpos_83 1))) else (((Zls.set cstate_80.dvec !cpos_83 self.t_63.der ; cpos_83 := (+) !cpos_83 1)))) ; result_85))) in let main_reset self = ((self.i_70 <- true ; self.t_63.pos <- 0. ; i_73_reset self.i_73 ): unit) in Node { alloc = main_alloc; step = main_step ; reset = main_reset }