Triangular Number Multiplication Study and demo example TCL calculator, numerical analysis

This page is under development. Constructive Comments are welcome, but please load any constructive comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks,gold15JUL2020


Preface

gold Here is some TCL scripts on the triangular number study. In reference to modern mathematics, the triangular number and modern extensions fall under the broad umbrella of the binomial theorem and algebra. Aside from the TCL calculator shell or graphics user interface gui, separate console programs were developed to dump the tables and check the algorithms as independent TCL procedures. Some testcases were developed using the available choose function in the TCLLIB math library, namespace export choose and <tcllib> ::math::choose returns the binomial coefficient C(n,k) = n!/k!(n-k)!


Introduction


gold 8/02/2020. I am shuffling some materials and reusing this older page. Unfortunately, the XXX network etc is blocking my access to this TCL WIKI, TCLLIB, SourceForge, ActiveState, and other TCL download sites, reference open science materials etc. So the prose is "catch can".


Formulas


From the modern derivations and formula extensions, there are a number of formulas that can be presented into TCL code. The modern extension to the multiplication algorithm from the binomial theorem is a*b = 0.5*{a+b)**2 -a**2-b**2}. A triangular number can be presented as choose (N 2) or math::choose (n+1 2) can be expressed as (n+1)!/ (n+1−2)!2!. Simplifies to n(n+1)/2. However, many of the early methods or formulas must converted into a formula or symbolic notation for the TCL computer code. The Binomial Theorem in Euclid II, 4, is formulated as (a + b)**2 = a**2 + 2ab+ b**2, Pascal triangle coefficients <1 2 1>. Some formulas were early published by Elie de Joncourt, 1762, Netherlands. The triangular number TN = N*(N+1)/2. The sum of consecutive TN numbers are squares. TN <aa> + TN <aa+1> = square number. Joncourt used TN to calculate square roots and cube roots. Joncourt used formula as aa * bb = <(aa+bb)**2 -aa**2 -bb**2>/2. The key term is <(aa+bb)**2 -aa**2 -bb**2>, which is twice answer. The Binomial theorem is formulated as a*b = 0.5*{(a+b)**2 -a**2-b**2}. The ground breaking formula for triangular numbers was from mathematician James Glaisher, as near as I can tell. James Glaisher published the triangular numbers TN formula in 1889. Triangular multiplication is formulated as aa * bb = TN <aa-1> + TN <bb> - TN <aa-bb-1>. The Glaisher formula returns the triangular multiplication product as an integer from two natural numbers. James Glaisher discussed TN and Quarter Square variants in his original papers. The conventional formula for Quarter Squares is a*b = <(a + b)**2 − (a − b)**2> * .25


The Glaisher formula returns the triangular multiplication product as an integer from two positive natural numbers. Triangular multiplication is formulated as aa * bb = TN <aa-1> + TN <bb> - TN <aa-bb-1>. The Glaisher formula does not define the Triangular Number for negative numbers. As understood here, the term TN <aa-bb-1> might return negative numbers for bb > aa, so suggest swap or reorder to avoid TN<-n>.


  • ab = (1/2) * (a-1) *a + (1/2) * (b+1) *b - (1/2) * (a-b-1 ) *(a-b ) ;# derivation, constraints below on a and b
  • aa * bb = TN <aa-1> + TN <bb> - TN <aa-bb-1> ;# Glaisher formula

Formulas of M. Arnaudeau, France ca. 1896


The works of M. Arnaudeau on triangular numbers were largely manuscript and were never completely published, but a review article by Edward L. Stabler in 1897 gave many details of the planned work of M. Arnaudeau . Apparently, these formulas used a base of (a+b)**2 = a**2 + b**2 + 2ab, or follow on to ab = (1/2) * ((a+b)**2 - a**2 - b**2 ), and then substitute the algebraic quantities on the right side with quantities from triangular numbers. The planned inclusion of reciprocals makes it possible to use the tables of triangular numbers to perform divisions.


  • S(n)= 1 + 2 + 3 ... n = n * (n + 1 ) / 2. ;# explanation in similar notation
  • ab = S(a) + S(b-1) - S(a-b) ;# constraints below on a and b
  • ab = S(a-1) + S(b) - S(a-b-1)
  • ab = S(a-n) + S(b+n-1) - S(a-b-n) - S(n-1) ;# for any n
  • ab = S((a-1)/2 +b) - S((a-1)/2 -b)
  • ab = S((a/2)+b-1) - S((a/2)-b-1) + b
  • ab = S(a+b) + S(a) - S(b)


Modern Identities with Triangular Numbers


  • T(0) = 0
  • T(n+1) = T(n) + (n + 1 ) ;# HOGGATT, JR., and MARJORIE BICKWELL
  • n**2 = T(n) + T(n - 1) ;# HOGGATT, JR., and MARJORIE BICKWELL

BarTa Rectangle in the Babylonian math problems <draft>

One of the favorite rectangles in the Babylonian math problems was the Bar-Ta rectangle. The linguists are saying that Bar-ta or Dar-Ta means cross bar, cross piece, or transversal in the tablet glyphs, see Muroi. The Bar-Ta rectangle is related to the 3/4/5 triangle scaled by 1/4. Meaning divide the dimensions of the 3/4/5 triangle by 4 to get 3/4 4/4 5/4>. The Bar-Ta rectangle is two of the rescaled triangles. The conceptual math problem asks for the sides of a rectangle whose area is 0:45 and whose diagonal is 1;15 in base_60. Converting to base_10, the equivalent decimal numbers are 0.75 for the area, and 1.25 for the diagonal. Then in decimal, Side a = 1 , then side b= 0.75. area a*b = 0.75 decimal.


