Squares

General FreeBASIC programming questions.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 04, 2020 0:38

@Richard

n1 = 8 bits input ( 1 byte )
n2 = "1" + mid( n1 , 3 ) + left( n1 , 2 ) , = 9 bits output ( 256 + )
n2 = bin( val( "&B" + n2 ) OR 384 )

The ( n2 OR 384 ) you mentioned , compressed by 100,000 bytes to 53% after 100 loops,
The ( n2 AND 127 ) you mentioned , only compresses 100,000 bytes by 2.4% after 100 loops..

How would you undo it??
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Jul 04, 2020 0:52

albert wrote:How would you undo it??
You can't undo destruction.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 04, 2020 1:07

@Richard

You told me that ( n2 OR 384 ) would return the number , and include the top 2 bits.. the 128 bit , and the 256 bit..

Now your saying , "it can't be done" ? "You can't undo destruction."
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Jul 04, 2020 1:27

albert wrote:@Richard
You told me that ( n2 OR 384 ) would return the number , and include the top 2 bits.. the 128 bit , and the 256 bit..
Now your saying , "it can't be done" ? "You can't undo destruction."
I thought you asked how to set a bit if you knew it was a one.

In the real world, time goes in one direction only.
If you destroy something by deleting bits of it, you can't expect to repair it by winding the clock back.
Can you "un-swat" a fly, or "un-destroy" a vehicle written off in a collision ?
Can you go back in time to "un-clog" your arteries and lower your blood pressure, by giving up smoking and drinking before you originally began ?
Will you get all the years back that you wasted seeking infinite compression, once you realise it is quite impossible ?
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 04, 2020 2:13

@Richard

n1 = bin( *ubp ) : ubp+=1

if len( n1 ) < 5 then n2 = n1 : map+= "0"

if len( n1 ) > 4 and len( n1 ) < 8 then n2 = "1" + mid( n1 , 3 ) + left( n1 , 2 ) : map+= "1" , = ( 6 , 7 , 8 bits )

if len( n1 ) = 8 then
n2 = "1" + mid( n1 , 3 ) + left( n1 , 2 ) , = ( 9 bits )
map+="1"
end if

outs1+= chr( val( "&B" + n2 ) )

With both the 5-7 bit , and 8 bit , maps = "1" then it compresses 97% after 100 loops.. if you make the two maps different , it expands....go figure!!

I think the Zlib , has AI built-in to foil compression attempts!!!

One bit makes the difference between mass compression and mass expansion....
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 04, 2020 2:46

!!~~OFF TOPIC~~!!

With the whole world hopping on to the "Black Live Matter" protests..

For "Black Lives Matter" U.S.A.

I've arrived at a solution....
Each county in every U.S. state , creates a non-police ( IG ) Inspector General office to investigate police misconduct...

The IG office would be separate from the police so their would be no fellowship.. to get in the way..

The IG office would investigate..

1. police use of weapons ( batons , tasers , firearms , tear gas , pepper spray )
2. police theft of evidence ( drugs , weapons , cash , personal property )
3. police negligence for not providing ( beds , soap , razors , paper , pencils , envelopes , clean linens , clean uniforms , deoderant , shampoo , food , etc.. )

The IG office would have powers to fire and prosecute , city police , Sheriff's deputies , Highway Patrol , State police and even elected County Sheriff's...

It would create a fair and just policing... And ensure that all abusive police entities are eradicated from the police forces...

!!!! Power To The People !!!!
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Jul 04, 2020 4:04

Albert wrote:I think the Zlib , has AI built-in to foil compression attempts!!!
Zlib does not need to use AI, it can rely on your paranoia.
Zlib identifies and compresses duplicates.
Once that has been done there is no more compression possible.
If Zlib output could be further compressed, then Zlib would have done it.

Albert wrote:One bit makes the difference between mass compression and mass expansion....
The problem is that you insist on destroying that bit, and all the bits that follow, then call it compression. But you have more than one bit, so if you compress a byte you will have to correctly guess all 8 bits. There are 2^8 = 256 possibilities, the chance of guessing it right is 1/256 = 0.39%. You may as well give up and admit that it is impossible.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 04, 2020 17:43

@Richard

if len( n1 ) = 8 then
n2 = mid( n1 , 3 ) + left( n1 , 2 )
if left( n2 , 1 ) = "1" then map+= "1"
n2 = bin( val( "&B" + n2 ) mod 128 )
map+= "11"
end if

