doubly stochastic matrix study notes tute0069

index ; update 2017-07-12
WHY doubly stochastic matrix each row sum to one? begin, end
WHY doubly stochastic matrix each column sum to one? begin, end




<a name=index> WHY doubly stochastic matrix each row sum to one?
■ WHY doubly stochastic matrix each column sum to one?
■ sequence α ≺ sequence β 
■ α = DSM * β 
■ textbook page 195, 196 copied 
■ α1 ≦ β1 α12 ≦ β12
■ define ∆k What is ct
■ eqn.BX022 adding a zero 
■ begin study textbook page 197, line 2,3
■ arrive eqn.BX023 
■ equality eqn.BX023 has inequality in it 
■ textbook page 195, 196 problem solved 
■ function doublStochMat(aStr,bStr) document 
■ function jkCheck2() document 
■ function robinMatrixf() document 
■ UnicodeSymbol ≺ ≻ ≼ ≽ ≾ ≿ ⊀ ⊁

<a name="textbook">
This file is a note for reading inequality
book written by Professor J. Michael Steele
The Cauchy-Schwarz Master Class   ★★★★★
Below use 'textbook' as abbreviation.
Freeman also read web pages online, and will 
indicate the source URL at discussion point.
2017-06-30-14-00 copied above textbook source 
from http://freeman2.com/tute0046.htm


<a name="docA001">
2017-06-30-16-15
This page 
http://freeman2.com/tute0069.htm
is doubly stochastic matrix study notes 
related pages are 
http://freeman2.com/tute0046.htm
http://freeman2.com/tute0047.htm
http://freeman2.com/tute0048.htm
http://freeman2.com/dbstochm.htm
http://freeman2.com/jsmajor2.htm

Doubly stochastic matrix is a topic of 
mathematics inequality majorization. 
Hardy, Littlewood, Polya joint work solved 
majorization problem. 

<a name="docA002">
Majorization concern given property (wealth) 
distribution among given members. Assume a 
family has total treasure=30 and total five 
members. The division of treasure has many 
different methods. For example 
D1=[ 30,  0,  0,  0,  0 ] 
D2=[ 15, 15,  0,  0,  0 ]
D3=[ 10, 10, 10,  0,  0 ]
D4=[7.5,7.5,7.5,7.5,  0 ]
D5=[  6,  6,  6,  6,  6 ] 
'D' in 'D1' represent distribution. 
Most diverse distribution is D1
Most  even   distribution is D5

<a name="docA003">
To discuss distribution, usually take two 
distribution methods. 
More average distribution is called alpha α 
sequence. 
More diverse distribution is called beta β 
sequence. This page tute0069.htm use the 
following 
α seq. =[ 10, 7, 6, 5, 2 ] ---eqn.BX001
β seq. =[ 12,10, 5, 2, 1 ] ---eqn.BX002

<a name="docA004">
α sequence and β sequence have the following 
requirement.
α sequence must be in descending order 
β sequence must be in descending order 
α seq. member count = β seq. member count 
α seq. total treasure = β seq. total treasure 

If one sequence four member the other five, 
this is not a distribution problem. 
If one sequence total treasure =30, the 
other 40, this is not a distribution problem. 

<a name="docA005">
Example 
α seq. =[ 10, 7, 6, 5, 2 ] ---eqn.BX001
β seq. =[ 12,10, 5, 2, 1 ] ---eqn.BX002
satisfy above requirements.

α seq. and β seq. are equal in terms of total 
treasure. 

α seq. and β seq. are NOT equal in terms of 
distribution method. Mathematician use a symbol
'≺' and '≻' for this equal_in_total and 
UNequal_in_distribution situation. 

Mathematician say 
α sequence is majorized by β sequence 
α ≺ β  ---eqn.BX003
or β sequence majorize α sequence 
β ≻ α  ---eqn.BX004
http://freeman2.com/tute0046.htm#ch13a008

<a name="docA006">

Why many comparison? Review 
α seq. =[ 10, 7, 6, 5, 2 ] ---eqn.BX001
β seq. =[ 12,10, 5, 2, 1 ] ---eqn.BX002

One element comparison,
α1 < β1 ---eqn.BX005
that is 10 < 12

Two element comparison,
α12 < β12 ---eqn.BX006
that is 10+7 < 12+10

<a name="docA007">
Three element comparison,
α123 < β123 ---eqn.BX007
that is 10+7+6 < 12+10+5

Four element comparison,
α1234 < β1234 ---eqn.BX008
that is 10+7+6+5 < 12+10+5+2

Five element comparison,
α12345 = β12345 ---eqn.BX009
that is 10+7+6+5+2 = 12+10+5+2+1

Above equations are special case for numerical 
α sequence and β sequence. General expression 
is textbook page 191 equations above (13.1).

<a name="docA008">
Copy as next.α sequence majorized by β sequence 
α[1] ≦ β[1] ---eqn.BX010
α[1][2] ≦ β[1][2] ---eqn.BX011
.....
α[1][2][3]+...+α[n-1] ≦ β[1][2][3]+...+β[n-1] ---eqn.BX012
α[1][2][3]+...+α[n] = β[1][2][3]+...+β[n] ---eqn.BX013

Textbook use α1 as first element before sort. 
use α[1] as first (largest) element after sort. 

<a name="docA009">
The statement β sequence majorize α sequence 
is equivalent to eqn.BX010 to eqn.BX013 n equations.
First n-1 equations are αpartial ≦ βpartial
Last (n-th) equation is  αtotal = βtotal
Because family total treasure is a given number. 
Cannot change family total, cannot change member count.
2017-06-30-17-41

<a name="docA010">
2017-07-01-09-26
Above is α sequence (more average) and β sequence 
(more diverse) many inequality comparison. 
Next is α sequence and β sequence equality. 
α and β inequality change to α and β equality? 
Yes! α equal β exist by multiplying an averaging 
matrix, commonly known as doubly stochastic matrix.

<a name="docA011">
Goto 
http://freeman2.com/dbstochm.htm 
find next two lines
α seq. α more average α=dsm*β OK 0.688...
β seq. β more diverseβ=dsm*α NO  decimal
Click two buttons RUN 11 ☞ ,
Output may contain error. Please verify first. Liu,Hsinhan 劉鑫漢 a606131440
<a name="docA012">
from 
α sequence = [ 10, 7, 6, 5, 2 ] ---eqn.BX001
β sequence = [ 12,10, 5, 2, 1 ] ---eqn.BX002
get α = matrix * β next 
Doubly stochastic matrix table is created by http://freeman2.com/dbstochm.htm

doublStochMat() Date/Time: 2017-06-30-10-48-11.009, elapse=1.937 sec.
<a name="docA013"> In Output may contain error. Please verify first. click verify goto dbstochm.htm Box13 next click verify dbstochm.htm Box13 output next Verify matrix multiplication [[ a606122217 alfa[i0]=mat[i0][j0]*beta[j0] alfa[i0]= 10 ?=? 9.999999999999998 =mat[i0][j0]*beta[j0] alfa[i0]= 7 ?=? 6.999999999999999 =mat[i0][j0]*beta[j0] alfa[i0]= 6 ?=? 6 =mat[i0][j0]*beta[j0] alfa[i0]= 5 ?=? 5 =mat[i0][j0]*beta[j0] alfa[i0]= 2 ?=? 1.9999999999999995 =mat[i0][j0]*beta[j0] ]] <a name="docA014"> First row alfa[i0]= 10 ?=? 9.999999999999998 =mat[i0][j0]*beta[j0] numerical calculation is next alfa[i0]= 10 ?=? equal ? or not equal next (63/80)*12+(9/350)*10+(9/1400)*5+(9/112)*2+(1/10)*1 Goto Real number calculator http://freeman2.com/dec2frac.htm#bx81 paste next two lines to Box81 [[ aa=(63/80)*12+(9/350)*10+(9/1400)*5+(9/112)*2+(1/10)*1 aa ]] <a name="docA015"> Click "Box81 input Box82 output" Box82 output next [[ aa 9.999999999999998 ]] Number 9.999999999999998 is 10 which confirm First row alfa[i0]= 10 ?=? 9.999999999999998 =mat[i0][j0]*beta[j0] 2nd row to 5th row calculation are the same. <a name="docA016"> Only verify matrix multiplication that is not enough. Doubly stochastic matrix must have additional property, which we must verify. That is Doubly stochastic matrix each row sum to one. Doubly stochastic matrix each column sum to one. After click verify dbstochm.htm Box14 output next [[ doubly stochastic matrix row 1 sum=1 doubly stochastic matrix row 2 sum=0.9999999999999999 doubly stochastic matrix row 3 sum=1 doubly stochastic matrix row 4 sum=1 doubly stochastic matrix row 5 sum=1 doubly stochastic matrix column 1 sum=1 doubly stochastic matrix column 2 sum=1 doubly stochastic matrix column 3 sum=1 doubly stochastic matrix column 4 sum=1 doubly stochastic matrix column 5 sum=1 Above click verify calculation <a name="docA017"> Next list row element_by_element addition , and list column element_by_element addition allow user exam element entry and paste to Real number calculator to confirm. http://freeman2.com/dec2frac.htm#bx81 each line is one row sum. 63/80+9/350+9/1400+9/112+1/10 0/2+4/7+1/7+2/7+0/2 0/2+1/5+4/5+0/2+0/2 1/8+1/5+1/20+5/8+0/2 7/80+1/350+1/1400+1/112+9/10 each line is one column sum. 63/80+0/2+0/2+1/8+7/80 9/350+4/7+1/5+1/5+1/350 9/1400+1/7+4/5+1/20+1/1400 9/112+2/7+0/2+5/8+1/112 1/10+0/2+0/2+0/2+9/10 ]] <a name="docA018"> 2017-07-01-10-36 here Doubly stochastic matrix must have each row sum to one and must have each column sum to one. Why!? This question is very easy to explain. See next <a name="docA019"> First row
10 = 63/80* 12  + 9/350* 10  + 9/1400* 5  + 9/112* 2  + 1/10* 1 ---eqn.BX015
say that after averaging, α sequence first element 10 has 63/80 come from before averaging, β sequence first element 12 and has 9/350 come from before averaging, β sequence second element 10 and has 9/1400 come from before averaging, β sequence third element 5 and has 9/112 come from before averaging, β sequence fourth element 2 and has 1/10 come from before averaging, β sequence fifth element 1 <a name="docA020"> α sequence first element 10 all source considered, then
10 percentage source 63/80  + 9/350  + 9/1400  + 9/112  + 1/10 MUST sum to one.
Similar reason apply to Doubly stochastic matrix row 2, row 3, row 4 and row 5. This after averaging, α sequence all element HOW ITS PROPERTY COME FROM? consideration require matrix each row sum to one. <a name="docA021"> 2017-07-01-11-23 here Next see how to explain Doubly stochastic matrix each column elements sum to one. Above is expanded five equations. Compare above with Doubly stochastic matrix equation below. <a name="docA022"> 2017-07-01-11-48 to explain Doubly stochastic matrix each column elements sum to one, please see eqn.BX016 to eqn.BX020. Read only "*12" part. Which is before averaging, β sequence first element 12 HOW ITS PROPERTY RE-DISTRIBUTED? β sequence first element 12 has 63/80 goto after averaging, α sequence first element 10 and has 0 goto after averaging, α sequence second element 7 and has 0 goto after averaging, α sequence third element 6 and has 1/8 goto after averaging, α sequence fourth element 5 and has 7/80 goto after averaging, α sequence fifth element 2 <a name="docA023"> β sequence first element 12 all target considered. then view first column sum
12 percentage target 63/80  + 0  + 0  + 1/8  + 7/80 MUST sum to one.
Similar reason apply to Doubly stochastic matrix column 2, column 3, column 4 and column 5. This before averaging, β sequence all element HOW ITS PROPERTY RE-DISTRIBUTED? consideration require matrix each column sum to one. 2017-07-01-12-23 <a name="docA024"> 2017-07-01-15-47 Given More average distribution alpha α sequence. More diverse distribution beta β sequence. one example is α sequence = [ 10, 7, 6, 5, 2 ] ---eqn.BX001 β sequence = [ 12,10, 5, 2, 1 ] ---eqn.BX002 α seq. and β seq. have inequality relation α[1] ≦ β[1] ---eqn.BX010 α[1][2] ≦ β[1][2] ---eqn.BX011 ..... α[1][2][3]+...+α[n-1] ≦ β[1][2][3]+...+β[n-1] ---eqn.BX012 α[1][2][3]+...+α[n] = β[1][2][3]+...+β[n] ---eqn.BX013 <a name="docA025"> On the other hand α seq. and β seq. have equality relation Mark above equation as α = DSM * β DSM = Doubly Stochastic Matrix <a name="docA026"> Consider next question. If we have given equality α = DSM * β in hand. From given eqn.BX014, can we derive the inequality relation eqn.BX010 to eqn.BX013 ? textbook page 196 to page 197 solve this problem. Liu,HsinHan copy textbook related section first, then write Liu,HsinHan study notes. Let reader has easy reference, if Liu,HsinHan made any mistake. 2017-07-01-16-18 <a name="docA027"> 2017-07-01-16-25 Yellow back ground section copied from textbook page 196 to page 197

From the representation α=Dβ to the majorization α≺β Since the relations α∈H(β) and α≺β are unaffected by permutation of the coordinates of α and β , there is no loss of generality if we assume that α1≧α2≧...≧αn and β1≧β2≧...≧βn. If we then sum the representation (13.7)
 
αj
=
τ∈Sn
pτβτ(j) =
k=n
k=1
{
τ:τ(j)=k
pτ
}
βk =
k=n
k=1
djkβk
--- (13.7)
 
where for brevity, we have set
djk
=
τ:τ(j)=k
pτ
--- (13.8)
textbook page 195, equation (13.7) width of above equation 2017-07-01-17-12 <a name="docA028"> 2017-07-01-18-22 If we then sum the representation (13.7) over the initial segment 1≦j≦k , then we find the identity
 
j=k
j=1
αj
=
j=k
j=1
t=n
t=1
dβt =
t=n
t=1
ctβt
--- (13.11)
 
where define ct as ct
def
=
j=k
j=1
djt
--- (13.11)
textbook page 196, equation (13.11) width of above equation <a name="docA029"> Since ct is the sum of first k elements of t-th column of D, the fact D is Doubly Stochastic Matrix then gives us 0 ≦ ct ≦ 1 for all 1≦t≦n and c1+c2+...+cn=k ...(13.12) These constraints strongly suggest that the differences
 
k
def
=
j=k
j=1
αj
j=k
j=1
βj
=
t=n
t=1
ctβt
j=k
j=1
βj
---eqn.BX021
textbook page 196, line -3 width of above equation <a name="docA030"> 2017-07-01-19-13 These constraints strongly suggest that the differences are nonpositive for each 1≦k≦n, but an honest proof can be elusive. One must somehow exploit the identity (13.12) and a simple (yet clever) //textbook page 196 end way is to write //textbook page 197 start
 
k
=
j=n
j=1
cjβj
j=k
j=1
βj
βk
[
k -
j=n
j=1
cj
]
---eqn.BX022
 
k
=
j=k
j=1
k-βj)*(1-cj)
j=n
j=k+1
cj*(βj-βk)
---eqn.BX023
textbook page 197, line 2,3 width of above equation <a name="docA031"> It is now evident that ∆k≦0 since for all 1≦j≦k we have βj≧βk while for all k<j≦n we have βj≦βk . It is trivial that ∆n=0, so the relation ∆k≦0 for 1≦k<n complete our check of the definition. We therefore find that α≺β , and the solution of the second challenge problem is complete. 2017-07-01-19-59

Yellow back ground section copied from textbook page 196 to page 197 <a name="docA032"> 2017-07-02-13-41 Next study if given equality equation <a name="docA033"> How to get the inequality equation ? <a name="docA034"> Compare with matrix-expanded equation eqn.BX024 right hand side has β1 , β2 , β3 , β4 , β5 This sum of betas equal α1. We cannot compare α1 with β1 , but we can compare β1 with β1 to β5 a607021416 Textbook use β1 , β2 , β3 , β4 , β5 as before sort sequence, example β_seq=[5,10,1,12,2] Textbook use β[1] , β[2] , β[3] , β[4] , β[5] as after sort sequence, example β_seq=[12,10,5,2,1] tute0069.htm use β1 , β2 , β3 , β4 , β5 as after sort sequence. tute0069.htm insist sort before discuss. <a name="docA035"> Target α1 ≦ β1 ---eqn.BX010 become ?≦? β1 ---eqn.BX029 The symbol "?≦?" indicate our goal is to proof "≦" But before proof, "≦" is uncertain "?≦?" <a name="docA036"> It is hard to compare β1 with β1 , β2 , β3 , β4 , β5 . But we can compare β1 in terms of d111 +d121 +d131 +d141 +d151 with α1 in terms of d111 +d122 +d133 +d144 +d155 <a name="docA037"> equality in eqn.BX029 IS α1 in terms of β1, β2, β3, β4, β5. How to get β1 in terms of β1 , β2 , β3 , β4 , β5 ? It is easy, let β1 multiply by one, not change any. Observe eqn.BX024 and tute0069.htm#docA020 WHY doubly stochastic matrix each row sum to one? We know d11+d12+d13+d14+d15 = 1 ---eqn.BX030 In eqn.BX016 , eqn.BX030 has next numerical form 63/80 + 9/350 + 9/1400 + 9/112 + 1/10 = 1 Here d11=63/80, d12=9/350, d13=9/1400, d14=9/112 and d15=1/10 . <a name="docA038"> Let β1 multiply by one, this one is eqn.BX030. We convert from α1 ?≦? β1 ---eqn.BX010 to β1 in terms of d111 +d121 +d131 +d141 +d151 with α1 in terms of d111 +d122 +d133 +d144 +d155 That is ?≦? β1 = d111 +d121 +d131 +d141 +d151 ---eqn.BX031 <a name="docA039"> In eqn.BX031, inequality both side d111 cancel to zero. Compare d12 coefficient β2≦β1, this β2≦β1 is required before discussion. β sequence be sorted, such that in [β1, β2, β3, β4, β5] it has β1 ≧ β2 ≧ β3 ≧ β4 ≧ β5 relation. Next, how about dij? Doubly Stochastic Matrix entries are all non-negative. All matrix entries are positive or zero. In eqn.BX031, d111 both side cancel to zero d122 ≦ d121 d133 ≦ d131 d144 ≦ d141 d155 ≦ d151 In eqn.BX031, the inequality "?≦?" is true, In eqn.BX031, it is OK change "?≦?" to "≦". 2017-07-02-15-25 <a name="docA040"> 2017-07-02-19-08 Above is Below is <a name="docA041"> Inequality eqn.BX612 has alpha side sum and beta side sum. First step use given condition (equality equation) change alpha side to sum of beta. See next α12= <a name="docA042"> Because α12 expression has dij i=1,2 and j=1 to 5 //"?≦?" is value comparison, "?≺?" is array comparison. To show α12 ?≦? β12 Need express β1 and β2 in terms of d11,d12,d13,d14,d15 and d21,d22,d23,d24,d25 Such that it is possible to compare α12 ?≦? β12 <a name="docA043"> doubly stochastic matrix has a property that each row of doubly stochastic matrix sum to one. Then we have d11+d12+d13+d14+d15 = 1 ---eqn.BX033 and d21+d22+d23+d24+d25 = 1 ---eqn.BX034 Because β1 * 1 = β1 and β2 * 1 = β2 Change α12 ?≦? β12 to α12 ?≦? β1 * 1 +β2 * 1 Left side α12 use eqn.BX032 Right side use eqn.BX033 and eqn.BX034. Get next <a name="docA044"> ?≦? β1 * [d11+d12+d13+d14+d15] +β2 * [d21+d22+d23+d24+d25] <a name="docA045"> Long form equation is next α12 = d111+d122+d133+d144+d155 +d211+d222+d233+d244+d255 ?≦? β12 = // ---eqn.BX035 above 3 lines, below 3 lines d111+d121+d131+d141+d151 +d212+d222+d232+d242+d252 <a name="docA046"> In eqn.BX035 , red cancel red, blue cancel blue. After cancellation, get d122 +d133+d144+d155 +d211 +d233+d244+d255 ?≦? // ---eqn.BX036 above 3 lines, below 3 lines d121 +d131+d141+d151 +d212 +d232+d242+d252 Given β1 ≧ β2 ≧ β3 ≧ β4 ≧ β5 Blue on green ≦ Red on green is for sure. But d122+d211 ?≦? d121+d212 is uncertain. 2017-07-02-20-18 here <a name="docA047"> 2017-07-03-06-48 Above eqn.BX036 cannot give us a decisive conclusion which side is greater. Next turn to textbook page 196, line -3 , eqn.BX021
 
k
def
=
j=k
j=1
αj
j=k
j=1
βj
=
t=n
t=1
ctβt
j=k
j=1
βj
---eqn.BX021
textbook page 196, line -3
width of above equation
<a name="docA048">
Compare eqn.BX021 with eqn.BX032
eqn.BX021 "∑[j=1,k]{αj}" part is eqn.BX032, k=2,n=5. 
eqn.BX021 "- ∑[j=1,k]{βj}" part will be added later. 
n=5, because α = [ 10, 7, 6, 5, 2 ] and 
     β = [ 12,10, 5, 2, 1 ] both have 5 elements.
k=2, because in α12 ≦ β12 ---eqn.BX612
     we discuss two elements α12 and β12 
j=1,2 in eqn.BX021, sum α1 with α2 , β1 with β2 

Re-write eqn.BX035 in eqn.BX021 form. Define ∆2 as 
∆2 = [α12] - [β12] ---eqn.BX037 
Our goal is  α12 ≦ β12 ---eqn.BX612 
Then we wish show that 
∆2 <= 0.  ---eqn.BX038 
<a name="docA049">
Textbook say 
a simple (yet clever) way is to 
write eqn.BX021 as eqn.BX022
Observe that eqn.BX021 + zero = eqn.BX022
2017-07-03-07-44
What is ct? See (13.11) Review 

c1=d11+d21 ---eqn.BX039 (cut off at k=2)
c2=d12+d22 ---eqn.BX040 (cut off at k=2)
c3=d13+d23 ---eqn.BX041 (cut off at k=2)
c4=d14+d24 ---eqn.BX042 (cut off at k=2)
c5=d15+d25 ---eqn.BX043 (cut off at k=2)
<a name="docA050">
then 

become 
α12 = ---eqn.BX044
 (d11+d21)*β1+(d12+d22)*β2+(d13+d23)*β3+(d14+d24)*β4+(d15+d25)*β5
Further simplify to 
α12 = ---eqn.BX045
 c11+c22+c33+c44+c55
<a name="docA051">
Compare with numerical example 

When k=2, consider eqn.BX016 and eqn.BX017 only 
eqn.BX045 become 
 10 + 7 = ---eqn.BX046
  (63/80 + 0)*12 +(9/350 + 4/7)*10 + (9/1400 + 1/7)*5
 +(9/112 + 2/7)*2 +(1/10 + 0)*1 

