Assembing a Rational Number from Constituent Digit Vectors Relative to a Given Base

The Set-up

The given vectors are u, v, w, and the given base is b. In each case the subscripts on the coordinates of the digit vectors increase from left to right. For example, in base 10 if

 u  =  [3, 6]  ,     v  =  [5, 4] ,      and     w  =  [1, 2]  , 

then the indicated decimal expansion is

 36.5412121212…  , 

and its representation as a quotient of coprime integers is

 {60293}/{1650}    . 

Formulas:

 result  =  r + s + t      where

r  
 = 
SUM_{j = 1}^{k}[u_{j} b^{k-j} ]
s
 = 
SUM_{j = 1}^{l}[v_{j} b^{-k}  ]
t1
 = 
SUM_{j = 1}^{m}[w_{j} b^{m-j} ]
t2
 = 
(b^{l})(b^{m} - 1)
t
 = 
t1/t2

with

  k  =  length(u)          l  =  length(v)          m  =  length(w)     .

Exercise

Raise issues you find with the following code proposed for the task:

ratFromVecs := proc (u, v, w) local b, r, s, t, j, k, l, m, c1, c2, n;
u := [u[1],...,u[k]];
v := [v[1],...,v[l]];
w := [w[1],...,w[m]];
k := nops(u);
l := nops(v);
m := nops(w);
r := sum('u[j]*b^(k-j)', 'j' = (1 .. k));
s := Sum('v[j]*b^(-j)', 'j' = (1 .. l));
t1 := sum('w[j]*b^(m-j)', 'j' = (1 .. m));
t2 := b^l*(b^m-1);
t := t1/t2;
for j to k do n := r+s+t; end do;
n;
end;