aboutsummaryrefslogtreecommitdiff
path: root/src/interp/bc-misc.boot
blob: 5d140aac1acedc589528dbad1bcac8084e79280b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
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
-- Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
-- All rights reserved.
-- Copyright (C) 2007-2009, Gabriel Dos Reis.
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are
-- met:
--
--     - Redistributions of source code must retain the above copyright
--       notice, this list of conditions and the following disclaimer.
--
--     - Redistributions in binary form must reproduce the above copyright
--       notice, this list of conditions and the following disclaimer in
--       the documentation and/or other materials provided with the
--       distribution.
--
--     - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--       names of its contributors may be used to endorse or promote products
--       derived from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import bc_-util
namespace BOOT

--Hypertex commands other than solve and matrix

bcDrawIt2(ind,a,b) == strconc('"{}",ind,'"=",a,'"{}..",b,'"{}")

bcIndefiniteIntegrate() ==
  htInitPage("Indefinite Integration Basic Command",nil)
  htMakePage '(
     (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain SY (Symbol)))
     (text . "\newline ")
     (text . "\menuitemstyle{}\tab{2}")
     (text . "Enter the {\em function} you would like to integrate:")
     (text . "\newline\tab{2} ")
     (bcStrings (45 "1/(x**2 + 6)" integrand EM))
     (text . "\blankline")
     (text . "\newline ")
     (text . "\menuitemstyle{}\tab{2}")
     (text . "Enter the {\em variable of integration}:")
     (text . "\tab{37}")
     (bcStrings (10 x symbol SY))
     (doneButton "Continue" bcIndefiniteIntegrateGen))
  htShowPage()

bcIndefiniteIntegrateGen htPage ==
  integrand := htpLabelInputString(htPage,'integrand)
  var := htpLabelInputString(htPage,'symbol)
  bcGen strconc('"integrate(",integrand,'",",var,")")


bcDefiniteIntegrate() ==
  htInitPage("Definite Integration Basic Command",nil)
  htMakePage '(
     (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain SY (Symbol)))
     (text . "\newline ")
     (text . "\menuitemstyle{}\tab{2}")
     (text . "Enter the {\em function} you would like to integrate:")
     (text . "\newline\tab{2} ")
     (bcStrings (45 "1/(x**2 + 6)" integrand EM))
     (text . "\blankline")
     (text . "\newline ")
     (text . "\menuitemstyle{}\tab{2}")
     (text . "Enter the {\em variable of integration}:")
     (text . "\tab{37}")
     (bcStrings (10 x symbol SY))
     (text . "\blankline")
     (text . "\newline ")
     (text . "\menuitemstyle{}\tab{2}")
     (text . "\newline Enter {\em lower limit}:")
     (radioButtons fromButton
       ("" "Minus infinity" minusInfinity)
       (""  (
         (text . "A finite point:\tab{15}")
         (bcStrings (10 0 from EM . bcOptional))) fromPoint))
     (text . "\blankline")
     (text . "\newline ")
     (text . "\menuitemstyle{}\tab{2}")
     (text . "\indent{2}\newline Enter {\em upper limit}:")
     (radioButtons toButton
       ("" "Plus infinity" plusInfinity)
       ("" (
         (text "A finite point:\tab{15}")
         (bcStrings (10 y to EM . bcOptional))) toPoint))
     (doneButton "Continue" bcDefiniteIntegrateGen))
  htShowPage()