verify // http://freeman2.com/prime_e4.htm#bx81
aa=(63/80 + 0)*12 +(9/350 + 4/7)*10 + (9/1400 + 1/7)*5 +(9/112 + 2/7)*2 +(1/10 + 0)*1 
Box 82 output 
aa
17
<a name="docA052">
What is ct? 
In eqn.BX024 and eqn.BX025 two rows, k=2, 
ct for t=1 to 5 is equation eqn.BX039 to eqn.BX043.
 
Now go back to eqn.BX022
2017-07-03-08-13

<a name="docA053">
2017-07-03-10-46
Red term in eqn.BX022 is zero. 
 
k
=
j=n
j=1
cjβj
j=k
j=1
βj
βk
[
k -
j=n
j=1
cj
]
---eqn.BX022
 
k
=
j=k
j=1
k-βj)*(1-cj)
j=n
j=k+1
cj*(βj-βk)
---eqn.BX023
textbook page 197, line 2,3
width of above equation
<a name="docA054">
eqn.BX022 come from eqn.BX021 plus a zero. 
Red term in eqn.BX022 is zero. Why it is zero? 
See eqn.BX032. In eqn.BX032 
d11+d12+d13+d14+d15=1 //D.S. matrix row 1 sum to 1 
d21+d22+d23+d24+d25=1 //D.S. matrix row 2 sum to 1 
Red term in eqn.BX022 c1=d11+d21 ---eqn.BX047
c2=d12+d22,  c3=d13+d23,  c4=d14+d24,  c5=d15+d25, 
Red term ∑[j=1,5]cj=c1+c2+c3+c4+c5 = 2 = k then 
[k - ∑(j=1,5)cj] = 0  ---eqn.BX048
2017-07-03-11-10

<a name="docA055">
2017-07-03-14-08
Consider eqn.BX022 in the case n=5, k=2 
n=5 is 5x5 square matrix, k=2 is row 1 & 2.
∆2= 
  d111+d122+d133+d144+d155
 +d211+d222+d233+d244+d25512 //+ zero below 
 +β2*[2-(d11+d21+d12+d22+d13+d23+d14+d24+d15+d25) ] ---eqn.BX049

∆2= 
  c11+c22+c33+c44+c5512 //+ zero below 
 +β2*[2-(c1+c2+c3+c4+c5) ] ---eqn.BX050

<a name="docA056">2= 
  c11+c22
+c33+c44+c55122*[2-(c1+c2)] ---eqn.BX051 
2*[▬c3▬c4▬c5 ] //a607040736 change '+' to '▬' 2= 
 c11+c22122*[2-(c1+c2)]
+c33+c44+c55
▬c32▬c42▬c52 ---eqn.BX052

<a name="docA057">2= 
 c111
+c2222*[1-c1  +1-c2]
+c33+c44+c55
▬c32▬c42▬c52 ---eqn.BX053

∆2= 
 -β1*(1-c1)
2*(1-c2)2*(1-c1)
2*(1-c2)
+c33+c44+c55
▬c32▬c42▬c52 ---eqn.BX054

<a name="docA058">2= 
 (β21)*(1-c1)
+(β22)*(1-c2)
+c33+c44+c55
▬c32▬c42▬c52 ---eqn.BX055

∆2= 
 ∑[j=1,2](β2j)*(1-cj)
+∑[j=3,5]cj*(βj2) ---eqn.BX056 (eqn.BX023)

In eqn.BX056, sub_2 has the role of sub_k
sub_3 has the role of sub_(k+1); and 5=n.

2017-07-03-15-00

<a name="docA059">
2017-07-03-16-12
eqn.BX022 and eqn.BX023 are general equation. 
To understand these equations, start from eqn.BX049 
use special case n=5, k=2 to observe how eqn.BX022 
change to eqn.BX023 . 
The following start from eqn.BX022 end at eqn.BX023 ,
fill in all detail steps. 

Red term in eqn.BX022 is zero. 
 
k
=
j=n
j=1
cjβj
j=k
j=1
βj
βk
[
k -
j=n
j=1
cj
]
---eqn.BX022
 
k
=
j=k
j=1
k-βj)*(1-cj)
j=n
j=k+1
cj*(βj-βk)
---eqn.BX023
textbook page 197, line 2,3
width of above equation
<a name="docA060">
From eqn.BX050 to eqn.BX051 special case observation 
build general equation from eqn.BX057 to eqn.BX063

eqn.BX057 split ∑[j=1,n] to ∑[j=1,k]  ∑[j=k+1,n] 
Red term in eqn.BX057 is zero. 
eqn.BX058 identify two blue ∑[j=k+1,n] terms. 
 
k
=
j=k
j=1
cjβj
j=n
j=k+1
cjβj
j=k
j=1
βj
βk
[
k -
j=k
j=1
cj
j=n
j=k+1
cj
]
---eqn.BX057
 
k
=
j=k
j=1
cjβj
j=n
j=k+1
cjβj
j=k
j=1
βj
βk *
[
k -
j=k
j=1
cj
]
βk *
j=n
j=k+1
cj
---eqn.BX058
width of above equation
<a name="docA061">
eqn.BX059 put ∑[j=1,k] as a group and put ∑[j=k+1,n] 
as another group .
eqn.BX060 merge ∑[j=1,k]βj terms and merge blue 
∑[j=k+1,n] terms. 
 
k
=
j=k
j=1
βj
j=k
j=1
[cjβj]
βk *
[
k -
j=k
j=1
cj
]
j=n
j=k+1
cjβj
j=n
j=k+1
cjβk
---eqn.BX059
 
k
=
[
j=k
j=1
βj
j=k
j=1
cjβj
]
βk *
[
k -
j=k
j=1
cj
]
j=n
j=k+1
cj*(βj - βk)
---eqn.BX060
width of above equation
<a name="docA062">
eqn.BX061 and eqn.BX062 adjust ∑[j=1,k] terms to 
a similar manner, allow merge ∑[j=1,k] terms later.
 
k
=
[
j=k
j=1
βj
j=k
j=1
cjβj
]
βk *
[
j=k
j=1
1
j=k
j=1
cj
]
j=n
j=k+1
cj*(βj - βk)
---eqn.BX061
 
k
=
[
j=k
j=1
βj*(1▬ cj)
]
βk *
[
j=k
j=1
(1▬cj)
]
j=n
j=k+1
cj*(βj - βk)
---eqn.BX062
width of above equation
<a name="docA063">
eqn.BX063 write ∑[j=1,k] terms to one unified term.
eqn.BX063 is identical with eqn.BX023 
eqn.BX023 is textbook page 197, line 2,3 equation.
 
k
=
j=k
j=1
[
k - βj)
*
(1-cj)
]
j=n
j=k+1
cj*(βj - βk)
---eqn.BX063
 
k
=
j=k
j=1
k-βj)*(1-cj)
j=n
j=k+1
cj*(βj-βk)
---eqn.BX023
width of above equation
2017-07-03-18-06 done eqn.BX057 to eqn.BX063 
Up to here, eqn.BX023 is equality. 
Inequality show up at docA066

<a name="docA064">k is defined at eqn.BX021k is shown in eqn.BX011k numerical example see 
1 is 10-12 < 0
∆2 is 10+7-(12+10) < 0
∆3 is 10+7+6-(12+10+5) < 0
∆4 is 10+7+6+5-(12+10+5+2) < 0
∆5 is 10+7+6+5+2-(12+10+5+2+1)=0

<a name="docA065">
Above numerical example β seq.=[12,10, 5, 2, 1 ]
In this case n=5. n is a constant. 
If we discuss "∆2 is 10+7-(12+10) < 0 "
then k=2 , k is a constant if we fix k in ∆k 
j is a variable, 1≦j≦k 
β sequence must be in descending order. Under 
this requirement, we have 
β1≧ ... ≧βj ≧ ... ≧βk≧- ... ≧βn-1≧βn ---eqn.BX064

<a name="docA066">
Now, eqn.BX023 (same as eqn.BX063) must be ≦0 
In j=1 to j=k range, βj ≧ ... ≧βk
then (βkj) ≦0 
In j=k+1 to j=n range, βj ≦ ... ≦βk
then (βjk) ≦0 
In eqn.BX023 (same as eqn.BX063) cj≧0 and cj≦1
(1-cj)≧0 
In eqn.BX023, ∆k≦0 is confirmed.

<a name="docA067">
If k=n, special case. 
In eqn.BX023 ∑(j=n+1,n) does not exist. 
In eqn.BX023 ∑(j=1,k) become ∑(j=1,n) all c1=1
(1-c1)=0 then ∆k=∆n=0 
satisfy eqn.BX013.
Now textbook  page 195, 196 problem solved. 

problem was 
From given doubly stochastic matrix eqn.BX014, 
ask derive the inequality eqn.BX010 to eqn.BX013.
2017-07-03-19-12

2017-07-04-06-27 start proofread 
2017-07-04-07-53 done  proofread 



<a name="docA068"> 2017-07-05-17-18 Following is document for doubly stochastic matrix calculator http://freeman2.com/dbstochm.htm main function function doublStochMat( //a606120748 aStr //define alpha sequence, more average , bStr //define beta sequence, more diverse ) { code ... } Document use input α seqqence = [ 10, 7, 6, 5, 2 ] α more average β seqqence = [ 12,10, 5, 2, 1 ] β more diverse and follow code flow see how input change variable value and how to build doubly stochastic matrix. α β inequality α≺β ; α β equality α = DSM*β <a name="docA069"> function doublStochMat(aStr,bStr) where aStr=' 10, 7, 6, 5, 2 ' bStr=' 12,10, 5, 2, 1 ' Here both aStr and bStr are strings. Program need array of numbers. Later in function, code will change string to array. At the end of function doublStochMat() return stochMat; stochMat is array of numbers for doubly stochastic matrix. White on blue part is doubly stochastic matrix <a name="docA070"> Next yellow background part is program code.

var stochMat; //a606121723 global var alfa; //α sequence more average var beta; //β sequence more diverse //why beta change to alfa? //a606121956 var betaBgn; //a606121957 //doubly stochastic matrix function doublStochMat( //a606120748 aStr //define alpha sequence, more average , bStr //define beta sequence, more diverse ) { //9906172025 start stochastic0() //a606120748 start doublStochMat()

<a name="docA071"> var stochMat is answer, doubly stochastic matrix var alfa; is input α sequence more average var beta; is input β sequence more diverse var betaBgn; is input β Above variable declaration are above (outside of) function doublStochMat(), variables are global, visible by other function code. Debug code, echo print the input values. Ⅱ dbstochn.htm [a606280906dbg] ; enter aStr=[ 10, 7, 6, 5, 2 ] enter bStr=[ 12,10, 5, 2, 1 ] They are as expected. <a name="docA072">

var i0,j0,k0,L0,m0,n0; var dim0=0; //doubly stochastic matrix dimension var tol0=1.0e-8; //a606121649 if(typeof(aStr)=='string' //a607051942 if() &&typeof(bStr)=='string') { m0=0; n0=aStr.length; while(m0<n0&&aStr.charCodeAt(m0)<=32)m0++; //a606120909 (n0-1) while(m0<n0&&aStr.charCodeAt(n0-1)<=32)n0--; aStr=aStr.substring(m0,n0) //a606120911 m0=0; n0=bStr.length; while(m0<n0&&bStr.charCodeAt(m0)<=32)m0++; while(m0<n0&&bStr.charCodeAt(n0-1)<=32)n0--; bStr=bStr.substring(m0,n0) //a606120912

