-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrsp2.scm
3517 lines (3052 loc) · 62 KB
/
grsp2.scm
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
;; =========================================================================
;;
;; grsp2.scm
;;
;; Real num. functions and general-purpose stuff. In general, these
;; functions constitute the basis for other functions found in the
;; grspX.scm files, where X > 2.
;;
;; =========================================================================
;;
;; Copyright (C) 2018 - 2024 Pablo Edronkin (pablo.edronkin at yahoo.com)
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Lesser General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU Lesser General Public License for more details.
;;
;; You should have received a copy of the GNU Lesser General Public
;; License along with this program. If not, see
;; <https://www.gnu.org/licenses/>.
;;
;; =========================================================================
;;;; General notes:
;;
;; - Read sources for limitations on function parameters.
;; - As a general policy, multithreaded functions are kept to a minimum at
;; this level in order to simplify mth architecture at higher
;; programming levels.
;;
;; Sources:
;;
;; See code of functions used and their respective source files for more
;; credits and references.
;;
;; - [1] https://en.wikipedia.org/wiki/Falling_and_rising_factorials
;; - [2] En.wikipedia.org. 2020. Triangular Number. [online] Available at:
;; https://en.wikipedia.org/wiki/Triangular_number [Accessed 20 November
;; 2020].
;; - [3] En.wikipedia.org. (2020). Binomial coefficient. [online] Available
;; at: https://en.wikipedia.org/wiki/Binomial_coefficient [Accessed 13
;; Jan. 2020].
;; - [4] En.wikipedia.org. (2020). Bailey–Borwein–Plouffe formula. [online]
;; Available at:
;; https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93
;; Plouffe_formula [Accessed 9 Jan. 2020].
;; - [5] En.wikipedia.org. (2020). Hyperoperation. [online] Available at:
;; https://en.wikipedia.org/wiki/Hyperoperation [Accessed 1 Jan. 2020].
;; - [6] En.wikipedia.org. (2020). Woodall number. [online] Available at:
;; https://en.wikipedia.org/wiki/Woodall_number
;; [Accessed 6 Jan. 2020]. En.wikipedia.org. (2020).
;; - [7] En.wikipedia.org. (2020). Cullen number. [online] Available at:
;; https://en.wikipedia.org/wiki/Cullen_number [Accessed 6 Jan. 2020].
;; - [8] En.wikipedia.org. (2020). Proth prime. [online] Available at:
;; https://en.wikipedia.org/wiki/Proth_prime [Accessed 9 Jan. 2020].
;; - [9] Mersenne.org. (2020). Great Internet Mersenne Prime Search -
;; PrimeNet. [online] Available at:
;; https://www.mersenne.org/ [Accessed 9 Jan. 2020].
;; - [10] Mathworld.wolfram.com. (2020). Mersenne Number -- from Wolfram
;; MathWorld. [online] Available at:
;; http://mathworld.wolfram.com/MersenneNumber.html [Accessed 16 Jan.
;; 2020].
;; - [11] En.wikipedia.org. (2020). Repdigit. [online] Available at:
;; https://en.wikipedia.org/wiki/Repdigit [Accessed 11 Jan. 2020].
;; - [12] En.wikipedia.org. (2020). Wagstaff prime. [online] Available at:
;; https://en.wikipedia.org/wiki/Wagstaff_prime [Accessed 11 Jan. 2020].
;; - [13] En.wikipedia.org. (2020). Williams number. [online] Available at:
;; https://en.wikipedia.org/wiki/Williams_number [Accessed 11 Jan. 2020].
;; - [14] En.wikipedia.org. (2020). Catalan number. [online] Available at:
;; https://en.wikipedia.org/wiki/Catalan_number [Accessed 13 Jan. 2020].
;; - [15] En.wikipedia.org. (2020). Wagstaff prime. [online] Available at:
;; https://en.wikipedia.org/wiki/Wagstaff_prime [Accessed 11 Jan. 2020].
;; - [16] En.wikipedia.org. (2020). Dobiński's formula. [online] Available
;; at: https://en.wikipedia.org/wiki/Dobi%C5%84ski%27s_formula
;; [Accessed 14 Jan. 2020].
;; - [17] En.wikipedia.org. (2020). Newton's method. [online] Available at:
;; https://en.wikipedia.org/wiki/Newton%27s_method [Accessed 23 Jan.
;; 2020].
;; - [18] En.wikipedia.org. (2020). Numerical analysis. [online] Available
;; at: https://en.wikipedia.org/wiki/Numerical_analysis [Accessed 24
;; Jan. 2020].
;; - [19] En.wikipedia.org. (2020). Euler method. [online] Available at:
;; https://en.wikipedia.org/wiki/Euler_method [Accessed 24 Jan. 2020].
;; - [20] En.wikipedia.org. (2020). Numerical analysis. [online] Available
;; at: https://en.wikipedia.org/wiki/Numerical_analysis [Accessed 24
;; Jan. 2020].
;; - [21] En.wikipedia.org. (2020). Linear interpolation. [online]
;; Available at: https://en.wikipedia.org/wiki/Linear_interpolation
;; [Accessed 24 Jan. 2020].
;; - [22] En.wikipedia.org. 2020. Torus. [online] Available at:
;; https://en.wikipedia.org/wiki/Torus [Accessed 3 November 2020].
;; - [23] En.wikipedia.org. 2020. Asymptotic Analysis. [online] Available
;; at: https://en.wikipedia.org/wiki/Asymptotic_analysis
;; [Accessed 8 November 2020].
;; - [24] En.wikipedia.org. 2020. Stirling's Approximation. [online]
;; Available at: https://en.wikipedia.org/wiki/Stirling%27s_approximation
;; [Accessed 8 November 2020].
;; - [25] En.wikipedia.org. 2020. Airy Function. [online] Available at:
;; https://en.wikipedia.org/wiki/Airy_function [Accessed 9 November
;; 2020].
;; - [26] En.wikipedia.org. 2020. Factorial. [online] Available at:
;; https://en.wikipedia.org/wiki/Factorial#Superfactorial
;; [Accessed 17 November 2020].
;; - [27] En.wikipedia.org. 2020. Alternating Factorial. [online]
;; Available at: https://en.wikipedia.org/wiki/Alternating_factorial
;; [Accessed 17 November 2020].
;; - [28] En.wikipedia.org. 2020. Exponential Factorial. [online]
;; Available at: https://en.wikipedia.org/wiki/Exponential_factorial
;; [Accessed 17 November 2020].
;; - [29] En.wikipedia.org. 2020. Derangement. [online] Available at:
;; https://en.wikipedia.org/wiki/Derangement [Accessed 18 November 2020].
;; - [30] Gnu.org. 2020. Exactness (Guile Reference Manual). [online]
;; Available at:
;; https://www.gnu.org/software/guile/manual/html_node/Exactness.html
;; [Accessed 28 November 2020].
;; - [31] En.wikipedia.org. 2021. Test functions for optimization -
;; Wikipedia. [online] Available at:
;; https://en.wikipedia.org/wiki/Test_functions_for_optimization
;; [Accessed 13 April 2021].
;; - [32] Gnu.org. 2021. Random (Guile Reference Manual). [online]
;; Available at:
;; https://www.gnu.org/software/guile/manual/html_node/Random.html
;; [Accessed 30 July 2021].
;; - [33] Gnu.org. 2021. Parallel Forms (Guile Reference Manual). [online]
;; Available at:
;; https://www.gnu.org/software/guile/manual/html_node/Parallel-Forms.html
;; [Accessed 30 July 2021].
;; - [34] Mathworld.wolfram.com. 2021. Hailstone Number -- from Wolfram
;; MathWorld. [online] Available at:
;; https://mathworld.wolfram.com/HailstoneNumber.html
;; [Accessed 30 July 2021].
;; - [35] Es.wikipedia.org. 2021. Fórmula de Euler-Maclaurin - Wikipedia,
;; la enciclopedia libre. [online] Available at:
;; https://es.wikipedia.org/wiki/F%C3%B3rmula_de_Euler-Maclaurin
;; [Accessed 27 August 2021].
;; - [36] Es.wikipedia.org. 2021. Regla del trapecio - Wikipedia, la
;; enciclopedia libre. [online] Available at:
;; https://es.wikipedia.org/wiki/Regla_del_trapecio [Accessed 27 August
;; 2021].
;; - [37] En.wikipedia.org. 2021. Kronecker delta - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Kronecker_delta
;; [Accessed 30 August 2021].
;; - [38] En.wikipedia.org. 2021. Dirac delta function - Wikipedia.
;; [online] Available at:
;; <https://en.wikipedia.org/wiki/Dirac_delta_function [Accessed
;; 30 August 2021].
;; - [39] Es.wikipedia.org. 2021. Teoría de distribuciones - Wikipedia, la
;; enciclopedia libre. [online] Available at:
;; https://es.wikipedia.org/wiki/Teor%C3%ADa_de_distribuciones
;; [Accessed 2 September 2021].
;; - [40] En.wikipedia.org. 2021. Heaviside step function - Wikipedia.
;; [online] Available at:
;; https://en.wikipedia.org/wiki/Heaviside_step_function
;; [Accessed 2 September 2021].
;; - [41] En.wikipedia.org. 2021. Rectangular function - Wikipedia.
;; [online]
;; Available at: https://en.wikipedia.org/wiki/Rectangular_function
;; [Accessed 9 September 2021].
;; - [42] En.wikipedia.org. 2021. Triangular function - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Triangular_function
;; [Accessed 9 September 2021].
;; - [43] En.wikipedia.org. 2021. Absolute value - Wikipedia. [online]
;; Available at: https://en.wikipedia.org/wiki/Absolute_value [Accessed 9
;; September 2021].
;; - [44] En.wikipedia.org. 2020. Givens Rotation. [online] Available at:
;; https://en.wikipedia.org/wiki/Givens_rotation [Accessed 25 March
;; 2020].
;; - [45] Crenel function (2017) Wikipedia. Wikimedia Foundation.
;; Available at:
;; https://en.wikipedia.org/wiki/Crenel_function (Accessed: December
;; 19, 2022).
;; - [46] Racional Diádico (2022) Wikipedia. Wikimedia Foundation.
;; Available at: https://es.wikipedia.org/wiki/Racional_di%C3%A1dico
;; (Accessed: December 19, 2022).
;; - [47] https://en.wikipedia.org/wiki/Numerical_differentiation
(define-module (grsp grsp2)
#:use-module (grsp grsp0)
#:use-module (grsp grsp1)
#:use-module (ice-9 threads)
#:export (grsp-gtels
grsp-sign
grsp-eiget
grsp-is-prime
grsp-fact
grsp-sumat
grsp-biconr
grsp-bicowr
grsp-gtls
grsp-getles
grsp-krnb
grsp-bpp
grsp-sexp
grsp-slog
grsp-woodall-number
grsp-cullen-number
grsp-proth-number
grsp-mersenne-number
grsp-repdigit-number
grsp-wagstaff-number
grsp-williams-number
grsp-thabit-number
grsp-fermat-number
grsp-catalan-number
grsp-wagstaff-prime
grsp-dobinski-formula
grsp-method-newton
grsp-method-euler
grsp-lerp
grsp-givens-rotation
grsp-fitin
grsp-fitin-0-1
grsp-eccentricity-spheroid
grsp-rcurv-oblate-ellipsoid
grsp-volume-ellipsoid
grsp-third-flattening-ellipsoid
grsp-flattening-ellipsoid
grsp-eccentricityf-ellipsoid
grsp-mrc-ellipsoid
grsp-pvrc-ellipsoid
grsp-dirc-ellipsoid
grsp-urc-ellipsoid
grsp-r1-iugg
grsp-r2-iugg
grsp-r3-iugg
grsp-r4-iugg
grsp-fxyz-torus
grsp-stirling-approximation
grsp-airy-function
grsp-sfact-pickover
grsp-sfact-sp
grsp-hfact
grsp-fact-alt
grsp-fact-exp
grsp-fact-sub
grsp-fact-low
grsp-fact-upp
grsp-ratio-derper
grsp-ratio-derper-mth
grsp-intifint
grsp-log
grsp-log-mth
grsp-dtr
grsp-opz
grsp-eex
grsp-e
grsp-pi
grsp-em
grsp-phi
grsp-nan
grsp-naninf
grsp-absop
grsp-rprnd
grsp-ifrprnd
grsp-nabs
grsp-onhn
grsp-salbm-omth
grsp-hailstone-number
grsp-rectangle-method
grsp-kronecker-delta
grsp-dirac-delta
grsp-multi-delta
grsp-multi-heavyside-step
grsp-euler-number
grsp-rectangular
grsp-triangular
grsp-2ex
grsp-1n
grsp-pn123n
grsp-closestn
grsp-closestd
grsp-coinflip
grsp-fn
grsp-fn3
grsp-eq
grsp-n12n2
grsp-crenel
grsp-padic
grsp-n2c
grsp-bop1
grsp-dqnss
grsp-dqsym))
;;;; grsp-gtels - Finds if p_n1 is greater, equal or smaller than p_n2.
;; this function is equivalent to the sgn math function.
;;
;; Keywords:
;;
;; - functions, comparison, conditional
;;
;; Parameters:
;;
;; - p_n1: number.
;; - p_n2: number.
;;
;; Output:
;;
;; - 1 if (> p_n1 p_n2).
;; - 0 if (= p_n1 p_n2).
;; - (-1) if (< p_n1 p_n2).
;;
(define (grsp-gtels p_n1 p_n2)
(let ((res1 0))
(cond ((> p_n1 p_n2)
(set! res1 1))
((< p_n1 p_n2)
(set! res1 -1)))
res1))
;;;; grsp-sign - Returns 1 if p_n1 >= 0, -1 otherwise.
;;
;; Keywords:
;;
;; - functions, comparison, conditional
;;
;; Parameters:
;;
;; - p_n1: number.
;;
;; Output:
;;
;; - Numeric.
;;
(define (grsp-sign p_n1)
(let ((res1 0))
(set! res1 (grsp-gtels p_n1 0))
(cond ((equal? res1 0)
(set! res1 1)))
res1))
;;;; grsp-eiget - Finds out if p_n1 is an exact integer equal or greater
;; than p_n2.
;;
;; Keywords:
;;
;; - functions, comparison
;;
;; Parameters:
;;
;; - p_n1: integer.
;; - p_n2: integer.
;;
;; Output:
;;
;; - Boolean.
;;
;; - Returns #t if p_n1 is an integer and equal or greater than p_n2.
;; - Returns #f otherwise.
;;
(define (grsp-eiget p_n1 p_n2)
(let ((res1 #f))
(cond ((exact-integer? p_n1)
(cond ((>= p_n1 p_n2)
(set! res1 #t)))))
res1))
;;;; grsp-is-prime - This is a very simple procedure, inefficient but
;; sufficient for small numbers to find if they are prime or not. For large
;; numbers other methods will likely be more adequate.
;;
;; Keywords:
;;
;; - functions, primes, prime number
;;
;; Parameters:
;;
;; - p_n: integer.
;;
;; Output:
;;
;; - Boolean.
;;
;; - Returns #t of p_n is prime.
;; - #f otherwise.
;;
(define (grsp-is-prime p_n1)
(let ((res1 #t)
(b1 #f)
(i1 2))
;; Cycle.
(while (eq? b1 #f)
(cond ((= 0 (remainder p_n1 i1))
(set! res1 #f)
(set! b1 #t)))
(set! i1 (+ i1 1))
(cond ((>= i1 p_n1)
(set! b1 #t))))
(cond ((grsp-getles p_n1 -1 1)
(set! res1 #f)))
res1))
;;;; grsp-fact - Calculates the factorial of p_n1.
;;
;; Keywords:
;;
;; - functions, factorial
;;
;; Parameters:
;;
;; - p_n1: natural number.
;;
;; Output:
;;
;; - Numeric.
;;
;; - Returns 1 if p_n1 is not a natural number.
;; - Returns the factorial of p_n1 otherwise.
;;
(define (grsp-fact p_n1)
(let ((res1 1))
(cond ((eq? (grsp-eiget p_n1 1) #t)
(set! res1 (* p_n1 (grsp-fact (- p_n1 1))))))
res1))
;;;; grsp-sumat - Calculates the summation of p_n1 (triangular number).
;;
;; Keywords:
;;
;; - functions, summation
;;
;; Parameters:
;;
;; - p_n1: integer >= 0.
;;
;; Output:
;;
;; - Numeric.
;;
;; - Returns 0 if p_n1 is not a natural number.
;; - Summation value of p_n1 otherwise.
;;
;; Sources:
;;
;; - [2].
;;
(define (grsp-sumat p_n1)
(let ((res1 0))
(cond ((eq? (grsp-eiget p_n1 0) #t)
(set! res1 (+ p_n1 (grsp-sumat (- p_n1 1))))))
res1))
;;;; grsp-biconr - Binomial coefficient. Lets you choose p_k1 elements
;; from a set of p_n1 elements without repetition.
;;
;; Keywords:
;;
;; - functions, combinatorics, conditional
;;
;; Parameters:
;;
;; - p_n1: integer >= 0
;; - p_k1: integer between [0, p_n1].
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [3].
;;
(define (grsp-biconr p_n1 p_k1)
(let ((res1 0))
(cond ((eq? (grsp-eiget p_n1 0) #t)
(cond ((eq? (grsp-eiget p_k1 0) #t)
(cond ((>= p_n1 p_k1)
(set! res1 (/ (grsp-fact p_n1)
(* (grsp-fact (- p_n1 p_k1))
(grsp-fact p_k1))))))))))
res1))
;;;; grsp-bicowr - Binomial coefficient. Les you choose p_k1 elements from
;; a set of p_n1 elements with repetition.
;;
;; Keywords:
;;
;; - functions, combinatorics
;;
;; Parameters:
;;
;; - p_n1: integer >= 0.
;; - p_k1: integer >= 0 and <= p_n1.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [3].
;;
(define (grsp-bicowr p_n1 p_k1)
(let ((res1 0))
(set! res1 (grsp-biconr (+ p_n1 (- p_k1 1)) p_k1))
res1))
;;;; grsp-gtls - "gtls = Greater than, less than" Finds if number p_n1 is
;; greater than p_n2 and smaller than p_n3, or in the interval (p_n2:p_n3).
;;
;; Keywords:
;;
;; - functions, comparison
;;
;; Parameters:
;;
;; - p_n1: number.
;; - p_n2: number.
;; - p_n3: number.
;;
;; Output:
;;
;; - Boolean.
;;
;; - Returns #t if the condition holds.
;; - #f otherwise.
;;
(define (grsp-gtls p_n1 p_n2 p_n3)
(let ((res #f))
(cond ((> p_n1 p_n2)
(cond ((< p_n1 p_n3)
(set! res #t)))))
res))
;;;; grsp-getles - "getles = Greater or equal than, less or equal than"
;; Finds if number p_n1 is greater or equal than p_n2 and smaller or
;; equal than p_n3.
;;
;; Keywords:
;;
;; - functions, comparison
;;
;; Parameters:
;;
;; - p_n1: number.
;; - p_n2: number.
;; - p_n3: number.
;;
;; Output:
;;
;; - Boolean.
;;
;; - Returns #t if the condition holds.
;; - #f otherwise.
;;
(define (grsp-getles p_n1 p_n2 p_n3)
(let ((res #f))
(cond ((>= p_n1 p_n2)
(cond ((<= p_n1 p_n3)
(set! res #t)))))
res))
;;;; grsp-k2nb - Returns the value of (p_k1 * (p_r1**p_n1)) + p_b1.
;;
;; Keywords:
;;
;; - functions
;;
;; Parameters:
;;
;; - p_k1: number.
;; - p_r1: number.
;; - p_n1: number.
;; - p_b1: number.
;;
;; Output:
;;
;; - Numeric.
;;
(define (grsp-krnb p_k1 p_r1 p_n1 p_b1)
(let ((res1 0))
(set! res1 (+ (* p_k1 (expt p_r1 p_n1)) p_b1))
res1))
;;;; grsp-bpp - Bailey–Borwein–Plouffe formula.
;;
;; Keywords:
;;
;; - functions
;;
;; Parameters:
;;
;; - p_k1: summation iterations desired.
;; - p_b1: integer base.
;; - p_pf: polynomial with integer coef.
;; - p_qf: polynomial with integer coef.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [4].
;;
(define (grsp-bpp p_k1 p_b1 p_pf p_qf)
(let ((res1 0))
(cond ((exact-integer? p_k1)
(cond ((eq? (grsp-eiget p_b1 2) #t)
(let loop ((k1 0))
(if (< k1 p_k1)
(begin (set! res1 (+ res1 (* (/ 1 (expt p_b1 k1))
(/ (p_pf k1)
(p_qf k1)))))
(loop (+ k1 1)))))))))
res1))
;;;; grsp-sexp - Performs a tetration operation on p_x1 of height
;; p_n1. sexp stands for super exponential.
;;
;; Keywords:
;;
;; - functions, exp, expt
;;
;; Parameters:
;;
;; - p_x1: base.
;; - p_n1: rank or height of the power tower.
;;
;; Output:
;;
;; - Numeric.
;;
;; Notes:
;;
;; - This operation might have a significant impact on the performance of
;; your computer due to its very fast function growth. Use with care.
;;
;; Sources:
;;
;; - [5].
;;
(define (grsp-sexp p_x1 p_n1)
(let ((res1 0))
(cond ((= p_n1 0)
(set! res1 1))
((< p_n1 0)
(set! res1 0))
((> p_n1 0)
(set! res1 p_x1)
(let loop ((i1 1))
(if (< i1 p_n1)
(begin (set! res1 (expt p_x1 res1))
(loop (+ i1 1)))))))
res1))
;;;; grsp-slog - Performs a non-recursive super logarithm operation on
;; p_x1 of height p_n1.
;;
;; Keywords:
;;
;; - functions, logarithm
;;
;; Parameters:
;;
;; - p_x1: base.
;; - p_n1: rank or height of the power tower of the super exponentiation
;; for which grsp-slog is inverse.
;;
;; Output:
;;
;; - Numeric.
;;
;; Notes:
;;
;; - This operation might have a significant impact on the performance of
;; your computer due to its very fast function growth. Use with care.
;;
(define (grsp-slog p_x1 p_n1)
(let ((res1 0))
(set! res1 (/ 1 (grsp-sexp p_x1 p_n1)))
res1))
;;;; grsp-woodall-number - Calculates the Woodall number of p_n1.
;;
;; Keywords:
;;
;; - functions, number
;;
;; Parameters:
;;
;; - p_n1: natural number.
;;
;; Output:
;;
;; - Numeric.
;;
;; - If p_n1 is not a natural number, the function returns 1.
;; - Otherwise, it returns the Woodall number of p_n1.
;;
;; Sources:
;;
;; - [6].
;;
(define (grsp-woodall-number p_n1)
(let ((res1 1))
(cond ((eq? (grsp-eiget p_n1 1) #t)
(set! res1 (grsp-krnb p_n1 2 p_n1 -1))))
res1))
;;;; grsp-cullen-number - Calculates the Cullen number of p_n1.
;;
;; Keywords:
;;
;; - functions, number
;;
;; Parameters:
;;
;; - p_n1: natural number.
;;
;; Output:
;;
;; - Numeric.
;;
;; - If p_n1 is not a natural number, the function returns 1.
;; - Otherwise, it returns the Cullen number of p_n1.
;;
;; Sources:
;;
;; - [7].
;;
(define (grsp-cullen-number p_n1)
(let ((res1 1))
(cond ((eq? (grsp-eiget p_n1 1) #t)
(set! res1 (grsp-krnb p_n1 2 p_n1 1))))
res1))
;;;; grsp-proth-number - Returns the value of a Proth number if:
;;
;; - Both p_n1 and p_k1 are positive integers.
;; - p_k1 s odd.
;; - 2**p_n1 > p_k1.
;;
;; Keywords:
;;
;; - functions, numbers
;;
;; Parameters:
;;
;; - p_k1: positive integer.
;; - p_n1: positive integer.
;;
;; Output:
;;
;; - Numeric.
;;
;; - 0 if p_n1 and p_k1 do not fill the requisites to calculate a Proth
;; number.
;; - The Proth number if both p_n1 and p_k1 satisfy the conditions
;; mentioned.
;;
;; Sources:
;;
;; - [8].
;;
(define (grsp-proth-number p_n1 p_k1)
(let ((res1 0))
(cond ((exact-integer? p_n1)
(cond ((exact-integer? p_k1)
(cond ((odd? p_k1)
(cond ((> (expt 2 p_n1) p_k1)
(set! res1 (grsp-krnb p_k1
2
p_n1
1))))))))))
res1))
;;;; grsp-mersenne-number - Calculates a Mersenne number according to
;; Mn = 2**p_n1 - 1.
;;
;; Keywords:
;;
;; - functions, numbers
;;
;; Parameters:
;;
;; - p_n1: positive integer.
;;
;; Output:
;;
;; - Numeric.
;;
;; - 0 if p_n1 is not a positive integer.
;; - Mn if p_n1 is a positive integer.
;;
;; Sources:
;;
;; - [9][10].
;;
(define (grsp-mersenne-number p_n1)
(let ((res1 0))
(cond ((exact-integer? p_n1)
(set! res1 (grsp-krnb 1 2 p_n1 -1))))
res1))
;;;; grsp-repdigit-number - Produces a repdigit number composed by p_n1
;; repeated p_d1 instances.
;;
;; Keywords:
;;
;; - functions, numbers
;;
;; Parameters:
;;
;; - p_n1: natural number between [1,9].
;; - p_d1: natural number.
;;
;; Output:
;;
;; - Numeric.
;;
;; Sources:
;;
;; - [11].
;;
(define (grsp-repdigit-number p_n1 p_d1)
(let ((res1 0)
(i1 0))
(cond ((exact-integer? p_n1)
(cond ((exact-integer? p_d1)
(cond ((eq? (grsp-gtls p_n1 0 10) #t)
(while (< i1 p_d1)
(set! res1 (+ res1 p_n1))
(set! i1 (+ i1 1))
(cond ((< i1 p_d1)
(set! res1 (* res1 10)))))))))))
res1))
;;;; grsp-wagstaff-number - Produces a Wagstaff number of base p_b1.
;;
;; Keywords:
;;
;; - functions, numbers
;;
;; Parameters:
;;
;; - p_n1: natural number.
;; - p_b1: natural number >= 2.
;;
;; Output:
;;
;; - Numeric.
;;
;; - If conditions for arguments are met, the result is a Wagstaff
;; number.
;; - Otherwise the function returns zero.
;;
;; Sources:
;;
;; - [12].
;;
(define (grsp-wagstaff-number p_n1 p_b1)
(let ((res1 0))
(cond ((eq? (grsp-eiget p_n1 1) #t)
(cond ((eq? (grsp-eiget p_b1 2) #t)
(set! res1 (* 1.0 (/ (+ (expt p_b1 p_n1) 1) (+ p_b1 1))))))))
res1))
;;;; grsp-williams-number - Produces a Williams number of base p_b1.
;;
;; Keywords:
;;
;; - functions, numbers
;;
;; Parameters:
;;
;; - p_n1: Natural number >= 1.
;; - p_b1: Natural number >= 2.
;;
;; Output:
;;
;; - Numeric.
;;
;; - If conditions for arguments are met, the result is a Williams
;; number.
;; - Otherwise the function returns zero.
;;
;; Sources:
;;
;; - [13].
;;
(define (grsp-williams-number p_n1 p_b1)
(let ((res1 0))
(cond ((eq? (grsp-eiget p_n1 1) #t)
(cond ((eq? (grsp-eiget p_b1 2) #t)
(set! res1 (- (* (- p_b1 1) (expt p_b1 p_n1)) 1))))))
res1))
;;;; grsp-thabit-number - Produces a Thabit number.
;;
;; Keywords:
;;
;; - functions, numbers
;;
;; Parameters:
;;
;; - p_n1: positive integer.
;;
;; Output:
;;
;; - Numeric.
;;
;; - If conditions for arguments are met, the result is a Thabit number.
;; - Otherwise the function returns zero.
;;
(define (grsp-thabit-number p_n1)
(let ((res1 0))