bcDefiniteIntegrateGen htPage ==
  integrand := htpLabelInputString(htPage,'integrand)
  var := htpLabelInputString(htPage,'symbol)
  lowerLimit :=
    htpButtonValue(htPage,'fromButton) is 'fromPoint =>
      htpLabelInputString(htPage,'from)
    '"%minusInfinity"
  upperLimit :=
    htpButtonValue(htPage,'toButton) is 'toPoint =>
      htpLabelInputString(htPage,'to)
    '"%plusInfinity"
  varpart := strconc(var,'" = ",lowerLimit,'"..",upperLimit)
  bcGen
   strconc('"integrate(",integrand,'",",varpart,'")")

bcSum() ==
  htInitPage("Sum Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain SY (Symbol)))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em function} you would like to sum:")
    (text . "\newline\tab{2} ")
    (bcStrings (44 "i**3" summand EM))
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em summation index}:")
    (text . "\tab{36}")
    (bcStrings (10 i index SY))
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the limits of the sum:")
    (text . "\newline\tab{10}{\em From:}")
    (bcStrings (10 1 first S))
    (text . "\tab{32}{\em To:}")
    (text . "\tab{36}")
    (bcStrings (10  n  last S))
    (doneButton "Continue" bcSumGen))
  htShowPage()

bcSumGen htPage ==
  mand := htpLabelInputString(htPage,'summand)
  index := htpLabelInputString(htPage,'index)
  first := htpLabelInputString(htPage,'first)
  last := htpLabelInputString(htPage,'last)
  bcGen strconc('"sum(",mand,'",",index,'" = ",first,'"..",last,'")")

bcProduct() ==
  htInitPage("Product Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain SY (Symbol)))
    (text . "Enter the {\em function} you would like to compute the product of:")
    (inputStrings ("" "" 45 "i**2" mand EM))
    (text . "\vspace{1}\newline")
    (inputStrings ("Enter the {\em index of the product}:" "" 5 i index SY))
    (text . "\vspace{1}\newline Enter the limits of the index:")
    (inputStrings
      ("\newline{\em From:}" "" 10 "1" first  EM)
      ("{\em To:}\space{2}" "" 10  "n" last   EM))
    (doneButton "Continue" bcProductGen))
  htShowPage()

bcProductGen htPage ==
  mand := htpLabelInputString(htPage,'mand)
  index := htpLabelInputString(htPage,'index)
  first := htpLabelInputString(htPage,'first)
  last := htpLabelInputString(htPage,'last)
  bcGen strconc('"product(",mand,'",",index,'",",first,'",",last,'")")

bcDifferentiate() ==
  htInitPage("Differentiate Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain SY (Symbol)))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em function} you want to differentiate:")
    (text . "\newline\tab{2} ")
    (bcStrings (55 "sin(x*y)" diffand EM))
    (text . "\blankline")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "\newline List the {\em variables} you want to differentiate with respect to?")
    (text . "\newline\tab{2} ")
    (bcStrings (55 "x y" variables S . quoteString))
    (text . "\blankline")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "\newline List the number of {\em times} you want to differentiate with respect to each variable (leave blank if once for each)")
    (text . "\newline\tab{2} ")
    (bcStrings (55 "1 2" times S . quoteString)))
  htMakeDoneButton('"Continue", 'bcDifferentiateGen)
  htShowPage()

bcDifferentiateGen htPage ==
  mand := htpLabelInputString(htPage,'diffand)
  varlist := bcString2WordList htpLabelInputString(htPage,'variables)
  indexList := bcString2WordList htpLabelInputString(htPage,'times)
  varpart :=
    #varlist > 1 => bcwords2liststring varlist
    first varlist
  indexpart :=
    null indexList => nil
    null rest indexList => first indexList
    #indexList = #varlist => bcwords2liststring indexList
    bcError '"You must say how many times you want to differentiate with respect to each variable---or leave that entry blank"
  lastPart :=
    indexpart => strconc('",",indexpart,'")")
    '")"
  bcGen strconc('"differentiate(",mand,'",",varpart,lastPart)

bcDraw() ==
  htInitPage('"Draw Basic Command",nil)
  bcHt '"What would you like to draw?"
  bcHt '"\newline\centerline{{\em Two Dimensional Plots}}\newline"
  bcHt '"\lispdownlink{A function of one variable}{(|bcDraw2Dfun|)}"
  bcHt '"\space{2}y = f(x)\newline"
  bcHt '"\lispdownlink{A parametrically defined curve}{(|bcDraw2Dpar|)}"
  bcHt '"\space{2}(x(t), y(t))\newline"
  bcHt '"\lispdownlink{A solution to a polynomial equation}{(|bcDraw2DSolve|)}"
  bcHt '"\space{2} p(x,y) = 0\newline"
  bcHt '"\vspace{1}\newline "
  bcHt '"\centerline{{\em Three Dimensional Surfaces}}\newline\newline"
  bcHt '"\lispdownlink{A function of two variables}{(|bcDraw3Dfun|)}"
  bcHt '"\space{2} z = f(x,y)\newline"
  bcHt '"\lispdownlink{A parametrically defined tube}{(|bcDraw3Dpar|)}"
  bcHt '"\space{2}(x(t), y(t), z(t))\newline"
  bcHt '"\lispdownlink{A parameterically defined surface}{(|bcDraw3Dpar1|)}"
  bcHt '"\space{2}(x(u,v), y(u,v), z(u,v))\newline"
  htShowPage()


bcDraw2Dfun() ==
  htInitPage('"Draw Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text
      "\centerline{Drawing {\em y = f(x)}}\newline "
      "\centerline{where {\em y} is the dependent variable and}\newline "
      "\centerline{where {\em x} is the independent variable}\vspace{1}\newline "
      "\menuitemstyle{}\tab{2}What {\em function} f would you like to draw?\newline\tab{2}")
    (bcStrings (55 "x*cos(x)" function EM))
    (text . "\vspace{1}\newline\menuitemstyle{}\tab{2}Enter {\em dependent} variable:")
    (bcStrings (6 y dependent SY))
    (text . "\newline\vspace{1}\newline ")
    (text . "\menuitemstyle{}\tab{2}Enter {\em independent} variable and {\em range}:\newline\tab{2} ")
    (text . "{\em Variable:}")
    (bcStrings (6 x ind SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 0 from1 F))
    (text . "{\em to:}")
    (bcStrings (9 30 to1 F))
    (text
      "\indent{0}\vspace{1}\newline\menuitemstyle{}\tab{2} "
      "Optionally enter a {\em title} for your curve:"
      )
    (bcStrings (15 "y = x*cos(x)" title S))
    (text . "\indent{0}")
    (doneButton "Continue" bcDraw2DfunGen)
    (text . "{}"))
  htShowPage()

bcDraw2DfunGen htPage ==
  fun := htpLabelInputString(htPage,'function)
  dep := htpLabelInputString(htPage,'dependent)
  ind := htpLabelInputString(htPage,'ind)
  from1 := htpLabelInputString(htPage,'from1)
  to1 := htpLabelInputString(htPage,'to1)
  title := htpLabelInputString(htPage,'title)
  if (title isnt '"") then
    titlePart := strconc('"{}",'"title ==_"",title,'"_"")
    bcFinish('"draw",fun,bcDrawIt2(ind,from1,to1),titlePart)
  else
    bcFinish('"draw",fun,bcDrawIt2(ind,from1,to1))


bcDraw2Dpar() ==
  htInitPage('"Draw Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text
      "\centerline{Drawing a parametrically defined curve:}\newline "
      "\centerline{{\em ( f1(t), f2(t) )}}\newline "
      "\centerline{in terms of two functions {\em f1} and {\em f2}}"
      "\centerline{and an independent variable {\em t}}\vspace{1}\newline"
      "\menuitemstyle{}\tab{2}Enter the two {\em functions:}")
    (text . "\newline\tab{2}{\em Function 1:}")
    (bcStrings (44 "-9*sin(4*t/5)" function1 EM))
    (text . "\newline\tab{2}{\em Function 2:}")
    (bcStrings (44 "8*sin(t)" function2 EM))
    (text ."\vspace{1}\newline\menuitemstyle{}\tab{2}Enter {\em independent} variable and range:\newline\tab{2} ")
    (text . "{\em Variable:}")
    (bcStrings (6 t ind SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 "-5*\%pi" from1 F))
    (text . "{\em to:}")
    (bcStrings (9 "5*\%pi" to1 F))
    (text
      "\vspace{1}\newline\menuitemstyle{}\tab{2}"
      "Optionally enter a {\em title} for your curve:")
    (bcStrings (15 "Lissajous" title S))
    (text . "\indent{0}")
    (doneButton "Continue" bcDraw2DparGen))
  htShowPage()

bcDraw2DparGen htPage ==
  fun1 := htpLabelInputString(htPage,'function1)
  fun2 := htpLabelInputString(htPage,'function2)
  ind := htpLabelInputString(htPage,'ind)
  from1 := htpLabelInputString(htPage,'from1)
  to1 := htpLabelInputString(htPage,'to1)
  title := htpLabelInputString(htPage,'title)
  curvePart := strconc('"curve(",'"{}",fun1,'",{}",fun2,'")")
  if (title isnt '"") then
    titlePart := (title is '"" => nil; strconc('"{}",'"title ==_"",title,'"_""))
    bcFinish('"draw",curvePart,bcDrawIt2(ind,from1,to1),titlePart)
  else
    bcFinish('"draw",curvePart,bcDrawIt2(ind,from1,to1))

bcDraw2DSolve() ==
  htInitPage('"Draw Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text
      "\centerline{Plotting the solution to {\em p(x,y) = 0}, where} "
      "\centerline{{\em p} is a polynomial in two variables {\em x} and {\em y}}"
      "\vspace{1}\newline\menuitemstyle{}\tab{2}Enter the {\em polynomial} p:"
      "\newline\tab{2}")
    (bcStrings (40 "y**2+7*x*y-(x**3+16*x)" function EM))
    (text . "\vspace{1}\newline\menuitemstyle{}\tab{2}Enter the {\em variables}:")
    (text . "\newline\tab{2}{\em Variable 1:} ")
    (bcStrings (4 x independent1 SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 -15 from1 F))
    (text . "{\em to:}")
    (bcStrings (9 10 to1 F))
    (text . "\newline\tab{2}{\em Variable 2:} ")
    (bcStrings (4 y independent2 SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 -10 from2 F))
    (text . "{\em to:}")
    (bcStrings (9 50 to2 F))
    (text
      "\indent{0}\vspace{1}\newline\menuitemstyle{}\tab{2} "
      "Optionally enter a {\em title} for your curve:")
    (bcStrings (15 "" title S))
    (text . "\indent{0}"))
  htMakeDoneButton('"Continue",'bcDraw2DSolveGen)
  htShowPage()

bcDraw2DSolveGen htPage ==
  fun := htpLabelInputString(htPage,'function)
  ind1 := htpLabelInputString(htPage,'independent1)
  from1 := htpLabelInputString(htPage,'from1)
  to1 := htpLabelInputString(htPage,'to1)
  ind2 := htpLabelInputString(htPage,'independent2)
  from2 := htpLabelInputString(htPage,'from2)
  to2 := htpLabelInputString(htPage,'to2)
  title := htpLabelInputString(htPage,'title)
  clipPart := strconc('"{}",'"range==[{}",from1,'"..",to1,",{}",from2,'"..",to2,'"]")
  if (title isnt '"") then
    titlePart := (title is '"" => nil; strconc('"{}",'"title ==_"",title,'"_""))
    bcFinish('"draw",strconc(fun,'" = 0 "),ind1,ind2,clipPart,titlePart)
  else
    bcFinish('"draw",strconc(fun,'" = 0 "),ind1,ind2,clipPart)

bcDraw3Dfun() ==
  htInitPage('"Three Dimensional Draw Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text
      "\centerline{Drawing {\em z = f(x,y)}}\newline "
      "\centerline{where {\em z} is the dependent variable and}\newline "
      "\centerline{where {\em x, y} are the independent variables}\vspace{1}\newline\menuitemstyle{}\tab{2} "
      "What {\em function} f which you like to draw?\newline\tab{2}")
    (bcStrings (55 "exp(cos(x-y)-sin(x*y))-2" function EM))
    (text . "\newline\menuitemstyle{}\tab{2}Enter {\em dependent} variable:")
    (bcStrings (6 z dependent SY))
    (text
      "\vspace{1}\newline\menuitemstyle{}\tab{2}"
      "Enter {\em independent} variables and ranges:\newline\tab{2} "
      "{\em Variable:}")
    (bcStrings (6 x independent1 SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 -5 from1 F))
    (text . "{\em to:}")
    (bcStrings (9 5 to1 F))
    (text . "\newline\tab{2}{\em Variable:}")
    (bcStrings (6 y independent2 SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 -5 from2 F))
    (text . "{\em to:}")
    (bcStrings (9 5 to2 F))
    (text
      "\indent{0}\vspace{1}\newline\menuitemstyle{}\tab{2} "
      "Optionally enter a {\em title} for your surface:")
    (bcStrings (15 "" title S))
    (text . "\indent{0}")
    (doneButton "Continue" bcDraw3DfunGen))
  htShowPage()

bcDraw3DfunGen htPage ==
  fun := htpLabelInputString(htPage,'function)
  dep := htpLabelInputString(htPage,'dependent)
  ind1 := htpLabelInputString(htPage,'independent1)
  from1 := htpLabelInputString(htPage,'from1)
  to1 := htpLabelInputString(htPage,'to1)
  ind2 := htpLabelInputString(htPage,'independent2)
  from2 := htpLabelInputString(htPage,'from2)
  to2 := htpLabelInputString(htPage,'to2)
  title := htpLabelInputString(htPage,'title)
  if (title ~= '"") then
    titlePart := (title = '"" => nil;strconc('"{}",'"title ==_"",title,'"_""))
    bcFinish('"draw",fun,bcDrawIt2(ind1,from1,to1),bcDrawIt2(ind2,from2,to2),titlePart)
  else
    bcFinish('"draw",fun,bcDrawIt2(ind1,from1,to1),bcDrawIt2(ind2,from2,to2))

bcDraw3Dpar() ==
  htInitPage('"Draw Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text
      "\centerline{Drawing a parametrically defined curve:"
      "{\em ( f1(t), f2(t), f3(t) )}}\newline "
      "\centerline{in terms of three functions {\em f1}, {\em f2}, and {\em f3}}\newline "
      "\centerline{and an independent variable {\em t}}\vspace{1}\newline\menuitemstyle{}\tab{2} "
      "Enter the three {\em functions} of the independent variable:")
    (text . "\newline\tab{2}{\em Function f1:}")
    (bcStrings (42 "1.3*cos(2*t)*cos(4*t) + sin(4*t)*cos(t)" function1 EM))
    (text . "\newline\tab{2}{\em Function f2:}")
    (bcStrings  (42 "1.3*sin(2*t)*cos(4*t) - sin(4*t)*sin(t)" function2 EM))
    (text . "\newline\tab{2}{\em Function f3:}")
    (bcStrings  (42 "2.5*cos(4*t)" function3 EM))
    (text ."\vspace{1}\newline\menuitemstyle{}\tab{2}Enter {\em independent} variable and range:\newline\tab{2} ")
    (text ."{\em Variable:}")
    (bcStrings (6 t ind SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 0 from1 F))
    (text "{\em to:}")
    (bcStrings (9 "4*\%pi" to1 F))
    (text
      "\indent{0}\vspace{1}\newline\menuitemstyle{}\tab{2} "
      "Optionally enter a {\em title} for your surface:")
    (bcStrings (15 "knot" title S))
    (text . "\indent{0}")
    (doneButton "Continue" bcDraw3DparGen))
  htShowPage()

bcDraw3DparGen htPage ==
  fun1 := htpLabelInputString(htPage,'function1)
  fun2 := htpLabelInputString(htPage,'function2)
  fun3 := htpLabelInputString(htPage,'function3)
  ind := htpLabelInputString(htPage,'ind)
  from1 := htpLabelInputString(htPage,'from1)
  to1 := htpLabelInputString(htPage,'to1)
  title := htpLabelInputString(htPage,'title)
  curvePart := strconc('"curve(",'"{}",fun1,'",{}",fun2,'",{}",fun3,'")")
  tubePart := '"{}tubeRadius==.25,{}tubePoints==16"
  if (title ~= '"") then
    titlePart := (title = '"" => nil; strconc('"{}",'"title ==_"",title,'"_""))
    bcFinish('"draw",curvePart,bcDrawIt2(ind,from1,to1),tubePart,titlePart)
  else
    bcFinish('"draw",curvePart,bcDrawIt2(ind,from1,to1),tubePart)

bcDraw3Dpar1() ==
  htInitPage('"Draw Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text
      "\centerline{Drawing a parametrically defined surface:}\newline "
      "\centerline{{\em ( f1(u,v), f2(u,v), f3(u,v) )}}\newline "
      "\centerline{in terms of three functions {\em f1}, {\em f2}, and {\em f3}}\newline "
      "\centerline{and two independent variables {\em u} and {\em v}}\vspace{1}\newline\menuitemstyle{}\tab{2}"
      "Enter the three {\em functions} of the independent variables:")
    (text . "\newline\tab{2}")
    (text . "{\em Function f1:}")
    (bcStrings (43 "u*sin(v)" function1 EM))
    (text . "\newline\tab{2}")
    (text . "{\em Function f2:}")
    (bcStrings (43 "v*cos(u)" function2 EM))
    (text . "\newline\tab{2}")
    (text . "{\em Function f3:}")
    (bcStrings (43 "u*cos(v)" function3 EM))
    (text . "\newline\menuitemstyle{}\tab{2}Enter independent {\em variables} and ranges:")
    (text . "\newline\tab{2}")
    (text . "{\em Variable 1:}")
    (bcStrings (5 u ind1 SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 "-\%pi" from1 F))
    (text . "{\em to:}")
    (bcStrings (9 "\%pi" to1 F))
    (text . "\newline\tab{2}")
    (text . "{\em Variable 2:}")
    (bcStrings (5 v ind2 SY))
    (text . "ranges {\em from:}")
    (bcStrings (9 "-\%pi/2" from2 F))
    (text . "{\em to:}")
    (bcStrings (9 "\%pi/2" to2 F))
    (text
      "\indent{0}\newline\menuitemstyle{}\tab{2} "
      "Optionally enter a {\em title} for your surface:")
    (bcStrings (15 "surface" title S))
    (text . "\indent{0}"))
  htMakeDoneButton ('"Continue",'bcDraw3Dpar1Gen)
  htShowPage()

bcDraw3Dpar1Gen htPage ==
  fun1 := htpLabelInputString(htPage,'function1)
  fun2 := htpLabelInputString(htPage,'function2)
  fun3 := htpLabelInputString(htPage,'function3)
  ind1 := htpLabelInputString(htPage,'ind1)
  from1 := htpLabelInputString(htPage,'from1)
  to1 := htpLabelInputString(htPage,'to1)
  ind2 := htpLabelInputString(htPage,'ind2)
  from2 := htpLabelInputString(htPage,'from2)
  to2 := htpLabelInputString(htPage,'to2)
  title := htpLabelInputString(htPage,'title)
  r1 := bcDrawIt2(ind1,from1,to1)
  r2 := bcDrawIt2(ind2,from2,to2)
  surfacePart := strconc('"surface(",'"{}",fun1,'",{}",fun2,'",{}",fun3,'")")
  if (title ~= '"") then
    titlePart := (title = '"" => nil; strconc('"{}",'"title ==_"",title,'"_""))
    bcFinish('"draw",surfacePart,r1,r2,titlePart)
  else
    bcFinish('"draw",surfacePart,r1,r2)

bcSeries() ==
  htInitPage('"Series Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain SY (Symbol)))
   (text .  "Create a series by: ")
   (text . "\beginmenu")
   (text . "\item ")
   (bcLinks ("\menuitemstyle{Expansion}" "" bcSeriesExpansion NILl))
   (text . "\tab{11}Expand a function in a series around a point")
   (text . "\item ")
   (bcLinks ("\menuitemstyle{Formula}"  "" bcSeriesByFormula NIL))
   (text . "\tab{11}Give a formula for the {\em i}'th coefficient")
   (text . "\endmenu"))
  htShowPage()

bcSeriesExpansion(a,b) ==
  htInitPage('"Series Expansion Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain EEM (Expression $EmptyMode))
       (isDomain S (String))
       (isDomain SY (Symbol)))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em function} you want to expand in a power series")
    (text . "\newline\tab{2} ")
    (bcStrings (55 "log(cot(x))" function EM))
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em power series variable}")
    (text . "\tab{49}")
    (bcStrings (8 x variable SY))
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em point} about which you want to expand")
    (text . "\tab{49}")
    (bcStrings (8 "\%pi/2" point EM)))
  htMakeDoneButton('"Continue",'bcSeriesExpansionGen)
  htShowPage()

bcSeriesExpansionGen htPage ==
  fun := htpLabelInputString(htPage,'function)
  var := htpLabelInputString(htPage,'variable)
  point := htpLabelInputString(htPage,'point)
  terms := htpLabelInputString(htPage,'numberOfTerms)
  bcFinish("series",fun,strconc(var,'" = ",point))

bcSeriesByFormula(a,b) ==
  htInitPage('"Power Series Basic Command",nil)
  htMakePage '(
    (text . "Select the kind of power series you want to create:")
    (text . "\beginmenu")
    (text . "\item ")
    (bcLinks ("\menuitemstyle{Taylor Series}" "" bcTaylorSeries taylor))
    (text . "\newline Series where the exponent ranges over the integers from a {\em non-negative integer} value to plus infinity by an arbitrary {\em positive integer} step size")
    (text . "\item ")
    (bcLinks ("\menuitemstyle{Laurent Series}" "" bcLaurentSeries laurent))
    (text . "\newline Series where the exponent ranges from an arbitrary {\em integer} value to plus infinity by an arbitrary {\em positive integer} step size")
    (text . "\item ")
    (bcLinks ("\menuitemstyle{Puiseux Series}" "" bcPuiseuxSeries puiseux))
    (text . "\newline Series where the exponent ranges from an arbitrary {\em rational value} to plus infinity by an arbitrary {\em positive rational number} step size")
    (text . "\endmenu"))
  htShowPage()

bcTaylorSeries(a,b) ==
  htInitPage('"Taylor Series Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain EEM (Expression $EmptyMode))
       (isDomain S (String))
       (isDomain SY (Symbol)))
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the formula for the general coefficient of the series")
    (text . "\newline\tab{2} ")
    (bcStrings (55 "1/factorial(i)" formula EM))
    (text . "\blankline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em index variable} for your formula")
    (text . "\tab{49}")
    (bcStrings (8 i index SY))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em power series variable}")
    (text . "\tab{49}")
    (bcStrings (8 x variable SY))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em point} about which you want to expand")
    (text . "\tab{49}")
    (bcStrings (8 0 point EM))
    (text . "\blankline ")
    (text ."For Taylor Series, the exponent of the power series variable ranges  from an {\em initial value}, an arbitrary non-negative integer, to plus infinity; the {\em step size} is any positive integer.")
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em initial value} of the index (an integer)")
    (text . "\tab{49}")
    (bcStrings (8 "0" min I))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em step size} (a positive integer)")
    (text . "\tab{49}")
    (bcStrings (8 "1" step PI))
    (doneButton "Continue" bcTaylorSeriesGen))
  htShowPage()

bcSeriesByFormulaGen htPage == 
  bcNotReady htPage

bcLaurentSeries(a,b) ==
  htInitPage('"Laurent Series Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain EEM (Expression $EmptyMode))
       (isDomain S (String))
       (isDomain I (Integer))
       (isDomain PI (PositiveInteger))
       (isDomain SY (Symbol)))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the formula for the general coefficient of the series")
    (text . "\newline\tab{2} ")
    (bcStrings (55 "(-1)**(n - 1)/(n + 2)" formula EM))
    (text . "\vspace{1}\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em index variable} for your formula")
    (text . "\tab{49}")
    (bcStrings (8 n index SY))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em power series variable}")
    (text . "\tab{49}")
    (bcStrings (8 x variable SY))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em point} about which you want to expand")
    (text . "\tab{49}")
    (bcStrings (8 0 point F))
    (text . "\blankline")
    (text . "\newline For Laurent Series, the exponent of the power series variable ranges from an {\em initial value}, an arbitrary integer value, to plus infinity; the {\em step size} is any positive integer.")
    (text . "\blankline")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em initial value} of the index (an integer)")
    (text . "\tab{49}")
    (bcStrings (8 "-1" min I))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em step size} (a positive integer)")
    (text . "\tab{49}")
    (bcStrings (8 "1" step PI))
    (doneButton "Continue" bcLaurentSeriesGen))
  htShowPage()

bcPuiseuxSeries(a,b) ==
  htInitPage('"Puiseux Series Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain EEM (Expression $EmptyMode))
       (isDomain S (String))
       (isDomain I (Integer))
       (isDomain PI (PositiveInteger))
       (isDOmain RN (Fraction (Integer)))
       (isDomain SY (Symbol)))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text ."Enter the {\em formula} for the general coefficient of the series")
    (text . "\newline\tab{2} ")
    (bcStrings(55 "(-1)**((3*n - 4)/6)/factorial(n - 1/3)" formula EM))
    (text . "\vspace{1}\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em index variable} for your formula")
    (text . "\tab{49}")
    (bcStrings (8 n index SY))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em power series variable}")
    (text . "\tab{49}")
    (bcStrings (8 x variable SY))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em point} about which you want to expand")
    (text . "\tab{49}")
    (bcStrings (8 0 point F))
    (text . "\blankline ")
    (text . "For Puiseux Series, the exponent of the power series variable ranges from an {\em initial value}, an arbitary rational number, to plus infinity; the {\em step size} is an any positive rational number.")
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em initial value} of index (a rational number)")
    (text . "\tab{51}")
    (bcStrings (6 "4/3" min RN))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em step size} (a positive rational number)")
    (text . "\tab{51}")
    (bcStrings (6 "2" step RN))
    (doneButton "Continue" bcPuiseuxSeriesGen))
  htShowPage()

bcTaylorSeriesGen htPage == bcSeriesGen(htPage)

bcLaurentSeriesGen htPage ==
  bcSeriesGen(htPage)

bcPuiseuxSeriesGen htPage ==
  bcSeriesGen(htPage)

bcSeriesGen(htPage) ==
  step:= htpLabelInputString(htPage,'step)
  min := htpLabelInputString(htPage,'min)
  formula := htpLabelInputString(htPage,'formula)
  index   := htpLabelInputString(htPage,'index)
  var := htpLabelInputString(htPage,'variable)
  point := htpLabelInputString(htPage,'point)
  varPart := strconc(var,'" = ",point)
  minPart := strconc(min,'"..")
  bcFinish('"series",strconc(index,'" +-> ",formula),varPart,minPart,step)

bcLimit() ==
  htInitPage('"Limit Basic Command",nil)
  htMakePage '(
   (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain SY (Symbol)))
   (text . "What kind of limit do you want to compute? ")
   (text . "\blankline ")
   (text . "\beginmenu")
   (text . "\item ")
   (bcLinks ("\menuitemstyle{A real limit?}" "" bcRealLimit real))
   (text . "\indentrel{17}\tab{0}")
   (text . "The limit as the variable approaches a {\em real} value along the real axis")
   (text . "\indentrel{-17}")
   (text . "\item ")
   (text . "\blankline ")
   (bcLinks ("\menuitemstyle{A complex limit?}" "" bcComplexLimit complex))
   (text . "\indentrel{17}\tab{0}")
   (text . "The limit as the variable approaches a {\em complex} value along any path in the complex plane")
   (text . "\indentrel{-17}")
   (text . "\endmenu")
    )
  htShowPage()

bcRealLimit(a,b) ==
  htInitPage('"Real Limit Basic Command",nil)
  htMakePage '(
    (domainConditions
       (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em function} you want to compute the limit of:")
    (text . "\newline\tab{2} ")
    (bcStrings (45 "x*sin(1/x)" expression EM))
    (text . "\blankline")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the name of the {\em variable}: ")
    (text . "\tab{41}")
    (bcStrings (6 x variable SY))
    (text . "\blankline")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Compute the limit at")
    (radioButtons location
      ("A finite point:" (
        (text . "\tab{33}")
        (bcStrings (6 0 point F))) finitePoint)
      ("Plus infinity" "" plusInfinity)
      ("Minus infinity" "" minusInfinity))
    (doneButton "Continue" bcRealLimitGen))
  htShowPage()

bcRealLimitGen htPage ==
  (p := htpButtonValue(htPage,'location)) ~= 'finitePoint =>
    fun := htpLabelInputString(htPage,'expression)
    var := htpLabelInputString(htPage,'variable)
    loc :=
      p = 'plusInfinity => '"%plusInfinity"
      '"%minusInfinity"
    bcFinish('"limit",fun,strconc(var,'" = ",loc))
  page := htInitPage('"Real Limit Basic Command",nil)
  htMakePage '(
    (text . "Compute the limit")
    (lispLinks
       ("\menuitemstyle{From both directions}" "" bcRealLimitGen1 both)
       ("\menuitemstyle{From the right}" "" bcRealLimitGen1 right)
       ("\menuitemstyle{From the left}" "" bcRealLimitGen1 left)))
  htpSetProperty(page,'fun,htpLabelInputString(htPage,'expression))
  htpSetProperty(page,'var,htpLabelInputString(htPage,'variable))
  htpSetProperty(page,'loc,htpLabelInputString(htPage,'point))
  htShowPage()

bcRealLimitGen1(htPage,key) ==
  direction :=
    key = 'right => '"_"right_""
    key = 'left => '"_"left_""
    nil
  fun := htpProperty(htPage,'fun)
  var := htpProperty(htPage,'var)
  loc := htpProperty(htPage,'loc)
  varPart := strconc(var,'" = ",loc)
  bcFinish('"limit",fun,varPart,direction)

bcComplexLimit(a,b) ==
  htInitPage('"Complex Limit Basic Command",nil)
  htMakePage '(
    (domainConditions
        (isDomain EM $EmptyMode)
       (isDomain S (String))
       (isDomain F (Float))
       (isDomain SY (Symbol)))
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the {\em function} you want to compute the limit of:")
    (text . "\newline\tab{2} ")
    (bcStrings (40 "sin(a*x)/tan(b*x)" expression EM))
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Enter the name of the {\em variable}: ")
    (text . "\tab{37}")
    (bcStrings (5 x variable SY))
    (text . "\blankline ")
    (text . "\newline ")
    (text . "\menuitemstyle{}\tab{2}")
    (text . "Compute the limit at")
    (radioButtons location
      ("A finite point:" (
       (text . "\newline\space{0}Real part:\space{3}")
       (bcStrings (20 0 real F))
       (text . "\newline Complex part:")
       (bcStrings (20 0 complex F))) finitePoint)
      ("Complex infinity" "" complexInfinity))
     (doneButton "Continue" bcComplexLimitGen))
  htShowPage()

bcComplexLimitGen htPage ==
  fun := htpLabelInputString(htPage,'expression)
  var := htpLabelInputString(htPage,'variable)
  loc :=
    (p := htpButtonValue(htPage,'location)) = 'finitePoint =>
      real := htpLabelInputString(htPage,'real)
      comp := htpLabelInputString(htPage,'complex)
      complexPart :=
        comp = '"0" => '""
        comp = '"1" => '"%i"
        strconc(comp,'"*%i")
      real = '"0" =>
        complexPart = '"" => '"0"
        complexPart
      complexPart = '"" => real
      strconc(real,'" + ",complexPart)
    '"%infinity"
  varPart := strconc(var,'" = ",loc)
  bcFinish('"complexLimit",fun,varPart)