<a name="docA073"> If function input arguments are two strings, enter this if() { body } change string to array. aStr is alpha string, more average. aStr=' 10, 7, 6, 5, 2 ' Program allow input use comma as separator and input use blank as separator. If input string has ',' then use comma. Otherwise, change ' ' to comma. Example aStr=' 10, 7, 6, 5, 2 ' Above code delete leading ' ' and delete end ' '. After aStr=aStr.substring(m0,n0) aStr change to aStr='10, 7, 6, 5, 2' This delete leading ' ' and delete end ' ' code carry out for any input aStr and for any input bStr. <a name="docA074">

if(aStr.indexOf(',')<0) { if(aStr.indexOf(' ')<0) return 'doublStochMat() error 01. //a606120810\n' +'Alpha sequence=['+aStr+']\n' +'Code use comma or space to separate data.\n' +'Alpha sequence do not have either one.\n' while(aStr.indexOf(' ')>0) aStr=aStr.replace(/ /g,' '); aStr=aStr.replace(/ /g,','); } //if(aStr.indexOf(',')<0) if(bStr.indexOf(',')<0) { if(bStr.indexOf(' ')<0) return 'doublStochMat() error 02. //a606120812\n' +'Beta sequence=['+bStr+']\n' +'Code use comma or space to separate data.\n' +'Beta sequence do not have either one.\n' while(bStr.indexOf(' ')>0) bStr=bStr.replace(/ /g,' '); bStr=bStr.replace(/ /g,','); } //if(bStr.indexOf(',')<0)

<a name="docA075"> If user input α seq.=' 10 7 6 5 2 ' Come to this point α='10 7 6 5 2' no ',' in α seq. next if() active if(aStr.indexOf(',')<0) //aStr.indexOf(',')=-1<0 If user input α seq.='10;7;6;5;2' This string no ',' and no ' ' . if(aStr.indexOf(' ')<0) is active , program ends, return message error 01 Otherwise, user input α='10 7 6 5 2', change all double space to single space. while(aStr.indexOf(' ')>0) aStr=aStr.replace(/ /g,' '); After exit while() loop, change all ' ' to ',' aStr=aStr.replace(/ /g,','); Above line "g" mean general = all Similar treatment for β sequence. 2017-07-05-18-45 <a name="docA076">

alfa=aStr.split(','); beta=bStr.split(','); if(alfa.length!=beta.length) return 'doublStochMat() error 03. //a606120815\n' +'Alpha sequence length='+alfa.length+'\n' +'Beta sequence length='+beta.length+'\n' +'Two length are not equal.\n' +'Alpha sequence=['+aStr+']\n' +'Beta sequence=['+bStr+'] \n' } //if(typeof(aStr)=='string'&&typeof(bStr)=='string') else if(typeof(aStr)=='object' //a607051946 if() &&typeof(bStr)=='object') { alfa=aStr; beta=bStr; } else return 'doublStochMat(arg1,arg2) error 08. //a607051948 \n' +'arguments arg1,arg2 are not string and not array.\n'

<a name="docA077"> 2017-07-05-21-04 After replace ' ' to ',' all input string use comma as separator. Command alfa=aStr.split(','); change string '10, 7, 6, 5, 2' to array of string alfa=['10',' 7',' 6',' 5',' 2'] square bracket [ ] indicate array. alfa has five strings '10' and ' 7' and ' 6' and ' 5' and ' 2' they are not real numbers, they are string numbers. α≺β require α member count = β member count. Code line if(alfa.length!=beta.length) exam member count. If member count not equal, stop program. function doublStochMat( ) input argumrnts can be string and can be arrays. String come from input box textarea. Array of numbers come from other function call. If input argumrnts are arrays, change input name aStr to alfa, change input name bStr to beta. Because later use alfa and beta. If function doublStochMat( ) input argumrnts are two numbers, they are not string and not array, return as error 08. dbstochm.htm Box11 has error-on-purpose example. has array input example. Echo print code present string values are Ⅱ aStr=[10, 7, 6, 5, 2] , bStr=[12,10, 5, 2, 1] <a name="docA078">

