diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..615d64b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Django PowerTools cache (generated) +/djangoPowerTools/ diff --git a/.idea/DataCompression.iml b/.idea/DataCompression.iml new file mode 100644 index 0000000..2455e85 --- /dev/null +++ b/.idea/DataCompression.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f5b713b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bbc1ed0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Counting/Counting.py b/Counting/Counting.py new file mode 100644 index 0000000..928cd82 --- /dev/null +++ b/Counting/Counting.py @@ -0,0 +1,42 @@ +import logging +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s - %(levelname)s - %(message)s', + handlers=[ + logging.FileHandler('arithmetic_coding.log'), + logging.StreamHandler() + ] +) +dict={ + "A":[0,0.1], + "R":[0.1,0.2], + "I":[0.2,0.4], + "T":[0.4,0.6], + "H":[0.6,0.7], + "M":[0.7,0.8], + "E":[0.8,0.9], + "C":[0.9,1], +} + +def count(word): + low = 0.0 + high = 1.0 + + for char in word: + if char not in dict: + raise ValueError(f"Character '{char}' not in probability dictionary") + + # Calculate new range + range_ = high - low + new_low = low + dict[char][0] * range_ + new_high = low + dict[char][1] * range_ + + # Update range + low, high = new_low, new_high + print(f'({low:.15f}, {high:.15f})') + logging.info(f" Range updated to: [{new_low:.15f}, {new_high:.15f}] (width: {new_high-new_low:.15f})") + # Return the final range + return (low + high) / 2 + +if __name__ == "__main__": + count("ARITHMETIC") diff --git a/Counting/Snipaste_2025-10-23_13-01-54.png b/Counting/Snipaste_2025-10-23_13-01-54.png new file mode 100644 index 0000000..7614398 Binary files /dev/null and b/Counting/Snipaste_2025-10-23_13-01-54.png differ diff --git a/Counting/__init__.py b/Counting/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Counting/arithmetic_coding.log b/Counting/arithmetic_coding.log new file mode 100644 index 0000000..d237912 --- /dev/null +++ b/Counting/arithmetic_coding.log @@ -0,0 +1,78 @@ +2025-10-23 12:57:16,149 - INFO - Starting arithmetic coding for word: ARITHMETIC +2025-10-23 12:57:16,149 - INFO - Processing character 1/10: 'A' (range: [0.0000, 0.1000]) +2025-10-23 12:57:16,149 - INFO - Range updated to: [0.000000000000000, 0.100000000000000] (width: 0.100000000000000) +2025-10-23 12:57:16,149 - INFO - Processing character 2/10: 'R' (range: [0.1000, 0.2000]) +2025-10-23 12:57:16,149 - INFO - Range updated to: [0.010000000000000, 0.020000000000000] (width: 0.010000000000000) +2025-10-23 12:57:16,149 - INFO - Processing character 3/10: 'I' (range: [0.2000, 0.4000]) +2025-10-23 12:57:16,149 - INFO - Range updated to: [0.012000000000000, 0.014000000000000] (width: 0.002000000000000) +2025-10-23 12:57:16,171 - INFO - Processing character 4/10: 'T' (range: [0.4000, 0.6000]) +2025-10-23 12:57:16,171 - INFO - Range updated to: [0.012800000000000, 0.013200000000000] (width: 0.000400000000000) +2025-10-23 12:57:16,171 - INFO - Processing character 5/10: 'H' (range: [0.6000, 0.7000]) +2025-10-23 12:57:16,171 - INFO - Range updated to: [0.013040000000000, 0.013080000000000] (width: 0.000040000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 6/10: 'M' (range: [0.7000, 0.8000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013068000000000, 0.013072000000000] (width: 0.000004000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 7/10: 'E' (range: [0.8000, 0.9000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071200000000, 0.013071600000000] (width: 0.000000400000000) +2025-10-23 12:57:16,172 - INFO - Processing character 8/10: 'T' (range: [0.4000, 0.6000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071360000000, 0.013071440000000] (width: 0.000000080000000) +2025-10-23 12:57:16,172 - INFO - Processing character 9/10: 'I' (range: [0.2000, 0.4000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071376000000, 0.013071392000000] (width: 0.000000016000000) +2025-10-23 12:57:16,172 - INFO - Processing character 10/10: 'C' (range: [0.9000, 1.0000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.013071390400000, 0.013071392000000] (width: 0.000000001600000) +2025-10-23 12:57:16,172 - INFO - Final result for 'ARITHMETIC': 0.013071391200000 +2025-10-23 12:57:16,172 - INFO - -------------------------------------------------- +2025-10-23 12:57:16,172 - INFO - Starting arithmetic coding for word: MATH +2025-10-23 12:57:16,172 - INFO - Processing character 1/4: 'M' (range: [0.7000, 0.8000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.700000000000000, 0.800000000000000] (width: 0.100000000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 2/4: 'A' (range: [0.0000, 0.1000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.700000000000000, 0.710000000000000] (width: 0.010000000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 3/4: 'T' (range: [0.4000, 0.6000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.704000000000000, 0.706000000000000] (width: 0.002000000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 4/4: 'H' (range: [0.6000, 0.7000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.705200000000000, 0.705400000000000] (width: 0.000200000000000) +2025-10-23 12:57:16,172 - INFO - Final result for 'MATH': 0.705300000000000 +2025-10-23 12:57:16,172 - INFO - -------------------------------------------------- +2025-10-23 12:57:16,172 - INFO - Starting arithmetic coding for word: RICE +2025-10-23 12:57:16,172 - INFO - Processing character 1/4: 'R' (range: [0.1000, 0.2000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.100000000000000, 0.200000000000000] (width: 0.100000000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 2/4: 'I' (range: [0.2000, 0.4000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.120000000000000, 0.140000000000000] (width: 0.020000000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 3/4: 'C' (range: [0.9000, 1.0000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.138000000000000, 0.140000000000000] (width: 0.002000000000000) +2025-10-23 12:57:16,172 - INFO - Processing character 4/4: 'E' (range: [0.8000, 0.9000]) +2025-10-23 12:57:16,172 - INFO - Range updated to: [0.139600000000000, 0.139800000000000] (width: 0.000200000000000) +2025-10-23 12:57:16,172 - INFO - Final result for 'RICE': 0.139700000000000 +2025-10-23 12:57:16,172 - INFO - -------------------------------------------------- +2025-10-23 12:57:54,803 - INFO - Starting arithmetic coding for word: ARITHMETIC +2025-10-23 12:57:54,804 - INFO - Processing character 1/10: 'A' (range: [0.0000, 0.1000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.000000000000000, 0.100000000000000] (width: 0.100000000000000) +2025-10-23 12:57:54,804 - INFO - Processing character 2/10: 'R' (range: [0.1000, 0.2000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.010000000000000, 0.020000000000000] (width: 0.010000000000000) +2025-10-23 12:57:54,804 - INFO - Processing character 3/10: 'I' (range: [0.2000, 0.4000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.012000000000000, 0.014000000000000] (width: 0.002000000000000) +2025-10-23 12:57:54,804 - INFO - Processing character 4/10: 'T' (range: [0.4000, 0.6000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.012800000000000, 0.013200000000000] (width: 0.000400000000000) +2025-10-23 12:57:54,804 - INFO - Processing character 5/10: 'H' (range: [0.6000, 0.7000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013040000000000, 0.013080000000000] (width: 0.000040000000000) +2025-10-23 12:57:54,804 - INFO - Processing character 6/10: 'M' (range: [0.7000, 0.8000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013068000000000, 0.013072000000000] (width: 0.000004000000000) +2025-10-23 12:57:54,804 - INFO - Processing character 7/10: 'E' (range: [0.8000, 0.9000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071200000000, 0.013071600000000] (width: 0.000000400000000) +2025-10-23 12:57:54,804 - INFO - Processing character 8/10: 'T' (range: [0.4000, 0.6000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071360000000, 0.013071440000000] (width: 0.000000080000000) +2025-10-23 12:57:54,804 - INFO - Processing character 9/10: 'I' (range: [0.2000, 0.4000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071376000000, 0.013071392000000] (width: 0.000000016000000) +2025-10-23 12:57:54,804 - INFO - Processing character 10/10: 'C' (range: [0.9000, 1.0000]) +2025-10-23 12:57:54,804 - INFO - Range updated to: [0.013071390400000, 0.013071392000000] (width: 0.000000001600000) +2025-10-23 12:57:54,804 - INFO - Final result for 'ARITHMETIC': 0.013071391200000 +2025-10-23 12:57:54,804 - INFO - -------------------------------------------------- +2025-10-23 13:01:05,602 - INFO - Range updated to: [0.000000000000000, 0.100000000000000] (width: 0.100000000000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.010000000000000, 0.020000000000000] (width: 0.010000000000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.012000000000000, 0.014000000000000] (width: 0.002000000000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.012800000000000, 0.013200000000000] (width: 0.000400000000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013040000000000, 0.013080000000000] (width: 0.000040000000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013068000000000, 0.013072000000000] (width: 0.000004000000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071200000000, 0.013071600000000] (width: 0.000000400000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071360000000, 0.013071440000000] (width: 0.000000080000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071376000000, 0.013071392000000] (width: 0.000000016000000) +2025-10-23 13:01:05,603 - INFO - Range updated to: [0.013071390400000, 0.013071392000000] (width: 0.000000001600000)