Decrementing maximiser

Code commentary on the implementation of Tractable and Practicable Inducers/Python Implementation/Decrementing maximiser

Sections

Maximum-roll-by-derived-dimension tuple partitioner

Tuple-partition value roller

Maximum-roll-by-derived-dimension tuple partitioner

In order to implement the maximum-roll-by-derived-dimension limited-valency contracted decrementing linear non-overlapping fuds list maximiser initial set, $R_{P,A,A_R,F,\mathrm{n,w},-,K,\mathrm{mm}}$, the maximum-roll-by-derived-dimension tuple partitioner $I_{P,U,\mathrm{K},\mathrm{mm}} \in \mathrm{computers}$ is defined such that (i) $\mathrm{domain}(I_{P,U,\mathrm{K},\mathrm{mm}}) = (\mathrm{P}(\mathcal{V}_U) \times \mathcal{A}_U \times \mathcal{A}_U) \times \mathbf{Q}$, (ii) $\mathrm{range}(I_{P,U,\mathrm{K},\mathrm{mm}}) = \mathrm{P}(\mathcal{L}(\mathcal{S}_U \to \mathbf{N}) \times \mathcal{A}_U \times \mathcal{A}_U)$, and (iii) the application is (Text) \[ \begin{eqnarray} &&I_{P,U,\mathrm{K},\mathrm{mm}}^{ * }(((K,B,B_R),y_1)) = \\ &&\hspace{1em}\bigcup \{\mathrm{topd}(\mathrm{pmax})(\{((N,C,C_R),~((y_1-a_2+b_2)/c,~b_2/c,~-m,~D_{\mathcal{X}}(J))) :\\ &&\hspace{3em}Y \in \mathrm{S}(K,m),~(\forall J \in Y~(|J^{\mathrm{C}}| \leq \mathrm{umax})),\\ &&\hspace{3em}N = \{(i,\mathrm{order}(D_{\mathrm{S}},J^{\mathrm{CS}})) : (J,i) \in \mathrm{order}(D_{\mathrm{P}(\mathcal{V})},Y)\},\\ &&\hspace{3em}T=(\{\bigcup \{S \cup \{(w,u)\} : (w,(S,u)) \in L\} : L \in \prod N\}^{\mathrm{U}},\{1 \ldots m\}),\\ &&\hspace{3em}C = I_{ * \mathrm{T}}^{ * }((T,B)),~C_R = I_{ * \mathrm{T}}^{ * }((T,B_R)),\\ &&\hspace{3em}a_2 = I_{\mathrm{\mathrm{S}\approx\mathrm{ln}!}}^{ * }(I_{\mathrm{X}}^{ * }(C)),~b_2 = I_{\mathrm{\mathrm{S}\approx\mathrm{ln}!}}^{ * }(I_{\mathrm{X}}^{ * }(C_R)),~c=I_{\approx\mathrm{pow}}^{ * }((v,1/m))\}) : \\ &&\hspace{2em}m \in \{2 \ldots \mathrm{mmax}\}\} \end{eqnarray} \]

The tuple partitioner is defined in module AlignmentPracticable,

parametersSystemsPartitionerMaxRollByM :: 
  Integer -> Integer -> Integer -> System -> Set.Set Variable -> Histogram -> Histogram -> Double ->
  Maybe (Set.Set ([Set.Set (State,Int)], Histogram, Histogram))

as

def parametersSystemsPartitionerMaxRollByM(mmax,umax,pmax,uu,kk,bb,bbrr,y1):
    ...
    pp = []
    for m in range(2,mmax+1):
        c = vol(uu,kk) ** (1.0/m)
        mm = []
        for yy in stirsll(kk,m):
            if all([vol(uu,jj) <= umax for jj in yy]):
                nn = sset([sset([(ss,i) for (i,ss) in enumerate(cart(uu,jj))]) for jj in yy])
                qq = []
                for ll in prod(nn):
                    rr = sempty()
                    for (w,(ss,u)) in enumerate(ll):
                        rr = sunion(rr,sunion(ss,ssgl(VarIndex(w),ValIndex(u))))
                    qq.append(rr)
                tt = trans(unit(qq),sset([VarIndex(w) for w in range(0,m)]))
                cc = tmul(bb,tt)
                ccrr = tmul(bbrr,tt)
                a2 = sumfacln(ind(cc))
                b2 = sumfacln(ind(ccrr))
                mm.append(((nn, cc, ccrr), ((y1-a2+b2)/c, b2, -m)))
        pp.extend(topd(pmax,mm))
    return sset(pp)