for(i0=0;i0<alfa.length;i0++) { //a606122040 parseFloat() alfa[i0]=parseFloat(alfa[i0]) if(isNaN(alfa[i0])) return 'doublStochMat() error 04. //a606120817 \n' +'Alpha sequence=['+aStr+'] contain none-number.\n' //a606122041 parseFloat() beta[i0]=parseFloat(beta[i0]) if(isNaN(beta[i0])) return 'doublStochMat() error 05. //a606120819 \n' +'Beta sequence=['+bStr+'] contain none-number.\n' } //for(i0=0;i0<alfa.length;i0++)

If user input α seq.=[ ten, 7, 6, 5, 2 ] Code return error 04. If user input β seq.=[ 12,10, 5, 2, one ] Code return error 05. <a name="docA079">

betaBgn=[]; //a606121959 for(i0=0;i0<beta.length;i0++) betaBgn[i0]=beta[i0]; //a606122000

When code progress, beta sequence change value. Liu,HsinHan need input beta value, assign betaBgn=beta before change value. Echo print get Ⅱ betaBgn=beta=[12,10,5,2,1] <a name="docA080">

var asum=bsum=0; //a606120924 for(i0=0;i0<alfa.length;i0++)asum+=alfa[i0]; for(i0=0;i0<beta.length;i0++)bsum+=beta[i0]; if((asum-bsum)>1.0e-10||(asum-bsum)<-1.0e-10) return 'doublStochMat() error 06. //a606120925 \n' +'Alpha sequence=['+aStr+'] sum to '+asum+'.\n' +' Beta sequence=['+bStr+'] sum to '+bsum+'.\n' +'Two sum are different. (|asum-bsum|>1.0e-10)\n'

α≺β require α total sum = β total sum, see eqn.BX013 Code line if((asum-bsum)>1.0e-10||(asum-bsum)<-1.0e-10) exam eqn.BX013 requirement. If total sum not equal, stop program. <a name="docA081">

var asum=bsum=0; //a606121159 for(i0=0;i0<alfa.length;i0++) { asum+=alfa[i0]; bsum+=beta[i0]; //if(asum>bsum) //a606162054 if((asum-bsum)>1.0e-10) return 'doublStochMat() error 07. //a606121200 \n' +'Please arrange α seq. and β seq. in descending order. \n' +'Alpha sequence=['+aStr+'] first '+(i0+1)+' sum to '+asum+'.\n' +' Beta sequence=['+bStr+'] first '+(i0+1)+' sum to '+bsum+'.\n' +'Alpha partial sum > Beta partial sum , this is an error.\n' +'Assume family total wealth=10, total menber=5.\n' +'Wealth distribution α=[2,2,2,2,2] is perfect equal. If \n' +'Wealth distribution β=[4,3,1.5,1,0.5] this is inequality.\n' +'Relate by α=[doubly stochastic matrix]*β ; Partial sums are \n' +'α1=2<4=β1; α2=2+2<4+3=β2; ... α5=2+2+2+2+2=4+3+1.5+1+0.5=β5;\n' +'Alpha partial sum always <= Beta partial sum. a606121213' } //for(i0=0;i0<alfa.length;i0++)

α≺β require α partial sum ≦ β partial sum, see eqn.BX010 to eqn.BX012 Code line if((asum-bsum)>1.0e-10) exam eqn.BX010 requirement. If α partial sum not ≦ β partial sum stop program. Above exam input α sequence and β sequence. After this point, α sequence and β sequence are acceptable data. 2017-07-05-21-58 dbstochm.htm has α⊀β , α⊁β example. //a607111833 <a name="docA082"> 2017-07-06-10-30

var tota=alfa.length; var totb=beta.length; n0=alfa.length; //a606121541 var id=new Array(n0); for(i0=0;i0<n0;i0++) id[i0]=new Array(n0); for(i0=0;i0<n0;i0++) for(j0=0;j0<n0;j0++) { id[i0][j0]=0; if(i0==j0)id[i0][j0]=1; }

Ⅱ a606280912 before majstatus=majCheck(alfa,beta,tol0) alfa=[10,7,6,5,2]; beta=[12,10,5,2,1]; tol0=[1e-8] id[]= 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 id[] is identity matrix dimension 5*5 2017-07-06-10-50 <a name="docA083"> 2017-07-06-15-20

stochMat=id; //a606121713 //var stochMat; //a606121723 global var jkstatus; var maxIt=100; //a606121618 var iter0=0;

Above code line prepare initial data for next while() loop which is the heart of function doublStochMat(). Matrix stochMat is the final answer see return stochMat; stochMat start as an identity matrix. Code set maxIt=100 to limit while() loop iteration. 2017-07-06-15-30 <a name="docA084">

while(iter0<maxIt) { iter0++; //a606121632 jkCheck2() jkstatus=jkCheck2(alfa,beta);

2017-07-06-15-41 read function jkCheck2() jkCheck2(alfa,beta) document <a name="docA085"> 2017-07-06 write next notes Pay attention to index selection (red numbers) Start from center to outer OK, the other way error. Ⅱ iter0=1 jkstatus=[1,2,5] say switch 1th(10) and 2th(5) in beta 5 in [1,2,5] say alfa and beta has 5 miss-match elements jkstatus=jkCheck2(alfa,beta)=jkstatus=[1,2,5] alfa=[10, 7,6,5,2] beta=[12,10,5,2,1] index 0, 1,2,3,4 //switch result see next iteration beta Ⅱ iter0=2 jkstatus=jkCheck2(alfa,beta)=jkstatus=[1,3,4] alfa=[10,7,6,5,2] beta=[12,9,6,2,1] //12,9,2,1 four element different from alfa index 0,1,2,3,4 Ⅱ iter0=3 jkstatus=jkCheck2(alfa,beta)=jkstatus=[0,3,3] alfa=[10,7,6,5,2] beta=[12,7,6,4,1] //12,4,1 three element different from alfa index 0,1,2,3,4 Ⅱ iter0=4 jkstatus=jkCheck2(alfa,beta)=jkstatus=[0,4,2] alfa=[10,7,6,5,2] beta=[11,7,6,5,1] //11,1 two element different from alfa index 0,1,2,3,4 Ⅱ iter0=5 jkstatus=jkCheck2(alfa,beta)=jkstatus=[-1,-1,0] alfa=[10,7,6,5,2] beta=[10,7,6,5,2] 2017-07-06 write above notes <a name="docA086"> 2017-07-09-18-27

j=jkstatus[0]; //9906201228 k=jkstatus[1]; if(j==-1)break; //9906201736 job is done if(j==k) { //a606121636 return "Smooth two elements have SAME index. Error."; }

<a name="docA087"> Call jkstatus=jkCheck2(alfa,beta); jkCheck2() return an array of three integers Example if input alfa=[10,7,6,5,2] beta=[12,9,6,2,1] //12,9,2,1 four element different from alfa index 0,1,2,3,4 jkstatus=jkCheck2(alfa,beta)=jkstatus=[1,3,4] 1,3 suggest Robinhood next time grab beta[1] and give to beta[3] . Goal is approach alfa sequence. Then Robinhood take 2 from beta[1]=9 (new beta[1]=7) give to beta[3]=2 (new beta[3]=4) After this switch, beta[1]=7=alfa[1] they are equal, achieve avgrage goal. beta[3]=4 ≠ 5=alfa[3] wait for future work. j=jkstatus[0]; k=jkstatus[1]; save 1 to j , save 3 to k let next code robinMatrixf(tota,j,k,bj,bk,alfa[j],alfa[k]); use. If j=-1, work is done, stop. If j=k, send error message. <a name="docA088">

if(Math.abs(beta[j]-beta[k])<=tol0) { /** a607091854 del i2=i3=0 for(i0=j;i0<=k;i0++) { i2+=alfa[i0]; i3+=beta[i0]; } /**/ //a606121637 return "code ERR beta[j]==beta[k] j,k,beta[j]="+j+","+k+","+beta[j] } //if(Math.abs(beta[j]-beta[k])<=tol0) //var aj,ak,bj,bk; if((typeof beta[j])=='number') {bj=beta[j]; bk=beta[k]; } else //9906230831 if((typeof beta[j])=='object') {bj=beta[j][0]; bk=beta[k][0]; }

<a name="docA089"> 2017-07-09-19-00 Liu,Hsinhan code is not very efficient. Early code need i2+=alfa[i0]; and i3+=beta[i0]; Later code not need, but still keep redundunt code. beta[j] and beta[k] are more diverse members, if they are equal, they are already even, cannot do anything. One input has such trouble Example button [52] has α seq. = [ 5 3 2 1 1 ] β seq. = [ 6 2 2 2 0 ] index 0 1 2 3 4 wrong choice! If function jkCheck2(alfa,beta) choose index 1, 3 Robinhood refuse change from β[1]=2, β[3]=2, to α[1]=3, α[3]=1. This example correct choice is index 0, 1. After correct choice, code line if(Math.abs(beta[j]-beta[k])<=tol0) never active. code line bj=beta[j]; bk=beta[k]; prepare robinMatrixf(tota,j,k,bj,bk,alfa[j],alfa[k]); needed data. 2017-07-09-19-19 <a name="docA090"> 2017-07-10-09-16 arg1=α seq. more average arg2=β seq. more diverse Assume input next α2, β2 α2 sequence=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] β2 sequence=[3.5, 3,2.8,2.5,1.5,1.2, 1,0.5] index 0 1 2 3 4 5 6 7 Ⅱg before RobinHood=robinMatrixf(tota,j,k,bj,bk,alfa[j],alfa[k]) Ⅱh tota=8; j,k=2,5; bj,bk=2.8,1.2; alfa[j],alfa[k]=2.5,1.5 beta=[3.5,3,2.8,2.5,1.5,1.2,1,0.5] tota=8 say build a 8*8 averaging matrix j,k=2,5 say in α2, β2 switch only index=2 (blue) and index=5 (red) two members. bj,bk=2.8,1.2; say β[j=2]=2.8, β[j=5]=1.2 these two number will be changed. alfa[j],alfa[k]=2.5,1.5 say after averaging, the goal is β[j=2]=2.8 become α[j=2]=2.5 and β[j=5]=1.2 become α[j=5]=1.5 2017-07-10-09-30 <a name="docA091"> 2017-07-10-16-30

RobinHood=robinMatrixf(tota,j,k ,bj,bk,alfa[j],alfa[k]); if((typeof beta)=='object') //9906192027 j3=readdata(beta); else { //a606121638 return "(typeof beta)!=object) Error." } j4=''; for(i=0;i<j3.length;i++) { // j4 is used below at 9906172256 // if rename j4 must do completely. // 9906191640 record j4+=j3[i]+'\n'; }

<a name="docA092"> function robinMatrixf() has document below. Debug print has next value. Ⅱj before j3=readdata(beta)=beta=[3.5,3,2.8,2.5,1.5,1.2,1,0.5] Ⅱk after, j3=readdata(beta)=j3= 3.5,3,2.8,2.5,1.5,1.2,1,0.5 j4+=j3[i] ; =j4= 3.5 3 2.8 2.5 1.5 1.2 1 0.5 j3 is beta row vector j4 is beta column vector. 8*8 matrix × 8*1 column vector <a name="docA093">

//9906221747 change from [,j4] //to [,s2a(j4,'column')] bet2=matMVecf(RobinHood,s2a(j4,'column')); //9906172256 //error message 'rows as one string' //9906221638

<a name="docA094"> In matrix equation α=dsm*β α is 8*1 column vector, doubly stochastic matrix=dsm is 8*8 square matrix. β must be 8*1 column vector. β2 sequence=[3.5, 3,2.8,2.5,1.5,1.2, 1,0.5] this is 1*8 row vector. Not 8*1 column vector. Code line bet2=matMVecf(RobinHood,s2a(j4,'column')); ask matMVecf(RobinHood,columnVec) multiply square matrix RobinHood with column Vector This column vector is s2a(j4,'column') ask function s2a() change string to array. String j4 is '3.5\n3\n2.8\n2.5\n1.5\n1.2\n1\n0.5' s2a(j4,'column') return column vector [[3.5], [ 3], [2.8], [2.5], [1.5], [1.2], [ 1], [0.5]] 8*8 square matrix is compatible with 8*1 column vector not compatible with string. <a name="docA095">

//create permute matrix //bet2 is target sequence to //be re-order. for example //bet2=[3,2,6,4,5] //'0' in permutef(mat2str(bet2),0) // indicate decending order //'1' in permutef(mat2str(bet2),1) // indicate ascending order //bet2 is 2-dimensional matrix //i9 is a string of numbers //to create permutation matrix //need a string of numbers. //9906231848 perMat=permutef(mat2str(bet2),0);//9906231840

<a name="docA096"> /**9906212008 //bet2 is RobinHood averaged j4=beta if given problem is α seq: 0.2 0.2 0.2 0.2 0.2 β seq: 1 0 0 0 0 index: 0 1 2 3 4 after RobinHood first transformation β seq: 1 0 0 0 0 become bet2 next β seq: 0.8 0 0.2 0 0 following permutation reorder to β seq: 0.8 0.2 0 0 0 9906212016 /**/ <a name="docA097"> from β seq: 0.8 0 0.2 0 0 to β seq: 0.8 0.2 0 0 0 need permutation matrix But from beta=[3.5,3,2.8,2.5,1.5,1.2,1,0.5] to bet2=[3.5,3,2.5,2.5,1.5,1.5,1,0.5] bet2 is already in descending order, permutation matrix is just identity matrix. Ⅱs-after,perMat=permutef(mat2str(bet2),0)=perMat=[ 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 ] <a name="docA098">

//9906181251 before call matMVecf() //right data need change to column //that is insert '\n' // j7=readdata(bet2); j8=''; for(i=0;i<j7.length;i++) { j8+=j7[i]+'\n'; //9906181241 } //j8=s2a(j8); //9906221622 j8=s2a(j8,'column'); //9906231312 bet3=matMVecf(perMat,j8); //9906181246

2017-07-10-17-12 <a name="docA099"> 2017-07-10-19-19 Code line bet3=matMVecf(perMat,j8); reorder β seq. to descending order. When write doubly stochastic matrix, at first choose far away index pair (wrong) to average see study notes http://freeman2.com/tute0047.htm#ch13b044 In that wrong case, need re-order β sequence to descending order. Now function jkCheck2() is in good shape, Code line bet3=matMVecf(perMat,j8); is possibly removable. Next is debug print Ⅱw after,bet3=matMVecf(perMat,j8)= bet3=[3.5,3,2.5,2.5,1.5,1.5,1,0.5] bet2=[3.5,3,2.5,2.5,1.5,1.5,1,0.5] beta=[3.5,3,2.8,2.5,1.5,1.2,1,0.5] beta is input data bet2 is Robinhood averaged result bet3 is re-ordered bet2 , because function jkCheck2() is in good shape, bet2 is already in descending order and bet3=bet2. <a name="docA100">

if((typeof bet3)=='object') //9906192020 beta=bet3; //9906191311 else { //a606121639 return "Error. (typeof bet3)!=object Box4 may have infinity, 1/0" }

Above code update beta to bet3 value. Input beta sequence is gradually change to alpha sequence. alpha never change, beta change. <a name="docA101">

//next two line accumulate transformation //matrix toward final answer stochastic matrix stochM0=matMVecf(perMat,RobinHood); stochMat=matMVecf(stochM0,stochMat); //9906191747 } //while(iter0<maxIt)

<a name="docA102"> stochMat is compatible with beta2, RobinHood averaging matrix is compatible with beta2. premute matrix change beta sequence order from bet2 to bet3. then RobinHood averaging matrix should permute in same order. Code line stochM0=matMVecf(perMat,RobinHood); do this job. If function jkCheck2() is in good shape, bet2 is already in descending order, no need premute bet2 to bet3. then no need premute RobinHood to stochM0 either. Today, Liu,Hsinhan still keep these possible redundant code. <a name="docA103"> Robinhood each action average one pair, grab one rich, give one poor. α,β sequences need Robinhood work multiple times. Code line stochMat=matMVecf(stochM0,stochMat); accumulate Robinhood averging work to a final once do all matrix. <a name="docA104">

if(typeof(QBfraction)=='object' &&QBfraction.checked &&typeof(decimal2fraction)=='function' ) { for(i0=0;i0<stochMat.length;i0++) for(j0=0;j0<stochMat.length;j0++) stochMat[i0][j0]=decimal2fraction(stochMat[i0][j0]); //a606181625 fraction output OK } //if(typeof(QBfraction)='object'&&QBfraction.checked) return stochMat; //9906191748; a606121622; a606181626 } //function doublStochMat() //a606162016

<a name="docA105"> If user ask output fraction answer, Code line stochMat[i0][j0]=decimal2fraction(stochMat[i0][j0]); change decimal number to fraction number. How to change decimal to fraction ? Please visit http://freeman2.com/dec2frac.htm#document Code line return stochMat; send doubly stochastic matrix back to calling function/clickButton. function doublStochMat() is done. 2017-07-10-20-06

<a name="docA301"> j,k determination alert 2017-07-07-14-45 The following is document for function jkCheck2() doubly stochastic matrix calculator http://freeman2.com/dbstochm.htm manager function is function doublStochMat() Actually doing averaging is RobinHood matrix function robinMatrixf(n,j,k,bj,bk,aj,ak ) If input α seq.=[ 10, 7, 6, 5, 2 ] β seq.=[ 12,10, 5, 2, 1 ] RobinHood cannot grab several rich and give to several poor at one time. <a name="docA302"> Each time RobinHood grab one rich and give to one poor. Before call robinMatrixf(), code need to find j,k value. function jkCheck2() find j,k for robinMatrixf() . j is rich index, k is poor . α seq. is more average; β seq. is more diverse. α seq. and β seq. total sum be the same. α seq. and β seq. both are in descending order. In α seq. and β seq. initial several members must have β[j]>α[j] last several members must have β[k]<α[k] j is rich end index j<k is poor end index. In α seq.=[ 10, 7, 6, 5, 2 ] β seq.=[ 12,10, 5, 2, 1 ] index 0 1 2 3 4 β[0]>α[0] (12 > 10) , β[1]>α[1] (10 > 7) . j=0,1 β[2]<α[2] ( 5 < 6) , β[3]<α[3] ( 2 < 5) . k=2,3,4 <a name="docA303"> function jkCheck2() variables jl,jr,kl,kr represent jLeft, jRight, kLeft, kRight. In above α,β index jl=0,jr=1,kl=2,kr=4 . Debug code line is jl=0, jr=1; ml=-1, mr=-1; kl=2, kr=4; N=5 Last N=5 represent α seq., β seq. has five menber are not equal. Debug code line contain ml=-1, mr=-1 ml,mr are middleLeft, middleRight. -1 say not found. ml,mr point to α,β middle equal elements. <a name="docA304"> See another example α seq.=[ 3.5, 2.5, 2.5, 2.5, 1.5, 1.5, 1.5, 0.5 ] β seq.=[ 3.5, 3.0, 2.8, 2.5, 1.5, 1.2, 1.0, 0.5 ] index 0 1 2 3 4 5 6 7 has debug code line jl=1, jr=2; ml=3, mr=4; kl=5, kr=6; N=4 β[0]=α[0] (3.5=3.5) , β[1]>α[1] (3.0>2.5) . β[2]>α[2] (2.8>2.5) , β[3]=α[3] (2.5=2.5) . β[4]=α[4] (1.5=1.5) , β[5]<α[5] (1.2<1.5) . β[6]<α[6] (1.0<1.5) , β[7]=α[7] (0.5=0.5) . <a name="docA305"> After decide jl, jr; ml, mr; kl, kr; N Code select j closer to middle ml, mr and select k closer to middle ml, mr. function jkCheck2() return [j,k,N]; where j,k let RobinHood know which one rich to grab and which one poor to give. N tell programmer how many unequal member exist. 2017-07-07-15-46 j,k determination alert //9906272038 jkstatus //docG is a document in // function stochastic0() //before the command //jkstatus=jkCheck(alfa,beta,tol0); //now move docG to //function jkCheck() // var docG='<pre>' +'\n\n' +'<a name=docG007></a>\n' +'2010-06-30-07-16 start\n' +'function jkCheck() use \n' +'jl (j left bound)\n' +'jr (j right bound)\n' +'ml (m left bound)\n' +'mr (m right bound)\n' +'kl (k left bound)\n' +'kr (k right bound)\n' +'to determine j,k value.\n' +'<a name=docG008></a>\n' +'jl is first β[jl] > α[jl] \n' +'jr is last β[jr] > α[jr] \n' +'kl is first β[kl] < α[kl] \n' +'kr is last β[kr] < α[kr] \n' +'jl<=j<=jr\n' +'kl<=k<=kr\n' +'ml is middle equality left bound\n' +'mr is middle equality right bound\n' +'<a name=docG009></a>\n' +'Example 1\n' +'α1 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5 \n' +'β1 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 \n' +'index 0 1 2 3 4 5 6 7\n' +'Left equality α1[0]=β1[0]=3.5 are ignored.\n' +'Right equality α1[7]=β1[7]=0.5 are ignored.\n' +'<a name=docG010></a>\n' +'For α1,β1 find\n' +'jl=1 first β1[1] > α1[1] 3.0>2.5\n' +'jr=3 last β1[3] > α1[3] 2.5>2.4\n' +'kl=4 first β1[4] < α1[4] 1.5<1.6\n' +'kr=6 last β1[6] < α1[6] 1.0<1.5\n' +'ml=-1 no middle equality\n' +'mr=-1\n' +'<a name=docG011></a>\n' +'2010-06-30-07-30 here\n' +'α2 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5\n' +'β2 sequence 3.5 3 2.8 2.4 1.6 1.2 1 0.5\n' +'index 0 1 2 3 4 5 6 7\n' +'<a name=docG012></a>\n' +'For α2,β2 find\n' +'jl=1 first β2[1] > α2[1] 3.0>2.5\n' +'jr=2 last β2[2] > α2[2] 2.8>2.5\n' +'kl=5 first β2[5] < α2[5] 1.2<1.5\n' +'kr=6 last β2[6] < α2[6] 1.0<1.5\n' +'ml=3 first β2[3] = α2[3] 2.4=2.4\n' +'mr=4 last β2[4] = α2[4] 1.6=1.6\n' +'<a name=docG013></a>\n' +'With j,k,m bounds in hand,\n' +'Next goto j,k determination\n' +'section\n' +'//Set j=k=-1; as initial state\n' +'j=k=-1;\n' +'//if middle_left ml defined (greater than -1)\n' +'//if middle_rite mr defined (greater than -1)\n' +'if(ml>-1&&mr>-1)\n' +' {\n' +'<a name=docG014></a>\n' +'//set index j to be ml-1. For above\n' +'//α2 β2 example, ml=3, then j=2=3-1\n' +'j=ml-1;\n' +'//if β[j]-α[j]<1.e-8, they are equal\n' +'//if j is greater than zero\n' +'//move index j toward zero\n' +'<a name=docG015></a>\n' +'while(Math.abs(beta[j]-alfa[j])<=tolerance0\n' +' && j>0\n' +' )\n' +'j--; //9906201722\n' +'\n' +'<a name=docG016></a>\n' +'//set index k to be mr+1. For above\n' +'//α2 β2 example, mr=4, then j=5=4+1\n' +'k=mr+1\n' +'//if α[j]-β[j]<1.e-8, they are equal\n' +'//if k is less than 8 (total 8 elements)\n' +'//move index k toward 8\n' +'<a name=docG017></a>\n' +'while(Math.abs(beta[k]-alfa[k])<=tolerance0\n' +' && k<tota-1\n' +' )\n' +'k++; //9906201726\n' +' }\n' +'<a name=docG018></a>\n' +'//if middle_left ml is not defined\n' +'//if middle_rite mr is not defined\n' +'else\n' +' {\n' +'//set j to j right bound\n' +'j=jr;\n' +'//set k to k left bound\n' +'k=kl; //9906201628\n' +'//α1 β1 example, jr=3, then j=3\n' +'//α1 β1 example, kl=4, then k=4\n' +' }\n' +'2010-06-30-08-02 here\n' +'<a name=docG019></a>\n' +'2010-06-30-08-42 start\n' +'On 2010-06-23 re-write code for\n' +'jl,jr;kl,kr;ml,mr determination\n' +'from 9906232224 (please read)\n' +' to 9906232254 (source code)\n' +'<a name=docG020></a>\n' +'It is in logic order, then \n' +' if(N>0) //9906202342\n' +' {...}\n' +'is not necessary and deleted.\n' +'2010-06-30-08-46 stop\n' +'\n' +'<a name=docG021></a>\n' +'2010-06-30-09-36 start\n' +'Example button 52 is\n' +'α52 sequence 5 3 2 1 1\n' +'β52 sequence 6 2 2 2 0\n' +'index 0 1 2 3 4\n' +'Comment is\n' +'[[\n' +'RobinHood refused \'average\' \n' +'[2 2 2] to [3 2 1], now OK\n' +']]\n' +'<a name=docG022></a>\n' +'Early version had trouble here\n' +'\'average\' [2 2 2] to [3 2 1]\n' +'is an infinite loop. Stop at\n' +'iteration upper bound.\n' +'How new code persuade RobinHood\n' +'continue to work ?\n' +'α52 and β52 has α52[2]=β52[2]=2\n' +'middle section has one common\n' +'value, why ml=mr=-1=undefined?\n' +'<a name=docG023></a>\n' +'The reason is the following.\n' +'ml and mr are defined only if\n' +'α[middle]=β[middle] or\n' +'abs(α[middle]-β[middle])<1.e-8\n' +'AND kl,kr are undefined.\n' +'<a name=docG024></a>\n' +'Now before α[middle]=β[middle]=2\n' +'there is α[1]=3>2=β[1]\n' +'When α[1]>β[1], kl is defined.\n' +'Next come to i=2, although\n' +'α[2]=β[2]=2, but kl is defined\n' +'then ml=mr=-1=undefined.\n' +'All the way to the end i=4\n' +'defined jl=jr=0, kl=1, kr=4\n' +'<a name=docG025></a>\n' +'These definition, let jkCheck()\n' +'define j=0=jr and k=1=kl, \n' +'invite RobinHood to average\n' +'index=j,k that is index=0,1\n' +'α52 sequence 5 3\n' +'β52 sequence 6 2\n' +'index 0 1\n' +'in\n' +'<a name=docG026></a>\n' +'α52 sequence 5 3 2 1 1\n' +'β52 sequence 6 2 2 2 0\n' +'RobinHood happly do the job.\n' +'β52 new-seq. 5 3 2 2 0 \n' +'index 0 1 2 3 4\n' +'<a name=docG027></a>\n' +'Better logic code\n' +'from 9906232224 (please read)\n' +' to 9906232254 (source code)\n' +'solved old code problem.\n' +'2010-06-30-10-02 stop\n' +'\n' +'Above is document for\n' +'function jkCheck()\n' +'</pre>' <a name="docA306">

//9906222100 jkCheck() //a606121609 jkCheck2() delete debug function jkCheck2( arg1 //alpha sequence, more average , arg2 //beta sequence, more diverse //, arg3 //tolerance, suggest 1.e-8 //a606121610 use 1.e-8 ) { var i; //i is index of for() loop var i0,i1,i2,i3; var tolerance0=tiny0=1.e-8; if(typeof arg1=='string') alfa=readdata(arg1) else { if(typeof arg1[0]=='number') alfa=arg1; else { alfa=new Array(arg1.length) for(i=0;i<alfa.length;i++) alfa[i]=arg1[0][i]; //9906222140 } } //<a name="docA307"> if(typeof arg2=='string') beta=readdata(arg2) else { if(typeof arg2[0]=='number') beta=arg2; else { beta=new Array(arg2.length) for(i=0;i<beta.length;i++) beta[i]=arg2[i][0]; //9906222142 } } //<a name="docA308"> var tota=alfa.length; var totb=beta.length; if(tota!=totb) //return [-2,-2,-2]; //9906201327 return [-2,tota,totb]; //9906232032 var suma=0; var sumb=0; for(i=0;i<tota;i++)suma+=alfa[i]; for(i=0;i<totb;i++)sumb+=beta[i]; if(Math.abs(suma-sumb)>tolerance0) //return [-3,-3,-3]; //9906201328 return [-3,suma,sumb]; //9906232033

<a name="docA309"> 2017-07-07-16-31 Above is code make sure α seq. α more average β seq. β more diverse satisfy α≺β j,k determination alert <a name="docA310">

var aMinusb=0; //9906191945 var N=0; //N=number of elements //that alfa_j != beta_j var jl=jr=kl=kr=-1; //9906201258 var j=k=-1; //j,k is main number in jkCheck2() var ml=mr=-1; //9906201505 //ml=Middle Left //mr=Middle Right //middle mean the middle //equal alfa_j == beta_j //section. for example //α2 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 //β2 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 // ml=3, mr=4 //and //α1 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5 //β1 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 // ml=-1, mr=-1 // //next input // alfa=[5,3,2,1,1] // beta=[6,2,2,2,0] //need ml,mr to pull jr=0 to jr=1 //9906201509

<a name="docA311">

for(i=0;i<tota;i++) { aMinusb=alfa[i]-beta[i]; //if(aMinusb>=0)j=i-1; //9906191946 //if use >=0, j run to the end of array aMinusb=Math.abs(aMinusb); //9906201401 //all comparison use abs() //if α[0]=1.0 and β[0]=1.000000000001 //they are EQUAL ! only if use abs() //can skip above ill condition. //α1 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5 //β1 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 //above α1,β1 jl=1 //now i=0, do nothing, //continue to next iteration. if( //9906232224 aMinusb<=tolerance0 //beta[i]==alfa[i] &&jl==-1 //jl not yet define ) { continue; }

<a name="docA312"> In above α1 sequence and β1 sequence α[0]=3.5 , β[0]=3.5 ; α[0]=β[0] is true. Before re-distribution and after re-distribution [0]-th element not change. No need Robinhood do anything. Richer j , poor k index not point to [0]-th element, simply continue to next i ([1]) <a name="docA313">

//α1 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5 //β1 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 //above α1,β1 jl=1 if( //9906232226 beta[i]>alfa[i] &&jl==-1 //jl not yet define ) { jl=i; //9906232226 N++; //9906232227 beta[i]>alfa[i] not equal, N++ continue; }

<a name="docA314"> In above α1 sequence and β1 sequence α[1]=2.5 , β[1]=3.0 ; β[1]>α[1] (beta[i]>alfa[i]) is true. jl==-1 is true. Enter if() body, assign jl=i=1 Increase N by one. N record not equal count. jl (jLeft) , jl is first β[jl] > α[jl]. In next //α1 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5 //β1 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 index jl=1 is first β[jl] > α[jl] 3.0 > 2.5 debug code output Ⅴ enter for(i) i=2; //a607071108 jl=1, jr=-1; ml=-1, mr=-1; kl=-1, kr=-1; N=1 j,k determination alert <a name="docA315">

//α1 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5 //β1 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 //above α1,β1 jl=1 if( beta[i]>alfa[i] &&jl>-1 //jl already define &&kl==-1 //kl not yet define &&ml==-1 //ml not yet define ) { //jr move forward until ml or kl defined jr=i; //9906232231 N++; //9906232052 continue; }

<a name="docA316"> In above α1 sequence and β1 sequence α[3]=2.4 , β[3]=2.5 ; β[3]>α[3] (beta[3]>alfa[3]) is true. jl=1>-1 is true. Enter if() body, assign jr=i=3 Increase N by one. N record not equal count. jr (jRight) , jr is last β[jr] > α[jr]. In next //α1 sequence 3.5 2.5 2.5 2.4 1.6 1.5 1.5 0.5 //β1 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 index jr=3 is last β[jr] > α[jr] 2.5 > 2.4 debug code output Ⅴ for(i),C jr=i=3; N++=3 i=3 jl=1, jr=3; ml=-1, mr=-1; kl=-1, kr=-1; N=3 <a name="docA317">

//α2 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 //β2 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 //above α2,β2 jr=2; //abs(aMinusb)<=tol0 say α[3]=β[3]=2.5 if( //9906232236 aMinusb<=tolerance0 //beta[i]==alfa[i] &&jl>-1 //jl already define &&kl==-1 //kl not yet define &&ml==-1 //ml not yet define ) { ml=i; //9906232237 jr=i-1; //9906232309 continue; }

<a name="docA318"> In above α2 sequence and β2 sequence α[3]=2.5 , β[3]=2.5 ; β[3]=α[3] (beta[3]=alfa[3]) is true. α[3]-β[3]=0<=tol0=1.e-8 is true. jl=1>-1 is true. Enter if() body, assign ml=i=3 assign jr=i-1=3-1=2 Increase N by one. N record not equal count. ml (middleLeft) , ml is first β[ml]=α[ml]. ml>jl>-1 In next //α2 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 //β2 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 Although α[0]=β[0]=3.5, but jl=1, ml>jl>-1 not allow ml=0 index ml=3 is first β[ml]=α[ml] 2.5=2.5 debug code output Ⅴ enter for(i) i=4; //a607071108 jl=1, jr=2; ml=3, mr=-1; kl=-1, kr=-1; N=2 <a name="docA319"> If input α3 sequence 5, 3, 2, 1, 1 β3 sequence 6, 2, 2, 2, 0 index 0 1 Ⅱ 3 4 Robinhood refuse average '2 2 2' to '3 2 1' Code assign jl=jr=0, because β[0]=6>5=α[0] Code assign kl=1, because β[1]=2<3=α[1] At end of function jkCheck2() code select j=jr and select k=kl. jkCheck2() send [j,k]=[0,1] to Robinhood. 0,1 are index, β[0]=6>2=β[1]. 0,1 are not value. Output doubly stochastic matrix verification OK. 2017-07-07-18-10 j,k determination alert <a name="docA320">

//α2 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 //β2 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 //above α1,β1 jr=3; if( beta[i]<alfa[i] &&kl==-1 ) { kl=i; //9906232241 if(ml>-1)mr=i-1; //9906232242 else jr=i-1; //9906232311 N++; continue; }

<a name="docA321"> 2017-07-07-18-44 Above code determine kl=kLeft, k is poor side index In α seq.=[ 10, 7, 6, 5, 2 ] β seq.=[ 12,10, 5, 2, 1 ] index 0 1 2 3 4 10,7; 12,10 are rich side, use jl,jr (jLeft,jRight) β[0]>α[0] (12 > 10) , β[1]>α[1] (10 > 7) 6, 5, 2 ; 5, 2, 1 are poor side, use kl,kr β[2]<α[2] ( 5 < 6) , β[3]<α[3] ( 2 < 5) , β[4]<α[4] ( 1 < 2) If β[i]<α[i] and kl not defined (kl==-1) enter if() body assign kl=i; if(ml>-1)mr=i-1; if middle section left bound ml defined, define middle section right bound mr to i-1 If ml is not defined, define rich side lower bound jr to i-1. β[i]<α[i] cause inequal counter N add one. 2017-07-07-19-07 <a name="docA322">

//α2 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 //β2 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 //above α2,β2 kl=5; if( //9906232244 beta[i]<alfa[i] &&kl>-1 ) { //kr move forward until i=tota-1 //or until beta[i]==alfa[i] kr=i; //9906232245 N++; continue; }

<a name="docA323"> 2017-07-07-20-03 Above code determine kr, poor side smaller end index. Code line beta[i]<alfa[i] say early example red number smaller end β[4]<α[4] (1 < 2) Code line &&kl>-1 say kl (kLeft) is defined, then define kr (kRight) kr=i; . Condition beta[i]<alfa[i] let inequal counter N increase one. <a name="docA324">

//α2 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 //β2 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 //above α2,β2 kl=5; if( //9906232244 aMinusb<=tolerance0 //beta[i]==alfa[i] &&kr>-1 ) { //kr stop move forward break; //9906232254 } } //for(i=0;i<tota;i++) 9906201421

<a name="docA325"> Above //α2 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 //β2 sequence 3.5 3.0 2.8 2.5 1.5 1.2 1.0 0.5 //index 0 1 2 3 4 5 6 7 has equality α[7]=β[7]=0.5 and kr is defined, enter this if() body. Do one thing break from for(i=0;i<tota;i++) But what if input α4 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 0.0 β4 sequence 3.5 3.0 2.7 2.5 1.5 1.2 1.0 0.5 0.1 α[7]=β[7]=0.5 is not last member. 2017-07-07-20-18 //a607072022_trouble //a607072121 j,k determination alert <a name="docA326"> 2017-07-08-09-22 α4 sequence 3.5 2.5 2.5 2.5 1.5 1.5 1.5 0.5 0.0 β4 sequence 3.5 3.0 2.7 2.5 1.5 1.2 1.0 0.5 0.1 do not have α, β majorization relation. α4 member count = β4 member count = 9 α4 total sum = β4 total sum = 16 α4 eight member partial sum = 16 β4 eight member partial sum = 15.9 15.9 not ≧ 16 α4 and β4 do not have majorization relation. Even if switch α, β role, still fail. See α seq. and β seq. inequality requirement. 2017-07-08-09-36 <a name="docA327"> Above done for(i=0;i<tota;i++) loop. Below from ml,mr,jr,kl select j,k

j=k=-1; if(ml>-1&&mr>-1) { j=ml-1; while(Math.abs(beta[j]-alfa[j])<=tolerance0 && j>0 ) j--; //9906201722 k=mr+1 while(Math.abs(beta[k]-alfa[k])<=tolerance0 && k<tota-1 ) k++; //9906201726 } else { j=jr; k=kl; //9906201628 } var rho=(beta[j]+beta[k])/2; var tau= beta[j]-rho; //9906201636 return [j,k,N]; //990623 } //function jkCheck2()

<a name="docA328"> Above code select index value for j, k . j, k will be used by Robinhood averaging code. j, k selection is j, k as close as possible. for example if α2 sequence=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] β2 sequence=[3.5, 3,2.8,2.5,1.5,1.2, 1,0.5] index 0 1 2 3 4 5 6 7 program debug code before return from jkCheck2() Ⅴ return [j,k,N]; j=2, k=5, N=4 Tell Robinhood next step averaging work grab β2[2]=2.8, give to β2[5]=1.2 such that β2 approach α2 . This special example, Robinhood let β2[2] match α2[2] and β2[5] match α2[5] at same time. But in most case, one averaging let one β member equal α member . Here, function jkCheck2() document is done. 2017-07-08-09-59 <a name="docA329"> 2017-07-08-18-53 j,k determination please read study notes http://freeman2.com/tute0047.htm#ch13b040 from above to next http://freeman2.com/tute0047.htm#ch13b071 If choose wrong j,k pair ask RobinHood average wrong pair, get error output!

<a name="docA401"> 2017-07-09-09-35 Next is function robinMatrixf() Robinhood matrix average two beta elements toward two alpha elements. Please read earlier study notes Robinhood matrix http://freeman2.com/tute0047.htm#ch13b072 Hardy, Littlewood and Polya Representation eqn.13.14 http://freeman2.com/tute0047.htm#ch13b084 Prove HLP matrix is doubly stochastic http://freeman2.com/tute0047.htm#ch13b110 Prove Doubly stochastic matrix A multiply Doubly stochastic matrix B get Doubly stochastic matrix C. http://freeman2.com/tute0047.htm#ch13b263 Convex combination of several doubly stochastic is doubly stochastic matrix . http://freeman2.com/tute0047.htm#ch13b297 Please read textbook chapter 13. 2017-07-09-09-57

var docH='<pre>' +'<a name=docH001>\n' +'The following is document for\n' +'function robinMatrixf()\n' +'2010-06-28-20-30\n' +'Robin Hood transformation is most\n' +'important material.\n' +'function robinMatrixf() document\n' +'is in study notes page tute0047.htm\n' +'The following discuss the error\n' +'caused by beta[j]=beta[k]. Please\n' +'visit study notes, please read\n' +'The Cauchy-Schwarz Master Class\n' +'chapter 13 for complete document.\n' +'2010-06-28-20-37\n' +'<a name=docH002>\n' +'2010-06-21-18-22\n' +'If the condition\n' +'beta[j]=beta[k] //ERROR\n' +'is true, then next two lines\n' +'rho=(beta[j]+beta[k])/2;\n' +'tau= beta[j]-rho;\n' +'<a name=docH003>\n' +'create tau=0. matrix elements\n' +'j1=(tau+sigma)/2/tau;\n' +'j2=(tau-sigma)/2/tau;\n' +'become infinity.\n' +'Next if() try to stop this case, \n' +'<a name=docH004>\n' +'First method is copy from alpha\n' +'to beta\n' +'beta[i0]=alfa[i0];\n' +'result OK. trouble is by-pass \n' +'matrix transformation. Final\n' +'"Bx7 stochastic mat" is not \n' +'complete.\n' +'<a name=docH005>\n' +'Second method is use Reverse \n' +'Robin Hood Matrix robinMatrixr()\n' +'result same disaster.\n' +'[ robinMatrixr() is deleted ]\n' +'Both solution fail.\n' +'2010-06-21-18-31\n' +'\n' +'<a name=docH006>\n' +'Newer version do j,k update correct.\n' +'New version do not have above trouble.\n' +'2010-06-28-20-43\n' +'</pre>'

<a name="docA402">

//9906201930 function robinMatrixf( n,j,k,bj,bk,aj,ak ) { n=parseInt(n); var robinMat0=identity(n) var rho=(bj+bk)/2; var tau= bj-rho; var sigma=Math.abs(ak-rho); var i0=Math.abs(aj-rho); if(i0>sigma)sigma=i0; //9906172233 var j1=(tau+sigma)/2/tau; var j2=(tau-sigma)/2/tau; robinMat0[j][j]=robinMat0[k][k]=j1; robinMat0[j][k]=robinMat0[k][j]=j2; return robinMat0; } //9906201938 function robinMatrixf()

<a name="docA403"> 2017-07-09-16-24 Now use numerical value explain function robinMatrixf() arg1=α seq. more average arg2=β seq. more diverse arg1=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] arg2=[3.5, 3,2.8,2.5,1.5,1.2, 1,0.5] index 0 1 2 3 4 5 6 7 function robinMatrixf(n,j,k,bj,bk,aj,ak ) n=8, because α seq. and β seq. each has eight elements. Build a avreaging matrix dimension 8*8. <a name="docA404"> j=2, k=5, ask Robinhood average index=2 and index=5 elements. Change β[2]=2.8 and change β[5]=1.2 toward α[2]=2.5,α[5]=1.5. α[2],α[5] are goal, not change. Pay attention to index=3,4 α[3]=β[3]=2.5 α[4]=β[4]=1.5 already match. bj=β[2]=2.8 , bk=β[5]=1.2 aj=α[2]=2.5 , ak=α[5]=1.5 Above are function robinMatrixf() input value. Next debug print. <a name="docA405"> Ⅳ ===robinMatrixf_1=== just enter function robinMatrixf() n,j,k=8,2,5 aj,ak=2.5,1.5 bj,bk=2.8,1.2 (aj+ak)/2=2 (bj+bk)/2=2 robinMat0=identity(n) build a 8*8 identity matrix robinMat0=[ 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 ] <a name="docA406"> rho=(bj+bk)/2=(2.8+1.2)/2=2 tau= bj-rho=2.8-2=0.8 sigma=Math.abs(ak-rho)=abs(1.5-2)=0.5 i0=Math.abs(aj-rho)=abs(2.5-2)=0.5 if(i0>sigma)sigma=i0; if(0.5>0.5) false, sigma=0.5 not change j1=(tau+sigma)/2/tau=(0.8+0.5)/2/0.8=0.8125 j2=(tau-sigma)/2/tau=(0.8-0.5)/2/0.8=0.1875 robinMat0[j][j]=robinMat0[k][k]=j1; robinMat0[j][k]=robinMat0[k][j]=j2; robinMat0=[ 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0.8125 0 0 0.1875 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0.1875 0 0 0.8125 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 ] <a name="docA407"> program return above value change array from arg1=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] arg2=[3.5, 3,2.8,2.5,1.5,1.2, 1,0.5] index 0 1 2 3 4 5 6 7 to arg1=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] arg2=[3.5, 3,2.5,2.5,1.5,1.5, 1,0.5] Blue numbers average to red number. <a name="docA408"> Next iteration start from arg1=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] arg2=[3.5, 3,2.5,2.5,1.5,1.5, 1,0.5] index 0 1 2 3 4 5 6 7 Red numbers are Robinhood focus rich/poor target. function jkCheck2() choose rich side index 1 and choose poor side index 6 Ⅲo jkCheck2() return [j,k,N]; j=1, k=6, N=2 Ⅳ ===robinMatrixf_1=== just enter function robinMatrixf() n,j,k=8,1,6 aj,ak=2.5,1.5 bj,bk=3,1 (aj+ak)/2=2 (bj+bk)/2=2 <a name="docA409"> this time averaging matrix is robinMat0=[ 1 0 0 0 0 0 0 0 0 0.75 0 0 0 0 0.25 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0.25 0 0 0 0 0.75 0 0 0 0 0 0 0 0 1 ] change array from arg1=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] arg2=[3.5, 3,2.5,2.5,1.5,1.5, 1,0.5] index 0 1 2 3 4 5 6 7 to arg1=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] arg2=[3.5,2.5,2.5,2.5,1.5,1.5,1.5,0.5] Blue numbers average to red number. <a name="docA410"> Here arg1=arg2 is true, program still send arg1 and arg2 to function jkCheck2(), jkCheck2() return [j,k,N] = [-1,-1,0] a sign to stop. N=0 mean arg1 and arg2 two arrays mismatch number count is zero. j=-1, k=-1 mean cannot suggest rich side index, cannot suggest poor side index. After this [j,k,N] = [-1,-1,0] program print doubly stochastic matrix to output box. <a name="docA411"> Please read earlier study notes Robinhood matrix http://freeman2.com/tute0047.htm#ch13b072 Hardy, Littlewood and Polya Representation eqn.13.14 http://freeman2.com/tute0047.htm#ch13b084 Prove HLP matrix is doubly stochastic http://freeman2.com/tute0047.htm#ch13b110 Prove Doubly stochastic matrix A multiply Doubly stochastic matrix B get Doubly stochastic matrix C. http://freeman2.com/tute0047.htm#ch13b263 Convex combination of several doubly stochastic is doubly stochastic matrix . http://freeman2.com/tute0047.htm#ch13b297 2017-07-09-17-23

