File: DataTypes.texi

package info (click to toggle)
maxima-sage 5.45.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 113,788 kB
  • sloc: lisp: 440,833; fortran: 14,665; perl: 14,369; tcl: 10,997; sh: 4,475; makefile: 2,520; ansic: 447; python: 262; xml: 59; awk: 37; sed: 17
file content (936 lines) | stat: -rw-r--r-- 27,880 bytes parent folder | download
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
@menu
* Numbers::
* Strings::
* Constants::
* Lists::
* Arrays::
* Structures::
@end menu

@c -----------------------------------------------------------------------------
@node Numbers, Strings, Data Types and Structures, Data Types and Structures
@section Numbers
@c -----------------------------------------------------------------------------

@menu
* Introduction to Numbers::
* Functions and Variables for Numbers::
@end menu

@c -----------------------------------------------------------------------------
@node Introduction to Numbers, Functions and Variables for Numbers, Numbers, Numbers
@subsection Introduction to Numbers
@c -----------------------------------------------------------------------------

@c -----------------------------------------------------------------------------
@subheading Complex numbers
@c -----------------------------------------------------------------------------

A complex expression is specified in Maxima by adding the real part of the
expression to @code{%i} times the imaginary part.  Thus the roots of the
equation @code{x^2 - 4*x + 13 = 0} are @code{2 + 3*%i} and @code{2 - 3*%i}.
Note that simplification of products of complex expressions can be effected by
expanding the product.  Simplification of quotients, roots, and other functions
of complex expressions can usually be accomplished by using the @code{realpart},
@code{imagpart}, @code{rectform}, @code{polarform}, @code{abs}, @code{carg}
functions.

@opencatbox
@category{Complex variables}
@closecatbox

@c -----------------------------------------------------------------------------
@node Functions and Variables for Numbers, , Introduction to Numbers, Numbers
@subsection Functions and Variables for Numbers
@c -----------------------------------------------------------------------------

@c -----------------------------------------------------------------------------
@anchor{bfloat}
@deffn {Function} bfloat (@var{expr})

@code{bfloat} replaces integers, rationals, floating point numbers, and some symbolic constants
in @var{expr} with bigfloat (variable-precision floating point) numbers.

The constants @code{%e}, @code{%gamma}, @code{%phi}, and @code{%pi}
are replaced by a numerical approximation.
However, @code{%e} in @code{%e^x} is not replaced by a numeric value
unless @code{bfloat(x)} is a number.

@code{bfloat} also causes numerical evaluation of some built-in functions,
namely trigonometric functions, exponential functions, @code{abs}, and @code{log}.
@c ALSO ENTIER BUT LET'S NOT GO INTO IT.

The number of significant digits in the resulting bigfloats is specified by the
global variable @mrefdot{fpprec}
Bigfloats already present in @var{expr} are replaced with values which have
precision specified by the current value of @mref{fpprec}.

When @mref{float2bf} is @code{false}, a warning message is printed when
a floating point number is replaced by a bigfloat number with less precision.

Examples:

@code{bfloat} replaces integers, rationals, floating point numbers, and some symbolic constants
in @var{expr} with bigfloat numbers.

@c ===beg===
@c bfloat([123, 17/29, 1.75]);
@c bfloat([%e, %gamma, %phi, %pi]);
@c bfloat((f(123) + g(h(17/29)))/(x + %gamma));
@c ===end===
@example
(%i1) bfloat([123, 17/29, 1.75]);
(%o1)        [1.23b2, 5.862068965517241b-1, 1.75b0]
(%i2) bfloat([%e, %gamma, %phi, %pi]);
(%o2) [2.718281828459045b0, 5.772156649015329b-1, 
                        1.618033988749895b0, 3.141592653589793b0]
(%i3) bfloat((f(123) + g(h(17/29)))/(x + %gamma));
         1.0b0 (g(h(5.862068965517241b-1)) + f(1.23b2))
(%o3)    ----------------------------------------------
                    x + 5.772156649015329b-1
@end example