For example,

def facln(x):
	return gammaln(float(x) + 1)

def sumfacln(aa):
	return sum([facln(c) for (_,c) in aall(aa)])

def partermm(aa,rr,mmax,umax,pmax):
    return [[statesSetVar([ss for (ss,i) in xx][0]) for xx in x] for (x,_,_) in parametersSystemsPartitionerMaxRollByM(mmax,umax,pmax,sys(aa),vars(aa),aa,rr,sumfacln(aa)-sumfacln(rr))]

aa = resize(1000,mul(regpivot(3,2),cdtp(regdiag(3,2),[3,4])))

rpln(partermm(aa,ind(aa),4,3**3,1))
# [{1}, {2}, {3}, {4}]
# [{1, 4}, {2}, {3}]
# [{1, 4}, {2, 3}]

rpln(partermm(aa,ind(aa),4,3**3,2))
# [{1}, {2}, {3}, {4}]
# [{1, 3}, {2}, {4}]
# [{1, 3}, {2, 4}]
# [{1, 4}, {2}, {3}]
# [{1, 4}, {2, 3}]

rpln(partermm(aa,ind(aa),3,3**3,1))
# [{1, 4}, {2}, {3}]
# [{1, 4}, {2, 3}]

rpln(partermm(aa,ind(aa),3,3**3,2))
# [{1, 3}, {2}, {4}]
# [{1, 3}, {2, 4}]
# [{1, 4}, {2}, {3}]
# [{1, 4}, {2, 3}]

rpln(partermm(aa,ind(aa),2,3**3,1))
# [{1, 4}, {2, 3}]

rpln(partermm(aa,ind(aa),2,3**3,2))
# [{1, 3}, {2, 4}]
# [{1, 4}, {2, 3}]

Tuple-partition value roller

