aboutsummaryrefslogtreecommitdiff
path: root/src/interp/rulesets.boot
blob: a2a05ed5ceb2ceeefdf7e331cf7e916083533680 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
-- Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
-- All rights reserved.
-- Copyright (C) 2007-2008, Gabriel Dos Reis.
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
--     - Redistributions of source code must retain the above copyright
--       notice, this list of conditions and the following disclaimer.
--
--     - Redistributions in binary form must reproduce the above copyright
--       notice, this list of conditions and the following disclaimer in
--       the documentation and/or other materials provided with the
--       distribution.
--
--     - Neither the name of The Numerical Algorithms Group Ltd. nor the
--       names of its contributors may be used to endorse or promote products
--       derived from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import vmlisp
namespace BOOT

$ruleSetsInitialized := false

--% Mode and Type Resolution Rule Data and Ruleset Creation

--% resolveTT Rules

-- These rules are applied only once at the outermost position of a term
-- some things can't be done by term rewriting conveniently (e.g. set
-- difference), so a form is created which is interpreted by
-- resolveTTRed later. The meanings of these forms are:
-- Incl(x,y): y if x is a member of y, failed otherwise
-- SetEqual(x,y): x if y is a permutation of x, failed otherwise
-- SetComp(x,y): x-y, if y is a subset of x, failed otherwise
-- SetInter(x,y): intersection of x and y, if nonempty, failed otherwise
-- SetDiff(x,y): x-y, if x and y have a nonempty intersection, failed ...

-- These first rules will be expanded for each of MP, DMP and NDMP

$mpolyTTRules == '( _
  ((Resolve (RN) (mpoly1 x t1)) . (mpoly1 x (Resolve (RN) t1))) _
  ((Resolve (UP x t1) (mpoly1 y t2)) . _
    (Resolve t1 (mpoly1 (Incl x y) t2))) _
  ((Resolve (mpoly1 x t1) (G t2)) . _
    (mpoly1 x (G (VarEqual t1 t2)))) _
  ((Resolve (VARIABLE x) (mpoly1 y t2)) . _
    (mpoly1 (Incl x y) t2)) _
  ((Resolve (mpoly1 x t1) (mpoly1 y t2)) . _
    (mpoly1 (SetEqual x y) (Resolve t1 t2))) _
  ((Resolve (mpoly1 x t1) (mpoly1 y t2)) . _
    (mpoly1 x (Resolve t1 (mpoly1 (SetComp y x) t2)))) _
  ((Resolve (mpoly1 x t1) (mpoly1 y t2)) . _
    (mpoly1 y (Resolve (mpoly1 (SetComp x y) t1) t2))) _
  ((Resolve (mpoly1 x t1) (mpoly1 y t2)) . _
    (mpoly1 (SetInter x y) (Resolve _
      (mpoly1 (SetDiff x y) t1) (mpoly1 (SetDiff y x) t2)))) _
  )

-- These are the general rules, excluding those above.