The Barta triangle was used in terms of a comparison using the conventional modern trigonometry of sin/tangent and the concepts of Rational Trigonometry, reference to expanded P322(CR-Decimal8) table in Mansfield and Wildberger on P322 table. The first part is to identify the triangle or closest Babylonian triplet on P322. The beta or b/l equals (3/4)/1 as expr { (3/4.)/1.} or 0.75 units. The delta or d/l equals (1.25)/1 as expr { (1.25)/1.} or 1.25 units. The delta squared or (d/l)**2 equals ((1.25)/1)**2 as expr { ((1.25)/1.)**2} or 1.5625 decimal units. The equivalent line on P322 was line 11 and the triplet in base_60 was ( 45/60, 1, 1+15/60 ). Most of the linguists agree that the lines on the tablet are triangles normalized to a length l of unity. The normalized triangles are reduced mostly to sides with no common factors other than 1, hence the high proportions of prime numbers on the tablet. For comparison in modern angles, the angle A was arctangent expr { .75/1 } or 36.869 degrees. The angle B was arctangent expr { .75/1 } or 53.129 degrees. The diagonal equals expr {((1.*1)+(.75*.75))**.5 } or 1.25 decimal.


Unless the problem uses one of the special triangles, it is believed that the triangle would have to be normalized and rescaled to a middle side of 1, solved with the Babylonian triplets, then the answers rescaled and interpolated to the orignal size.


Push Button Operation

For the push buttons, the recommended procedure is push a testcase and fill frame, change first three entries etc, push solve, and then push report. Report allows copy and paste from console. For testcases in a computer session, the TCL calculator increments a new testcase number internally, eg. TC(1), TC(2)., TC(3), TC(4) etc. The testcase number is internal to the calculator and will not be printed until the report button is pushed for the current result numbers. The current result numbers will be cleared on the next solve button. For comparison of the Babylonian algorithm with conventional Western methods, TCL code will include redundant procs, redundant calculation paths, and printout check formulas to compute product and area.


Conclusions

The Old Babylonian quarter squares multiplication formula requires three math operations as opposed to one math operation in modern logarithms, per two numbers. Considering hand calculations and omitting the table lookups, the Old Babylonian quarter squares multiplication formula is about three times the work of the modern logarithm method. Under the same considerations, the Old Babylonian half squares multiplication formula requires four math operations and is about four times the work of the the modern logarithm method. In using the Babylonian multiplication formula in taking base_60 squares, using many place numbers in a hand multiplication array, there must be breakpoints where the effort of the multiplication formula is less than taking the many place square by hand calculation. Given the amount of Babylonian effort that developed the many place reciprocals in base_60 on the clay tablets, is it possible that the known Babylonian multiplication formulas, base_60 reciprocals, and terms could be manipulated into an algorithm, formula, or even modern logarithm of fewer operations?


Table 1 : Triangular Numbers Study

Table 1: Triangular Numbers Tables printed in tcl format
a subbing a*(a+1)*.5 number series comments if any
0 0.00000
1 1.0000
2 3.0000
3 6.0000
4 10.000
5 15.000
6 21.000
7 28.000
8 36.000
9 45.000
10 55.000
11 66.000
12 78.000
13 91.000
14 105.00
15 120.00
16 136.00
17 153.00
18 171.00
19 190.00
20 210.00

Table 2 : Proof of Abu Al Karachi


formula 1**3 + 2**3 + 3**3 ... + N**3 = ( 1 + 2 + 3 ... + n)**2


table 2 printed inTCL format
expression answer comment, if any
expr { 1 } ;# -> 1
expr { 1 + 2 } ;# -> 3
expr { 1 + 2 + 3 } ;# -> 6
expr { 1 + 2 + 3 + 4 } ;# -> 10
expr { 1 + 2 + 3 + 4 + 5 } ;# -> 15
expr { 1**3 } ;# -> 1
expr { 1**3 + 2**3 + } ;# -> 9
expr { 1**3 + 2**3 + 3**3 } ;# -> 36
expr { 1**3 + 2**3 + 3**3 + 4**3} ;# -> 100
expr { 1**3 + 2**3 + 3**3 + 4**3 + 5**3 } ;# -> 225

Table 3 : Powers of 2 with added Modern Logarithm Notation


Table 3: Powers of 2 printed in tcl format
N 2**N modern notation log2 N = base_60 reciprocal, decimals comments if any
0 1.0000 log2 1 = 0.0 60.000
1 2.0000 log2 2 = 1.0 30.000
2 4.0000 log2 4 = 2.0 15.000 Ref MCT
3 8.0000 log2 8 = 3.0 7.5000
4 16.000 log2 16 = 4.0 3.7500
5 32.000 log2 32 = 5.0 1.8750
6 64.000 log2 64 = 6.0 0.93800
7 128.00 log2 128 = 7.0 0.46900
8 256.00 log2 256 = 8.0 0.23400
9 512.00 log2 512 = 9.0 0.11700
10 1024.0 log2 1024 = 10.0 0.059000

Table 4 : Standard Multiplication Table


Multiplication Table printed in tcl format
x 1 2 3 4 5 6 7 8 9 10 11 12
1 1 2 3 4 5 6 7 8 9 10 11 12
2 4 6 8 10 12 14 16 18 20 22 24
3 9 12 15 18 21 24 27 30 33 36
4 16 20 24 28 32 36 40 44 48
5 25 30 35 40 45 50 55 60
6 36 42 48 54 60 66 72
7 49 56 63 70 77 84
8 64 72 80 88 96
9 81 90 99108
10 100110120
11 121132
12 144

Reference. Gnumeric Spreadsheet.


Table 5 : Standard Multiplication Table, another


Multiplication Table printed in tcl format
123456789101112 X
123456789101112
24681012141618202224
369121518212427303336
4812162024283236404448
51015202530354045505560
61218243036424854606672
71421283542495663707784
81624324048566472808896
918273645546372819099108
102030405060708090100110120
112233445566778899110121132
1224364860728496108120132144

Reference. Gnumeric Spreadsheet.


Testcases Section


Testcase 1

table 1printed in tcl format
quantity value comment, if any
1:testcase_number
1.0 :aa integer quantity N1:
2.0 :bb integer quantity N2:
3.0 :cc integer quantity N3:
4.0 :dd integer quantity N4:
1.0 :optional:
1.0 :triangular number TN1
2.0 :multiplication from TCL mathlib:
4.0 :test slot, TN1+TN2 from triangular numbers :

Testcase 2


table 2printed in tcl format
quantity value comment, if any
2:testcase_number
3.0 :aa integer quantity N1:
4.0 :bb integer quantity N2:
7.0 :cc integer quantity N3:
9.0 :dd integer quantity N4:
1.0 :optional:
6.0 :triangular number TN1
12.0 :multiplication from TCL mathlib:
16.0 :test slot, TN1+TN2 from triangular numbers :

Testcase 3


table 3printed in tcl format
quantity value comment, if any
3:testcase_number
3.0 :aa integer quantity N1:
6.0 :bb integer quantity N2:
5.0 :cc integer quantity N3:
7.0 :dd integer quantity N4:
1.0 :optional:
6.0 :triangular number TN1
18.0 :multiplication from TCL mathlib:
27.0 :test slot, TN1+TN2 from triangular numbers :


Testcase 4 testing block procedure


table 3printed in tcl format
quantity value comment, if any
4:testcase_number
777.0 :aa integer quantity N1:
778.0 :bb integer quantity N2:
3.0 :cc integer quantity N3:
4.0 :dd integer quantity N4:
302253.0 303031.0 6.0 10.0 :optional:
302253.0 :triangular number TN1
604506.0 :multiplication from TCL mathlib:
604506.0 :test slot >> multiplication TN1*TN2 from triangular numbers :
>>>>> testing block procedure <<<<
15.0 3.0 6.0 10.0 test slot >> TN1*TN2 :
TN <1 2 3 4 > returns 3.0 6.0 10.0 test slot >> TN1 TN2 :
TN <1 2 0 4 > returns 3.0 10.0 test slot >> TN1 TN2 :
TN <1 2 0 0 > returns 3.0 test slot >> TN1 TN2 :
TN <1 2 -3 4 > returns 3.0 -6.0 10.0 test slot >> TN1 TN2 :
TN < .1 .2 .3 .4 > returns 0 0 0 0 test slot >> TN1 TN2 :
TN < .1 .2 0. .4 > returns 0 0 0 test slot >> TN1 TN2 :
TN < 0. > returns 0 test slot >> TN1 TN2 :
TN < 1. > returns 0 test slot >> TN1 TN2 :
TN <10 20 30 40> returns 55.0 210.0 465.0 820.0 test slot >> TN1 TN2 :
>>>> test invoking TCLLIB library <<<<
= 0.33333333333333331 huge = 1.7976931348623157e+308
math choose statements 45 6 55
>>>> testing large number <<<<
302253.0 303031.0 6.0 10.0 301476.0 303031.0 -1.0 604506.0
604506.0 777.0 778.0 604506.0
Check TN<777> + TN<778> should equal square.
expr { 302253.0 + 303031.0} #= 605284.0
expr { 605284.0**.5 } #= 778.0 clean root
Check sum of Glaisher terms should equal product.
expr { 301476.0 + 303031.0 -1.0 } #= 604506.0
expr { 777*778 } #= 604506 from mathlibc

Screenshots Section

figure 1. Calculator Screenshot

Triangular Number calculator screenshot


figure 1b. Calculator Screenshot


Triangular Number Multiplication printout


figure 2.Triangular Number chart


Triangular Number demo chart


figure 3. Favorite


BabylonianRectangle

figure 4. Triangular Numbers in box


Triangular Number Multiplication sample


figure 5. Sum successive TN(S) and get square.


Triangular Number Multiplication box

figure 6. Euclid Multiplication proof?


Triangular Number Multiplication proof?


figure 7.



figure 8.



figure 9.