@code{bfloat} also causes numerical evaluation of some built-in functions.

@c ===beg===
@c bfloat(sin(17/29));
@c bfloat(exp(%pi));
@c bfloat(abs(-%gamma));
@c bfloat(log(%phi));
@c ===end===
@example
(%i1) bfloat(sin(17/29));
(%o1)                 5.532051841609784b-1
(%i2) bfloat(exp(%pi));
(%o2)                  2.314069263277927b1
(%i3) bfloat(abs(-%gamma));
(%o3)                 5.772156649015329b-1
(%i4) bfloat(log(%phi));
(%o4)                 4.812118250596035b-1
@end example

@opencatbox
@category{Numerical evaluation}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{bfloatp}
@deffn {Function} bfloatp (@var{expr})

Returns @code{true} if @var{expr} is a bigfloat number, otherwise @code{false}.

@opencatbox
@category{Numerical evaluation}
@category{Predicate functions}
@closecatbox
@end deffn

@c --- 03.11.2011 --------------------------------------------------------------
@anchor{bftorat}
@defvr {Option variable} bftorat
Default value: @code{false}

@code{bftorat} controls the conversion of bfloats to rational numbers.  When
@code{bftorat} is @code{false}, @mref{ratepsilon} will be used to control the
conversion (this results in relatively small rational numbers).  When
@code{bftorat} is @code{true}, the rational number generated will accurately
represent the bfloat.

Note: @code{bftorat} has no effect on the transformation to rational numbers
with the function @mrefdot{rationalize}

Example:

@c ===beg===
@c ratepsilon:1e-4;
@c rat(bfloat(11111/111111)), bftorat:false;
@c rat(bfloat(11111/111111)), bftorat:true;
@c ===end===
@example
(%i1) ratepsilon:1e-4;
(%o1)                         1.e-4
(%i2) rat(bfloat(11111/111111)), bftorat:false;
`rat' replaced 9.99990999991B-2 by 1/10 = 1.0B-1
                               1
(%o2)/R/                       --
                               10
(%i3) rat(bfloat(11111/111111)), bftorat:true;
`rat' replaced 9.99990999991B-2 by 11111/111111 = 9.99990999991B-2
                             11111
(%o3)/R/                     ------
                             111111
@end example

@opencatbox
@category{Numerical evaluation}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{bftrunc}
@defvr {Option variable} bftrunc
Default value: @code{true}

@code{bftrunc} causes trailing zeroes in non-zero bigfloat numbers not to be
displayed.  Thus, if @code{bftrunc} is @code{false}, @code{bfloat (1)}
displays as @code{1.000000000000000B0}.  Otherwise, this is displayed as
@code{1.0B0}.

@opencatbox
@category{Numerical evaluation}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{evenp}
@deffn {Function} evenp (@var{expr})

@c THIS IS STRANGE -- SHOULD RETURN NOUN FORM IF INDETERMINATE
Returns @code{true} if @var{expr} is a literal even integer, otherwise
@code{false}.

@code{evenp} returns @code{false} if @var{expr} is a symbol, even if @var{expr}
is declared @code{even}.

@opencatbox
@category{Predicate functions}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{float}
@deffn {Function} float (@var{expr})

Converts integers, rational numbers and bigfloats in @var{expr} to floating
point numbers.  It is also an @mrefcomma{evflag} @code{float} causes
non-integral rational numbers and bigfloat numbers to be converted to floating
point.

@opencatbox
@category{Numerical evaluation}
@category{Evaluation flags}
@closecatbox
@end deffn

@c --- 08.10.2010 DK -----------------------------------------------------------
@anchor{float2bf}
@defvr {Option variable} float2bf
Default value: @code{true}
 
When @mref{float2bf} is @code{false}, a warning message is printed when
a floating point number is replaced by a bigfloat number with less precision.
@c DOES THAT APPLY ONLY TO BFLOAT, OR DO OTHER FUNCTIONS CALL IT ??

