EEvencrest
Workflows

Coding workflows · Exact uncorrected Gini coefficient

03
Built around your work

A concrete starting point

Return an exact uncorrected Gini fraction for 1–4096 nonnegative integer counts bounded by 10^9. Test equal counts, permutations and all-zero input, defining zero for the latter and rejecting Boolean values without making fairness judgments.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Exact uncorrected Gini coefficient

A concrete starting point
from fractions import Fraction

def gini_fraction(values):
    if type(values) is not list or not 1 <= len(values) <= 4096 or any(type(x) is not int or not 0 <= x <= 10**9 for x in values):
        raise ValueError("gini.values")
    total, n = sum(values), len(values)
    if total == 0:
        return Fraction(0, 1)
    numerator = sum((2*i-n-1)*value for i, value in enumerate(sorted(values), 1))
    return Fraction(numerator, n*total)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