-
Notifications
You must be signed in to change notification settings - Fork 1
/
translation.ss
120 lines (116 loc) · 2.75 KB
/
translation.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#lang scheme/base
(provide Scheme->Mathematica
Mathematica->Scheme)
(define (translate table)
(lambda (exp)
(let ((op (hash-ref table (car exp) #f)))
(cond ((symbol? op)
(cons op (cdr exp)))
((procedure? op)
(apply op (cdr exp)))
(else
exp)))))
(define Scheme->Mathematica
(translate
(make-immutable-hasheqv
`((* . Times)
(- . ,(case-lambda
((x) `(Minus ,x))
((x . y) `(Subtract ,x (Plus ,@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-hasheqv
`((Times . *)
(Plus . +)
(Less . <)
(LessEqual . <=)
(Equal . =)
(Greater . >)
(GreaterEqual . >=)
(ArcCos . acos)
(And . and)
(Arg . angle)
(ArcSin . asin)
(ArcTan . atan)
(CompoundExpression . begin)
(Ceiling . ceiling)
(Cos . cos)
(Denominator . denominator)
(DirectedInfinity . ,(lambda (z)
(case z
((1) +inf.0)
((-1) -inf.0)
(else `(DirectedInfinity ,z)))))
(Exp . exp)
(Power . expt)
(Floor . floor)
(GCD . gcd)
(If . if)
(Im . imag-part)
(LCM . lcm)
(List . ,vector)
(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 . ,/)
(Complex . ,make-rectangular)))))