@opencatbox
@category{Numerical evaluation}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{floatnump}
@deffn {Function} floatnump (@var{expr})

Returns @code{true} if @var{expr} is a floating point number, otherwise
@code{false}.

@opencatbox
@category{Numerical evaluation}
@category{Predicate functions}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{fpprec}
@defvr {Option variable} fpprec
Default value: 16

@code{fpprec} is the number of significant digits for arithmetic on bigfloat
numbers.  @code{fpprec} does not affect computations on ordinary floating point
numbers.

See also @mref{bfloat} and @mrefdot{fpprintprec}

@opencatbox
@category{Numerical evaluation}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{fpprintprec}
@defvr {Option variable} fpprintprec
Default value: 0

@code{fpprintprec} is the number of digits to print when printing an ordinary
float or bigfloat number.

For ordinary floating point numbers,
when @code{fpprintprec} has a value between 2 and 16 (inclusive),
the number of digits printed is equal to @code{fpprintprec}.
Otherwise, @code{fpprintprec} is 0, or greater than 16,
and the number of digits printed is 16.

For bigfloat numbers,
when @code{fpprintprec} has a value between 2 and @code{fpprec} (inclusive),
the number of digits printed is equal to @code{fpprintprec}.
Otherwise, @code{fpprintprec} is 0, or greater than @code{fpprec},
and the number of digits printed is equal to @code{fpprec}.

For both ordinary floats and bigfloats,
trailing zero digits are suppressed.
The actual number of digits printed is less than @code{fpprintprec}
if there are trailing zero digits.

@code{fpprintprec} cannot be 1.

@opencatbox
@category{Numerical evaluation}
@category{Display flags and variables}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{integerp}
@deffn {Function} integerp (@var{expr})

Returns @code{true} if @var{expr} is a literal numeric integer, otherwise
@code{false}.

@code{integerp} returns @code{false} if @var{expr} is a symbol, even if @var{expr}
is declared @code{integer}.

Examples:

@c ===beg===
@c integerp (0);
@c integerp (1);
@c integerp (-17);
@c integerp (0.0);
@c integerp (1.0);
@c integerp (%pi);
@c integerp (n);
@c declare (n, integer);
@c integerp (n);
@c ===end===
@example
(%i1) integerp (0);
(%o1)                         true
(%i2) integerp (1);
(%o2)                         true
(%i3) integerp (-17);
(%o3)                         true
(%i4) integerp (0.0);
(%o4)                         false
(%i5) integerp (1.0);
(%o5)                         false
(%i6) integerp (%pi);
(%o6)                         false
(%i7) integerp (n);
(%o7)                         false
(%i8) declare (n, integer);
(%o8)                         done
(%i9) integerp (n);
(%o9)                         false
@end example

@opencatbox
@category{Predicate functions}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{m1pbranch}
@defvr {Option variable} m1pbranch
Default value: @code{false}

@code{m1pbranch} is the principal branch for @code{-1} to a power.
Quantities such as @code{(-1)^(1/3)} (that is, an "odd" rational exponent) and 
@code{(-1)^(1/4)} (that is, an "even" rational exponent) are handled as follows:

@c REDRAW THIS AS A TABLE
@example
              domain:real
                            
(-1)^(1/3):      -1         
(-1)^(1/4):   (-1)^(1/4)   

             domain:complex              
m1pbranch:false          m1pbranch:true
(-1)^(1/3)               1/2+%i*sqrt(3)/2
(-1)^(1/4)              sqrt(2)/2+%i*sqrt(2)/2
@end example

@opencatbox
@category{Expressions}
@category{Global flags}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{nonnegintegerp}
@deffn {Function} nonnegintegerp (@var{n})

Return @code{true} if and only if @code{@var{n} >= 0} and @var{n} is an integer.

@opencatbox
@category{Predicate functions}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{numberp}
@deffn {Function} numberp (@var{expr})

Returns @code{true} if @var{expr} is a literal integer, rational number, 
floating point number, or bigfloat, otherwise @code{false}.