Is there a way to undo the MOD 128 ?? ( I'm not understanding how the MOD works... )

The map "11" = 8 bits...
If n2 starts with a "1" then the map = "111" else it equals "0" ( <=6 bits ) or "10" ( =7 bits )

Or , is there another logic that would work , instead of the MOD


n2 = mid( n1 , 3 ) + left( n1 , 2 ) <-- compresses
n2 = mid( n1 , 2 ) + left( n1 , 1 ) <-- expands
n2 = mid( n1 , 4 ) + left( n1 , 3 ) <-- expands
Etc.. expands...
Only 3 , 2 compresses... Like looking for a needle in a hay stack....
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Jul 04, 2020 22:27

Albert wrote:Is there a way to undo the MOD 128 ?? ( I'm not understanding how the MOD works... )
MOD destroys the most significant part of an integer, and just keeps the remainder.
Real programmers know that MOD is the remainder left after an integer divide.
There is no way of reversing MOD, unless the result of the integer divide “\” has also been kept.

The result of an integer divide; d = a \ b
And the remainder of the same; r = a MOD b
Can only be restored by; a = ( b * d ) + r

You need to experiment with integer \ and MOD in very simple code until you understand them.
You should not use a math function until you understand the math behind it.

@albert, you are drowning because you are out of your depth when it comes to simple math.
You should not use a math function until you really understand the math behind it.
You should not be posting code on this forum unless it works, and you cannot explain how and why it works.
The moderators have made that very clear to you. I expect they are about to ban you again.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 04, 2020 23:54

@Richard

The moderators didn't mind , my lack of understanding trigonometry..
When i posted 100's of fumbling trig doodles..

All the trig doodles i posted , were just an amature playing around with trig functions , i don't understand...

I never took advanced math classes in high school , just general math..

So i need help with advanced math functions..
I need someone who understands math , to look over my compression codes..
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 05, 2020 0:07

@Richard

I found a snafu of sorts... In my code..

if len( n1 ) = 8 then
n2 = mid( n1 , 3 ) + left( n1 , 2 )
if left( n2 , 1 ) = "1" then map+= "1"
n2 = bin( val( "&B" + n2 ) mod 128 )
map+= "11"
end if

Since 8 bit values happen 50% of the time.. it's possible for several 8 bits values to follow each other..

Thus:
if left( n2 , 1 ) = "1" then map+= "1" <-- ensures that the leading 1 ( 8'th bit ) in mod 128 is preserved..
map+= "11"

With 2 , 8 bit values following each other:

map could be 11 or 111 or 111-11 or 11-111 or 111-111
I need to alter the map output , so there are no possibilities of equating runs..
Richard
Posts: 3030
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Jul 05, 2020 8:17

albert wrote:@Richard
I found a snafu of sorts... In my code..

That is your problem.
Go away, and don't come back until you have studied math.
coderJeff
Site Admin
Posts: 3316
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Squares

Postby coderJeff » Jul 05, 2020 12:18

Albert, as moderator, I don't mind your lack of understanding. What I do mind, and what results in your temporary ban, is that you ask the same question over and over even though it's been answered over and over. If you have no other question to ask, then just take the answers at face value that compression of random data is impossible.

If I can also be at the same time just another forum member ...
A few years ago, I wrote an implementation of LZW compression/decompression in C. Not so much that I was interested in compression. More so that the patent expired and I wanted to see what the fuss was about. End result firmly cemented my dislike for software patents. (Maybe I'll post it, but can't promise that I can find it now, as I believe it is buried on an old ZIP disk, possibly lost forever if I can't find a ZIP drive to read it. Ironic?)

Anyway, I didn't really need to know the maths to write an implementation. However, combination of studying maths and studying an already working algorithm is very useful to deeper understanding. I never really studied set theory but I can kind of make my way through a paper about compression that uses set theory because of the maths I have studied, plus examining a working implementation.

Bottom line: if you can't understand the subject, or worse, not even willing to ask yourself why or what you don't understand, then it just might not be the thing for you. There are some really smart people on this forum. You should just listen to them.
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 06, 2020 0:53

Richard said "The only way to compress data , is to look for patterns."

A random string "AFETHUNIOPLKM"

There are no patterns to search for...
Each element , is different from the others , and their all jumbled together..

You can't look for patterns in random data..

You have to ( resort to ) , manipulating the element values.. by ( add , sub , mul , div , or , xor , and , imp , eqv ) or some combinations of them..
or shorting the binary value by removing the leading "1" : with a map.
or shorting the binary value by rtrim ( "0" or "1" ) : with a map.

ltrim ( "1" ) works , but you don't know how many leading 0's are left , if you turn the leading 0 into a 1 with a map , it expands the final output..

In most cases where you use a map , the map expands the final output...
albert
Posts: 5916
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Jul 06, 2020 2:12

I found a formula that seems to work , LTRIM( n1 , "1" )

===================================
n1 = bin( *ubp ) : ubp+=1

v1 = instr( 1 , n1 , "0" )

if v1 < 4 then
map+= right( "00" + bin( v1 ) , 2 )
n1 = ltrim( n1 , "1" )
else
map+= "00"
end if

outs1+= chr( val( "&B" + n1 ) )
===================================

Compresses 1,000,000 bytes by 65% after 100 loops.. Takes 134 seconds though ( way to slow!! )
100,000 bytes and under , doesn't compress...
200,000 compresses by 41% after 100 loops...

Do i have an error somewhere????

Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests