# Array report contract v1 ## C1 Build and interface Use `make` with the available native gcc C11 toolchain. This is software execution on x86_64, not ARM certification. The four submitted translation units link with array_report.h and observer.c; no external dependencies or extra files are used. The callable entry is `int ra_process(const ra_request *, const ra_port *)`; the header defines all structures and helper interfaces. All helper functions declared by the header remain linkable; their outputs have the definitions below. A port offers allocate(context, bytes), release(context, pointer), and publish(context, report). Each invocation is independent. Input structures must not be changed. stderr may contain arbitrary diagnostic bytes without a size limit. ## C2 Validation and results A request is valid exactly when count=0..128, seed=0..65535, base=-100..100, step=-7..7, mode=0..3, cutoff=0..100, window=1..16, bins=1..8 and fail_at=0..2. Missing request/port/callback is invalid. Invalid requests return -2 without allocating, releasing or publishing. A valid count=0 returns 1 with no callbacks. For nonempty valid input request count*sizeof(ra_cell) bytes, then count*sizeof(unsigned) bytes, in that order, once each. The allocator returns NULL on call fail_at when fail_at is 1 or 2. Otherwise it returns distinct malloc-backed storage. A NULL result returns -1 without publishing. Release every successful allocation exactly once on every exit path; never release NULL or unknown storage. On success publish exactly one fully computed report, release both buffers and return 0. Publication occurs before either buffer is released. No failed invocation publishes partial output. No unbounded allocation, real OOM, overflow or freed-storage access is needed. ## C3 Source array and selection Begin with uint32_t word=seed. At each original position i=0..count-1, replace word by (1664525*word+1013904223) modulo 2^32. Let raw=base+(i modulo 11)*step+((word>>16) modulo 101)-50. mode 0 keeps raw; mode 1 takes abs(raw); mode 2 clamps raw into [-25,25]; mode 3 takes sign(raw)*raw*raw (zero stays zero). Keep a transformed cell exactly when abs(value)>=cutoff. Keep original positions and preserve source order in the selected sequence. Only the first selected_count cells and order entries are defined; unused tails have no required contents. `ra_valid`, `ra_transform` and `ra_generate` implement these definitions. ## C4 Report fields 0..22: sequence analytics All 56 fields are signed long long; initialise them to zero and then set the fields below. All results fit signed 64 bits. 0 original count; 1 selected count n; 2 rejected count; 3 sum; 4 sum of absolute values; 5 sum of value squares. 6 sum of (original_position+1)*value. 7 minimum; 8 maximum; 9 original position of first minimum; 10 original position of first maximum. 11 negative count; 12 zero count; 13 positive count; 14 sum of even values; 15 sum of odd values. 16 longest contiguous nondecreasing run length; 17 longest contiguous nonincreasing run length; empty sequences have run length zero. 18 sum of abs(difference) between neighbours of the selected sequence. 19 largest sum of a window of min(window,n) consecutive selected cells; 20 first selected-sequence index attaining it. 21 largest sum of a nonempty contiguous segment (may be negative). For empty sequences fields 7..10,19..21 remain zero. 22 uint32 checksum: begin 2166136261, for each selected cell xor uint32(value), multiply 16777619 modulo 2^32, then xor original_position and multiply 16777619 modulo 2^32. Empty checksum is 2166136261. `ra_analyse` sets exactly fields 3..22. ## C5 Report fields 23..35: order analytics `ra_order` writes indexes of selected cells sorted by value ascending, ties by original position ascending. 23 number of distinct values; 24,25,26 sorted values at floor((n-1)*k/4) for k=1,2,3 respectively. 27 sum of (sorted_rank+1)*sorted_value; 28 largest gap between sorted neighbours (zero for n<2). 29 sum of abs(value-lower_median), where lower_median is field25. 30 original position of first sorted cell. Partition [minimum,maximum] into bins integer buckets: index=floor((value-minimum)*bins/(maximum-minimum+1)). When minimum=maximum every selected cell has bucket0. 31 earliest bucket with largest count; 32 that count; 33 number of occupied buckets; 34 sum of (bucket+1)*bucket_count. All fields23..34 are zero for empty selection. 35 number of pairs ivalue[j]. `ra_rank` sets exactly fields23..35. ## C6 Report fields 36..55: signal analytics 36 minimum prefix sum and 37 maximum prefix sum, including the empty prefix of sum0. 38 number of strictly positive contiguous runs; 39 number of strictly negative contiguous runs; zero terminates both kinds. 40 longest strictly positive run length; 41 longest strictly negative run length. 42 number of strict interior local maxima; 43 number of strict interior local minima; endpoints are excluded. 44 number of equal neighbour pairs; 45 sum of products of neighbours. 46 largest count of skipped original positions between selected neighbours; 47 total skipped positions between selected neighbours. 48 length of longest strictly increasing subsequence; 49 length of longest strictly decreasing subsequence (not necessarily contiguous). 50 most frequent value, tied by its first occurrence in selected source order; 51 its frequency; 52 number of equal-value pairs i