@code{numberp} returns @code{false} if @var{expr} is a symbol, even if @var{expr}
is a symbolic number such as @code{%pi} or @code{%i}, or declared to be
@code{even}, @code{odd}, @code{integer}, @code{rational}, @code{irrational},
@code{real}, @code{imaginary}, or @code{complex}.

Examples:

@c ===beg===
@c numberp (42);
@c numberp (-13/19);
@c numberp (3.14159);
@c numberp (-1729b-4);
@c map (numberp, [%e, %pi, %i, %phi, inf, minf]);
@c declare (a, even, b, odd, c, integer, d, rational, e, irrational, f, real, g, imaginary, h, complex);
@c map (numberp, [a, b, c, d, e, f, g, h]);
@c ===end===
@example
(%i1) numberp (42);
(%o1)                         true
(%i2) numberp (-13/19);
(%o2)                         true
(%i3) numberp (3.14159);
(%o3)                         true
(%i4) numberp (-1729b-4);
(%o4)                         true
(%i5) map (numberp, [%e, %pi, %i, %phi, inf, minf]);
(%o5)      [false, false, false, false, false, false]
(%i6) declare (a, even, b, odd, c, integer, d, rational,
     e, irrational, f, real, g, imaginary, h, complex);
(%o6)                         done
(%i7) map (numberp, [a, b, c, d, e, f, g, h]);
(%o7) [false, false, false, false, false, false, false, false]
@end example

@opencatbox
@category{Predicate functions}
@closecatbox
@end deffn

@c NEEDS CLARIFICATION, EXAMPLES
@c WHAT ARE THE FUNCTIONS WHICH ARE EVALUATED IN FLOATING POINT ??
@c WHAT IS A "NUMERVAL" ?? (SOMETHING DIFFERENT FROM A NUMERIC VALUE ??)
@c NEED TO MENTION THIS IS AN evflag

@c -----------------------------------------------------------------------------
@anchor{numer}
@defvr {Option variable} numer

@code{numer} causes some mathematical functions (including exponentiation)
with numerical arguments to be evaluated in floating point.  It causes
variables in @code{expr} which have been given numerals to be replaced by
their values.  It also sets the @mref{float} switch on.

See also @mrefdot{%enumer}

Examples:

@c ===beg===
@c [sqrt(2), sin(1), 1/(1+sqrt(3))];
@c [sqrt(2), sin(1), 1/(1+sqrt(3))],numer;
@c ===end===
@example
@group
(%i1) [sqrt(2), sin(1), 1/(1+sqrt(3))];
                                        1
(%o1)            [sqrt(2), sin(1), -----------]
                                   sqrt(3) + 1
@end group
@group
(%i2) [sqrt(2), sin(1), 1/(1+sqrt(3))],numer;
(%o2) [1.414213562373095, 0.8414709848078965, 0.3660254037844387]
@end group
@end example

@opencatbox
@category{Numerical evaluation}
@category{Evaluation flags}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{numer_pbranch}
@defvr {Option variable} numer_pbranch
Default value: @code{false}

The option variable @code{numer_pbranch} controls the numerical evaluation of 
the power of a negative integer, rational, or floating point number.  When
@code{numer_pbranch} is @code{true} and the exponent is a floating point number
or the option variable @mref{numer} is @code{true} too, Maxima evaluates
the numerical result using the principal branch.  Otherwise a simplified, but
not an evaluated result is returned.

Examples:

@c ===beg===
@c (-2)^0.75;
@c (-2)^0.75,numer_pbranch:true;
@c (-2)^(3/4);
@c (-2)^(3/4),numer;
@c (-2)^(3/4),numer,numer_pbranch:true;
@c ===end===
@example
@group
(%i1) (-2)^0.75;
                                 0.75
(%o1)                       (- 2)
@end group
@group
(%i2) (-2)^0.75,numer_pbranch:true;
(%o2)       1.189207115002721 %i - 1.189207115002721
@end group
@group
(%i3) (-2)^(3/4);
                               3/4  3/4
