help-glpk
[Top][All Lists]

## [Help-glpk] A model which multiplies 2 positive variables.

 From: Nigel Galloway Subject: [Help-glpk] A model which multiplies 2 positive variables. Date: Tue, 29 Apr 2014 05:20:38 -0700

```Andrew,

I begin my attempt to explain my model for estimating the
square root of a variable by presenting a simpler model which
uses the same technique to multiply 2 variables. You may add
the attached model to glpk's examples.

Let us work through multiplying 13 by 5 in longhand. I shall
represent 13 as 1*2**0+0*2**1+1*2**2+1*2**3 or 1011; I shall
represent 5 as 1*2**0+0*2**1+1*2**2 or 101.

1011 * 101 can be calculated:

1011   +
0000  +
1011 =
102111 or 1*2**0+0*2**1+2*2**2+1*2**3+1*2**4+1*2**5 which
is represented as 65 in decimal.

I need a data structure to hold this calculation. In some
languages it is possible to write something like:
gn{x in 0 .. 4, y in x .. 4+x}
mathprog doesn't complain if you try this, but neither does it
produce a useful result.

I could define a data structure:
101100
000000
001011
and read the result by summing the columns but for this model
I have chosen to define:
1011
0000
1011
with the cost that the result must now be extracted by summing
the diagonals from right to left. The advantage for explaining
the solution is that if I now add a third dimension and I fill in the
front layer with 13 horizontally:
1011
1011
1011
and the rear layer with 5 vertically:
1111
0000
1111
I think that the reader will easily see that the result that
I require is the logical and of the front and rear layer. The two
rules gn3 and gn4 achieve this.

Vx, Vy, and P define the maximum size of the two variables and
the precision of the variables in decimal digits. The model is
fast so one does not need to be mean in setting them.

i1 through i8 convert the variables from decimal to the format
I have described above.

r1 extracts the result, for the model as is:

923.250000 * 123.750000 = 114252.187500

--
Nigel Galloway

--
http://www.fastmail.fm - Send your email first class

--
http://www.fastmail.fm - Does exactly what it says on the tin

``` multd.mathprog
Description: Text document