1. ## Reversing an calculation

Hello.

I've ran into a problem reversing a calculation I'm doing. I'm not sure if this is solvable but I figure if there's a way to move forward there must be a way to move backwards too.

here are the constraints
 b1=1+v4, b2=1+v3, b3=1+v2, b4=1+v1, if b1=b4 then b4=0 if b1=b3 then b3=0 if b1=b2 then b2=0 if b2=b4 then b4=0 if b2=b3 then b3=0 if b3=b4 then b4=0

So say for example I started with
v4 = 70
v3 = 00
v2 = 00
v1 = 00

b1 = v4 + 1 = 70 + 1 = 71
b2 = v3 + 1 = 01
b3 = v2 + 1 = 01
b4 = v1 + 1 = 01

Now b2 = b3 = b4 so b3 and b4 now = 00

So results for the calculation is b1 = 71, b2 = 01, b3 = 00, b4 = 00.

The problem sets in when I need to reverse this. assuming I have no other information except the end value of b1 = 71, b2 = 01, b3 = 00, b4 = 00

now b1 - 1 = v4
v4 = 71 - 1 = 70

if b2 = 0 then b2 must be = to b1, b2 is not 0, therefore b2 -1 = v3, 01 -1 = 00 = v3.

So far so good nothing complicated but then..

when I get to b3 and b3 = 00, for b3 to = 00 either b1 = b3, or b2 = b3, therefore v2 is either 70 or 00 and this is where I'm stuck

what I need is to reverse it back into its original form of 70 00 00 00 (assuming I don't know what the original form looks like) but since starting from b3 onwards there's more than 1 answer I'm completely stuck. also consider than b4 is also dependent on b3.

there can't be b2 if b1 is 0
there can't be a b3 if b2 is 0
there can't be b4 if b3 is 0

ie it's hierarchical.

any help would be much appreciated.

2. ## Re: Reversing an calculation

Hey Lilstormcloud.

Because you have multiple conditions that can be met, it means that if you meet multiple conditions then you will set multiple things to zero and thus lose information.

If you want to avoid this you will need to restrict the number of zeroing operations to such that you can actually reverse the computation.

This will involve looking at all combinations of zero operations and structuring the if statements so that the maximum number of zero operations for a given permutation is set. Otherwise you will lose information.

3. ## Re: Reversing an calculation

Cool Thanks, I thought as much. the problem is those constraints weren't set by me I actually just use them to convert an ID into a usable format then use it to match and retrieve another set of IDs which I then have to convert back in order to use. I guess more information is required so I'll go digging around and perhaps find out why those conditions are required, perhaps the total of v1+v2+v3+v4 has to equal some predefined maximum number. In any case I really appreciate the fast reply, thanks .

anyone know how I change this thread to [solved]?