(module translation mzscheme
(define (translate hash-table)
(lambda (exp)
(let ((op (hash-table-get hash-table
(car exp)
(lambda () #f))))
(cond ((symbol? op)
(cons op (cdr exp)))
(op (apply op (cdr exp)))
(else
exp)))))
(define Scheme->Mathematica
(translate
(make-immutable-hash-table
`((* . Times)
(- . ,(case-lambda
((x) (list 'Minus x))
((x y) (list 'Subtract x y))
((x . y)
`(Plus ,x
,@(map (lambda (z)
(list '- z))
y)))))
(+ . Plus)
(/ . Divide)
(< . Less)
(<= . LessEqual)
(= . Equal)
(> . Greater)
(>= . GreaterEqual)
(abs . Abs)
(acos . ArcCos)
(and . And)
(angle . Arg)
(asin . ArcSin)
(atan . ArcTan)
(begin . CompoundExpression)
(ceiling . Ceiling)
(cos . Cos)
(denominator . Denominator)
(exp . Exp)
(expt . Power)
(floor . Floor)
(gcd . GCD)
(if . If)
(imag-part . Im)
(lcm . LCM)
(list . List)
(log . Log)
(magnitude . Abs)
(max . Max)
(min . Min)
(modulo . Mod)
(negative? . Negative)
(not . Not)
(number? . NumberQ)
(numerator . Numerator)
(odd? . OddQ)
(or . Or)
(positive? . Positive)
(quotient . Quotient)
(rationalize . Rationalize)
(round . Round)
(sin . Sin)
(sqrt . Sqrt)
(tan . Tan)
(truncate . IntegerPart)))))
(define Mathematica->Scheme
(translate
(make-immutable-hash-table
`((Times . *)
(Plus . +)
(Less . <)
(LessEqual . <=)
(Equal . =)
(Greater . >)
(GreaterEqual . >=)
(ArcCos . acos)
(And . and)
(Arg . angle)
(ArcSin . asin)
(ArcTan . atan)
(Author . ,(case-lambda
(() "朱崇恺/Zhu Chongkai")
(any (cons 'Author any))))
(CompoundExpression . begin)
(Ceiling . ceiling)
(Cos . cos)
(Denominator . denominator)
(Exp . exp)
(Power . expt)
(Floor . floor)
(GCD . gcd)
(If . if)
(Im . imag-part)
(LCM . lcm)
(List . list)
(Log . log)
(Abs . magnitude)
(Max . max)
(Min . min)
(Mod . modulo)
(Negative . negative?)
(Not . not)
(NumberQ . number?)
(Numerator . numerator)
(OddQ . odd?)
(Or . or)
(Positive . positive?)
(Quotient . quotient)
(Rationalize . rationalize)
(Round . round)
(Sin . sin)
(Sqrt . sqrt)
(Tan . tan)
(IntegerPart . truncate)
(Rational . ,(lambda (n d)
(/ n d)))
(Complex . ,(lambda (r i)
(make-rectangular r i)))))))
(provide Scheme->Mathematica
Mathematica->Scheme))