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