<a name="docA601"> 2017-07-11-11-36 update 2017-07-12 in http://freeman2.com/tute0069.htm add document for doubly stochastic matrix calculator http://freeman2.com/dbstochm.htm tute0069.htm has three function document function doublStochMat() function jkCheck2() function robinMatrixf() <a name="docA602"> function doublStochMat() is the main engine to build doubly stochastic matrix. function jkCheck2() determine which two pair in beta sequence to average. If choose wrong pair, output has trouble. function robinMatrixf() is an easy work. Grab rich give to poor re-distribution process. α sequence is more average β sequence is more diverse Robinhood change β sequence step by step and finally, β sequence is same as α sequence. 2017-07-11-11-46 <a name="docA603"> 2017-07-11-18-05 start proofread document function doublStochMat() 2017-07-11-18-59 done proofread function doublStochMat() 2017-07-12-08-48 start proofread function jkCheck2() function robinMatrixf() 2017-07-12-10-16 done proofread [=][][]

<a name="docA900"> First exam numerical example numerical α1 is eqn.BX016 , 10 = 63/80*12 + 9/350*10 + 9/1400*5 + 9/112*2 + 1/10*1 ---eqn.BX016 eqn.BX010 is α[1], α[1], α[1], β[1] , β[1] , β[1] , Doubly Stochastic Matrix <a name="docA901"> 2017-07-02-08-05 <script language="javascript">tabl_55a()</script> <script language="javascript">tabl_55b()</script> <a name="docA902"> 2017-07-02-10-25 <script language="javascript">tabl_55c()</script> <a name="docA903"> <script language="javascript">t_55c(1)</script> <script language="javascript">t_55c(1,0)</script> <script language="javascript">t_55c(2)</script> <a name="docA904"> <script language="javascript">t_55c(2,0)</script> <script language="javascript">t_55c(3)</script> <script language="javascript">t_55c(4)</script> <a name="docA905"> <script language="javascript">t_55c(5)</script> <script language="javascript">t_55c(5,1)</script> 2017-07-02-11-11 <a name="docA906"> <script language="javascript">t_55d(3,'---eqn.BX567 ')</script> 2017-07-02-12-50 <script language="javascript">ab()</script> <script language="javascript">alert0()</script> <a name="docA907"> full table code
α1 = d11* β1  + d12* β2  + d13* β3  + d14* β4  + d15* β5 ---eqn.BX024
α2 = d21* β1  + d22* β2  + d23* β3  + d24* β4  + d25* β5 ---eqn.BX025
α3 = d31* β1  + d32* β2  + d33* β3  + d34* β4  + d35* β5 ---eqn.BX026
α4 = d41* β1  + d42* β2  + d43* β3  + d44* β4  + d45* β5 ---eqn.BX027
α5 = d51* β1  + d52* β2  + d53* β3  + d54* β4  + d55ij* β5 ---eqn.BX028
<a name="docA908"> 2017-07-02-13-50 <script language="javascript">BetaMAlfaN()</script> 2017-07-02-18-55 <script language="javascript">BetaMAlfa5(3)</script> <script language="javascript">BetaMAlfa5(2,4)</script> textbook [=][][]