After constructing the initial set in a tuple partitioner, $I_{P,U,\mathrm{K}}$, the remainder of the limited-valency contracted decrementing linear non-overlapping fuds list maximiser, $Z_{P,A,A_R,F,\mathrm{n,w},-,K}$, is implemented by means of value roll computers, defined in section ‘Value roll computers’. The tuple-partition value roller $I_{P,U,\mathrm{R}} \in \mathrm{computers}$ is defined such that (i) the domain is $\mathrm{domain}(I_{P,U,\mathrm{R}}) = \mathrm{P}(\mathcal{L}(\mathcal{S}_U \to \mathbf{N}) \times \mathcal{A}_U \times \mathcal{A}_U)$, (ii) the range is $\mathrm{range}(I_{P,U,\mathrm{R}}) = \mathrm{P}(\mathcal{L}(\mathcal{S}_U \to \mathbf{N}))$, and (iii) the application is (Text) \[ \begin{eqnarray} &&I_{P,U,\mathrm{R}}^{ * }(Q) = \\ &&\hspace{1em}\{N’ :\\ &&\hspace{2em}M = \{((N,R_A,R_B),(a-b)/c) : \\ &&\hspace{6em}(N,A,B) \in Q,\\ &&\hspace{6em}a=I_{\mathrm{a}}^{ * }(A),~b=I_{\mathrm{a}}^{ * }(B),\\ &&\hspace{6em}w = \prod_{(\cdot,I) \in N} |\mathrm{ran}(I)|,~m =|N|,~c = I_{\approx\mathrm{pow}}^{ * }((w,1/m)),\\ &&\hspace{6em}R_A = (a,A,I_{\mathrm{X}}^{ * }(A)),~R_B = (b,B,I_{\mathrm{X}}^{ * }(B))\}, \\ &&\hspace{2em}(N’,\cdot,\cdot) \in \mathrm{topd}(\mathrm{pmax})(\mathrm{rollb}(M,M))\} \end{eqnarray} \] where $\mathrm{rollb} \in \mathrm{rollbt} \times \mathrm{rollbt} \to \mathrm{rollbt}$, where $\mathrm{rollbt} = \mathcal{L}(\mathcal{S}_U \to \mathbf{N}) \times (\mathbf{Q} \times \mathcal{A}_U \times \mathcal{A}_U)^2 \to \mathbf{Q}$, is defined \[ \begin{eqnarray} &&\mathrm{rollb}(Q,P) = \\ &&\hspace{1em}\mathrm{if}(M \neq \emptyset, \mathrm{rollb}(M,P \cup M),P) : \\ &&\hspace{2em}M = \mathrm{top}(\mathrm{pmax})(\{((N’,R’_A,R’_B), (a’-b’)/c’) :\\ &&\hspace{4em}((N,R_A,R_B),\cdot) \in Q,\\ &&\hspace{4em}V=\mathrm{dom}(N),~(\cdot,A,A_{\mathrm{X}}) = R_A,~(\cdot,B,B_{\mathrm{X}}) = R_B,\\ &&\hspace{4em}Y_A = \mathrm{rals}(N,A,A_{\mathrm{X}}),~Y_B = \mathrm{rals}(N,B,B_{\mathrm{X}}),\\ &&\hspace{4em}(v,I) \in N,~|\mathrm{ran}(I)|>2,~s,t \in \mathrm{ran}(I),~s > t,\\ &&\hspace{4em}N’ = N \setminus \{(v,I)\} \cup \{(v,\{(s,t)\} \circ I)\},\\ &&\hspace{4em}R’_A = I_{\mathrm{R,a}}^{ * }(((V,v,s,t),Y_A,R_A)),\\ &&\hspace{4em}R’_B = I_{\mathrm{R,a}}^{ * }(((V,v,s,t),Y_B,R_B)),\\ &&\hspace{4em}(a’,\cdot,\cdot) = R’_A,~(b’,\cdot,\cdot) = R’_B,\\ &&\hspace{4em}w = \prod_{(\cdot,I’) \in N’} |\mathrm{ran}(I’)|,~m =|V|,~c’ = I_{\approx\mathrm{pow}}^{ * }((w,1/m)) \}) \end{eqnarray} \] where $I_{\mathrm{R,a}} = \mathrm{rollValueAlignmenter} \in \mathrm{computers}$ is defined as \[ \begin{eqnarray} &&I_{\mathrm{R,a}}^{ * }(((V,v,s,t), Y, (a,A,A^{\mathrm{X}})) = \\ &&\hspace{2em}(I^{ * }_{\mathrm{a}}(A * (V,v,s,t)^{\mathrm{R}}), A * (V,v,s,t)^{\mathrm{R}},(A * (V,v,s,t)^{\mathrm{R}})^{\mathrm{X}}) \end{eqnarray} \] and $\mathrm{rals} \in \mathcal{L}(\mathcal{S}_U \to \mathbf{N}) \times \mathcal{A} \times \mathcal{A} \to (\mathcal{V} \to (\mathcal{S} \to \mathbf{Q}))$ is defined as \[ \begin{eqnarray} &&\mathrm{rals}(N,A,A_{\mathrm{X}}) := \\ &&\hspace{2em}\{(w,\{(S, \sum (I_{\mathrm{\approx\mathrm{ln}!}}^{ * }(A(T)) : T \in A^{\mathrm{S}},~T \supseteq S) - \\ &&\hspace{5em}\sum (I_{\mathrm{\approx\mathrm{ln}!}}^{ * }(A_{\mathrm{X}}(T)) : T \in A_{\mathrm{X}}^{\mathrm{S}},~T \supseteq S)) : \\ & &\hspace{7em}u \in \mathrm{ran}(N_w),~S = \{(w,u)\}\}) : w \in \mathrm{dom}(N)\} \end{eqnarray} \]

The roller is defined in module AlignmentPracticable,

parametersRoller :: 
  Integer -> Set.Set ([Set.Set (State,Int)], Histogram, Histogram) -> Maybe (Set.Set [Set.Set (State,Int)])

as

def parametersRoller(pmax,qq):
    ...
    def algner(rv,yy,x):
        (a,aa,aaxx) = x
        return rollValueAlignmenter_u(rv,yy,a,aa,aaxx)
    def rals(nn,aa,aaxx):
        xx = sdict()
        for (i,ii) in enumerate(nn):
            v = VarIndex(i)
            yy = sdict()
            for (_,j) in ii:
                u = ValIndex(j)
                ss = ssgl(v,u)
                yy[ss] = sumfacln(mul(aa,unit(sgl(ss)))) - sumfacln(mul(aaxx,unit(sgl(ss))))
            xx[v] = yy
        return xx
    def rollb(qq,pp):
        mm = sdict()
        for ((nn,rraa,rrbb),_) in qq.items():
            vv = sset([VarIndex(i) for i in range(0,len(nn))])
            (_,aa,aaxx) = rraa
            (_,bb,bbxx) = rrbb
            yyaa = rals(nn,aa,aaxx)
            yybb = rals(nn,bb,bbxx)
            for (v,ii) in enumerate(nn):
                if len(ran(ii)) > 2:
                    for s in ran(ii):
                        for t in ran(ii): 
                            if s > t:
                                nn1 = sset(list(nn)[:v] + [join(ii,sgl((s,t)))] + list(nn)[v+1:])
                                rv = vvvstrv((vv, VarIndex(v), ValIndex(s), ValIndex(t)))
                                rraa1 = algner(rv,yyaa,rraa)
                                rrbb1 = algner(rv,yybb,rrbb)
                                (a1,_,_) = rraa1
                                (b1,_,_) = rrbb1
                                w = 1
                                for ii1 in nn1:
                                    w = w * len(ran(ii1))
                                m = len(vv)
                                c1 = w ** (1.0/m)
                                mm[(nn1,rraa1,rrbb1)] = (a1-b1)/c1
        mm = top(pmax,mm)
        if len(mm) > 0:
            rr = pp.copy()
            rr.update(mm)
            return rollb(mm,rr)
        return pp
    if pmax < 0:
        return None
    mm = sdict()
    for (nn,aa,bb) in qq:
        a = algn(aa)
        b = algn(bb)
        w = 1
        for ii in nn:
            w = w * len(ran(ii))
        m = len(nn)
        c = w ** (1.0/m)
        rraa = (a, aa, ind(aa))
        rrbb = (b, bb, ind(bb))
        mm[(nn,rraa,rrbb)] = (a-b)/c
    return sset([nn1 for (nn1,_,_) in topd(pmax,rollb(mm,mm))])

The roll value alignmenter is defined in module AlignmentPracticable,

rollValueAlignmenter_u :: RollValue -> Map.Map Variable (Map.Map State Double) -> Double -> Histogram -> Histogram -> 
  (Double, Histogram, Histogram) 

as

def rollValueAlignmenter_u(rv,yy,a,aa,bb):
    ...
    (_,v,s,t) = rvvvvst(rv)
    if s == t:
        return (a,aa,bb)
    (aa1,bb1) = rollValuer(rv,aa,bb)
    r1 = sumfacln(mul(aa1,unit(ssgl(v,t)))) - sumfacln(mul(bb1,unit(ssgl(v,t))))
    a1 = a - yy[v][ssgl(v,s)] - yy[v][ssgl(v,t)] + r1
    return (a1,aa1,bb1)

The roll valuer is defined in module AlignmentPracticable,

rollValuer :: RollValue -> Histogram -> Histogram -> (Histogram, Histogram) 

as

def rollValuer(rv,aa,bb):
    ...
    def rollv(v,s,t,aa):
        xx = mul(aa,unit(ssgl(v,t)))
        xx = add(xx,llaa([(sunion(sminus(ss,ssgl(v,s)),ssgl(v,t)), c) for (ss,c) in aall(mul(aa,unit(ssgl(v,s))))]))
        xx = add(xx,sub(aa,mul(aa,add(unit(ssgl(v,s)),unit(ssgl(v,t))))))
        return xx
    (_,v,s,t) = rvvvvst(rv)
    if s == t:
        return (aa, bb)
    return (rollv(v,s,t,aa), rollv(v,s,t,bb))

top