-
Notifications
You must be signed in to change notification settings - Fork 146
/
stackmaxima.mac
3334 lines (2959 loc) · 144 KB
/
stackmaxima.mac
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Author Chris Sangwin
Loughborough University
Copyright (C) 2014 Chris Sangwin
University of Edinburgh
Copyright (C) 2017 Chris Sangwin
This program is free software: you can redistribute it or modify
it under the terms of the GNU General Public License version two.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* ********************************** */
/* Global variable options */
/* ********************************** */
stack_reset(not_used) := block(
if featurep(all, constant) then remove(all, constant),
kill(allbut [functions]),
kill(trigsimp),
/* Very unlikley the function psi will be needed for assessment and it breaks the session
when it is used as a variable. */
kill(psi),
simpsum: true,
negdistrib: true, /* When negdistrib is true, -1 distributes over an expression. E.g., -(x + y) becomes - y - x. */
display2d: false,
linel: 2047,
nolabels: true,
logabs: true,
exptdispflag: true,
linsolvewarn: false,
ratprint: false,
factor_max_degree_print_warning:false,
/* Suppress warnings printed by mtell, e.g. by solve, rat and other functions. */
stack_mtell_quiet:false,
fpprintprec: 12, /* Print only 12 digits. */
fpprec: 20, /* Work with 20 digits. */
%E_TO_NUMLOG: true, /* "r" some rational number, and "x" some expression, %E^(r*LOG(x)) => x^r .*/
/* Synonyms to help students */
e: exp(1),
pi: %pi,
Pi: %pi,
PI: %pi,
pi() := %pi, /* Why does Excel do this?! */
/* Display of matrixes */
lmxchar: "[",
/* Sets up randomization, using Maxima's internal random command. */
stack_randseed(10000),
mminusbp120(true),
/*Reload local settings*/
STACK_SETUP(true),
MAXIMA_VERSION_STR: ?\*autoconf\-version\*,
MAXIMA_VERSION: map(parse_string, tokens(?\*autoconf\-version\*, 'digitcharp)),
/* We need the "if" statement below, because versions compiled from source give erroneous results. */
MAXIMA_VERSION_NUM: float(MAXIMA_VERSION[2]+(if is(length(MAXIMA_VERSION)>2)
then (if is(MAXIMA_VERSION[3]<10) then MAXIMA_VERSION[3]/10 else 0) else 0)),
OPT_OUTPUT: "LaTeX",
PLOT_TAGS: true,
/* Records the number of the plot. */
STACK_PLOT_UNIQUE_NUMBER: 0,
true
)$
/* Sometimes we need i,j,e etc to be *symbols*, not values. */
stack_reset_vars(ex) := block(kill(i, j, e, pi, Pi, PI));
/* Execute this command to ensure values have been set. */
stack_reset(true);
/* Make sure this is at least defined. */
debug:false;
/* TODO: remove this from install process. */
/* ********************************************************************* */
/* Evaluate variables are return errors, display, and content forms. */
/* ********************************************************************* */
/* This function executes ex, which is assumed to be a stack expression */
/* which is surrounded by errcatch. Hence we end up with a list. */
cte(var, ex) := block([str],
print("], key = ["),
print(var),
print("]"),
if ex = [] then block(
ex:STACKERROR,
print(", value = [], display = []")
)
else block(
print(", value = ["),
print(string(ex[1])),
print("], dispvalue = ["),
print(stack_dispvalue(ex[1])),
print("], display = ["),
print(stack_disp(ex[1], "")),
print("]"),
ex:ex[1]
),
print("], "),
return(ex)
)$
/* This function strips out functions to leave only things in the value which might be typed in. */
stack_dispvalue(ex) := block(
if not(stack_disp_control_structurep(ex)) then block(
if safe_op(ex)="%union" and is(length(args(ex))=1) then
ex: first(args(ex)),
ex: make_displaydpvalue(ex),
ex: make_displayscivalue(ex),
ex: subst("*", stackunits, ex),
ex: unary_minus_sort(ex),
ex: destackvector(ex)),
return(string(ex))
)$
/* ********************************** */
/* Load contributed packages */
/* ********************************** */
load("functs");
/* Not yet testsed: load("vect"); */
/* Load the logic package, but remove the "eq" infix operator which conflicts with too many existing things. */
/* We've edited the logic package which over writes the eq operator as xnor. */
load("stack_logic.lisp");
/* We don't want to allow people to put boxes round things. */
box(ex) := ex;
/* Although this works well in MAXIMA, |'s are not allowed in STACK */
/* The heuristics to catch the various errors do not work, since | is symmetrical */
matchfix("|", "|");
"|"([a]) := apply(abs, a);
/* Does not quite work yet ..... */
/* load("noninteractive.mac"); */
/* ********************************** */
/* Load STACK packages */
/* ********************************** */
/* This must come before stacktex.lisp as the latter relies on compiled functions in utils.mac. */
load("utils.mac");
load("errortostring.lisp");
load("assessment.mac");
load("validator.mac");
load("noun_simp.mac");
load("inequalities.mac");
load("intervals.mac");
load("geometry.mac");
load("proof.mac");
load("stackunits.mac");
load("stacktex.lisp");
load("stackstrings.mac");
load("fboundp.mac");
load("stacktex.lisp");
/* Ensure back compatability with versions before 5.41.0. */
if is(MAXIMA_VERSION_NUM<40.1) then load("stacktex40.lisp");
if is(MAXIMA_VERSION_NUM<44.0) then load("stack44.mac");
/* This file is a modified core Maxima function with local variable name clashes fixed. */
load("trigrat.lisp");
load("trigtools");
load("diag");
load("sregex");
load("numericaltest.mac");
load("local.mac");
/* Breaks on older versions of Maxima. */
if is(MAXIMA_VERSION_NUM>30.0) then compile(scientific_notation)$
texput(QMCHAR, "\\color{red}{?}");
texput(theta, "\\theta");
int([ex]) := apply(integrate, ex); /* Allows integrate to be called with int(). Avoid alias to allow nouns to work. */
alias(cosec,csc); /* Corresponds to current student expectations. */
alias(cosech,csch); /* Corresponds to current student expectations. */
alias(sgn,signum); /* Corresponds to current student expectations. */
texput(signum, "\\mathrm{sgn}");
declare ("#", commutative);
simplify(ex) := ev(fullratsimp(ex), simp); /* Allows simplify to be something. */
degree(ex, v) := ev(hipow(expand(ex), v), simp); /* See notes on hipow. */
make_complexJ(OPT_COMPLEXJ) := block(
if OPT_COMPLEXJ = "i" then
(i:%i,texput(%i,"\\mathrm{i}"))
else if OPT_COMPLEXJ = "j" then
(%j:%i,j:%i,texput(%i,"\\mathrm{j}"))
else if OPT_COMPLEXJ = "symi" then
(texput(%i,"\\mathrm{i}"))
else if OPT_COMPLEXJ = "symj" then
(texput(%i,"\\mathrm{j}"))
else true
)$
/* Choose the symbol for the multiplication sign. */
make_multsgn(OPT_MULTSGN) := block(
if OPT_MULTSGN = "cross" then texput("*", "\\times ", nary),
if OPT_MULTSGN = "dot" then texput("*", "\\cdot ", nary),
if OPT_MULTSGN = "onum" then texput("*", multsgnonlyfornumbers),
if OPT_MULTSGN = "blank" then texput("*", "\\, ", nary)
);
/* This only prints a multiplication sign for numbers. */
/* Thanks to Evgeniy Silchenko. */
texput(multsgnonlyfornumberssym, "\\times")$
multsgnonlyfornumbers(e) := block([arglist, resstr, a, lastisnum, isnum, multsgn, str],
arglist: args(e),
a: pop(arglist),
resstr: if (safe_op(a) = "-" or (real_numberp(a) and is(a<0))) then sconcat("\\left(", tex1(a), "\\right)")
else if (atom(a) or is(length(args(a))=1) or safe_op(a) = "^") then tex1(a)
else sconcat("\\left(", tex1(a), "\\right)"),
lastisnum: numberp(a),
for a in arglist do (
isnum: numberp(a),
multsgn: if (lastisnum and isnum) then tex1(multsgnonlyfornumberssym) else "\\,",
str: if (safe_op(a) = "-" or (real_numberp(a) and is(a<0))) then sconcat("\\left(", tex1(a), "\\right)")
else if (atom(a) or is(length(args(a))=1) or safe_op(a) = "^") then tex1(a)
else sconcat("\\left(", tex1(a), "\\right)"),
resstr: sconcat(resstr, multsgn, " ", str),
lastisnum: isnum
),
resstr
)$
make_logic(OPT_LOGIC) := block(
if OPT_LOGIC = "lang" then block(
texput("and", "\\,{\\mbox{ !AND! }}\\, ", nary),
texput("nounand", "\\,{\\mbox{ !AND! }}\\, ", nary),
texput("or", "\\,{\\mbox{ !OR! }}\\, ", nary),
texput("nounor", "\\,{\\mbox{ !OR! }}\\, ", nary),
texput("nand", "\\,{\\mbox{ !NAND! }}\\, ", nary),
texput("nor", "\\,{\\mbox{ !NOR! }}\\, ", nary),
texput("xor", "\\,{\\mbox{ !XOR! }}\\, ", nary),
texput("xnor", "\\,{\\mbox{ !XNOR! }}\\, ", nary),
texput("implies", "\\,{\\mbox{ !IMPLIES! }}\\, ", nary),
texput("not", "{\\rm !NOT!}", prefix),
texput("nounnot", "{\\rm !NOT!}", prefix)
),
if OPT_LOGIC = "symbol" then block(
texput("and", "\\land ", nary),
texput("nounand", "\\land ", nary),
texput("or", "\\lor ", nary),
texput("nounor", "\\lor ", nary),
texput("nand", "\\overline{\\land}", nary),
texput("nor", "\\underline{\\lor}", nary),
texput("xor", "\\oplus ", nary),
texput("xnor", "\\leftrightarrow ", nary),
texput("implies", "\\rightarrow ", nary),
texput("not", "\\neg ", prefix),
texput("nounnot", "\\neg ", prefix)
),
return(true)
)$
make_arccos(OPT_ACOS) := block(
if OPT_ACOS = "cos-1" then block(
?tex\-setup(?cdr([?%asin, "\\sin^{-1}"])),
?tex\-setup(?cdr([?%acos, "\\cos^{-1}"])),
?tex\-setup(?cdr([?%atan, "{\\tan^{-1}}"])),
?tex\-setup(?cdr([?%asec, "{\\rm sec}^{-1}"])),
?tex\-setup(?cdr([?%acsc, "{\\rm csc}^{-1}"])),
?tex\-setup(?cdr([?%acot, "{\\rm cot}^{-1}"])),
?tex\-setup(?cdr([?%asinh, "{\\rm sinh}^{-1}"])),
?tex\-setup(?cdr([?%acosh, "{\\rm cosh}^{-1}"])),
?tex\-setup(?cdr([?%atanh, "{\\rm tanh}^{-1}"])),
?tex\-setup(?cdr([?%asech, "{\\rm sech}^{-1}"])),
?tex\-setup(?cdr([?%acsch, "{\\rm csch}^{-1}"])),
?tex\-setup(?cdr([?%acoth, "{\\rm coth}^{-1}"]))
),
if OPT_ACOS = "arccos" then block(
?tex\-setup(?cdr([?%asin, "\\arcsin "])),
?tex\-setup(?cdr([?%acos, "\\arccos "])),
?tex\-setup(?cdr([?%atan, "\\arctan "])),
?tex\-setup(?cdr([?%asec, "{\\rm arcsec}"])),
?tex\-setup(?cdr([?%acsc, "{\\rm arccsc}"])),
?tex\-setup(?cdr([?%acot, "{\\rm arccot}"])),
?tex\-setup(?cdr([?%asinh, "{\\rm arcsinh}"])),
?tex\-setup(?cdr([?%acosh, "{\\rm arccosh}"])),
?tex\-setup(?cdr([?%atanh, "{\\rm arctanh}"])),
?tex\-setup(?cdr([?%asech, "{\\rm arcsech}"])),
?tex\-setup(?cdr([?%acsch, "{\\rm arccsch}"])),
?tex\-setup(?cdr([?%acoth, "{\\rm arccoth}"]))
),
if OPT_ACOS = "acos" then block(
?tex\-setup(?cdr([?%asin, "{\\rm asin}"])),
?tex\-setup(?cdr([?%acos, "{\\rm acos}"])),
?tex\-setup(?cdr([?%atan, "{\\rm atan}"])),
?tex\-setup(?cdr([?%asec, "{\\rm asec}"])),
?tex\-setup(?cdr([?%acsc, "{\\rm acsc}"])),
?tex\-setup(?cdr([?%acot, "{\\rm acot}"])),
?tex\-setup(?cdr([?%asinh, "{\\rm asinh}"])),
?tex\-setup(?cdr([?%acosh, "{\\rm acosh}"])),
?tex\-setup(?cdr([?%atanh, "{\\rm atanh}"])),
?tex\-setup(?cdr([?%asech, "{\\rm asech}"])),
?tex\-setup(?cdr([?%acsch, "{\\rm acsch}"])),
?tex\-setup(?cdr([?%acoth, "{\\rm acoth}"]))
),
if OPT_ACOS = "arccos-arcosh" then block(
?tex\-setup(?cdr([?%asin, "\\arcsin "])),
?tex\-setup(?cdr([?%acos, "\\arccos "])),
?tex\-setup(?cdr([?%atan, "\\arctan "])),
?tex\-setup(?cdr([?%asec, "{\\rm arcsec}"])),
?tex\-setup(?cdr([?%acsc, "{\\rm arccsc}"])),
?tex\-setup(?cdr([?%acot, "{\\rm arccot}"])),
?tex\-setup(?cdr([?%asinh, "{\\rm arsinh}"])),
?tex\-setup(?cdr([?%acosh, "{\\rm arcosh}"])),
?tex\-setup(?cdr([?%atanh, "{\\rm artanh}"])),
?tex\-setup(?cdr([?%asech, "{\\rm arsech}"])),
?tex\-setup(?cdr([?%acsch, "{\\rm arcsch}"])),
?tex\-setup(?cdr([?%acoth, "{\\rm arcoth}"]))
)
)$
/* Fine tune the display of fractions between inline and displayed. */
stackfractionsinline(e) := block ([a, b],
[a, b]: args(e),
/* We need to be more careful about when we have brackets around expressions in inline fractions. */
if (atom(b) or safe_op(b) = "^") then return(concat("{", tex1(a), "}/{", tex1(b), "}")),
if is(length(args(b))=1) then return(concat("{", tex1(a), "}/{", tex1(b), "}")),
concat("{", tex1(a), "}/{\\left(", tex1(b), "\\right)}")
)$
stackfractionsdisplay(e) := block ([a, b],
[a, b]: args (e),
concat("\\frac{", tex1(a), "}{", tex1(b), "}")
)$
stack_disp_fractions(ex) := block(
if is(ex="i") then
ev(texput("/", stackfractionsinline),simp)
else
ev(texput("/", stackfractionsdisplay),simp)
)$
/* This is needed to tweak the display of noun derivatives. */
nary("blankmult", 0, 0);
texput("blankmult", " ", nary);
/* ****************************************************** */
/* Unit testing of questions */
/* ****************************************************** */
/* This function allows a teacher to add unit tests to */
/* individual questions. At the end of the question */
/* variables, or in the feedback variables, particular */
/* values can throw runtime errors. */
/* ****************************************************** */
s_assert(ex1, ex2):= if is(ex1=ex2) then true else
error("s_assert: STACK expected '", string(ex2), "' but was given '", string(ex1), "'.");
/* ****************************************************** */
/* Random numbers */
/* ****************************************************** */
/* http://random.mat.sbg.ac.at/generators/ */
/* ****************************************************** */
/* Developer warning: random functions determining */
/* whether a question is a singleton. */
/* When adding new "random" functions, also update */
/* question->has_random_variants() */
/* ****************************************************** */
/* Change the random seed */
stack_randseed(s) := block(RANDOM_STATE:make_random_state(s), errcatch(ev(set_random_state(RANDOM_STATE), simp)))$
/* The top level function */
rand(ex) := block(
if setp(ex) then ex:listify(ex),
ex:ev(ex, simp),
if (integerp(ex)) then return(random(ex)),
if (floatnump(ex)) then return(random(ex)),
if (matrixp(ex)) then return(matrixmap(random, ex)),
if (listp(ex)) then return(randlist(ex))
)$
/* Allow zero as an argument to random. */
rand_zero(ex):= block(
if not(integerp(ex)) then error("rand_zero expects its argument to be an integer."),
if is(ex<0) then error("rand_zero expects its argument to be non-negative."),
if is(ex=0) then return(0),
return(rand(ex))
)$
randlist(ex) := block(
if (length(ex) > 0) then return(ex[ev(1+random(length(ex)),simp)]) else return([])
)$
/* Returns a random number from the set {lower, lower+step, lower+2*step, ... , final}. */
/* Jarno Ruokokoski, 29/10/2009 */
rand_with_step(lower, upper, step_parameter) := block([temprand],
temprand: rand(floor((upper-lower)/step_parameter)+1),
return(ev(step_parameter*temprand+lower, simp))
)$
/* Returns a random integer from the set [lower,upper] such that it cannot be any value in list. This list can include values which are also random variables, for example, generated by rand_with_step. */
/* Jarno Ruokokoski, 29/10/2009 */
rand_with_prohib(lower, upper, list) := block([currents, retVal, kloop],
currents: ev((makelist(i, i, lower, upper)), simp),
for kloop:1 thru length(list) do block(
currents: simplify(delete(list[ev(kloop, simp)], currents))
),
retVal: rand(currents),
return(retVal)
)$
/* CJS, 11/6/2021 */
rand_selection_with_replacement(ex, n) := block(
if setp(ex) then ex:listify(ex),
if not(listp(ex)) then (
error("rand_selection_with_replacement error: first argument must be a list."),
return([])
),
if not(integerp(n)) then (
error("rand_selection_with_replacement error: second argument must be an integer."),
return([])
),
return(rand_selection_with_replacement_fun(ex, n))
)$
/* We can't use makelist here because of the simp:false requirement.
rand_selection_with_replacement_fun(ex, n) := makelist(rand(ex), k, 1, n)$
*/
rand_selection_with_replacement_fun(ex, n) := block(
if is(n<=0) then return([]),
append([rand(ex)], rand_selection_with_replacement_fun(ex, ev(n-1,simp)))
)$
/* Make a random selection of n different items from the list, or set ex. */
/* CJS, 7/6/2016 */
rand_selection(ex, n) := block(
if setp(ex) then ex:listify(ex),
if not(listp(ex)) then (
error("rand_selection error: first argument must be a list or set."),
return([])
),
if not(integerp(n)) then (
error("rand_selection error: second argument must be an integer."),
return([])
),
if is(n>length(ex)) then (
error("rand_selection error: insuffient elements in the list/set."),
return([])
),
return(rand_selection_fun(ex, n))
)$
rand_selection_fun(exin, n) := block([k],
if is(n=0) then return([]),
k: ev(rand(length(exin))+1, simp),
cons(exin[k], rand_selection_fun(list_remove(exin, k), ev(n-1, simp)))
)$
/* Remove the n'th element from the list ex. */
list_remove(ex, n) := block([k, l],
if is(n>length(ex)) or is (n<1) then return(ex),
/* Using simplification make a list of indices, then without simplification use them. */
l: ev(append(makelist(k, k, 1, n-1), makelist(k, k, n+1, length(ex))), simp),
makelist(ex[k], k, l)
)$
/********************************************/
/*********** Random set generation *********/
/********************************************/
/* Could be implemented with rand_selection but would require two conversions
* between sets and lists*/
random_subset(u):=
disjoin(false, map(lambda([x], if rand(2)=0 then x), u));
random_subset_n(u,n) :=
setify(rand_selection(listify(u),n));
/* random non-empty subset */
random_ne_subset(u) := random_subset_n(u, rand(cardinality(u))+1);
/* Create a number in a random range. */
rand_range([ex]) := block(
if (length(ex)<2 or length(ex)>3) then error("rand_range must have 2 or 3 arguments."),
if not(integerp(ex[1])) then error("rand_range expects its first argument to be an integer."),
if not(integerp(ex[2])) then error("rand_range expects its second argument to be an integer."),
if is(length(ex)=2) then return(ev(ex[1]+rand_zero(ex[2]-ex[1]), simp)),
if not(integerp(ex[3])) then error("rand_range expects its third argument to be an integer."),
return(ev(ex[1]+ex[3]*rand_zero(floor((ex[2]-ex[1])/ex[3])), simp))
)$
/* Helper function for constructing MCQ arrays. */
multiselqn(corbase, numcor, wrongbase, numwrong):=block([ta1, ta2, ta, version],
if not(listp(corbase)) then error("multiselqn: first argument must be a list."),
if not(listp(wrongbase)) then error("multiselqn: third argument must be a list."),
if not(integerp(numcor)) then error("multiselqn: second argument must be an integer."),
if not(integerp(numwrong)) then error("multiselqn: fourth argument must be an integer."),
if length(corbase)<numcor then error("multiselqn: you have asked for more correct responses than are supplied in the list!"),
if length(wrongbase)<numwrong then error("multiselqn: you have asked for more correct responses than are supplied in the list!"),
ta1: maplist(lambda([ex], [ex, true]), rand_selection(corbase, numcor)),
ta2: maplist(lambda([ex], [ex, false]), rand_selection(wrongbase, numwrong)),
ta: random_permutation(append(ta1, ta2)),
version: map(first, ta),
return([ta, version])
)$
/* Helper function for constructing MCQ arrays with auto-generated alphabetic labels. Students choose the labels. */
multiselqnalpha([exs]):=block([corbase, numcor, wrongbase, numwrong, dispflag, ta1, ta2, ta3, talab, ta, version],
if length(exs)<4 then error("multiselqnalpha must have at least four arguments."),
corbase:first(exs),
numcor:second(exs),
wrongbase:third(exs),
numwrong:fourth(exs),
dispflag:"id",
if length(exs)>4 then dispflag:fifth(exs),
if not(listp(corbase)) then error("multiselqnalpha: first argument must be a list."),
if not(listp(wrongbase)) then error("multiselqnalpha: third argument must be a list."),
if not(integerp(numcor)) then error("multiselqnalpha: second argument must be an integer."),
if not(integerp(numwrong)) then error("multiselqnalpha: fourth argument must be an integer."),
if length(corbase)<numcor then error("multiselqnalpha: you have asked for more correct responses than are supplied in the list!"),
if length(wrongbase)<numwrong then error("multiselqnalpha: you have asked for more correct responses than are supplied in the list!"),
ta1: maplist(lambda([ex], [ex, true]), rand_selection(corbase, numcor)),
ta2: maplist(lambda([ex], [ex, false]), rand_selection(wrongbase, numwrong)),
ta3: random_permutation(append(ta1, ta2)),
/* Add in a slightly different display here. */
talab: ev(makelist(sconcat("(",ascii(96+i),")"), i, 1, length(ta3)), simp),
ta:zip_with(lambda([ex1, ex2], [ex1, ex2[2], sconcat("<b>", ex1, "</b> ",
if stringp(ex2[1]) then ex2[1] else stack_disp(ex2[1], dispflag))]), talab, ta3),
version: map(first, ta3),
return([ta, version])
)$
/* Helper function for constructing MCQ arrays where the values should not be shown to students. */
multiselqndisplay(corbase, numcor, wrongbase, numwrong):=block([ta1, ta2, ta, version],
if not(listp(corbase)) then error("multiselqndisplay: first argument must be a list."),
if not(listp(wrongbase)) then error("multiselqndisplay: third argument must be a list."),
if not(integerp(numcor)) then error("multiselqndisplay: second argument must be an integer."),
if not(integerp(numwrong)) then error("multiselqndisplay: fourth argument must be an integer."),
if length(corbase)<numcor then error("multiselqndisplay: you have asked for more correct responses than are supplied in the list!"),
if length(wrongbase)<numwrong then error("multiselqndisplay: you have asked for more correct responses than are supplied in the list!"),
/* */
corbase: zip_with("[", ev(makelist(k,k,1,length(corbase)),simp), corbase),
wrongbase: zip_with("[", ev(makelist(k,k,1+length(corbase),1+length(corbase)+length(wrongbase)),simp), wrongbase),
ta1: maplist(lambda([ex], [first(ex), true, second(ex)]), rand_selection(corbase, numcor)),
ta2: maplist(lambda([ex], [first(ex), false, second(ex)]), rand_selection(wrongbase, numwrong)),
ta: random_permutation(append(ta1, ta2)),
version: map(first, ta),
/* */
return([ta, version])
)$
/* Helper functions for MCQ arrays. */
mcq_correct(ta):=block(
if not(listp(ta)) then error("mcq_correct: first argument must be a list, but was passed: ", string(ta)),
if not(all_listp(listp, ta)) then error("mcq_correct: all list elements must be lists, but was passed: ", string(ta)),
if not(all_listp(lambda([ex], is(length(ex)>=2)), ta)) then error("mcq_correct: all list elements must be lists of length at least 2, but was passed: ", string(ta)),
maplist(first, sublist(ta, lambda([ex], second(ex))))
)$
mcq_incorrect(ta):=block(
if not(listp(ta)) then error("mcq_incorrect: first argument must be a list, but was passed: ", string(ta)),
if not(all_listp(listp, ta)) then error("mcq_incorrect: all list elements must be lists, but was passed: ", string(ta)),
if not(all_listp(lambda([ex], is(length(ex)>=2)), ta)) then error("mcq_incorrect: all list elements must be lists of length at least 2, but was passed: ", string(ta)),
maplist(first, sublist(ta, lambda([ex], not(second(ex)))))
)$
/* ********************************** */
/* Statistics function */
/* ********************************** */
/* ------------------ Mode function --------------------- */
/* mode(n) returns a list of all the modal elements in the list n */
mode(n):= block([i,j,count_elements,counts,highest_count,mode_set],
count_elements: makelist(0,i,1,length(n)),
for i: 1 thru length(n) do
(for j: 1 thru length(n) do
(if n[i]=n[j] then count_elements[i]: count_elements[i]+1)),
counts: listify(setify(count_elements)),
highest_count:counts[length(counts)],
mode_set:{},
for i:1 thru length(n) do
(if count_elements[i]=highest_count then mode_set: union(mode_set,{n[i]})),
mode_list:listify(mode_set),
return(mode_list)
)$
/* ********************************** */
/* cassession2 I/O management */
/* ********************************** */
/* Current statement identifier */
%stmt: "0"$
/* Collected errors */
%ERR: ["stack_map"]$
/* Collected notes */
%NOTES: ["stack_map"]$
/* Collected feedback */
%FEEDBACK: ["stack_map"]$
/* Function to declare errors from within logic. */
/* With reference to position in logic. */
_APPEND_ERR(err_list, reference) := if ev(stackmap_has_key(%ERR, %stmt), simp)
then
%ERR:stackmap_set(%ERR, %stmt, append(stackmap_get(%ERR,%stmt),[[err_list,reference]]))
else
%ERR:stackmap_set(%ERR, %stmt, [[err_list,reference]])$
_UNDO_ERR(err_list, reference) := block([%_tmp],
if (ev(stackmap_has_key(%ERR, %stmt), simp)) then (
%_tmp: stackmap_get(%ERR,%stmt),
%_tmp: delete([err_list,reference], %_tmp),
%ERR: stackmap_set(%ERR, %stmt, %_tmp)
)
)$
/* Function to attach a note to the current statement. */
_APPEND_NOTE(note) := if ev(stackmap_has_key(%NOTES, %stmt), simp)
then
%NOTES:stackmap_set(%NOTES,%stmt,append(stackmap_get(%NOTES,%stmt),[note]))
else
%NOTES:stackmap_set(%NOTES,%stmt,[note])$
_RESET_NOTES() := %NOTES:stackmap_unset(%NOTES,%stmt)$
/* Function to attach a note to the current statement. */
_APPEND_FEEDBACK(feedback) := if ev(stackmap_has_key(%FEEDBACK, %stmt), simp)
then
%FEEDBACK:stackmap_set(%FEEDBACK,%stmt,append(stackmap_get(%FEEDBACK,%stmt),[feedback]))
else
%FEEDBACK:stackmap_set(%FEEDBACK,%stmt,[feedback])$
/* Reset any feedback. */
_RESET_FEEDBACK() := %FEEDBACK:stackmap_unset(%FEEDBACK,%stmt)$
/* General error catching wrapper */
_EC(errcatched, reference) := if errcatched = []
then
(_APPEND_ERR([errormsgtostring()], reference), false)
else
true$
/* Shorthand for allowing even more to fit into the buffer. */
/* Note that stackmap_set is not very performance optimised and
as the CS2 context newer redefines values we can just append.
If we were to use the set functionality we meet trouble at around
250 keys. */
/* Catch to %_tmp before placement to list to check if the value is
a list just in case there is an error of some sort, if it is not
a list then that append would do bad things. */
_CS2v(_k,_v) := block([%_tmp],
%_tmp:[[_k, string(_v)]],
if listp(%_tmp) then _VALUES:append(_VALUES,%_tmp),
0)$
_CS2l(_k,_v) := block([%_tmp],
%_tmp:[[_k, stack_disp(_v, "")]],
if listp(%_tmp) then _LATEX:append(_LATEX,%_tmp),
0)$
_CS2dv(_k,_v) := block([%_tmp, simp],
/* We don't want to simplify products with zero to zero here. */
simp:false,
%_tmp:[[_k, stack_dispvalue(_v)]],
if listp(%_tmp) then _DVALUES:append(_DVALUES,%_tmp),
0)$
_CS2dvv(_k,_v) := (_CS2v(_k,_v),_CS2dv(_k,_v),0)$
_CS2out() := (
_RESPONSE : stackmap_set(_RESPONSE, "timeout", false),
_RESPONSE : stackmap_set(_RESPONSE, "values", _VALUES),
if length(%ERR) > 1 then
_RESPONSE : stackmap_set(_RESPONSE, "errors", %ERR),
if length(%NOTES) > 1 then
_RESPONSE : stackmap_set(_RESPONSE, "notes", %NOTES),
if length(%FEEDBACK) > 1 then
_RESPONSE : stackmap_set(_RESPONSE, "feedback", %FEEDBACK),
print("STACK-OUTPUT-BEGINS>"),
print(stackjson_stringify(_RESPONSE)),
print("<STACK-OUTPUT-ENDS")
)$
/* ********************************** */
/* Display */
/* ********************************** */
/* expr - expression to be displayed */
/* m - mode, either */
/* "i" inline or */
/* "d" for displayed, or */
/* "" for no delimiters. */
/* ********************************** */
stack_disp(expr, exprm) := block([str:"", expru],
/* LaTeX display */
if OPT_OUTPUT = "LaTeX" then
if not(ev(elementp(exprm, {"", "i", "d", "id", "i{", "{"}), simp)) then print(concat("ERROR: illegal delimiter option found: ", exprm)),
/* Fine tune display, e.g. sort out display of atoms like theta0. */
expru: %_ce_rem(expr),
if not(stack_disp_control_structurep(expr)) then block(
expru: unary_minus_sort(expr),
expru: stack_disp_sub_script(expru)),
str: block([expstr, ld, rd],
ld: "",
rd: "",
if exprm = "i" then block(ld: "\\(", rd:"\\)"),
if exprm = "i{" then block(ld: "\\({", rd:"}\\)"),
if exprm = "{" then block(ld: "{", rd:"}"),
if exprm = "id" then block(ld: "\\(\\displaystyle ", rd:"\\)"),
if exprm = "d" then block(ld: "\\[", rd:"\\]"),
mminusbp100(true),
expstr: tex(expru, false),
mminusbp120(true),
expstr: concat(ld, stack_disp_strip_dollars(expstr), rd)
),
/* String display */
if OPT_OUTPUT = "String" then str: string(expr),
/* If no correct options have been set. */
if str = "" then str:string(expr),
return(str)
)$
/* This function was renamed to improve the consistency of the coding style. */
/* We continue to support the old name, since question authors may have used */
/* it, even though that was not recommended practice. */
alias(StackDISP, stack_disp)$
/* If an expression contains these control structures then we don't fine-tune the display. */
stack_disp_control_structurep(ex) := not(freeof(?mdoin, ?mdo, ?mcond, catch, throw, ":=", lambda, setelmx, ex))$
stack_disp_strip_dollars(ex) := block(
if ?subseq(ex, 0, 2) = "$$" then
ex:?subseq(ex, 2, ev(?length(ex)-3, simp))
/* Remove \begin{verbatim}'s from Maxima's TEX command */
else if ?length(ex) > 17 and ?subseq(ex,1,17) = "\\begin{verbatim}" then
ex: ?subseq(ex, 18, ev(?length(ex)-18, simp)),
ex
)$
/* Display of numbers. Thanks to Robert Dodier. */
stackintfmt: "~d";
stackfltfmt: "~a";
stackfltsep: ".";
texput_decimal(ex):= stackfltsep:ex$
?texnumformat(x) := block([tx],
if ev(floatnump(x), simp) then block(
tx:ev(printf(false, stackfltfmt, x), simp)
) else if ev(integerp(x),simp) then (
if (is(stackintfmt="~r") or is(stackintfmt="~:r")) then
tx:sconcat("\\mbox{",ev(printf(false, stackintfmt, x), simp),"}")
else
tx:ev(printf(false, stackintfmt, x), simp)
) else
tx:string(x),
/* We need this separation because validation displays trailing zeros and this is controlled by stackfltfmt. */
if is(stackfltsep = ",") then (
tx:ssubst("\\ ", ",", tx),
tx:ssubst("{,}", ".", tx)
),
tx
)$
/* Some systems are throwing an error here, which is spurious. */
errcatch(compile(?texnumformat));
/* **************************************************** */
/* Display: Subscripts, and strip singular + operators. */
/* **************************************************** */
stack_disp_sub_script(ex) := block([s],
if taylorp(ex) then return(ex),
if safe_setp(ex) then return(apply(set, maplist(stack_disp_sub_script, args(ex)))),
if arrayp(ex) then return(arraymake(op(ex), maplist(stack_disp_sub_script, args(ex)))),
/* The following are not, strictly speaking, a subscript issue, but we don't want another recursive call. */
/* Strip out empty plus operators, which cause problems in display with simp:false. */
if is(safe_op(ex)="+") and is(length(args(ex))=1) then return(stack_disp_sub_script(first(args(ex)))),
/* Now deal with supscripts. */
if not(atom(ex)) then return(apply(op(ex), maplist(stack_disp_sub_script, args(ex)))),
if simp_numberp(ex) or stringp(ex) or ex or not(ex) then return(ex),
/* Check for an explicit entry in the texput database for this atom. */
if stringp(get_texword(ex)) then return(ex),
s: string(ex),
s: split(s, "_"),
/* If we can't parse the string back, just use the string. */
s: maplist(lambda([ex], block([parsed], parsed:errcatch(parse_string(ex)), if emptyp(parsed) then ex else first(parsed))), s),
stack_disp_sub_script_helper(s)
)$
stack_disp_sub_script_helper(l) := block(
if length(l) = 1 then return(first(l)),
texsub(stack_disp_sub_script_helper(reverse(rest(reverse(l)))), first(reverse(l)))
)$
/* This function turns a list into a string representation of its arguments, without braces.
stackcommaseparate([a,b,pi]);
"a, b, pi"
Not the TeX version, "a, b, \pi".
Useful for passing values to Javascript, R and so on, or generating data for students.
*/
stack_disp_comma_separate(ex):= block(
if not(listp(ex)) then error("stack_disp_comma_separate: expects its argument to be a list"),
return(simplode(maplist(string, ex), ", "))
)$
/* ********************************** */
/* Display: colour */
/* ********************************** */
COLOR_LIST:["red", "Blue", "YellowOrange", "Bittersweet", "BlueViolet", "Aquamarine", "BrickRed",
"Apricot", "Brown", "BurntOrange", "CadetBlue", "CarnationPink", "Cerulean", "CornflowerBlue",
"CyanDandelion", "DarkOrchid", "Emerald", "ForestGreen", "Fuchsia", "Goldenrod", "Gray",
"Green", "JungleGreen", "Lavender", "LimeGreen", "Magenta", "Mahogany", "Maroon", "Melon",
"MidnightBlue", "Mulberry", "NavyBlue", "OliveGreen", "Orange", "OrangeRed", "Orchid",
"Peach", "Periwinkle", "PineGreen", "Plum", "ProcessBlue", "Purple", "RawSienna", "Red",
"RedOrange", "RedViolet", "Rhodamine", "RoyalBlue", "RoyalPurple", "RubineRed", "Salmon",
"SeaGreen", "Sepia", "SkyBlue", "SpringGreen", "Tan", "TealBlue", "Thistle", "Turquoise",
"Violet", "VioletRed","WildStrawberry", "Yellow", "YellowGreen", "BlueGreen"]$
COLOR_LIST_LENGTH:length(COLOR_LIST)$
/* Decolour function */
detexcolor(ex) := block([argsex],
if mapatom(ex) then return(ex),
argsex:args(ex),
if op(ex) = texcolor then return(detexcolor(argsex[2])),
if op(ex) = texcolorplain then return(detexcolor(argsex[2])),
if op(ex) = "/" then return(detexcolor(argsex[1])/detexcolor(argsex[2])),
map(detexcolor, ex)
)$
/* We only display matrices with the following matching pairs of delimiters.
Mismatching pairs ruins the API, so we can't have lmxchar and rmxchar as arbitrary.
The list has three arguments, the first is the search string, the second is the left
parentheses, and the third is the right parentheses.
*/
stack_matrix_pairs:[ ["[", "[", "]"], ["(", "(", ")"], ["\{", "\\{", "\\}"], ["{", "\\{", "\\}"], ["", "", ""], [".", "", ""], ["|", "|", "|"]] $
stack_matrix_disp(m):= block([ret, lp, rp, parens],
if not(matrixp(m)) then error("stack_matrix_disp: argument must be a matrix."),
if not(stringp(lmxchar)) then error("stack_matrix_disp requires lmxchar to be a string. "),
parens: sublist(stack_matrix_pairs, lambda([ex], is(first(ex)=lmxchar))),
if emptyp(parens) then error(concat("stack_matrix_disp: cannot display matrices with parentheses ", string(lmxchar))),
parens: first(parens),
lp: second(parens),
rp: third(parens),
ret: maplist(lambda([ex], maplist(tex1, args(ex))), args(m)),
ret: maplist(lambda([ex], simplode(ex, " & ")), ret),
ret: simplode(ret, " \\\\ "),
ret: sconcat("\\begin{array}{", simplode(maplist(lambda([ex], "c"), first(args(m)))), "} ", ret, " \\end{array}"),
if ""#lp then
ret: sconcat("\\left", lp, ret),
if ""#rp then
ret: sconcat(ret, "\\right", rp),
ret
)$
texput(matrix, stack_matrix_disp)$
/* ********************************** */
/* Display: Sort out the unary minus */
/* ********************************** */
/* To see an interesting example, see the following.
simp:false;
p:y^3-2*y^2-8*y;
?print(p);
In the structure of this expression the first negative coefficient is -(2y^2) BUT the second is -(8)*y.
((MPLUS) ((MEXPT) $Y 3) ((MMINUS) ((MTIMES) 2 ((MEXPT) $Y 2))) ((MTIMES) ((MMINUS) 8) $Y))
This again is a crucial but subtle difference....
The following functions sort this out, pulling "-" out the front in a specific situation: that of
a product with a negative number at the front.
Another interesting example. This illustrates the interaction with quotients.
simp:false;
p:x^7/7-2*x^6/3-4*x^3/3;
*/
/* Traverses an entire expression and ensures that "-"(number) really is the negative number. */
/* Although we ultimately need to transform all integers back into "-"(number) for correct display */
/* this function gives us a definite form for comparison purposes in the interim.*/
unary_minus_traverse(ex) := block(
/* We want atom here, not mapatom to catch a[4]. */
if atom(ex) then return(ex),
if op(ex) = "-" and numberp(first(args(ex))) then return(ev(ex,simp)),
if arrayp(ex) then return(arraymake(op(ex), maplist(unary_minus_traverse, args(ex)))),
apply(op(ex), map(unary_minus_traverse, args(ex)) )
)$
/* Pulls out "-" to the front of any expression in a sum of products which needs it. */
/* For example, -(2*y^2) is ok */
/* But (-3)*7 is not. */
unary_minus_pull(ex) := block([ex2],
if atom(ex) then return(ex),
ex2: apply(op(ex), map(unary_minus_pull, args(ex))),
if arrayp(ex) then ex2:arraymake(op(ex), map(unary_minus_pull, args(ex))),
if op(ex) = "+" then ex2:apply("+", map(unary_minus_pull_helper, args(ex2))),
if op(ex) = "*" then ex2:unary_minus_pull_helper(ex2),
return(ex2)
)$
/* Looks for */
/* - a negative number */
/* - a product of an number and something. */
/* - a quotient of an number and something. */
/* Makes sure any minus sign is the top element */
unary_minus_pull_helper(ex) := block([fe],
if numberp(ex) and is(ex<0) then return(-(ev(-1*ex,simp))), /* Turns -8 into "-"(8) */
if atom(ex) then return(ex),
fe: first(args(ex)), /* First element of the arguments. Is this a negative number? */
if op(ex) = "*" then
if numberp(fe) and is(fe<0)
then return(-(apply("*", append([ev(-fe,simp)], rest(args(ex)))))),
/* (-4*x^3)/4 is transformed into -(4*x^3)/4 */
if op(ex) = "/" and safe_op(fe) = "-" then
return(-(apply("/",append(args(fe),[second(args(ex))])))),
return(ex)
)$
/* Sorts out display of expressions in the case simp:false */
unary_minus_sort(ex) := block([ex2],
if simp or atom(ex) or taylorp(ex) or functionp(ex) then return(ex),
ex2: unary_minus_traverse(ex),
return(unary_minus_pull(ex2))
)$
/* ********************************** */
/* Generate feedback */
/* ********************************** */
StackAddFeedback(fb, key, [ex]) := block([str, exprs, jloop],
/* Note, the ex's are assumed to already be strings.
There would be no other way to sort out the $ vs $$'s */
/* Loop over the expressions */
exprs: "",
ev(for jloop:1 thru length(ex) do
/* HACK: !quot! needs to be replaced with " when we get into PHP. */
exprs: concat(exprs, " , !quot!", ex[jloop], "!quot! "), simp),
str: sconcat("stack_trans('", key, "'", exprs, "); !NEWLINE!"),
_APPEND_FEEDBACK(str),
return(sconcat(fb, str))
)$
/* Separate notes with puncutation, to enable clearer reading
and the possibility to split them. */
StackAddNote(exnote, newnote) := (_APPEND_NOTE(newnote),concat(exnote, newnote, ". "))$
StackTrimNote(ex) := strim(". ", ex)$
/* In many situations we just need the most basic object. */
StackBasicReturn(validity, result, note) := [validity, result, StackAddNote("", note), StackAddFeedback("", note)]$
/* note the extra closing ] here. The corresponding opening [ is generated in PHP. */
/* This is about the most ugly API ever, but there we go..... */
/* *************************************/
/* Output graphics, */
/* *************************************/
set_plot_option([run_viewer, false]);
set_plot_option([plot_format, gnuplot]);
set_plot_option([nticks, 50]);
set_plot_option([adapt_depth, 10]);
set_plot_option([gnuplot_default_term_command, ""]);
plot(ex, [ra]) := /*stack_web_plot*/
block([simp:true, tfn, tfnp1, tfnp2, tfnp3, afn, ufn, lvs, preamble, sysp, sysr,
filename, tn, alt, altc, alttext, ral, ralforbid, pltargs, plotfunmake, plotdebug,
plotgrid2d, size, psize, plot_size, plot_tags, stack_mtell_quiet, plotpid, margin],
stack_mtell_quiet:true,
plotdebug: false,
/* Check for grid2d in the plotoptions. */
plotgrid2d: false,
if member(grid2d, ra) or member(STACKGRID, ra) then
plotgrid2d: true,
/* Arguments to plot must be lists. */
ral: sublist(ra, listp), /* The actual arguments used by plot. */
/* Check expressions to be plotted has/have only one variable. */
ex: ev(ex, nouns, simp),
/* Remove logarithms to other bases from expressions. */
if not(freeof(lg, ex)) then
ex:ev(ex, lg=logbasesimp),
lvs: listofvars(%_ce_rem(ex)),