<a name=UnicodeSymbol>
UnicodeSymbol : ℂ ℍ ℕ ℙ ℚ ℝ ℤ ℽ ℾ ℿ ⅀ ⅅ ⅆ ⅇ ⅈ ⅉ ; × ÷ ° ◦ º ¹ ² ³
≦ ≠ ≧ < = > ± ≡ ≈ ≌ ≒ ∏ ∑ √ ∛ ∜ ∝ → ∞ ∈ ∀ ∂ ⊥ ∃ ∋ ∆ ∇ ⊿ ∟ ∠ ∫ ∬ ∭ ∮ ∥
≺ ≻ ≼ ≽ ≾ ≿ ⊀ ⊁ ≭ ≮ ≯ ≰ ≱ ≲ ≳ ≴ ≵ ≶ ≷ ≸ ≹ ∧ ∨ ∩ ∪ ∴ ∵ ∶ ∷ ⊂ ⊃ ⊄ ⊅ ⊆ ⊇
Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ ΢ Σ Τ Υ Φ Χ Ψ Ω ☺ + - * /
α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω ☺ 〈v,w〉 ⊕ ⊙ ○ ● ◎ ■ □ ▢ ▣ ▤ ▥ ▦ ▧ ▨ ▩ ▪ ▫
§ ‰ ¼ ½ ¾ ⅓ ⅔ ⅕ ⅖ ⅗ ⅘ ⅙ ⅚ ⅛ ⅜ ⅝ ⅞ ⅟ ← ↑ → ↓ ↔ ↕ ↖ ↗ ↘ ↙
&#8544;=Ⅰ &#8545;=Ⅱ &#8546;=Ⅲ &#8547;=Ⅳ &#8548;=Ⅴ &#8549;=Ⅵ
&#8550;=Ⅶ &#8551;=Ⅷ &#8552;=Ⅸ &#8553;=Ⅹ &#8554;=Ⅺ &#8555;=Ⅻ
2017-06-20-20-44 Liu,Hsinhan access en.wikipedia.org
https://en.wikipedia.org/wiki/List_of_mathematical_symbols
en.wikipedia.org-wiki-List_of_mathematical_symbols.htm
http://freeman2.com/utility4.htm#extractUnicode
∧,⇒,−,∖,√,≥,≤,∓,⋅,⁄,⇔,∈,ℤ,ℝ,φ,π,∑,∫, ,∮,∯,∰,…,⋯,⋮,⋰,⋱,∴,∵,≠
˜ ,∝,∞,■,□,∎,▮,‣,≈,≃,≅,♎,≒,△,≡,≜,≝,≐,↔,≪,≫,≦,≧,≺,≻,◅,▻,→,⊃,⊆
⊂,∩,ℕ,ℚ,⊇,∪,↦,•,⊧,∨,⊢,⟨,⟩,ψ,α,β,–,‖,⌊,⌉,⌋,⌈,ℂ,∗,∣,∤,∥,∦,⋕,⊥
∃,≀,↯,※,⇐,⊕,⊻,∐,′,∀,∂,∉,∌,∋,ℍ,ω,○,∘,∅,ℙ,†,⊤,—,⊗,⋉,⋊,⋈,​,ℵ,ℶ
δ,∆,⊖,Δ,ƒ,∇,∏,σ,

∑,∫, ,∮,∯=,&#8202;, //a606301442








Javascript index
http://freeman2.com/jsindex2.htm   local
Save graph code to same folder as htm files.
http://freeman2.com/jsgraph2.js   local


related files

doubly stochastic matrix calculator
http://freeman2.com/dbstochm.htm
dbstochm.htm all debug code close

dbstochn.htm all debug code open for writing tute0069.htm
doubly stochastic matrix debug
http://freeman2.com/dbstochn.htm



file name tute0069.htm mean
TUTor, English, 69 th .htm

2017-06-29-15-42 save as tute0069.htm


doubly stochastic matrix study notes tute0069.htm
The address of this file is
http://freeman2.com/tute0069.htm
First upload 2017-07-04

Thank you for visiting Freeman's page.
Freeman Liu,Hsinhan 劉鑫漢
2017-06-30-13-53