(%o3)                     (- 1)    2
@end group
@group
(%i4) (-2)^(3/4),numer;
                                          0.75
(%o4)              1.681792830507429 (- 1)
@end group
@group
(%i5) (-2)^(3/4),numer,numer_pbranch:true;
(%o5)       1.189207115002721 %i - 1.189207115002721
@end group
@end example

@opencatbox
@category{Numerical evaluation}
@closecatbox
@end defvr

@c NEEDS CLARIFICATION, EXAMPLES
@c HOW TO FIND ALL VARIABLES WHICH HAVE NUMERVALS ??

@c -----------------------------------------------------------------------------
@anchor{numerval}
@deffn {Function} numerval (@var{x_1}, @var{expr_1}, @dots{}, @var{var_n}, @var{expr_n})

Declares the variables @code{x_1}, @dots{}, @var{x_n} to have
numeric values equal to @code{expr_1}, @dots{}, @code{expr_n}.
The numeric value is evaluated and substituted for the variable
in any expressions in which the variable occurs if the @code{numer} flag is
@code{true}.  See also @mrefdot{ev}

The expressions @code{expr_1}, @dots{}, @code{expr_n} can be any expressions,
not necessarily numeric.

@opencatbox
@category{Declarations and inferences}
@category{Numerical evaluation}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{oddp}
@deffn {Function} oddp (@var{expr})

@c THIS IS STRANGE -- SHOULD RETURN NOUN FORM IF INDETERMINATE
Returns @code{true} if @var{expr} is a literal odd integer, otherwise
@code{false}.

@code{oddp} returns @code{false} if @var{expr} is a symbol, even if @var{expr}
is declared @code{odd}.

@opencatbox
@category{Predicate functions}
@closecatbox
@end deffn

@c --- 03.11.2011 --------------------------------------------------------------
@anchor{ratepsilon}
@defvr {Option variable} ratepsilon
Default value: @code{2.0e-15}

@code{ratepsilon} is the tolerance used in the conversion
of floating point numbers to rational numbers, when the option variable
@mref{bftorat} has the value @code{false}.  See @code{bftorat} for an example.

@opencatbox
@category{Numerical evaluation}
@category{Rational expressions}
@closecatbox
@end defvr

@c -----------------------------------------------------------------------------
@anchor{rationalize}
@deffn {Function} rationalize (@var{expr})

Convert all double floats and big floats in the Maxima expression @var{expr} to
their exact rational equivalents.  If you are not familiar with the binary
representation of floating point numbers, you might be surprised that
@code{rationalize (0.1)} does not equal 1/10.  This behavior isn't special to
Maxima -- the number 1/10 has a repeating, not a terminating, binary
representation.

@c ===beg===
@c rationalize (0.5);
@c rationalize (0.1);
@c fpprec : 5$
@c rationalize (0.1b0);
@c fpprec : 20$
@c rationalize (0.1b0);
@c rationalize (sin (0.1*x + 5.6));
@c ===end===
@example
@group
(%i1) rationalize (0.5);
                                1
(%o1)                           -
                                2
@end group
@group
(%i2) rationalize (0.1);
                        3602879701896397
(%o2)                   -----------------
                        36028797018963968
@end group
(%i3) fpprec : 5$
@group
(%i4) rationalize (0.1b0);
                             209715
(%o4)                        -------
                             2097152
@end group
(%i5) fpprec : 20$
@group
(%i6) rationalize (0.1b0);
                     236118324143482260685
(%o6)                ----------------------
                     2361183241434822606848
@end group
@group
(%i7) rationalize (sin (0.1*x + 5.6));
               3602879701896397 x   3152519739159347
(%o7)      sin(------------------ + ----------------)
               36028797018963968    562949953421312
@end group
@end example

@opencatbox
@category{Numerical evaluation}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{ratnump}
@deffn {Function} ratnump (@var{expr})

Returns @code{true} if @var{expr} is a literal integer or ratio of literal
integers, otherwise @code{false}.

