#!/usr/bin/env python2

# Cleverly run Mathematica with the benefit of readline, which
# is something the usual commercial mathematica doesn't provide!
# See
#    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363500

import os, sys
f1 = os.popen('math ', 'w')
f1.flush()
try:
    while True:
        sys.stdout.write('')
        try:
            line = raw_input()
            f1.writelines(line+'\n')
            f1.flush()
        except KeyboardInterrupt:
            f1.close()
            break
except EOFError:
    pass
sys.stdout.write('\n')
sys.exit()
