restart: # g(n) calcutates the number-theoretic function considered by Collatz n := 6: # Change to whatever you wish interface(screenwidth=72); g := proc(n:posint) local m; m := modp(n,3); if m = 0 then 2*n/3; elif m=1 then (4*n-1)/3; else (4*n+1)/3; fi; end: print(`g(` .n. `)` = g(n)); g(6) = 4