References:

  • Primary references, Google <Babylonian Multiplication by M. Lewinter and W. Widulski>
  • Amazing-Traces-of-a-Babylonian-Origin-in-Greek-Mathematics,
  • Joran Friberg. Primary reference
  • google < Babylonian trapezoid Wikipedia >
  • Wikipedia search engine < quarter square multiplication algorithm >
  • Wikipedia search engine < multiplication algorithm > Primary reference
  • Wikipedia search engine < Babylonian Math >
  • Wikipedia search engine < history of logarithms >
  • Wikipedia search engine < Special right triangle >
  • precision math procedure used in TCL calculator Arjen Markus AM
  • Computers and real numbers
  • Floating-point formatting
  • On Multiplication by a Table of Single Entry.
  • J.W.L. Glaisher M.A. F.R.S., F.R.S.(1878)
  • Denis Roegel. A reconstruction of Plassmann’s table of quarter-squares (1933).
  • <Research Report> 2013, hal-00880838
  • Denis Roegel. A reconstruction of Blater’s table of quarter-squares (1887).
  • <Research Report> 2013, hal-00880836
  • Denis Roegel. A reconstruction of Laundy’s table of quarter-squares (1856).
  • <Research Report> 2013, hal-00880835
  • Denis Roegel. A reconstruction of Joncourt's table of triangular numbers (1762)
  • Ancient Babylonian Algorithms, Donald E. Knuth, Stanford
  • Mixed sums of squares and triangular numbers (III)
  • Byeong-Kweon Oh a,1, Zhi-Wei Sun
  • Department of Applied Mathematics, Sejong University
  • Series of Reciprocal Triangular Numbers
  • Paul Bruckman, Joseph B. Dence, Thomas P. Dence,
  • and Justin Young
  • On the representation of integers as sums of triangular numbers
  • KEN ONO, SINAI ROBINS, AND PATRICK T. WAHL
  • A reconstruction of Arnaudeau’s table of triangular numbers (ca. 1896)
  • Denis Roegel
  • On Triangular Numbers Which are Sums of Consecutive Squares
  • RAPHAEL FINKEJSTEIN, Department of Mathematics, Bowling Green State University,
  • hal-00654428v1 Reports
  • Denis Roegel. A reconstruction of Gingerich's table of
  • regular sexagesimals and a cuneiform version of the table (1965)
  • Denis Roegel. A reconstruction of Arnaudeau’s table of triangular numbers (ca. 1896)
  • Research Report LORIA - Université de Lorraine. 2014
  • Denis Roegel. A reconstruction of Centnerschwer's table of quarter-squares (1825)
  • Research Report, 2013
  • Denis Roegel. A reconstruction of Merpaut's table of quarter-squares (1832)
  • Research Report, 2013
  • Denis Roegel. A reconstruction of Laundy's table of quarter-squares (1856)
  • Research Report] 2013
  • Denis Roegel. A reconstruction of Plassmann's table of quarter-squares (1933)
  • Research Report, 2013
  • Denis Roegel. A reconstruction of Blater's table of quarter-squares (1887)
  • 2013
  • Denis Roegel. A reconstruction of Bojko's table of quarter-squares (1909)
  • 2013
  • Denis Roegel. A reconstruction of Bürger's table of quarter-squares (1817)
  • Squares, triangles and other labour-saving devices, Burkard Polster and Marty Ross
  • The Age, 17 March 2014, [L1 ]
  • Multiplication formulas [L2 ]
  • en.wikipedia.org, James_Whitbread_Lee_Glaisher
  • mathforum.org/library/drmath/ Doctor Mitteldorf at MathForum
  • en.wikipedia.org search engine on Multiplication_algorithm
  • en.wikipedia.org search engine on Quarter square multiplication
  • Triangular_numbers [L3 ]
  • Figurate_numbers [L4 ]
  • Orthoplex_numbers [L5 ]
  • al-Karaji, Al Karachi [L6 ]
  • al-Karaji, Al Karachi [L7 ]
  • Dicuil (9th century) on Triangular and Square Numbers
  • Helen Elizabeth Ross, British Journal for the History of Mathematics 2019, 34(2), 79-94
  • Quotes from Method of Quarter Squares, James Glaisher,1889 & reprinted several times
  • The American Philosophical Society Journal at Philadelphia
  • Glaisher, J. The Method of Quarter Squares. Nature 41, 9 (1889).
  • Journal of the Institute of Actuaries, Volume 28; Volume 28
  • Glaisher, J. W. L., and G. CAREY FOSTER. “The Method of Quarter Squares.”
  • Journal of the Institute of Actuaries (1886-1994), vol. 28, no. 3, 1890, pp. 227–235.

  • original quote in English for the Glaisher formula
  • a * b = (1/2) * (a -r) * a + (1/2) * b * (b + r) - n * (a - b -r) * (a - b)
  • or, as we may write it,
  • a * b = T(a -1) + T(b) - T(a -1 -b)

" T (n) denotes the nth triangular number. Thus, to multiply two numbers we subtract unity from the larger number, and enter the table with the larger number so diminished, with the smaller number, and with the difference of these two numbers."


Published Tables of Western Quarter-Squares
Table Range Pages Density
Voisin (1817) 20000 123 162.6
Bürger (1817) 20000 80 250.0
Centnerschwer (1825) 20000 40 500.0
Merpaut (1832) 40000 400 100.0
Kulik (1851) 30000 40 750.0
Laundy (1856) 100000 200 500.0
Blater (1887) 200000 200 1000.0
Bojko (1909) 20000 20 1000.0
Plassmann (1933) 20009 200 100.0
from Denis Roegel, 2013, Technical reports, LORIA, Nancy, France, 2013.