$generalTTRules == '( _
  ((Resolve (L (L t1)) (M t2)) . (M (Resolve t1 t2))) _
  ((Resolve (EQ t1) (B)) . (B)) _
  ((Resolve (SY) t1) . (Resolve (P (I)) t1)) _
  ((Resolve (M t1) (SM x t2)) . (M (Resolve t1 t2))) _
  ((Resolve (M t1) (RM x y t2)) . (M (Resolve t1 t2))) _
  ((Resolve (SM x t1) (RM y y t2)) . _
    (SM (VarEqual x y) (Resolve t1 t2))) _
  ((Resolve (V t1) (L t2)) . (V (Resolve t1 t2))) _
  ((Resolve (FF t1) (FR t2)) . (FR (Resolve t1 t2))) _
  ((Resolve (F) (RN)) . (F) ) _
 _
  ((Resolve (OV x) (OV y)) . (OV (SetUnion x y))) _
  ((Resolve (P t1) (UP y t2)) . (Resolve (P t1) t2)) _
 _
  ((Resolve (UP y t1) (G t2)) . (UP y (G (VarEqual t1 t2)))) _
  ((Resolve (P t1) (P t2)) . (P (Resolve t1 t2))) _
  ((Resolve (G t1) (G t2)) . (G (Resolve t1 t2))) _
  ((Resolve (G t1) (P t2)) . (P (G (VarEqual t1 t2)))) _
 _
  ((Resolve (AF t1) (EF t2)) . (EF (Resolve t1 t2))) _
  ((Resolve (AF t1) (LF t2)) . (LF (Resolve t1 t2))) _
  ((Resolve (AF t1) (FE t2)) . (FE (Resolve t1 t2))) _
  ((Resolve (EF t1) (LF t2)) . (LF (Resolve t1 t2))) _
  ((Resolve (EF t1) (FE t2)) . (FE (Resolve t1 t2))) _
  ((Resolve (LF t1) (FE t2)) . (FE (Resolve t1 t2))) _
 _
  ((Resolve (RN) (P t1)) . (P (Resolve (RN) t1))) _
  ((Resolve (RN) (UP x t1)) . (UP x (Resolve (RN) t1))) _
  ((Resolve (RN) (UPS x t1)) . (UPS x (Resolve (RN) t1))) _
  ((Resolve (RN) (CFPS x t1)) . (CFPS x (Resolve (RN) t1))) _
 _
  ((Resolve (RR) (EF t1)) . (EF (Resolve (RR) t1))) _
  ((Resolve (P t1) (AF t2)) . (AF (Resolve t1 t2 ))) _
  ((Resolve (P t1) (EF t2)) . (EF (Resolve t1 t2 ))) _
  ((Resolve (P t1) (LF t2)) . (LF (Resolve t1 t2 ))) _
 _
  ((Resolve (MP x t1) (DMP y t2)) . _
    (MP (SetEqual x y) (Resolve t1 t2))) _
  ((Resolve (MP x t1) (DMP y t2)) . _
    (MP x (Resolve t1 (DMP (SetComp y x) t2)))) _
  ((Resolve (MP x t1) (DMP y t2)) . _
    (MP y (Resolve (MP (SetComp x y) t1) t2))) _
  ((Resolve (MP x t1) (DMP y t2)) . _
    (MP (SetInter x y) (Resolve _
      (MP (SetDiff x y) t1) (DMP (SetDiff y x) t2)))) _
 _
  ((Resolve (MP x t1) (NDMP y t2)) . _
    (MP (SetEqual x y) (Resolve t1 t2))) _
  ((Resolve (MP x t1) (NDMP y t2)) . _
    (MP x (Resolve t1 (NDMP (SetComp y x) t2)))) _
  ((Resolve (MP x t1) (NDMP y t2)) . _
    (MP y (Resolve (MP (SetComp x y) t1) t2))) _
  ((Resolve (MP x t1) (NDMP y t2)) . _
    (MP (SetInter x y) (Resolve _
      (MP (SetDiff x y) t1) (NDMP (SetDiff y x) t2)))) _
 _
  ((Resolve (DMP x t1) (NDMP y t2)) . _
    (DMP (SetEqual x y) (Resolve t1 t2))) _
  ((Resolve (DMP x t1) (NDMP y t2)) . _
    (DMP x (Resolve t1 (NDMP (SetComp y x) t2)))) _
  ((Resolve (DMP x t1) (NDMP y t2)) . _
    (DMP y (Resolve (DMP (SetComp x y) t1) t2))) _
  ((Resolve (DMP x t1) (NDMP y t2)) . _
    (DMP (SetInter x y) (Resolve _
      (DMP (SetDiff x y) t1) (NDMP (SetDiff y x) t2)))) _
  )

-- The following creates the ruleset