@opencatbox
@category{Predicate functions}
@category{Rational expressions}
@closecatbox
@end deffn


@c -----------------------------------------------------------------------------
@page
@node Strings, Constants, Numbers, Data Types and Structures
@section Strings
@c -----------------------------------------------------------------------------

@menu
* Introduction to Strings::
* Functions and Variables for Strings::
@end menu

@c -----------------------------------------------------------------------------
@node Introduction to Strings, Functions and Variables for Strings, Strings, Strings
@subsection Introduction to Strings
@c -----------------------------------------------------------------------------

@cindex backslash
@c The following three lines were commented out since they made "make pdf" abort
@c with an error:
@c @ifnotinfo
@c @cindex \
@c @end ifnotinfo
@ifinfo
@c adding the backslash to the index here breaks the LaTeX syntax of the file
@c maxima.fns that is created by the first pdfLaTeX run by "make pdf".
@end ifinfo

Strings (quoted character sequences) are enclosed in double quote marks @code{"}
for input, and displayed with or without the quote marks, depending on the
global variable @mrefdot{stringdisp}

Strings may contain any characters, including embedded tab, newline, and
carriage return characters.  The sequence @code{\"} is recognized as a literal
double quote, and @code{\\} as a literal backslash.  When backslash appears at
the end of a line, the backslash and the line termination (either newline or
carriage return and newline) are ignored, so that the string continues with the
next line.  No other special combinations of backslash with another character
are recognized; when backslash appears before any character other than @code{"},
@code{\}, or a line termination, the backslash is ignored.  There is no way to
represent a special character (such as tab, newline, or carriage return)
except by embedding the literal character in the string.

There is no character type in Maxima; a single character is represented as a
one-character string.

The @code{stringproc} add-on package contains many functions for working with
strings.

Examples:

@c ===beg===
@c s_1 : "This is a string.";
@c s_2 : "Embedded \"double quotes\" and backslash \\ characters.";
@c s_3 : "Embedded line termination
@c in this string.";
@c s_4 : "Ignore the \
@c line termination \
@c characters in \
@c this string.";
@c stringdisp : false;
@c s_1;
@c stringdisp : true;
@c s_1;
@c ===end===
@example
@group
(%i1) s_1 : "This is a string.";
(%o1)                   This is a string.
@end group
@group
(%i2) s_2 : "Embedded \"double quotes\" and backslash \\ characters.";
(%o2) Embedded "double quotes" and backslash \ characters.
@end group
@group
(%i3) s_3 : "Embedded line termination
(%o3) Embedded line termination
in this string.
@end group
@group
(%i4) in this string.";
(%o4) Ignore the line termination characters in this string.
@end group
@group
(%i5) s_4 : "Ignore the \
(%o5)                         false
@end group
@group
(%i6) line termination \
(%o6)                   This is a string.
@end group
@group
(%i7) characters in \
(%o7)                         true
@end group
@group
(%i8) this string.";
(%o8)                  "This is a string."
@end group
(%i9) stringdisp : false;
@end example

@opencatbox
@category{Syntax}
@closecatbox

@c -----------------------------------------------------------------------------
@node Functions and Variables for Strings, , Introduction to Strings, Strings
@subsection Functions and Variables for Strings
@c -----------------------------------------------------------------------------

@c -----------------------------------------------------------------------------
@anchor{concat}
@deffn {Function} concat (@var{arg_1}, @var{arg_2}, @dots{})

Concatenates its arguments.  The arguments must evaluate to atoms.  The return
value is a symbol if the first argument is a symbol and a string otherwise.

@code{concat} evaluates its arguments.  The single quote @code{'} prevents
evaluation.

See also @mrefcomma{sconcat} that works on non-atoms, too, @mrefcomma{simplode}
@mref{string} and @mrefdot{eval_string}
For complex string conversions see also @mref{printf}.

@c ===beg===
@c y: 7$
@c z: 88$
@c concat (y, z/2);
@c concat ('y, z/2);
@c ===end===
@example
(%i1) y: 7$
(%i2) z: 88$
(%i3) concat (y, z/2);
(%o3)                          744
(%i4) concat ('y, z/2);
(%o4)                          y44
@end example

A symbol constructed by @code{concat} may be assigned a value and appear in
expressions.  The @mref{::} (double colon) assignment operator evaluates its
left-hand side.

@c ===beg===
@c a: concat ('y, z/2);
@c a:: 123;
@c y44;
@c b^a;
@c %, numer;
@c ===end===
@example
(%i5) a: concat ('y, z/2);
(%o5)                          y44
(%i6) a:: 123;
(%o6)                          123
(%i7) y44;
(%o7)                          123
(%i8) b^a;
@group
                               y44
(%o8)                         b
@end group
(%i9) %, numer;
                               123
(%o9)                         b
@end example

Note that although @code{concat (1, 2)} looks like a number, it is a string.

@c ===beg===
@c concat (1, 2) + 3;
@c ===end===
@example
(%i10) concat (1, 2) + 3;
(%o10)                       12 + 3
@end example

@opencatbox
@category{Expressions}
@category{Strings}
@closecatbox
@end deffn

@c -----------------------------------------------------------------------------
@anchor{sconcat}
@deffn {Function} sconcat (@var{arg_1}, @var{arg_2}, @dots{})

Concatenates its arguments into a string.  Unlike @mrefcomma{concat} the
arguments do @i{not} need to be atoms.

See also @mrefcomma{concat} @mrefcomma{simplode} @mref{string} and @mrefdot{eval_string}
For complex string conversions see also @mref{printf}.

@c ===beg===
@c sconcat ("xx[", 3, "]:", expand ((x+y)^3));
@c ===end===
@example
@group
(%i1) sconcat ("xx[", 3, "]:", expand ((x+y)^3));
(%o1)             xx[3]:y^3+3*x*y^2+3*x^2*y+x^3
@end group
@end example

Another purpose for @code{sconcat} is to convert arbitrary objects to strings. 
@c ===beg===
@c sconcat (x);
@c stringp(%);
@c ===end===
@example
@group
(%i1) sconcat (x);
(%o1)                           x
@end group
@group
(%i2) stringp(%);
(%o2)                         true
@end group
@end example

@opencatbox
@category{Expressions}
@category{Strings}
@closecatbox
@end deffn

@c NEEDS CLARIFICATION AND EXAMPLES

@c -----------------------------------------------------------------------------
@anchor{string}
@deffn {Function} string (@var{expr})

Converts @code{expr} to Maxima's linear notation just as if it had been typed
in.

The return value of @code{string} is a string, and thus it cannot be used in a
computation.

See also @mrefcomma{concat} @mrefcomma{sconcat} @mref{simplode} and
@mrefdot{eval_string}

@opencatbox
@category{Strings}
@closecatbox
@end deffn

@c SHOULD BE WRITTEN WITH LEADING ? BUT THAT CONFUSES CL-INFO SO WORK AROUND

@c -----------------------------------------------------------------------------
@anchor{stringdisp}
@defvr {Option variable} stringdisp
Default value: @code{false}

When @code{stringdisp} is @code{true}, strings are displayed enclosed in double
quote marks.  Otherwise, quote marks are not displayed.

@code{stringdisp} is always @code{true} when displaying a function definition.

Examples:

@c ===beg===
@c stringdisp: false$
@c "This is an example string.";
@c foo () := 
@c       print ("This is a string in a function definition.");
@c stringdisp: true$
@c "This is an example string.";
@c ===end===
@example
(%i1) stringdisp: false$
@group
(%i2) "This is an example string.";
(%o2)              This is an example string.
@end group
@group
(%i3) foo () :=
      print ("This is a string in a function definition.");
(%o3) foo() := 
              print("This is a string in a function definition.")
@end group
(%i4) stringdisp: true$
@group
(%i5) "This is an example string.";
(%o5)             "This is an example string."
@end group
@end example

@opencatbox
@category{Display flags and variables}
@closecatbox
@end defvr