Pseudocode & Equations Section


        more than one formula for 1) tables and 2) calculator shell
        Babylonian multiplication  rule  a * b = ((a + b)/2)^2 - ((a - b)/2)^2 # used in calculator shell
        conventional Western formula for quarter square multiplication tables
        is a * b= (1/4)*(((a+b)**2) - ( (a-b)**2 )  ) # used in Western tables circa 1600 to 1950 CE.
        quarter square multiplication formula for the tables
        is x*y = <.25* (x+y)**2> * <.25* (x-y)**2>. 
        # recommended, avoids division by zero
        half square multiplication formula for the tables
        may be equivalent to x*y = 0.5* <.5* (x+y)**2> * <.5* (x-y)**2> # used in tables,
        # recommended, avoids division by zero
        modern extension to the Babylonian multiplication algorithm 
        from the binomial theorem is a*b = 0.5*{a+b)**2 -a**2-b**2} # considered for calculator shell
        a * b = expr { $a * $b } # TCL math.c call for check answer
        QS(N) = (1/4) * N**2 , or 0.25 * N**2, or int’ed [ int [ expr 0.25*$N**2]]
        HS(N) = (1/2) * N**2 , or 0.5   * N**2, or int’ed  [ int [ expr 0.5*$N**2 ]]
        approximate Babylonian quadrilateral formula expr <((a+c)/2) *((b+d)/2) > (not exact!!!)
        product of 50*40*30 using modern base_60 logarithms,        # used in thinking pod 
        the sum of logs is expr { 0.95546+0.90096+0.830706} , 2.687126.
        The antilog in base_60 is expr 60**2.687126= 59995.193.
        For the tables, the int function is used to clip remainders to integers.
        the precision function by [AM] is used occasionally, but not every time.
        note: mental and undocumented  components in the Babylonian multiplication methods.
        #  exponent/ logarithm expressions
        log (sqrt (m)) = (1/2)*log (m)
        log (crt (m)) = (1/3)*log (m)
        log (sqrt (m)) = (1/2)*log (m)
        (1/2)     = log (sqrt (m)) /  log (m) 
        (1/2)     = log (sqrt (m)) - (m)) 
        log (crt (m)) = (1/3)*log (m)
        (1/3) = log (crt (m)) / log (m)
        (1/3) = log (crt (m)) - (m))
        (1/2)     =  log (sqrt (m)) /  log (m) 
        (2/1)     =  log (m) / log (sqrt (m))
        2           = log  (m - (sqrt (m))
        (3/1)     =  log (m) / log (crt (m))
        3          =  log  (m - (crt (m))
        N              =  log  (m - (N’rt(m))
        N+1          =  log  (m - ((N+1)’rt(m))
        log2 defined as  ln N / ln 2 , 
        log2 N =~ 1.442695 * ln N
        log2 N =~ 3.321928 * log10 N
        From: Doctor Mitteldorf at MathForum & Uri Wilensky, MathForum
        a(n) = sqrt of the nth square triangle number
        then a(n) = ((3 + sqrt (8))^(n+1)  - (3 - sqrt (8))^(n+1))  / 2 * sqrt (8)
        should be integer, maybe?

Appendix Code


Trial Calculator Shell


        # calculator is sticking on TCLLIB setup, TN calculation under trials
        # calculator is sticking on TCLLIB setup, TN calculation under trials
        # pretty print from autoindent and ased editor
        # Triangular Number Multiplication calculator V3
        # written on Windows 10 on TCL
        # working under TCL version 8.6
        # gold on TCL Club, 15jul2020
        # proc adapted from TCLLIB formatting
        package require Tk
        package require math::numtheory
        package require math::constants
        package require math::trig
        package require math
        #package require math::combinatorics
        #namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory }
        namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::trig math::constants }
        set tcl_precision 17
        frame .frame -relief flat -bg aquamarine4
        pack .frame -side top -fill y -anchor center
        set names {{} {aa integer quantity N1:} }
        lappend names {bb integer quantity N2:}
        lappend names {cc integer quantity N3: }
        lappend names {dd integer quantity N4: }
        lappend names {optional usually 1. :}
        lappend names {answers: triangular number TN1  : }
        lappend names {multiplication N1*N2 from TCL mathlib: }
        lappend names {test slot >>  multiplication N1*N2 from triangular numbers :}
        foreach i {1 2 3 4 5 6 7 8} {
            label .frame.label$i -text [lindex $names $i] -anchor e
            entry .frame.entry$i -width 35 -textvariable side$i
            grid .frame.label$i .frame.entry$i -sticky ew -pady 2 -padx 1 }
        proc about {} {
            set msg "Calculator for Triangular Number Multiplication V3
            from TCL Club,
            written on TCL "
            tk_messageBox -title "About" -message $msg }
        proc self_help {} {
            set msg "Calculator for Triangular Number Multiplication V3
            from TCL ,
            # self help listing
            # 4 givens follow.
            1) aa integer N1
            2) bb integer N2
            3) cc integer N3
            4) dd integer N4
            # some formulas pub. Elie de Joncourt, 1762, Netherlands
            # triangular number TN = N*(N+1)/2
            # sum of consecutive TN numbers are squares
            #  TN <aa> +  TN <aa+1> = square
            # Joncourt used TN to calculate square roots and cube roots
            # Joncourt used mult.  aa * bb = <(aa+bb)**2 -aa**2 -bb**2>/2
            # term  <(aa+bb)**2 -aa**2 -bb**2> is twice answer
            # binomial theorem >> a*b = 0.5*{(a+b)**2 -a**2-b**2}.
            # James Glaisher pub. TN  formula from 1889
            # t. multiplication aa * bb = TN <aa-1> +  TN <bb> - TN <aa-bb-1>
            # James Glaisher discussed TN and Quarter Square variants
            # Quarter Square >> a*b = <(a + b)**2 − (a − b)**2> * .25
            # The TCL procedures use base_10 in calculator.
            # Decimal fraction entries <1. clipped
            # to zero for TN calculations
            # For comparison, TCL code may include redundant paths & formulas.
            # The TCL calculator normally uses modern
            # units  for convenience to modern users and textbooks.
            # Any convenient and consistent in/output units might be used
            # like inches, feet, nindas, cubits, or dollars to donuts.
            # Recommended procedure is push testcase and fill frame,
            # change first three entries etc, push solve,
            # and then push report. Report allows copy and paste
            # from console to conventional texteditor. For testcases
            # testcase number is internal to the calculator and
            # will not be printed until the report button is pushed
            # for the current result numbers.
            # This posting, screenshots, and TCL source code is
            # copyrighted under the TCL/TK 8.6 license terms.
            # Editorial rights retained under the TCL/TK license terms
            # and will be defended as necessary in court.
            Conventional text editor formulas or  grabbed from internet
            screens can be pasted into green console.
            Try copy and paste following into green screen console
            set answer \[* 1. 2. 3. 4. 5. \]
            returns  120
            # gold on  TCL Club, 10jul2020 "
            tk_messageBox -title "self_help" -message $msg }
        proc precisionx {precision float}  {
            #  tcl:wiki:Floating-point formatting, <AM>
            # select numbers only, not used on every number.
            set x [ expr {round( 10 ** $precision * $float) / (10.0 ** $precision)} ]
            #  rounded or clipped to nearest 5ird significant figure
            set x [ format "%#.5g" $x ]
            return $x
        }
        proc swapper {target1 target2} {
            # not used now
            # if negative difference <target1 - target2>, possible use swapper
            if { $target1 > $target2   } { return }
            set keeper $target1
            set target1 $target2
            set target2 $keeper
            return $target1 $target2
        }
        proc pyramid_d {hh bb} { return [ acotand [expr (.5*$bb/$hh)  ]]  }
        proc pyra_d {hh bb} { return [ acotand [* .5 [/ $bb $hh]  ]]  } 
        # pyramid_degrees 57.692 106.346  answer 47.334157521261254
        # adapted from tcl Stats 2011-05-22, arithmetic mean  <RLE>
        # ::math::triangular_number --
        #
        # Return the triangular_number for  one,two, or more numbers
        # defined as quantity per price
        #
        #
        # Arguments:
        #
        #    args  values are one, two, or more given numbers
        #
        # Results: triangular_number
        #  works for positive numbers, negative numbers,
        #  and mixed positive & negative numbers.
        #  arg of zero returns zero
        #  arg of null returns zero
        #  filter foreach drops irregular zero elements from argument
        proc ::math::triangular_number { args} {
            set sum 0.
            set N [ expr { [ llength $args ] } ]
            if { $N == 0 } { return 0 }
            #if { $N == 1 || [ lindex $args 0 ] == 0 } { return 0 }
            #if { $N == 1 || [ lindex $args 0 ] == 0 } { return 1 }
            set res {};set counter2 0;
            # filter foreach drops irregular zero elements
            foreach item $args {
                if {$item != 0 } {
                    incr counter2 1;
                    #set item [ expr { abs($item)} ]
                    lappend res $item } }
            set counter 0
            foreach val $res {
                #if { $val > 1. }  { lappend listerx [expr { $val*($val+1.)*.5}]}
                if { $val > .9999999 }  { lappend listerx [expr { $val*($val+1.)*.5}]}
                #if { $val < 1. && $val > -1. }  {lappend listerx "*" }
                if { $val < 1. && $val > -1. }  {lappend listerx 0 }
                if { $val < -1. }  {
                    set val [ expr { abs($val)} ]
                    lappend listerx [expr { -1.* $val*($val+1.)*.5}]}
                incr counter 1
            }
            set   triangular_number1  [ lindex $listerx 0 ]
            # return $triangular_number1
            return $listerx
        }
        # various testcases on  triangular_number
        # puts  [::math::triangular_number  1 2 3 4 ]
        #  answer     "
        # puts   [ ::math::triangular_number 1 2 3 4 ]
        #  answer
        # ::math::triangular_number 3 4 7 9
        # answer  , correct
        # operator math formula follows
        # check
        # returns   , correct
        # puts " [ ::math::triangular_number .1 ] "
        # :math::triangular_number 3 6 5 7
        # answer
        # operator math formula follows
        # set check
        # check equals
        # puts " for (::math::triangular_number 1)
        # returns 1 "
        # ::math::triangular_number  {}
        # null returns zero, correct.
        # ::math::triangular_number 0
        # arg 0 returns 0 zero, correct.
        # addition dated 24sep2018
        # added filter foreach to remove zero's
        # irregular zeros,
        # test on fractions 0.1 0.2 0.3 0.4
        # returns 0 0 0 0 , correct
        # test on fractions and zero   0.1 0.2 0.0 0.4
        # returns 0 0 0  , correct
        proc trinity {aa} {expr { $aa*($aa+1.)*.5}}
        proc trinity_product {aa bb} {[+ [trinity [- $aa 1.0] ] [trinity $bb] [* -1.0 [trinity [- $aa  $bb 1.0 ] ]]]}
        proc calculate {     } {
            global answer2
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            global testcase_number
            incr testcase_number
            set side1 [* $side1 1. ]
            set side2 [* $side2 1. ]
            set side3 [* $side3 1. ]
            set side4 [* $side4 1. ]
            set side5 [* $side5 1. ]
            set side6 [* $side6 1. ]
            set side7 [* $side7 1. ]
            set side8 [* $side8 1. ]
            set triangular_number1 1.
            set triangular_number2 1.
            set triangular_number_product 1.
            #set triangular_number_product [ ::math::triangular_number_conversion 5 ]
            set integer1 [ expr { int($side1)} ]
            set integer2 [ expr { int($side2)} ]
            set integer3 [ expr { int($side3)} ]
            set integer4 [ expr { int($side4)} ]
            set  triangular_number1 1
            set  triangular_number2 1
            set  triangular_number1 [ expr { $integer1 * ($integer1 + 1 )*.5  } ]
            set  triangular_number2 [ expr { $integer2 * ($integer2 + 1 )*.5  } ]
            set triangular_number_product 999999
            set side5   [::math::triangular_number $integer1  $integer2 $integer3 $integer4]
            set side6 $triangular_number1
            set side7 [* $side1 $side2 ]
            #set side8 [+ $triangular_number1 $triangular_number2]
            #set side8 [trinity_product $side1 $side2 ]
            #set side8 [+ [trinity $side1]  [trinity $side2] ]
            set side8 [+ [trinity [- $integer1 1.0] ] [trinity $integer2] [* -1.0 [trinity [- $integer1  $integer2 1.0 ] ]]]
            puts " $side5  [trinity [- $integer1 1.0] ] [trinity $integer2] [* -1.0 [trinity [- $integer1  $integer2 1.0 ] ]] $side8 "
            set boo8 [+ [trinity [- $side1 1.0] ] [trinity $side2] [* -1.0 [trinity [- $side1  $side2 1.0 ] ]]]
            puts " $boo8  $side1 $side2 [+ [trinity [- $side1 1.0] ] [trinity $side2] [* -1.0 [trinity [- $side1  $side2 1.0 ] ]]] "
        }
        proc fillup {aa bb cc dd ee ff gg hh} {
            .frame.entry1 insert 0 "$aa"
            .frame.entry2 insert 0 "$bb"
            .frame.entry3 insert 0 "$cc"
            .frame.entry4 insert 0 "$dd"
            .frame.entry5 insert 0 "$ee"
            .frame.entry6 insert 0 "$ff"
            .frame.entry7 insert 0 "$gg"
            .frame.entry8 insert 0 "$hh"
        }
        proc clearx {} {
            foreach i {1 2 3 4 5 6 7 8 } {
                .frame.entry$i delete 0 end } }
        proc reportx {} {
            global side1 side2 side3 side4 side5
            global side6 side7 side8
            global testcase_number
            console show;
            console eval {.console config -bg palegreen}
            console eval {.console config -font {fixed 20 bold}}
            console eval {wm geometry . 40x20}
            console eval {wm title . " Triangular Number Multiplication  V2 Report , screen grab and paste from console 2 to texteditor"}
            console eval {. configure -background orange -highlightcolor brown -relief raised -border 30}
            puts "%|table $testcase_number|printed in| tcl format|% "
            puts "&| quantity| value| comment, if any|& "
            puts "&| $testcase_number:|testcase_number | |&"
            puts "&| $side1 :|aa integer quantity N1: |   |&"
            puts "&| $side2 :|bb integer quantity N2: | |& "
            puts "&| $side3 :|cc integer quantity N3: | |& "
            puts "&| $side4 :|dd integer quantity N4: | |&"
            puts "&| $side5 :|optional:  | |&"
            puts "&| $side6 :|triangular number TN1 |  |&"
            puts "&| $side7 :|multiplication from TCL mathlib: |  |&"
            puts "&| $side8 :|test slot >> multiplication TN1*TN2  from triangular numbers : |  |&"
            puts "&| [::math::triangular_number  5 2 3 4 ] |test slot >>   TN1*TN2    : |  |&"
            puts "&| TN <1 2 3 4 > returns [::math::triangular_number 1 2 3 4 ] |test slot >>   TN1 TN2    : |  |&"
            puts "&| TN <1 2 0 4 > returns [::math::triangular_number 1 2 0 4 ] |test slot >>   TN1 TN2    : |  |&"
            puts "&| TN <1 2 0 0 > returns [::math::triangular_number 1 2 0 0 ] |test slot >>   TN1 TN2    : |  |&"
            puts "&| TN <1 2 -3 4 > returns [::math::triangular_number 1 2 -3 4 ] |test slot >>   TN1 TN2    : |  |&"
            puts "&| TN <10 20 30 40> returns [::math::triangular_number  10 20 30 40 ] |test slot >>   TN1 TN2    : |  |&"
            puts " pyramid [ pyra_d 57.692 106.346 ] " 
        }
        frame .buttons -bg aquamarine4
        ::ttk::button .calculator -text "Solve" -command {set side5 1.; calculate   }
        ::ttk::button .test2 -text "Testcase1" -command {clearx;fillup 1. 2.  3.0 4.  1.0  1. 2.0 2.0}
        ::ttk::button .test3 -text "Testcase2" -command {clearx;fillup 3.0 4.0 7.0 9.0  1.0  6.0 12. 12. }
        ::ttk::button .test4 -text "Testcase3" -command {clearx;fillup 3.0 6.  5.0 7.0  1.0  6.0 18.0 18. }
        ::ttk::button .clearallx -text clear -command {clearx }
        ::ttk::button .about -text about -command {about}
        ::ttk::button .self_help -text self_help -command {self_help }
        ::ttk::button .cons -text report -command { reportx }
        ::ttk::button .exit -text exit -command {exit}
        pack .calculator  -in .buttons -side top -padx 10 -pady 5
        pack  .clearallx .cons .self_help .about .exit .test4 .test3 .test2   -side bottom -in .buttons
        grid .frame .buttons -sticky ns -pady {0 10}
        . configure -background aquamarine4 -highlightcolor brown -relief raised -border 30
        wm title . "Triangular Number Multiplication Calculator V3"