createResolveTTRules() ==
  -- expand multivariate polynomial rules
  mps := '(MP DMP NDMP)
  mpRules := "append"/[substitute(mp,'mpoly1,$mpolyTTRules) for mp in mps]
  $Res := CONS('(t1 t2 x y),
    EQSUBSTLIST($nameList,$abList,append($generalTTRules,mpRules)))
  true

--% resolveTM Rules

-- Same rules as for resolveTT, with two exceptions:
-- Diff(x,y): removes y from x, if possible, failed otherwise
-- SetIncl(x,y): y if x is a subset of y, failed otherwise

-- These first rules will be expanded for each of MP, DMP and NDMP

$mpolyTMRules == '( _
  ((Resolve (mpoly1 x t1) (P t2)) . (Resolve t1 (P t2))) _
  ((Resolve (mpoly1 (x) t1) (UP x t2)) . (UP x (Resolve t1 t2))) _
  ((Resolve (mpoly1 x t1) (UP y t2)) . _
    (UP y (Resolve (mpoly1 (Diff x y) t1) t2))) _
  ((Resolve (UP x t1) (mpoly1 y t2)) . _
    (Resolve t1 (mpoly1 (Incl x y) t2))) _
  ((Resolve (VARIABLE x) (mpoly1 y t2)) . _
    (mpoly1 (Incl x y) (Resolve (I) t2))) _
  ((Resolve (mpoly1 x t1) (mpoly2 y t2)) . _
    (Resolve t1 (mpoly2 (SetIncl x y) t2))) _
  ((Resolve (mpoly1 x t1) (mpoly2 y t2)) . _
    (mpoly2 y (Resolve (mpoly1 (SetComp x y) t1) t2))) _
  ((Resolve (mpoly1 x t1) (mpoly2 y t2)) . _
    (Resolve (mpoly1 (SetDiff x y) t1) (mpoly2 y t2))) _
 )

-- These are the general rules, excluding those above.

$generalTMRules == '( _
  ((Resolve (VARIABLE x) (P t1)) . (P (Resolve (I) t1))) _
  ((Resolve (VARIABLE x) (UP y t1)) . _
    (UP (VarEqual x y) (Resolve (I) t1))) _
  ((Resolve (VARIABLE x) (UPS y t1)) . _
    (UPS (VarEqual x y) (Resolve (I) t1))) _
  ((Resolve (VARIABLE x) (CFPS y t1)) . _
    (CFPS (VarEqual x y) (Resolve (RN) t1))) _
  ((Resolve (VARIABLE x) (ELFPS y t1)) . _
    (ELFPS (VarEqual x y) (Resolve (RN) t1))) _
  ((Resolve (VARIABLE x) (EF t1)) . (EF t1)) _
  ((Resolve (L (L (SY))) (M _*_*)) . (M (P (I)))) _
  ((Resolve (L (L (SY))) (SM x _*_*)) . (SM x (P (I)))) _
  ((Resolve (L (L t1)) (M t2)) . (M (Resolve t1 t2))) _
  ((Resolve (L (L t1)) (SM x t2)) . (SM x (Resolve t1 t2))) _
  ((Resolve (L (L t1)) (RM x y t2)) . (RM x y (Resolve t1 t2))) _
  ((Resolve (SY) t1) . (Resolve (P (I)) t1)) _
  ((Resolve (VARIABLE x) t1) . (Resolve (P (I)) t1)) _
  ((Resolve (SM x t1) (M t2)) . (M (Resolve t1 t2))) _
  ((Resolve (RM x y t1) (M t2)) . (M (Resolve t1 t2))) _
 _
  ((Resolve (M t1) (L _*_*)) . (L (L t1))) _
  ((Resolve (SM x t1) (L _*_*)) . (L (L t1))) _
  ((Resolve (RM x y t1) (L _*_*)) . (L (L t1))) _
  ((Resolve (M t1) (L t2)) . (L (Resolve (L t1) t2))) _
  ((Resolve (SM x t1) (L t2)) . (L (Resolve (L t1) t2))) _
  ((Resolve (RM x y t1) (L t2)) . (L (Resolve (L t1) t2))) _
 _
  ((Resolve (M t1) (V _*_*)) . (V (V t1))) _
  ((Resolve (SM x t1) (V _*_*)) . (V (V t1))) _
  ((Resolve (RM x y t1) (V _*_*)) . (V (V t1))) _
  ((Resolve (M t1) (V t2)) . (V (Resolve (V t1) t2))) _
  ((Resolve (SM x t1) (V t2)) . (V (Resolve (V t1) t2))) _
  ((Resolve (RM x y t1) (V t2)) . (V (Resolve (V t1) t2))) _
 _
  ((Resolve (L t1) (V t2)) . (V (Resolve t1 t2))) _
  ((Resolve (V t1) (L t2)) . (L (Resolve t1 t2))) _
  ((Resolve (FF t1) (FR t2)) . (FR (Resolve t1 t2))) _
  ((Resolve (UP x t1) (P t2)) . (Resolve t1 (P t2))) _
 )

