HP Forums
(49G) Shortest Integer Linear Combination of Two Vectors - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49G) Shortest Integer Linear Combination of Two Vectors (/thread-4435.html)



(49G) Shortest Integer Linear Combination of Two Vectors - Gerald H - 07-26-2015 10:34 AM

For input of two conformable vectors the programme returns a shortest integer linear combination.(A small problem of English - the indefinite article in the previous sentence seems awkward.)

eg For input

[ 6 26 38 146 ]

[ 35 49 77 462 ]

the programme returns

[ 17 -29 -37 24 ]

Code:

::
  CK2&Dispatch
  BINT68
  ::
    FPTR2 ^CKSAMESIZE
    NcaseSIZEERR
    FPTR2 ^PUSHFLAGS_
    "   Min Non-Zero Z-Linear Comb"
    DispCoord1
    SetDA3Temp
    FPTR2 ^SETEXACT
    FPTR2 ^QpiArry
    SWAP
    FPTR2 ^QpiArry
    OVERDUP
    FPTR2 ^XYext
    OVERDUP
    FPTR2 ^XYext
    2DUP
    Z<
    IT
    ::
      SWAP4ROLL
      3UNROLL
    ;
    BEGIN
    4PICK
    4PICK
    FPTR2 ^XYext
    2DUPSWAP
    FPTR2 ^QDiv
    Z1_
    Z2_
    FPTR2 ^NDXFext
    FPTR2 ^QAdd
    FPTR2 ^FXNDext
    FPTR2 ^ZQUOText
    4PICKOVER
    4ROLL
    FPTR2 ^QMul
    DUP
    FPTR2 ^QAdd
    FPTR2 ^QSub
    OVER
    FPTR2 ^ZSQ_
    4PICK
    FPTR2 ^QMul
    FPTR2 ^QAdd
    DUP
    4PICK
    Z>=
    ITE
    TRUE
    ::
      6ROLL
      ROT
      6PICK
      FPTR2 ^SCL*MAT
      FPTR2 ^MAT-
      4UNROLLROT
      DROPFALSE
    ;
    UNTIL
    6ROLL
    5DROP
    FPTR2 ^POPFLAGS_
  ;
;