appendix : TCL console Script on TN Tables


            # pretty print from autoindent and ased editor
            # Quarter Squares and Triangular Numbers Tables 
            # written on Windows XP on TCL
            # working under TCL version 8.6
            # gold on TCL, 10jul2020
            wm title . "  Quarter Squares Tables"
            namespace path {::tcl::mathop ::tcl::mathfunc}
            set tclprecision 17
            console show
            console eval {.console config -bg palegreen}
            console eval {.console config -font {fixed 20 bold}}
            console eval {wm geometry . 40x20}
            console eval {wm title . "  Quarter Squares Tables , cut and paste from console 2"}
            console eval {. configure -background orange -highlightcolor brown -relief raised -border 30}
            proc precisionx {precision float}  {
                #  tcl:wiki:Floating-point formatting, <AM>
                # select numbers only, not used on every number.
                set x [ expr {round( 10 ** $precision * $float) / (10.0 ** $precision)} ]
                #  rounded or clipped to nearest 5ird significant figure
                set x [ format "%#.5g" $x ]
                return $x
            }
            proc list_quarter_squares { aa bb} {
                for {set i $aa} {$i<=$bb} {incr i} {
                    puts " &| $i  |   [ precisionx 3 [ int  [* .25 $i $i]    ] ] | |& "; }
                return 1}
            proc list_half_squares { aa bb} {
                for {set i $aa} {$i<=$bb} {incr i } {
                    puts " &| $i  |   [ precisionx 3 [ int  [* .5 $i $i]    ] ] | |& ";
                    puts " &| [+ $i .5 ] | [ precisionx 3 [ int  [* .5 [+ $i .5] [+ $i .5] ]  ] ]  | |&  ";}
                return 1}
            proc list_binomial_theorem { aa bb} {
                for {set i $aa} {$i<=$bb} {incr i} {
                    set a $i
                    set b $i
                    puts " &| $i  |   [ precisionx 3 [expr { 0.5*(($a+$b)**2-$a**2-$b**2) } ] ] | |& "; }
                return 1}
            proc list_triangular_numbers { aa bb} {
                for {set i $aa} {$i<=$bb} {incr i} {
                    puts " &| $i  |   [ precisionx 3 [ int  [* .5 $i [+ $i 1]]    ] ] | |& "; }
                return 1}
            set testcase_number 1
            puts "%|Table $testcase_number:   Quarter Squares Tables |printed in| tcl  format|% "
            puts "%|N | int <N*N*.25> | comments if any|% "
            list_quarter_squares 0 18
            set testcase_number 2
            puts "%|Table $testcase_number:   Half Squares Tables |printed in| tcl  format|% "
            puts "%|N | int <N*N*.5> | comments if any|% "
            list_half_squares 0 20
            set testcase_number 3
            puts "%|Table $testcase_number: Binomial_Theorem Squares Tables |printed in| tcl  format|% "
            puts "%|a | a*a from subbing a*b = 0.5*(a+b)**2 -a**2-b**2) | comments if any |% "
            list_binomial_theorem 0 20
            set testcase_number 4
            puts "%|Table $testcase_number: Triangular Numbers Tables |printed in| tcl  format|% "
            puts "%|a |  subbing a*(a+1)*.5 number series  | comments if any |% "
            list_triangular_numbers 0 20
            # gold on TCL Club, 10jul;2020
            # This posting, prose, screenshots, and TCL source code is
            # copyrighted under the TCL/TK license terms.
            # Editorial rights and disclaimers retained
            # under the TCL/TK license terms
            # and will be defended as necessary in court.
            # end of file

appendix, Console script on Triangular Numbers List


    # written on Windows XP on TCL
    # working under TCL version 8.6
    # gold on TCL, 10jul2020
    wm title . "  Triangular Numbers TN List "
    console show
    console eval {.console config -bg palegreen}
    console eval {.console config -font {fixed 20 bold}}
    console eval {wm geometry . 40x20}
    console eval {wm title . "  Triangular Numbers TN List , cut and paste from console 2"}
    console eval {. configure -background orange -highlightcolor brown -relief raised -border 30}
    # Babylonian quasi_square2 is  n*(n+1),
    proc list_quasi_square2 { aa bb} { for {set i 1} {$i<=$bb} {incr i} {lappend boo [* 1. $i ] [*  $i  [+ $i 1]]};return $boo}
    # usage, list_quasi_square2 1 10
    # 1.0 2 2.0 6 3.0 12 4.0 20 5.0 30 6.0 42 7.0 56 8.0 72 9.0 90 10.0 110
    puts " [ list_quasi_square2 1 10 ] "
    # triangular_number_ref_quasi_square3 is  n*(n+1)/2,
    proc triangular_numbers_ref_quasi_square3 { aa bb} { for {set i 1} {$i<=$bb} {incr i} {lappend boo [* 1. $i ] [*  $i  [+ $i 1]  .5 ]};return $boo}
    # usage, list_quasi_square2 1 10
    # 1.0 2 2.0 6 3.0 12 4.0 20 5.0 30 6.0 42 7.0 56 8.0 72 9.0 90 10.0 110
    puts " [ triangular_numbers_ref_quasi_square3 1 10 ] "

