Information Density
Category: Information Density v0.12 result: C# narrowly wins (0.98x Calor/C# across 217 programs) What it measures: Semantic elements per token
Overview
The Information Density metric measures how much semantic content is packed into each token. Higher density means more meaning per token.
Why It Matters
Not all tokens carry equal semantic weight:
publiccarries visibility information{carries only structural information§E{cw}carries effect information
Languages that pack more meaning into fewer tokens use context windows more efficiently.
How It's Measured
Semantic Elements Counted
Calor elements:
| Element | What it represents |
|---|---|
Modules (§M{) | Namespace/module |
Functions (§F{) | Function definition |
Variables (§B{) | Variable binding |
Type annotations (§I{, §O{) | Type information |
Contracts (§Q, §S) | Preconditions/postconditions |
Effects (§E{) | Side effect declarations |
Control flow (§IF, §L) | Branches and loops |
Expressions (§C{, operators) | Computations |
C# elements (via Roslyn):
| Element | What it represents |
|---|---|
| Namespaces | Namespace declarations |
| Methods | Function definitions |
| Constructors | Constructor definitions |
| Variables | Variable declarations |
| Parameters | Function parameters |
| Type annotations | Type syntax nodes |
| Control flow | If/for/while/switch |
| Expressions | Invocations, binary ops |
Density Calculation
Density = TotalSemanticElements / TokenCountHigher density = more semantic content per token.
Why C# Narrowly Leads
1. Implicit Information
C# encodes information implicitly:
public static int Add(int a, int b) => a + b;This single line conveys:
- Visibility (public)
- Static binding
- Return type (int)
- Two parameters with types
- Expression body
Calor equivalent:
§F{f001:Add:pub}
§I{i32:a}
§I{i32:b}
§O{i32}
§R (+ a b)Same semantics, but spread across more tokens.
2. Indent Form Eliminates Most Closing Tags
In v0.12 indent form, every structural block (§M{…}, §F{…}, §CL{…}, …)
is terminated by dedent, so no structural closer is written. Current authored
source uses only §/C for call argument lists and §/LAM for block lambdas.
C# closing braces (}) carry minimal semantic weight but are still counted as tokens.
3. Effect Information is "Extra"
Calor's effect declarations add semantic content that C# doesn't have:
§E{cw,fs:r,net:rw} // 3+ semantic elementsBut C# has no equivalent, so it doesn't get penalized for missing this information.
Detailed Breakdown
Example: FizzBuzz
Calor:
§M{m001:FizzBuzz}
§F{f001:Main:pub}
§O{void}
§E{cw}
§L{for1:i:1:100:1}
§IF{if1} (== (% i 15) 0) → §P "FizzBuzz"
§EI (== (% i 3) 0) → §P "Fizz"
§EI (== (% i 5) 0) → §P "Buzz"
§EL → §P i| Element Type | Count |
|---|---|
| Module | 1 |
| Function | 1 |
| Output type | 1 |
| Effect | 1 |
| Loop | 1 |
| Conditionals | 4 |
| Expressions | 4 |
| Total | 13 |
Tokens: ~80 Density: 13/80 = 0.16
C#:
for (int i = 1; i <= 100; i++)
{
if (i % 15 == 0) Console.WriteLine("FizzBuzz");
else if (i % 3 == 0) Console.WriteLine("Fizz");
else if (i % 5 == 0) Console.WriteLine("Buzz");
else Console.WriteLine(i);
}| Element Type | Count |
|---|---|
| For statement | 1 |
| Variable decl | 1 |
| If statements | 4 |
| Method calls | 4 |
| Binary exprs | 7 |
| Total | 17 |
Tokens: ~50 Density: 17/50 = 0.34
Ratio: 0.16/0.34 = 0.47x
Sub-Metrics
The calculator provides detailed breakdowns:
Overall Density
Total semantic elements / total tokens
Type Density
Type annotations / total tokens
Contract Density
Contract elements / total tokens
Effect Density
Effect declarations / total tokens
Interpretation Nuance
The v0.12 ratio is 0.98x, so the aggregate difference is small. Its meaning still depends on what the calculator counts:
Calor's "Extra" Semantics
Calor includes semantic elements C# doesn't have:
- Explicit effects
- First-class contracts
- Optional explicit structural IDs
These are counted as semantic elements but have no C# equivalent.
Quality vs Quantity
Information density measures quantity of semantic content per token, not quality or usefulness.
Calor's explicit effects might be more valuable for agent reasoning than multiple C# type annotations, even if effects contribute fewer semantic elements.
When Density Matters Less
Low density is acceptable when:
- Explicitness has value - Contracts, effects worth the tokens
- Comprehension matters - Clear structure aids understanding
- Context is available - Large context windows reduce pressure
- Precision is needed - IDs enable precise targeting
The Tradeoff
This metric captures Calor's fundamental tradeoff:
| Approach | Density | Explicitness |
|---|---|---|
| C# | Slightly higher in the v0.12 corpus | More implicit |
| Calor | Slightly lower in the v0.12 corpus | More explicit |
Calor deliberately trades density for explicitness.
Improving Calor's Density
Potential improvements (with tradeoffs):
- Shorter tags -
§Fcould become@F(less distinctive) - Remove IDs - Skip unique identifiers (lose precision)
Note: Phase 4 already eliminated explicit closing tags via indent form (block boundaries are signalled by dedent), so the previous "implicit closing" suggestion has been realized.
Summary
The 0.98x result is the only C# win in the current eight-metric dashboard. It is a near-parity result for this specific semantic-elements-per-token definition, not a general measure of code quality.