various mathematica helper functions