File: io.chapt.txt

package info (click to toggle)
yacas 1.3.6-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 7,176 kB
  • ctags: 3,520
  • sloc: cpp: 13,960; java: 12,602; sh: 11,401; makefile: 552; perl: 517; ansic: 381
file content (1361 lines) | stat: -rw-r--r-- 40,275 bytes parent folder | download | duplicates (5)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361

			Input/output and plotting

*INTRO
This chapter contains commands to use for input and output and plotting. All output
commands write to the same destination stream, called the "current
output". This is initially the screen, but may be
redirected by some commands. Similarly, most input commands
read from the "current input" stream, which can also be redirected. The
exception to this rule are the commands for reading script files,
which simply read a specified file.

*CMD FullForm --- print an expression in LISP-format
*CORE
*CALL
	FullForm(expr)

*PARMS

{expr} -- expression to be printed in LISP-format

*DESC

Evaluates "expr", and prints it in LISP-format on the current
output. It is followed by a newline. The evaluated expression is also
returned.

This can be useful if you want to study the internal representation of
a certain expression.

*E.G. notest

	In> FullForm(a+b+c);
	(+ (+ a b )c )
	Out> a+b+c;
	In> FullForm(2*I*b^2);
	(* (Complex 0 2 )(^ b 2 ))
	Out> Complex(0,2)*b^2;

The first example shows how the expression {a+b+c} is
internally represented. In the second example, {2*I} is
first evaluated to {Complex(0,2)} before the expression
is printed.

*SEE LispRead, Listify, Unlist

*CMD Echo --- high-level printing routine
*STD
*CALL
	Echo(item)
	Echo(list)
	Echo(item,item,item,...)

*PARMS

{item} -- the item to be printed

{list} -- a list of items to be printed

*DESC

If passed a single item, {Echo} will evaluate it and print it to the
current output, followed by a newline. If {item} is a string, it is
printed without quotation marks.

If there is one argument, and it is a list, {Echo} will print all the
entries in the list subsequently to the current output, followed by a
newline. Any strings in the list are printed without quotation
marks. All other entries are followed by a space.

{Echo} can be called with a variable number of arguments, they will all
be printed, followed by a newline.

{Echo} always returns {True}.

*E.G. notest

	In> Echo(5+3);
	 8
	Out> True;
	In> Echo({"The square of two is ", 2*2});
	The square of two is 4
	Out> True;
	In> Echo("The square of two is ", 2*2);
	The square of two is 4 
	Out> True;

Note that one must use the second calling format if one wishes to
print a list:

	In> Echo({a,b,c});
	a b c
	Out> True;
	In> Echo({{a,b,c}});
	{a,b,c}
	Out> True;

*SEE PrettyForm, Write, WriteString, RuleBaseListed

*CMD PrettyForm --- print an expression nicely with ASCII art
*STD
*CALL
	PrettyForm(expr)

*PARMS

{expr} -- an expression

*DESC

{PrettyForm} renders an expression in a nicer way, using ascii art.
This is generally useful when the result of a calculation is more
complex than a simple number.

*E.G.

	In> Taylor(x,0,9)Sin(x)
	Out> x-x^3/6+x^5/120-x^7/5040+x^9/362880;
	In> PrettyForm(%)
	
	     3    5      7       9
	    x    x      x       x
	x - -- + --- - ---- + ------
	    6    120   5040   362880
	
	Out> True;

*SEE EvalFormula, PrettyPrinter'Set

*CMD EvalFormula --- print an evaluation nicely with ASCII art
*STD
*CALL
	EvalFormula(expr)

*PARMS

{expr} -- an expression

*DESC

