File: rtest_boolean.mac

package info (click to toggle)
maxima 5.47.0-9
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 193,104 kB
  • sloc: lisp: 434,678; fortran: 14,665; tcl: 10,990; sh: 4,577; makefile: 2,763; ansic: 447; java: 328; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (408 lines) | stat: -rw-r--r-- 8,845 bytes parent folder | download | duplicates (13)
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
(kill (all), 0);
0;

/* Test simplification of boolean expressions.
 * '(...) expressions are simplified but not evaluated.
 */

['("and" ()), '("or" ())];      /* analogous to * and + with no arguments */
[true, false];

/* These values are supposed to be ignored in quoted expressions '(...).
 */
(a : true, b : false, c : true, 0);
0;

('(a and b), [op (%%), args (%%)]);
["and", '[a, b]];

('(a or b), [op (%%), args (%%)]);
["or", '[a, b]];

('(not a), [op (%%), args (%%)]);
["not", '[a]];

('(a and b or c and d), [op (%%), args (%%)]);
["or", ['(a and b), '(c and d)]];

('((a or b) and (c or d)), [op (%%), args (%%)]);
["and", ['(a or b), '(c or d)]];

'(a and true);
'a;

'(a and false);
false;

'(a or true);
true;

'(a or false);
'a;

'[true and true, true and false, true or true, true or false, false and true, false and false, false or true, false or false];
[true, false, true, true, false, false, true, false];

'((a or true) and (b or true));
true;

'(a and true or b and true);
'(a or b);

'(a or b or c or false);
'(a or b or c);

'(a and b and c and true);
'(a and b and c);

'(not (a and b));
'((not a) or (not b));

'(not a and b);
'((not a) and b);

'(not (a or b));
'((not a) and (not b));

'(not (a or b or c or d or e));
'((not a) and (not b) and (not c) and (not d) and (not e));

'(not (a and b and c and d and e));
'((not a) or (not b) or (not c) or (not d) or (not e));

'(not (a or b and c or d and e));
'((not a) and ((not b) or (not c)) and ((not d) or (not e)));

'(not (a and not b or c and not d and not e));
'(((not a) or b) and ((not c) or d or e));

'(not a or b);
'((not a) or b);

'(not not a);
'a;

'(not not not a);
'(not a);

'(not not not not a);
'a;

/* Flattening nested expressions.
 * Maxima "and" and "or" are not commutative, so order of arguments should be preserved.
 * Flattening is a simplification => should happen in both simplification and evaluation.
 */

kill (all);
done;

('(x and b and ((h and d) and c) and y), [op (%%), args (%%)]);
["and", [x, b, h, d, c, y]];

('(x or b or ((h or d) or c) or y), [op (%%), args (%%)]);
["or", [x, b, h, d, c, y]];

'(x and b and ((h or d) or c) and (y and q and e));
x and b and (h or d or c) and y and q and e;

(x and b and ((h and d) and c) and y, [op (%%), args (%%)]);
["and", [x, b, h, d, c, y]];

(x or b or ((h or d) or c) or y, [op (%%), args (%%)]);
["or", [x, b, h, d, c, y]];

x and b and ((h or d) or c) and (y and q and e);
x and b and (h or d or c) and y and q and e;

/* Side-effects shouldn't happen in simplification (since arguments are not evaluated).
 */

(kill (a, b, c), 0);
0;

('((a : true) and (b : false) and (c : foo ())), [op (%%), args (%%), a, b, c]);
["and", '[a : true, b : false, c : foo ()], 'a, 'b, 'c];

('(not (a : true)), [op (%%), args (%%), a]);
["not", '[a : true], 'a];

/* Miscellaneous tests.
 */
expr: '(a > b and (equal (c, d) or e = 1) and not f <= g or notequal (h, %pi));
'(a > b and (equal (c, d) or e = 1) and f > g or notequal (h, %pi));

'(a > b and b > c and true or a < b and b < c and true or false or not true);
'((a > b and b > c) or (a < b and b < c));

'(not not not not a > b);
'(a > b);

'(not not not not not a > b);
'(a <= b);

'(not not not false and not not not not true);
true;

'(not foo (a));
''(funmake ("not", '[foo (a)]));

'[is (not a > b or false), is (not a > b or true), is (not a > b and false)];
'[is (a <= b), true, false];

'['is (not a > b or false), 'is (not a > b or true), 'is (not a > b and false)];
'['is (a <= b), true, false];

'[maybe (not a > b or false), maybe (not a > b or true), maybe (not a > b and false)];
'[maybe (a <= b), true, false];

'['maybe (not a > b or false), 'maybe (not a > b or true), 'maybe (not a > b and false)];
'['maybe (a <= b), true, false];

/* Test evaluation of boolean expressions.
 * Evaluate the arguments and simplify.
 */

["and" (), "or" ()];      /* analogous to * and + with no arguments */
[true, false];

(a and b, [op (%%), args (%%)]);
["and", '[a, b]];

(a or b, [op (%%), args (%%)]);
["or", '[a, b]];

(not a, [op (%%), args (%%)]);
["not", '[a]];

(a and b or c and d, [op (%%), args (%%)]);
["or", ['(a and b), '(c and d)]];

((a or b) and (c or d), [op (%%), args (%%)]);
["and", ['(a or b), '(c or d)]];

a and true;
'a;

a and false;
false;

a or true;
true;

a or false;
'a;

(a or true) and (b or true);
true;

a and true or b and true;
'(a or b);

a or b or c or false;
'(a or b or c);

a and b and c and true;
'(a and b and c);

not (a and b);
'((not a) or (not b));

not a and b;
'((not a) and b);

not (a or b);
'((not a) and (not b));

not (a or b or c or d or e);
'((not a) and (not b) and (not c) and (not d) and (not e));

not (a and b and c and d and e);
'((not a) or (not b) or (not c) or (not d) or (not e));

not (a or b and c or d and e);
'((not a) and ((not b) or (not c)) and ((not d) or (not e)));

not (a and not b or c and not d and not e);
'(((not a) or b) and ((not c) or d or e));

not a or b;
'((not a) or b);

not not a;
'a;

not not not a;
'(not a);

not not not not a;
'a;

/* Side-effects should happen in evaluation.
 */

((a : true) and (b : true) and (c : foo ()), [%%, a, b, c]);
[foo (), true, true, foo ()];

(not (a : bar ()), [%%, a]);
['(not bar ()), bar ()];

(kill (a, b, c), 0);
0;

/* Miscellaneous tests.
 */
expr: a > b and (equal (c, d) or e = 1) and not f <= g or notequal (h, %pi);
'(a > b and equal (c, d) and f > g or notequal (h, %pi));

''expr, e=1;
'(a > b and equal (c, d) and f > g or notequal (h, %pi));

''expr, e=1, h=%e;
true;

''expr, e=1, h=%pi;
'(a > b and equal (c, d) and f > g);

''expr, e=89, f = g + 1;
'(a > b and equal (c, d) or notequal (h, %pi));

(assume (notequal (c, d), equal (f, 100), g < 0), 0);
0;

''expr, e = 1;
'(notequal (h, %pi));

a > b and b > c and true or a < b and b < c and true or false or not true;
'((a > b and b > c) or (a < b and b < c));

not not not not a > b;
'(a > b);

not not not not not a > b;
'(a <= b);

not not not false and not not not not true;
true;

/* is-evaluation of conditionals.
 * is(foo) => true, false, and unknown or error (depending on prederror flag).
 */

ev (is (a > b or a > c), prederror=false);
unknown;

errcatch (ev (is (a > b or a > c), prederror=true));
[];

[is (not a > b or true), is (not a > b and false), 'is (not a > b or true), 'is (not a > b and false)];
[true, false, true, false];

[maybe (not a > b or false), maybe (not a > b or true), maybe (not a > b and false)];
[unknown, true, false];

['maybe (not a > b or false), 'maybe (not a > b or true), 'maybe (not a > b and false)];
['maybe (a <= b), true, false];

is (not a > b or true);
true;

is (not a > b and false);
false;

ev (maybe (not a > b or false), prederror=false);
unknown;

ev (maybe (not a > b or false), prederror=true);
unknown;

ev (maybe (not a > b), a = 100.0, b = 1000/3);
true;

ev (maybe (not a > b), b = 100.0, a = 1000/3);
false;

(kill (aa, bb, cc, dd),
 implies (a%, b%) := (not a%) or b%,
 equivalent (a%, b%) := implies (a%, b%) and implies (b%, a%),
 translate (implies, equivalent));
[implies, equivalent];

/* output not fully simplified -- these next two tests show bugs */

implies (aa and bb, cc or dd);
not (aa) or not (bb) or cc or dd;

implies (aa and bb, aa);
not (aa) or not (bb) or aa;

equivalent (aa, aa);
(not aa or aa) and (not aa or aa);

/* crime scene example from mailing list 2006/05/06 tnx Mario */

(kill (all),
 "=>" (r, s) := not r or s,
 infix ("=>"),
 implies (ante, conse, listvar) := block ([expr, npos, maxn, combis:[], bits, quot, div],
    npos: length(listvar),
    maxn: 2^npos - 1,
    expr: not ante or conse,
    for i:0 thru maxn do
       (bits: [],
        quot: i,
        for j: 1 thru npos do
           (div: divide (quot, 2),
            quot: div[1],
            bits: cons (listvar[j]=div[2], bits)),
        combis: cons (subst ([1=true, 0=false], bits), combis)),
    apply ("and", makelist (subst (k, expr), k, combis))), 0);
0;

implies ((p or q) and (q => r) and (p => s) and not r, s, [p, q, r, s]);
true;

/* charfun examples following email discussion circa 2007-03-23 */

(kill (x, y, z), expr : charfun (-1 < x and x < 1));
'(charfun (-1 < x and x < 1));

[ev (expr, x = 1/2), ev (expr, x = -3/2)];
[1, 0];

expr : charfun (x > 0 or y > 0);
'(charfun (x > 0 or y > 0));

[ev (expr, x = 1/2), ev (expr, x = -3/2), ev (expr, x = -3/2, y = -3/4)];
[1, '(charfun (y > 0)), 0];

/* ensure that arguments to is and maybe are evaluated exactly once */

(kill (aa, bb, cc),
 aa : bb : cc,
 cc : 1234,
 is (aa = bb));
true;

is (aa = 'cc and bb = 'cc);
true;

is ('aa = 'bb);
false;

maybe (aa = bb);
true;

maybe (aa = 'cc and bb = 'cc);
true;

maybe ('aa = 'bb);
false;

/* SF bug [ 1726148 ] maybe with prederror : true */

(kill (a), ev (maybe (a), prederror = true));
unknown;

ev (maybe (a or false), prederror = true);
unknown;