restart: n := 6: # Change to whatever you wish # g(n) calcutates the number-theoretic function # considered by Collatz 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));