-- Private abbreviation table for resolve rules
$resolveAbbreviations == '( _
    (P .  Polynomial) _
    (G .  Gaussian) _
    (L .  List) _
    (M .  Matrix) _
    (EQ . Equation) _
    (B .  Boolean) _
    (SY . Symbol) _
    (I .  Integer) _
    (SM . SquareMatrix) _
    (RM . RectangularMatrix) _
    (V .  Vector) _
    (FF . FactoredForm) _
    (FR . FactoredRing) _
    (RN . RationalNumber) _
    (F .  Float) _
    (OV . OrderedVariableList) _
    (UP . UnivariatePoly) _
    (DMP . DistributedMultivariatePolynomial) _
    (MP . MultivariatePolynomial) _
    (HDMP . HomogeneousDistributedMultivariatePolynomial) _
    (QF . QuotientField) _
    (RF . RationalFunction) _
    (RE . RadicalExtension) _
    (RR . RationalRadicals) _
    (UPS . UnivariatePowerSeries) _
    (CFPS . ContinuedFractionPowerSeries) _
    (ELFPS . EllipticFunctionPowerSeries) _
    (EF . ElementaryFunction) _
    (VARIABLE . Variable) _
 )

$newResolveAbbreviations == '( _
    (P .  Polynomial) _
    (G .  Complex) _
    (L .  List) _
    (M .  Matrix) _
    (EQ . Equation) _
    (B .  Boolean) _
    (SY . Symbol) _
    (I .  Integer) _
    (SM . SquareMatrix) _
    (RM . RectangularMatrix) _
    (V .  Vector) _
    (FF . Factored) _
    (FR . Factored) _
    (F .  Float) _
    (OV . OrderedVariableList) _
    (UP . UnivariatePolynomial) _
    (DMP . DistributedMultivariatePolynomial) _
    (MP . MultivariatePolynomial) _
    (HDMP . HomogeneousDistributedMultivariatePolynomial) _
    (QF . Fraction) _
    (UPS . UnivariatePowerSeries) _
    (VARIABLE . Variable) _
 )

-- The following creates the ruleset

createResolveTMRules() ==
  -- expand multivariate polynomial rules
  mps := '(MP DMP NDMP)
  mpRules0 := "append"/[substitute(mp,'mpoly1,$mpolyTMRules) for mp in mps]
  mpRules := "append"/[substitute(mp,'mpoly2,mpRules0) for mp in mps]
  $ResMode := CONS('(t1 t2 x y),
    EQSUBSTLIST($nameList,$abList,append(mpRules,$generalTMRules)))
  true

createTypeEquivRules() ==
  -- used by eqType, for example
  $TypeEQ := CONS('(t1), EQSUBSTLIST($nameList,$abList,'(
    ((QF (P t1)) . (RF t1))
      ((QF (I)) . (RN))
        ((RE (RN)) . (RR)) )))
  $TypeEqui := CONS(first $TypeEQ, [[b,:a] for [a,:b] in rest $TypeEQ])
  true

initializeRuleSets() ==
  $abList: local :=
    ASSOCLEFT $newResolveAbbreviations
  $nameList: local :=
    ASSOCRIGHT $newResolveAbbreviations
  createResolveTTRules()
  createResolveTMRules()
  createTypeEquivRules()
  $ruleSetsInitialized := true
  true