Possible problem with assign( function?

I started this thread just over a year ago. Dave has cleverly provide a solution to my original problem of import() within the assign( function and to one raised by John Bovenmyer. I now have another which is much more complex and I just can’t get my head around it. I have this code:

ArrayFilter arrayreverse(DividendArray,";"),DividendArray,";",pattern(val(import()) - Carry - val(array(ProductArray,L - seq(),";"))
    + 1000000 * assign(?(val(import()) - Carry - val(array(ProductArray,L - seq(),";")) < 0,1,0), "Carry"),"######")

and I’d like to use Dave’s idea of replacing the assign with an array element but I keep tripping over. Can you please help out again Dave?

I didn’t replace the assign with an array element. I replaced import() with the array element. Since the array you are filtering here is the reverse of DividendArray, I think it would be best to reverse it first, and then do the arrayfilter.

DividendArray = arrayreverse(DividendArray,";")
ArrayFilter DividendArray,DividendArray,";",pattern(val(array(DividendArray,seq(),";")) - Carry - val(array(ProductArray,L - seq(),";"))
    + 1000000 * assign(?(val(array(DividendArray,seq(),";")) - Carry - val(array(ProductArray,L - seq(),";")) < 0,1,0), "Carry"),"######")

And I have another statement:

ArrayFilter DivisorArray,ProductArray,";", pattern(QuotDigit * float(val(import())) + val(Carry),"######")[-6;6]
 + assign(pattern(QuotDigit * float(val(import())) + val(Carry),"######")[1,-7], "Carry")[1,0]

which I replaced with:

    ArrayFilter DivisorArray,ProductArray,";", pattern(QuotDigit * float(val(import())) + val(Carry),"######")[-6;6]
     + assign(pattern(QuotDigit * float(val(array(DivisorArray,seq(),";"))) + val(Carry),"######")[1,-7],"Carry")[1,0]

but I get very wrong results - does my amendment look right to you?

Your amendment looks correct. It looks like there is another bug associated with assign( and arrayfilter. When I tried it, it appeared that the assignment to the Carry variable was taking place prematurely during the first execution of the formula. Carry had been preset to “”, but the value of the assign( function was used instead, even though the assign( function doesn’t appear until later in the formula. For subsequent array elements, the value of the previous assign( function was used, as it should be.

This was my test.

local DivisorArray,ProductArray,QuotDigit,Carry
QuotDigit = 1000
Carry = ""
DivisorArray = "123456;891230;456789"

ArrayFilter DivisorArray,ProductArray,";", pattern(QuotDigit * float(val(import())) + val(Carry),"######")[-6;6]
     + assign(pattern(QuotDigit * float(val(array(DivisorArray,seq(),";"))) + val(Carry),"######")[1,-7],"Carry")[1,0]
A = ProductArray+";"+Carry

The result it returned was

456123;230123;789891;456

The correct result would be

456000;230123;789891;456

I got the correct result by changing the first val(Carry) to ?(seq()>1,val(Carry),0). That shouldn’t have been necessary.

On a side note, I see a couple of ways your code could be made more efficient in Panorama X.

Since Panorama X uses 64 bit integers, you don’t need to use floating point to get the precision you are after. 64 bit integers can easily handle the product of two, 6 digit decimal integers.

Your carry doesn’t need to be text. Instead of

pattern(QuotDigit * float(val(array(DivisorArray,seq(),";"))) + val(Carry),"######")[1,-7]

you could use

(QuotDigit * val(array(DivisorArray,seq(),";")) + Carry)\1000000

and then val(Carry) would be Carry in both places where it occurs.

Will you lodge a BitBucket entry for this?

Thanks for all your help on this - I suspect you remember it from several years back. Unfortunately, there is a minor fault in either my logic or my programming and the results are always out by a small but significant amount so I’ve gone back to an earlier, much clumsier implementation which works perfectly. I don’t have time to do any better than that at this stage - I may return to it.