Show an evaluation in a nice way, using {PrettyPrinter'Set}
to show 'input = output'.

*E.G.

	In> EvalFormula(Taylor(x,0,7)Sin(x))
	
	                                      3    5
	                                     x    x  
	Taylor( x , 0 , 5 , Sin( x ) ) = x - -- + ---
	                                     6    120


*SEE PrettyForm

*CMD TeXForm --- export expressions to $LaTeX$
*STD
*CALL
	TeXForm(expr)

*PARMS

{expr} -- an expression to be exported

*DESC

{TeXForm} returns a string containing a $LaTeX$ representation of the Yacas expression {expr}. Currently the exporter handles most expression types but not all.

*EG

	In> TeXForm(Sin(a1)+2*Cos(b1))
	Out> "$\sin a_{1} + 2 \cos b_{1}$";

*SEE PrettyForm, CForm

*CMD CForm --- export expression to C++ code
*STD
*CALL
	CForm(expr)
	
*PARMS

{expr} -- expression to be exported

*DESC

{CForm} returns a string containing C++ code that attempts to implement the Yacas expression {expr}. Currently the exporter handles most expression types but not all.

*EG

	In> CForm(Sin(a1)+2*Cos(b1));
	Out> "sin(a1) + 2 * cos(b1)";

*SEE PrettyForm, TeXForm, IsCFormable

*CMD IsCFormable --- check possibility to export expression to C++ code
*STD
*CALL
	IsCFormable(expr)
	IsCFormable(expr, funclist)
	
*PARMS

{expr} -- expression to be exported (this argument is not evaluated)

{funclist} -- list of "allowed" function atoms

*DESC

{IsCFormable} returns {True} if the Yacas expression {expr} can be exported
into C++ code. This is a check whether the C++ exporter {CForm} can be safely
used on the expression.

A Yacas expression is considered exportable if it contains only functions that can be translated into C++ (e.g. {UnList} cannot be exported). All variables and constants are considered exportable.

The verbose option prints names of functions that are not exportable.

The second calling format of {IsCFormable} can be used to "allow" certain function names that will be available in the C++ code.

*E.G. notest

	In> IsCFormable(Sin(a1)+2*Cos(b1))
	Out> True;
	In> V(IsCFormable(1+func123(b1)))
	IsCFormable: Info: unexportable function(s):
	  func123
	Out> False;
This returned {False} because the function {func123} is not available in C++. We can
explicitly allow this function and then the expression will be considered
exportable:

	In> IsCFormable(1+func123(b1), {func123})
	Out> True;

*SEE CForm, V

*CMD Write --- low-level printing routine
*CORE
*CALL
	Write(expr, ...)

*PARMS

{expr} -- expression to be printed

*DESC

The expression "expr" is evaluated and written to the current
output. Note that Write accept an arbitrary number of arguments, all
of which are written to the current output (see second
example). {Write} always returns {True}.

*E.G. notest

	In> Write(1);
	1Out> True;
	In> Write(1,2);
	 1 2Out> True;

Write does not write a newline, so the {Out>} prompt
immediately follows the output of {Write}.

*SEE Echo, WriteString

*CMD WriteString --- low-level printing routine for strings
*CORE
*CALL
	WriteString(string)

*PARMS

{string} -- the string to be printed

*DESC

The expression "string" is evaluated and written to the current
output without quotation marks. The argument should be a
string. WriteString always returns True.

*E.G. notest

	In> Write("Hello, world!");
	"Hello, world!"Out> True;
	In> WriteString("Hello, world!");
	Hello, world!Out> True;

This example clearly shows the difference between Write and
WriteString. Note that Write and WriteString do not write a newline,
so the {Out>} prompt immediately follows the output.

*SEE Echo, Write

*CMD Space --- print one or more spaces
*STD
*CALL
	Space()
	Space(nr)

*PARMS

{nr} -- the number of spaces to print

*DESC

The command {Space()} prints one space on the
current output. The second form prints {nr} spaces on the current
output. The result is always True.

*E.G. notest

	In> Space(5);
	     Out> True;

*SEE Echo, Write, NewLine

*CMD NewLine --- print one or more newline characters
*STD
*CALL
	NewLine()
	NewLine(nr)

*PARMS

{nr} -- the number of newline characters to print

*DESC

The command {NewLine()} prints one newline character
on the current output. The second form prints "nr" newlines on the
current output. The result is always True.

*E.G. notest

	In> NewLine();
	
	Out> True;

*SEE Echo, Write, Space

*CMD FromFile --- connect current input to a file
*CORE
*CALL
	FromFile(name) body

*PARMS

{name} - string, the name of the file to read

{body} - expression to be evaluated

*DESC

The current input is connected to the file "name". Then the expression
"body" is evaluated. If some functions in "body" try to read
from current input, they will now read from the file "name". Finally, the
file is closed and the result of evaluating "body" is returned.

*E.G. notest

Suppose that the file {foo} contains

	2 + 5;

Then we can have the following dialogue:

	In> FromFile("foo") res := Read();
	Out> 2+5;
	In> FromFile("foo") res := ReadToken();
	Out> 2;

*SEE ToFile, FromString, Read, ReadToken

*CMD FromString --- connect current input to a string
*CORE
*CALL
	FromString(str) body;

*PARMS

{str} -- a string containing the text to parse

{body} -- expression to be evaluated

*DESC

The commands in "body" are executed, but everything that is read
from the current input is now read from the string "str". The
result of "body" is returned.

*E.G.

	In> FromString("2+5; this is never read") \
	  res := Read();
	Out> 2+5;
	In> FromString("2+5; this is never read") \
	  res := Eval(Read());
	Out> 7;

*SEE ToString, FromFile, Read, ReadToken

*CMD ToFile --- connect current output to a file
*CORE
*CALL
	ToFile(name) body

*PARMS

{name} -- string, the name of the file to write the result to

{body} -- expression to be evaluated

*DESC

The current output is connected to the file "name". Then the expression
"body" is evaluated. Everything that the commands in "body" print
to the current output, ends up in the file "name". Finally, the
file is closed and the result of evaluating "body" is returned.

If the file is opened again, the old contents will be overwritten.
This is a limitation of {ToFile}: one cannot append to a file that has already been created.

*E.G. notest

Here is how one can create a file with C code to evaluate an expression:

	In> ToFile("expr1.c") WriteString(
	  CForm(Sqrt(x-y)*Sin(x)) );
	Out> True;
The file {expr1.c} was created in the current working directory and it
contains the line
	sqrt(x-y)*sin(x)

As another example, take a look at the following command:

	In> [ Echo("Result:");  \
	  PrettyForm(Taylor(x,0,9) Sin(x)); ];
	Result:
	
	     3    5      7       9
	    x    x      x       x
	x - -- + --- - ---- + ------
	    6    120   5040   362880
	
	Out> True;

Now suppose one wants to send the output of this command to a
file. This can be achieved as follows:

	In> ToFile("out") [ Echo("Result:");  \
	  PrettyForm(Taylor(x,0,9) Sin(x)); ];
	Out> True;

After this command the file {out} contains:

	
	Result:
	
	     3    5      7       9
	    x    x      x       x
	x - -- + --- - ---- + ------
	    6    120   5040   362880
	

*SEE FromFile, ToString, Echo, Write, WriteString, PrettyForm, Taylor

*CMD ToString --- connect current output to a string
*CORE
*CALL
	ToString() body

*PARMS

{body} -- expression to be evaluated

*DESC

The commands in "body" are executed. Everything that is printed on
the current output, by {Echo} for instance, is
collected in a string and this string is returned.

*E.G.

	In> str := ToString() [ WriteString(  \
	  "The square of 8 is "); Write(8^2); ];
	Out> "The square of 8 is  64";

*SEE FromFile, ToString, Echo, Write, WriteString

*CMD Read --- read an expression from current input
*CORE
*CALL
	Read()

*DESC

Read an expression from the current input, and return it unevaluated. When
the end of an input file is encountered, the token atom {EndOfFile} is returned.

*E.G.

	In> FromString("2+5;") Read();
	Out> 2+5;
	In> FromString("") Read();
	Out> EndOfFile;

*SEE FromFile, FromString, LispRead, ReadToken, Write



*CMD ToStdout --- select initial output stream for output
*CORE
*CALL
	ToStdout() body

*PARMS

{body} -- expression to be evaluated

*DESC

When using {ToString} or {ToFile}, it might happen that something needs to be
written to the standard default initial output (typically the screen). {ToStdout} can be used to select this stream.

*EG

	In> ToString()[Echo("aaaa");ToStdout()Echo("bbbb");];
	bbbb
	Out> "aaaa
	"

*SEE ToString, ToFile




*CMD ReadCmdLineString --- read an expression from command line and return in string
*CORE
*CALL
	ReadCmdLineString(prompt)

*PARMS

{prompt} -- string representing the prompt shown on screen

*DESC

This function allows for interactive input similar to the command line.
When using this function, the history from the command line is also available.

The result is returned in a string, so it still needs to be parsed.

This function will typically be used in situations where one wants a custom 
read-eval-print loop. 


*E.G. notest

The following defines a function that when invoked keeps asking
for an expression (the <i>read</i> step), and then takes 
the derivative of it (the <i>eval</i> step) and then 
uses PrettyForm to display the result (the <i>print</i> step).

	In> ReEvPr() := \
	In>   While(True) [ \
	In>     PrettyForm(Deriv(x) \
	In>      FromString(ReadCmdLineString("Deriv> "):";")Read()); \
	In> ];
	Out> True;

Then one can invoke the command, from which the following interaction
might follow:

	In> ReEvPr()
	Deriv> Sin(a^2*x/b)
	
	   /  2     \         
	   | a  * x |    2    
	Cos| ------ | * a  * b
	   \   b    /         
	----------------------
	           2          
	          b           
	
	Deriv> Sin(x)
	
	Cos( x )
	
	Deriv> 

*SEE Read, LispRead, LispReadListed


*CMD LispRead --- read expressions in LISP syntax
*CMD LispReadListed --- read expressions in LISP syntax
*CORE
*CALL
	LispRead()
	LispReadListed()

*DESC

The function {LispRead} reads an expression in the LISP syntax from the current input, and returns
it unevaluated. When the end of an input file is encountered, the
special token atom {EndOfFile} is returned.

The Yacas expression {a+b} is written in the LISP syntax as {(+ a b)}. The advantage of this syntax is that it is
less ambiguous than the infix operator grammar that Yacas uses by
default.

The function {LispReadListed} reads a LISP expression and returns
it in a list, instead of the form usual to Yacas (expressions).
The result can be thought of as applying {Listify} to {LispRead}.
The function {LispReadListed} is more useful for reading arbitrary LISP expressions, because the 
first object in a list can be itself a list (this is never the case for Yacas expressions where the first object in a list is always a function atom).

*E.G. notest

	In> FromString("(+ a b)") LispRead();
	Out> a+b;
	In> FromString("(List (Sin x) (- (Cos x)))") \
	  LispRead();
	Out> {Sin(x),-Cos(x)};
	In> FromString("(+ a b)")LispRead()
	Out> a+b;
	In> FromString("(+ a b)")LispReadListed()
	Out> {+,a,b};

*SEE FromFile, FromString, Read, ReadToken, FullForm

*CMD ReadToken --- read a token from current input
*CORE
*CALL
	ReadToken()

*DESC

Read a token from the current input, and return it unevaluated.
The returned object is a Yacas atom (not a string).
When
the end of an input file is encountered, the token atom {EndOfFile} is returned.

A token is for computer languages what a word is for human languages:
it is the smallest unit in which a command can be divided, so that the
semantics (that is the meaning) of the command is in some sense a
combination of the semantics of the tokens. Hence {a := foo} consists of three tokens, namely {a}, {:=}, and {foo}.

The parsing of the string depends on the syntax of the language.
The part of the kernel that does the parsing is the "tokenizer".
Yacas can parse its own syntax (the default tokenizer) or it can be instructed to parse XML or C++ syntax using the directives {DefaultTokenizer} or {XmlTokenizer}.
Setting a tokenizer is a global action that affects all {ReadToken} calls.

*E.G. notest

	In> FromString("a := Sin(x)") While \
	  ((tok := ReadToken()) != EndOfFile) \
	  Echo(tok);
	a
	:=
	Sin
	(
	x
	)
	Out> True;

We can read some junk too:
	In> FromString("-$3")ReadToken();
	Out> -$;
The result is an atom with the string representation {-$}.
Yacas assumes that {-$} is an operator symbol yet to be defined.
The "{3}" will be in the next token.
(The results will be different if a non-default tokenizer is selected.)


*SEE FromFile, FromString, Read, LispRead, DefaultTokenizer

*CMD Load --- evaluate all expressions in a file
*CORE
*CALL
	Load(name)

*PARMS

{name} -- string, name of the file to load

*DESC

The file "name" is opened. All expressions in the file are read and
evaluated. {Load} always returns {true}.

*SEE Use, DefLoad, DefaultDirectory, FindFile

*CMD Use --- load a file, but not twice
*CORE
*CALL
	Use(name)

*PARMS

{name} -- string, name of the file to load

*DESC

If the file "name" has been loaded before, either by an earlier call
to {Use} or via the {DefLoad}
mechanism, nothing happens. Otherwise all expressions in the file are
read and evaluated. {Use} always returns {true}.

The purpose of this function is to make sure that the file will at
least have been loaded, but is not loaded twice.

*SEE Load, DefLoad, DefaultDirectory

*CMD DefLoad --- load a {.def} file
*CORE
*CALL
	DefLoad(name)

*PARMS

{name} -- string, name of the file (without {.def} suffix)

*DESC

The suffix {.def} is appended to "name" and the
file with this name is loaded. It should contain a list of functions,
terminated by a closing brace \} (the end-of-list delimiter). This
tells the system to load the file "name" as soon as the user calls
one of the functions named in the file (if not done so already). This
allows for faster startup times, since not all of the rules databases
need to be loaded, just the descriptions on which files to load for
which functions.