Problem Solved

gold 8/4/2020. Statements below TCLLIB library on ActiveState 8.6.

            # pretty print from autoindent and ased editor
            # Triangular Square Numbers V2
            # console program
            # written on Windows 10 on TCL
            # working under TCL version 8.6
            # gold on TCL Club, 15jul2020
            package require Tk
            package require math::numtheory 
            package require math::constants
            package require math 
            namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::constants }
            # test includes invoke TCLLIB library
            set tcl_precision 17
            console show
            console eval {.console config -bg palegreen}
            console eval {.console config -font {fixed 20 bold}}
            console eval {wm geometry . 40x20}
            console eval {wm title . " Triangular Number Multiplication  V2 Report , screen grab and paste from console 2 to texteditor"}
            console eval {. configure -background orange -highlightcolor brown -relief raised -border 30} 
            proc precisionx {precision float}  {
            #  tcl:wiki:Floating-point formatting, <AM>
            # select numbers only, not used on every number.
            set x [ expr {round( 10 ** $precision * $float) / (10.0 ** $precision)} ]
            #  rounded or clipped to nearest 5ird significant figure
            set x [ format "%#.5g" $x ]
            return $x
            }
            proc ::math::sum_triangular_number2 { args} {
            set sum 0.
            set N [ expr { [ llength $args ] } ]
            if { $N == 0 } { return 0 }
            #if { $N == 1 || [ lindex $args 0 ] == 0 } { return 0 }
            set res {};set counter2 0;
            # filter foreach drops irregular zero elements
            foreach item $args {
                if {$item != 0 } {
                    incr counter2 1;
                    #set item [ expr { abs($item)} ]
                    lappend res $item } }
            set counter 0
            foreach val $res {               
                lappend listerx [expr { $val*($val+1.)*($val+2.)/6. }]
                incr counter 1
            }
            set   triangular_number1  [ lindex  $listerx 0 ]
            # return $term1
            return $listerx
            }
            proc sum_triangular_number {nn} { return [ expr { $nn*($nn+1.)*($nn+2.)/6. } ]}
            # sum_triangular_number series 1, 4,m
            puts " sum_triangular_number 1 = [ sum_triangular_number 1. ] "
            puts " sum_triangular_number 2 = [ sum_triangular_number 2. ] "
            puts " sum_triangular_number 3 = [ sum_triangular_number 3. ] "
            puts " expanded proc for sum_triangular_number 1 = [ precisionx 3 [  ::math::sum_triangular_number2 1. ] ]" 
            ::math::constants::constants radtodeg degtorad
            ::math::constants::constants onethird 
            ::math::constants::constants huge 
            puts "OneThird = $onethird huge = $huge"; 
            puts " math choose statements [::math::choose   10 2 ] [math::choose [+ 3 1 ]  2 ] [math::choose [+ 10 1 ]  2 ] " 
            # end of file    
output
 sum_triangular_number 1 = 1.0 
 sum_triangular_number 2 = 4.0 
 sum_triangular_number 3 = 10.0 
 expanded proc for sum_triangular_number 1 = 1.0000
 OneThird = 0.33333333333333331 huge = 1.7976931348623157e+308
 math choose statements 45 6 55 


gold10JUL2020. This page is copyrighted under the TCL/TK license terms, this license .


Hidden Comments Section

Please place any comments here with your wiki MONIKER and dates, Thanks,gold12JUL2020