use_cas Maple type_symb maple = unit Maple.t DynaMoW.symb module DC = DynaMoW_services.Content let ( @@@ ) = DC.(@@@) let ( @:@ ) = DC.(@:@) let gf_of_symb_spec spec = let res = << combstruct[gfsolve](\$(spec)[2],\$(spec)[3],_x) >> in if <:bool< evalb(\$(res) = FAIL) >> then None else Some << subs(\$(res),S(_x)) >> let title (_, egf) = let gftype = if egf then "Exponential" else "Ordinary" in <:text<\$(str:gftype) generating function>> let_service GeneratingFunction (spec : maple) (egf : bool) : DC.sec_entities * maple option with { title = title } = <:unit< with(combstruct) >> ; let gf_opt = gf_of_symb_spec spec in let body = match gf_opt with | Some gf -> <:par<<:dsymb< eval(\$(gf), _x=x) >>>> @:@ begin try let deq = << eval(gfun:-holexprtodiffeq(\$(gf), y(_x)), _x=x) >> in let order = <:int< nops(select(has, indets(\$(deq)), diff)) >> in if order = 0 || order = 1 then DC.ent_null else <:par< It satisfies the following differential equation of order \$(int:order): >> @:@ if <:bool< type(\$(deq), set) >> then <:par< <:dsymb< map(e -> if op(0, e) = `=` then e else e=0 fi, \$(deq)) >> >> else <:par<<:dsymb< \$(deq)=0 >>>> with _ -> DC.ent_null end | None -> <:par<<:dsymb< combstruct[gfeqns](\$(spec)[2],\$(spec)[3],x) >>>> in (DC.section (title (spec, egf)) body, gf_opt)