"""Exact half-open shard occupancy; synthetic arithmetic, not device reliability.""" from collections import Counter from fractions import Fraction import json def count_symbols(start, length): if not isinstance(start, Fraction) or not isinstance(length, Fraction): raise TypeError("Use exact Fraction coordinates in symbol units") if start < 0 or length <= 0: raise ValueError("Start must be nonnegative and length positive") end = start + length return -(-end.numerator // end.denominator) - start.numerator // start.denominator def periodic_counts(length, offset): if not isinstance(length, Fraction) or not isinstance(offset, Fraction): raise TypeError("Use Fraction coordinates") if not 0 <= offset < 1 or length <= 0: raise ValueError("Require positive length and an offset in [0, 1)") return dict(sorted(Counter(count_symbols(offset+i*length, length) for i in range(length.denominator)).items())) def lattice_mean(length_units, units_per_symbol): if type(length_units) is not int or type(units_per_symbol) is not int: raise TypeError("Use integer grid sizes") if length_units <= 0 or units_per_symbol <= 0: raise ValueError("Grid sizes must be positive") return Fraction(length_units+units_per_symbol-1, units_per_symbol) def entity_loss(sizes, lost): """Whole-entity effective loss for a fixed inventory, not damaged-byte count.""" if not isinstance(sizes, (list, tuple)) or not sizes: raise ValueError("Supply a nonempty fixed entity inventory") if any(type(size) is not int or size <= 0 for size in sizes): raise ValueError("Entity sizes must be positive integer bytes") ids = list(lost) if any(type(i) is not int or not 0 <= i < len(sizes) for i in ids): raise ValueError("Lost entity IDs must be valid integer inventory positions") unique = set(ids) return { "lostEntities": len(unique), "totalEntities": len(sizes), "effectiveLostBytes": sum(sizes[i] for i in unique), "totalBytes": sum(sizes), "entityFraction": str(Fraction(len(unique), len(sizes))), "effectiveByteFraction": str(Fraction(sum(sizes[i] for i in unique), sum(sizes))), } def observations(): return { "entityLossExamples": [ {"case": "Lose the 1-byte object", **entity_loss([1, 999], [0])}, {"case": "Lose the 999-byte object", **entity_loss([1, 999], [1])}, ], "scope": "Half-open intervals [start, end), positive-length overlap; exact synthetic arithmetic", "symbolUnits": "rational positions, no physical byte or time rate assumed", "length23over10": { "offset1over20": periodic_counts(Fraction(23,10), Fraction(1,20)), "offset1over10": periodic_counts(Fraction(23,10), Fraction(1,10)), }, "length3over10": { "offset1over20": periodic_counts(Fraction(3,10), Fraction(1,20)), "offset1over10": periodic_counts(Fraction(3,10), Fraction(1,10)), }, "uniform10PositionGridMean23over10": str(lattice_mean(23,10)), "continuousUniformOffsetMean23over10": str(Fraction(23,10)+1), "limitations": [ "Not a replication of the paper's reliability curves or device experiment.", "Exact boundary contacts occupy no positive length in this model.", "Uniform grid offsets are an explicit alternative assumption, not observed tape placement." ] } if __name__ == "__main__": print(json.dumps(observations(), indent=2, sort_keys=True))