*SEE Load, Use, DefaultDirectory

*CMD FindFile --- find a file in the current path
*CORE
*CALL
	FindFile(name)

*PARMS

{name} -- string, name of the file or directory to find

*DESC

The result of this command is the full path to the file that would be
opened when the command {Load(name)} would be
invoked. This means that the input directories are subsequently
searched for a file called "name". If such a file is not found, {FindFile} returns an empty string.

{FindFile("")} returns the name of the default directory (the first one on the search path).

*SEE Load, DefaultDirectory

*CMD PatchLoad --- execute commands between {<?} and {?>} in file
*CORE
*CALL
	PatchLoad(name)

*PARMS

{name} -- string, name of the file to "patch"

*DESC

{PatchLoad} loads in a file and outputs the contents to the current
output. The file can contain blocks delimited by {<?} and {?>}
(meaning "Yacas Begin" and "Yacas End"). The piece of text between
such delimiters is treated as a separate file with Yacas instructions,
which is then loaded and executed. All output of write statements
in that block will be written to the same current output.

This is similar to the way PHP works. You can have a static text file
with dynamic content generated by Yacas.

*SEE PatchString, Load

*CMD Nl --- the newline character
*STD
*CALL
	Nl()

*DESC

This function returns a string with one element in it, namely a newline
character. This may be useful for building strings to send to some
output in the end.

Note that the second letter in the name of this command is a lower
case {L} (from "line").

*E.G. notest

	In> WriteString("First line" : Nl() : "Second line" : Nl());
	First line
	Second line
	Out> True;

*SEE NewLine

*CMD V, InVerboseMode --- set verbose output mode
*STD
*CALL
	V(expression)
	InVerboseMode()

*PARMS

{expression} -- expression to be evaluated in verbose mode

*DESC

The function {V(expression)} will evaluate the expression in 
verbose mode. Various parts of Yacas can show extra information
about the work done while doing a calculation when using {V}.

In verbose mode, {InVerboseMode()} will return {True}, otherwise
it will return {False}.

*E.G. notest

	In> OldSolve({x+2==0},{x})
	Out> {{-2}};
	In> V(OldSolve({x+2==0},{x}))
	Entering OldSolve
	From  x+2==0  it follows that  x  = -2 
	   x+2==0  simplifies to  True 
	Leaving OldSolve
	Out> {{-2}};
	In> InVerboseMode()
	Out> False
	In> V(InVerboseMode())
	Out> True

*SEE Echo, N, OldSolve



*CMD Plot2D --- adaptive two-dimensional plotting
*STD
*CALL
	Plot2D(f(x))
	Plot2D(f(x), a:b)
	Plot2D(f(x), a:b, option=value)
	Plot2D(f(x), a:b, option=value, ...)
	Plot2D(list, ...)

*PARMS

{f(x)} -- unevaluated expression containing one variables (function to be plotted)

{list} -- list of functions to plot

{a}, {b} -- numbers, plotting range in the $x$ coordinate

{option} -- atom, option name

{value} -- atom, number or string (value of option)

*DESC
The routine {Plot2D} performs adaptive plotting of one or several functions
of one variable in the specified range.
The result is presented as a line given by the equation $y=f(x)$.
Several functions can be plotted at once.
Various plotting options can be specified.
Output can be directed to a plotting program (the default is to use
{data}) to a list of values.

The function parameter {f(x)} must evaluate to a Yacas expression containing
at most one variable. (The variable does not have to be called {x}.)
Also, {N(f(x))} must evaluate to a real (not complex) numerical value when given a numerical value of the argument {x}.
If the function {f(x)} does not satisfy these requirements, an error is raised.

Several functions may be specified as a list and they do not have to depend on the same variable, for example, {{f(x), g(y)}}.
The functions will be plotted on the same graph using the same coordinate ranges.

If you have defined a function which accepts a number but does not
accept an undefined variable, {Plot2D} will fail to plot it.
Use {NFunction} to overcome this difficulty.

Data files are created in a temporary directory {/tmp/plot.tmp/} unless otherwise requested.
File names
and other information is printed if {InVerboseMode()} returns {True} on using {V()}.

The current algorithm uses Newton-Cotes quadratures and some heuristics for error estimation (see <*yacasdoc://Algo/3/1/*>).
The initial grid of {points+1} points is refined between any grid points $a$, $b$ if the integral
$Integrate(x,a,b)f(x)$ is not approximated to the given precision by
the existing grid.

Default plotting range is {-5:5}. Range can also be specified as {x= -5:5} (note the mandatory space separating "{=}" and "{-}");
currently the variable name {x} is ignored in this case.

Options are of the form {option=value}. Currently supported option names
are: "points", "precision", "depth", "output", "filename", "yrange". Option values
are either numbers or special unevaluated atoms such as {data}.
If you need to use the names of these atoms
in your script, strings can be used. Several option/value pairs may be specified (the function {Plot2D} has a variable number of arguments).

*	{yrange}: the range of ordinates to use for plotting, e.g.
{yrange=0:20}. If no range is specified, the default is usually to
leave the choice to the plotting backend. 
*	{points}: initial number of points (default 23) -- at least that
many points will be plotted. The initial grid of this many points will be
adaptively refined. 
*	{precision}: graphing precision (default $10^(-6)$). This is interpreted as the relative precision of computing the integral of $f(x)-Min(f(x))$ using the grid points. For a smooth, non-oscillating function this value should be roughly 1/(number of screen pixels in the plot).
*	{depth}: max. refinement depth, logarithmic (default 5) -- means there will be at most $2^depth$ extra points per initial grid point.
*	{output}: name of the plotting backend. Supported names: {data} (default).
The {data} backend will return the data as a list of pairs such as {{{x1,y1}, {x2,y2}, ...}}.
*	{filename}: specify name of the created data file. For example: {filename="data1.txt"}.
The default is the name {"output.data"}.
Note that if several functions are plotted, the data files will have a number appended to the given name, for example {data.txt1}, {data.txt2}.

Other options may be supported in the future.

The current implementation can deal with a singularity within the plotting range only if the function {f(x)} returns {Infinity}, {-Infinity} or
{Undefined} at the singularity.
If the function {f(x)} generates a numerical error and fails at a
singularity, {Plot2D} will fail if one of the grid points falls on the
singularity.
(All grid points are generated by bisection so in principle the
endpoints and the {points} parameter could be chosen to avoid numerical
singularities.)

*WIN32



*SEE V, NFunction, Plot3DS



*CMD Plot3DS --- three-dimensional (surface) plotting
*STD
*CALL
	Plot3DS(f(x,y))
	Plot3DS(f(x,y), a:b, c:d)
	Plot3DS(f(x,y), a:b, c:d, option=value)
	Plot3DS(f(x,y), a:b, c:d, option=value, ...)
	Plot3DS(list, ...)

*PARMS

{f(x,y)} -- unevaluated expression containing two variables (function to be plotted)

{list} -- list of functions to plot

{a}, {b}, {c}, {d} -- numbers, plotting ranges in the $x$ and $y$ coordinates

{option} -- atom, option name

{value} -- atom, number or string (value of option)

*DESC
The routine {Plot3DS} performs adaptive plotting of a function
of two variables in the specified ranges.
The result is presented as a surface given by the equation $z=f(x,y)$.
Several functions can be plotted at once, by giving a list of functions.
Various plotting options can be specified.
Output can be directed to a plotting program (the default is to use
{data}), to a list of values.

The function parameter {f(x,y)} must evaluate to a Yacas expression containing
at most two variables. (The variables do not have to be called {x} and {y}.)
Also, {N(f(x,y))} must evaluate to a real (not complex) numerical value when given numerical values of the arguments {x}, {y}.
If the function {f(x,y)} does not satisfy these requirements, an error is raised.

Several functions may be specified as a list but they have to depend on the same symbolic variables, for example, {{f(x,y), g(y,x)}}, but not {{f(x,y), g(a,b)}}.
The functions will be plotted on the same graph using the same coordinate ranges.

If you have defined a function which accepts a number but does not
accept an undefined variable, {Plot3DS} will fail to plot it.
Use {NFunction} to overcome this difficulty.

Data files are created in a temporary directory {/tmp/plot.tmp/} unless otherwise requested.
File names
and other information is printed if {InVerboseMode()} returns {True} on using {V()}.

The current algorithm uses Newton-Cotes cubatures and some heuristics for error estimation (see <*yacasdoc://Algo/3/1/*>).
The initial rectangular grid of {xpoints+1}*{ypoints+1} points is refined within any rectangle where the integral
of $f(x,y)$ is not approximated to the given precision by
the existing grid.

Default plotting range is {-5:5} in both coordinates.
A range can also be specified with a variable name, e.g. {x= -5:5} (note the mandatory space separating "{=}" and "{-}").
The variable name {x} should be the same as that used in the function {f(x,y)}.
If ranges are not given with variable names, the first variable encountered in the function {f(x,y)} is associated with the first of the two ranges.

Options are of the form {option=value}. Currently supported option names
are "points", "xpoints", "ypoints", "precision", "depth", "output", "filename", "xrange", "yrange", "zrange". Option values
are either numbers or special unevaluated atoms such as {data}.
If you need to use the names of these atoms
in your script, strings can be used (e.g. {output="data"}). Several option/value pairs may be specified (the function {Plot3DS} has a variable number of arguments).

*	{xrange}, {yrange}: optionally override coordinate ranges. Note that {xrange} is always the first variable and {yrange} the second variable, regardless of the actual variable names.
*	{zrange}: the range of the $z$ axis to use for plotting, e.g.
{zrange=0:20}. If no range is specified, the default is usually to
leave the choice to the plotting backend. Automatic choice based on actual values may
give visually inadequate plots if the function has a singularity.
*	{points}, {xpoints}, {ypoints}: initial number of points (default 10 each) -- at least that
many points will be plotted in each coordinate.
The initial grid of this many points will be
adaptively refined.
If {points} is specified, it serves as a default for both {xpoints} and {ypoints}; this value may be overridden by {xpoints} and {ypoints} values.
*	{precision}: graphing precision (default $0.01$). This is interpreted as the relative precision of computing the integral of $f(x,y)-Min(f(x,y))$ using the grid points. For a smooth, non-oscillating function this value should be roughly 1/(number of screen pixels in the plot).
*	{depth}: max. refinement depth, logarithmic (default 3) -- means there will be at most $2^depth$ extra points per initial grid point (in each coordinate).
*	{output}: name of the plotting backend. Supported names: {data} (default).
The {data} backend will return the data as a list of triples such as {{{x1, y1, z1}, {x2, y2, z2}, ...}}.

Other options may be supported in the future.

The current implementation can deal with a singularity within the plotting range only if the function {f(x,y)} returns {Infinity}, {-Infinity} or
{Undefined} at the singularity.
If the function {f(x,y)} generates a numerical error and fails at a
singularity, {Plot3DS} will fail only if one of the grid points falls on the
singularity.
(All grid points are generated by bisection so in principle the
endpoints and the {xpoints}, {ypoints} parameters could be chosen to avoid numerical
singularities.)

The {filename} option is optional if using graphical backends, but can be used to specify the location of the created data file.

*WIN32

Same limitations as {Plot2D}.

*E.G. notest
	In> Plot3DS(a*b^2)
	Out> True;
	In> V(Plot3DS(Sin(x)*Cos(y),x=0:20, y=0:20,depth=3))
	CachedConstant: Info: constant Pi is being 
	  recalculated at precision 10
	CachedConstant: Info: constant Pi is being
	  recalculated at precision 11
	Plot3DS: using 1699  points for function Sin(x)*Cos(y)
	Plot3DS: max. used 8 subdivisions for Sin(x)*Cos(y)
	Plot3DS'datafile: created file '/tmp/plot.tmp/data1'
	Out> True;


*SEE V, NFunction, Plot2D

*CMD XmlExplodeTag --- convert XML strings to tag objects
*CORE
*CALL
	XmlExplodeTag(xmltext)
*PARMS

{xmltext} -- string containing some XML tokens

*DESC

{XmlExplodeTag} parses the first XML token in {xmltext}
and returns a Yacas expression.

The following subset of XML syntax is supported currently:

*	{<TAG [options]>} -- an opening tag
*	{</TAG [options]>} -- a closing tag
*	{<TAG [options] />} -- an open/close tag
*	plain (non-tag) text

The tag options take the form {paramname="value"}.

If given an XML tag, {XmlExplodeTag} returns a structure of the form {XmlTag(name,params,type)}.
In the returned object,
{name} is the (capitalized) tag name, {params} is an assoc list with
the options (key fields capitalized), and type can be either "Open", "Close" or "OpenClose".

If given a plain text string, the same string is returned.


*E.G.
	In> XmlExplodeTag("some plain text")
	Out> "some plain text";
	In> XmlExplodeTag("<a name=\"blah blah\"
	  align=\"left\">")
	Out> XmlTag("A",{{"ALIGN","left"},
	  {"NAME","blah blah"}},"Open");
	In> XmlExplodeTag("</p>")
	Out> XmlTag("P",{},"Close");
	In> XmlExplodeTag("<br/>")
	Out> XmlTag("BR",{},"OpenClose");

*SEE XmlTokenizer

*CMD DefaultTokenizer --- select the default syntax tokenizer for parsing the input
*CMD XmlTokenizer --- select an XML syntax tokenizer for parsing the input
*CORE
*CALL
	DefaultTokenizer()
	XmlTokenizer()

*DESC

A "tokenizer" is an internal routine in the kernel that parses the input into Yacas expressions.
This affects all input typed in by a user at the prompt and also the input redirected from files or strings using {FromFile} and {FromString} and read using {Read} or {ReadToken}.

The Yacas environment currently supports some experimental tokenizers for 
various syntaxes. {DefaultTokenizer} switches to the tokenizer used for
default Yacas syntax. {XmlTokenizer} switches to an XML syntax.
Note that setting the tokenizer is a global side effect.
One typically needs
to switch back to the default tokenizer when finished reading the special syntax.

Care needs to be taken when kernel errors are raised during a non-default tokenizer operation (as with any global change in the environment).
Errors need to be
caught with the {TrapError} function. The error handler code should re-instate
the default tokenizer,
or else the user will be unable to continue the session
(everything a user types will be parsed using a non-default tokenizer).

When reading XML syntax, the supported formats are the same as those of {XmlExplodeTag}.
The parser does not validate anything in the XML input.
After an XML token has been read in, it can be converted into an
Yacas expression with {XmlExplodeTag}.
Note that when reading XML, any plain text between tags is returned as one token.
Any malformed XML will be treated as plain text.


*EG notest

	In> [XmlTokenizer(); q:=ReadToken(); \
	  DefaultTokenizer();q;]
	<a>Out> <a>;

Note that:
*	1. after switching to {XmlTokenizer} the {In>} prompt disappeared; the user typed {<a>} and the {Out>} prompt with the resulting expression appeared.
*	2. The resulting expression is an atom with the string representation {<a>};
it is <i>not</i> a string.

*SEE OMRead, TrapError, XmlExplodeTag, ReadToken, FromFile, FromString



*CMD OMForm --- convert Yacas expression to OpenMath
*CMD OMRead --- convert expression from OpenMath to Yacas expression
*STD
*CALL
	OMForm(expression)
	OMRead()

*PARMS

{expression} -- expression to convert

*DESC

{OMForm} prints an OpenMath representation of the input parameter {expression}
to standard output. {OMRead} reads an OpenMath expression from standard
input and returns a normal Yacas expression that matches the input OpenMath
expression.

If a Yacas symbol does not have a mapping defined by {OMDef}, it is translated
to and from OpenMath as the OpenMath symbol in the CD "yacas" with the same
name as it has in Yacas.

*EG notest

	In> str:=ToString()OMForm(2+Sin(a*3))
	Out> "<OMOBJ>
	  <OMA>
	    <OMS cd="arith1" name="plus"/>
	    <OMI>2</OMI>
	    <OMA>
	      <OMS cd="transc1" name="sin"/>
	      <OMA>
	        <OMS cd="arith1" name="times"/>
	        <OMV name="a"/>
	        <OMI>3</OMI>
	      </OMA>
	    </OMA>
	  </OMA>
	</OMOBJ>
	";
	In> FromString(str)OMRead()
	Out> 2+Sin(a*3);

	In> OMForm(NotDefinedInOpenMath(2+3))
	<OMOBJ>
	  <OMA>
	    <OMS cd="yacas" name="NotDefinedInOpenMath"/>
	    <OMA>
	      <OMS cd="arith1" name="plus"/>
	      <OMI>2</OMI>
	      <OMI>3</OMI>
	    </OMA>
	  </OMA>
	</OMOBJ>
	Out> True

*SEE XmlTokenizer, XmlExplodeTag, OMDef



*CMD OMDef --- define translations from Yacas to OpenMath and vice-versa.
*STD
*CALL
	OMDef(yacasForm, cd, name)
	OMDef(yacasForm, cd, name, yacasToOM)
	OMDef(yacasForm, cd, name, yacasToOM, omToYacas)

*PARMS

{yacasForm} -- string with the name of a Yacas symbol, or a Yacas expression

{cd} -- OpenMath Content Dictionary for the symbol

{name} -- OpenMath name for the symbol

{yacasToOM} -- rule for translating an application of that symbol in Yacas into an OpenMath expression

{omToYacas} -- rule for translating an OpenMath expression into an application of this symbol in Yacas

*DESC

{OMDef} defines the translation rules for symbols between the Yacas
representation and {OpenMath}.
The first parameter, {yacasForm}, can be a string or an expression. The
difference is that when giving an expression only the {omToYacas} translation
is defined, and it uses the exact expression given. This is used for {OpenMath}
symbols that must be translated into a whole subexpression in Yacas, such
as {set1:emptyset} which gets translated to an empty list as follows:
	In> OMDef( {}, "set1","emptyset" )
	Out> True
	In> FromString("<OMOBJ><OMS cd=\"set1\" name=\"emptyset\"/></OMOBJ> ")OMRead()
	Out> {}
	In> IsList(%)
	Out> True
Otherwise, a symbol that is not inside an application (OMA) gets translated to
the Yacas atom with the given name:
	In> OMDef( "EmptySet", "set1","emptyset" )
	Warning: the mapping for set1:emptyset was already defined as {} , but is redefined now as EmptySet
	Out> True
	In> FromString("<OMOBJ><OMS cd=\"set1\" name=\"emptyset\"/></OMOBJ> ")OMRead()
	Out> EmptySet

The definitions for the symbols in the Yacas
library are in the {*.rep} script subdirectories. In those modules for which
the mappings are defined, there is a file called {om.ys} that contains the
{OMDef} calls. Those files are loaded in {openmath.rep/om.ys}, so any new
file must be added to the list there, at the end of the file.

A rule is represented as a list of expressions. Since both OM and
Yacas expressions are actually lists, the syntax is the same in both
directions. There are two template forms that are expanded before the
translation:

*	{$}: this symbol stands for the translation of the symbol applied
in the original expression.

*	{_path}: a path into the original expression (list) to extract an
element, written as an underscore applied to an integer or a list of integers.
  Those integers are indexes into expressions, and integers in a list are
  applied recursively starting at the original expression.
  For example, {_2} means the second parameter of the expression, while
  {_{3,2,1}} means the first parameter of the second parameter of the third
  parameter of the original expression.

They can appear anywhere in the rule as expressions or subexpressions.

Finally, several alternative rules can be specified by joining them with
the {|} symbol, and each of them can be annotated with a post-predicate
applied with the underscore {_} symbol, in the style of Yacas' simplification
rules. Only the first alternative rule that matches is applied, so the more
specific rules must be written first.

There are special symbols recognized by {OMForm} to output {OpenMath}
constructs that have no specific parallel in Yacas, such as an OpenMath
symbol having a {CD} and {name}: Yacas symbols have only a name.
Those special symbols are:

*	{OMS(cd, name)}: {<OMS cd="cd" name="name">}
*	{OMA(f x y ...)}: {<OMA>f x y ...</OMA>}
*	{OMBIND(binderSymbol, bvars, expression)}: {<OMBIND>binderSymbol bvars expression</OMBIND>}, where {bvars} must be produced by using {OMBVAR(...)}.
*	{OMBVAR(x y ...)}: {<OMBVAR>x y ...</OMBVAR>}
*	{OME(...)}: {<OME>...</OME>}

When translating from OpenMath to Yacas, we just store unknown symbols as
{OMS("cd", "name")}. This way we don't have to bother defining bogus symbols
for concepts that Yacas does not handle, and we can evaluate expressions that
contain them.

*E.G. notest

	In> OMDef( "Sqrt" ,  "arith1", "root", { $, _1, 2 }, $(_1)_(_2=2) | (_1^(1/_2)) );
	Out> True
	In> OMForm(Sqrt(3))
	<OMOBJ>
	  <OMA>
	    <OMS cd="arith1" name="root"/>
	    <OMI>3</OMI>
	    <OMI>2</OMI>
	  </OMA>
	</OMOBJ>
	Out> True
	In> FromString("<OMOBJ><OMA><OMS cd=\"arith1\" name=\"root\"/><OMI>16</OMI><OMI>2</OMI></OMA></OMOBJ> ")OMRead()
	Out> Sqrt(16)
	In> FromString("<OMOBJ><OMA><OMS cd=\"arith1\" name=\"root\"/><OMI>16</OMI><OMI>3</OMI></OMA></OMOBJ> ")OMRead()
	Out> 16^(1/3)

	In> OMDef("Limit", "limit1", "limit", \
	      {  $, _2, OMS("limit1", "under"), OMBIND(OMS("fns1", "lambda"), OMBVAR(_1), _4) }_(_3=Left)  \
	      |{ $, _2, OMS("limit1", "above"), OMBIND(OMS("fns1", "lambda"), OMBVAR(_1), _4) }_(_3=Right) \
	      |{ $, _2, OMS("limit1", "both_sides"), OMBIND(OMS("fns1", "lambda"), OMBVAR(_1), _3) },      \
	      { $, _{3,2,1}, _1, Left,  _{3,3}}_(_2=OMS("limit1", "below")) \
	      |{$, _{3,2,1}, _1, Right, _{3,3}}_(_2=OMS("limit1", "above")) \
	      |{$, _{3,2,1}, _1, _{3,3}}                                    \
	     );
	In> OMForm(Limit(x,0) Sin(x)/x)
	<OMOBJ>
	  <OMA>
	    <OMS cd="limit1" name="limit"/>
	    <OMI>0</OMI>
	    <OMS cd="limit1" name="both_sides"/>
	    <OMBIND>
	      <OMS cd="fns1" name="lambda"/>
	      <OMBVAR>
	        <OMV name="x"/>
	      </OMBVAR>
	      <OMA>
	        <OMS cd="arith1" name="divide"/>
	        <OMA>
	          <OMS cd="transc1" name="sin"/>
	          <OMV name="x"/>
	        </OMA>
	        <OMV name="x"/>
	      </OMA>
	    </OMBIND>
	  </OMA>
	</OMOBJ>
	Out> True
	In> OMForm(Limit(x,0,Right) 1/x)
	<OMOBJ>
	  <OMA>
	    <OMS cd="limit1" name="limit"/>
	    <OMI>0</OMI>
	    <OMS cd="limit1" name="above"/>
	    <OMBIND>
	      <OMS cd="fns1" name="lambda"/>
	      <OMBVAR>
	        <OMV name="x"/>
	      </OMBVAR>
	      <OMA>
	        <OMS cd="arith1" name="divide"/>
	        <OMI>1</OMI>
	        <OMV name="x"/>
	      </OMA>
	    </OMBIND>
	  </OMA>
	</OMOBJ>
	Out> True
	In> FromString(ToString()OMForm(Limit(x,0,Right) 1/x))OMRead()
	Out> Limit(x,0,Right)1/x
	In> %
	Out> Infinity

*SEE OMForm, OMRead