aced/includes/cg.h

75 lines
2.9 KiB
C

#ifndef ACED_INCLUDES_CG_H
#define ACED_INCLUDES_CG_H
// This file provides utilities to convert from and to P and CG notation.
//
// P notation refers to writing a set of joint probabilities of a two player
// game (or associated coefficients) as the explicit set of all possible joint
// probabilities, i.e.,
//
// P[0,0|0,0] ... P[<A outputs>-1, <B outputs>-1 | <A inputs>-1, <B inputs>-1] L
//
// where L is the element associated to the identity.
// For the elisions, the indexing order is B's outputs varying first, then B's
// inputs, then A's outputs, then A's inputs. For the partials, we consider
// (following the same reasoning) that the outputs vary "faster" than the
// inputs.
//
// Collins-Gisin (CG) notation represents the coefficients associated to a set
// of probabilities as in P notation, but in a condensed form, namely
//
// P[0,0|0,0] ... P[<A outputs>-2,<B outputs>-2|<A inputs>-1,<B outputs>-1],
// P_A[0|0] ... P_A[<A outputs>-2|<A inputs>-1]
// P_B[0|0] ... P_B[<B outputs>-2|<B inputs>-1]
//
// where we introduce the notion of marginal distributions P_A and P_B, meaning
// the coefficients associated to, respectively
//
// for all(i_A, o_A), sum(o_B) p(o_A, o_B | i_A, i_B), for all(i_B)
// for all(i_B, o_B), sum(o_A) p(o_A, o_B | i_A, i_B), for all(i_A)
//
// The same elision rules apply.
#include <stddef.h>
#include "../includes/data.h"
#include "../includes/permutation.h"
// Convert from CG representation to P representation, under a given
// permutation.
//
// `p` isn't required to be initialized, only allocated.
void FromCgToP(const size_t a_out, const size_t b_out, const size_t a_in,
const size_t b_in, const data_t* restrict cg, data_t* restrict p,
const size_t* a_in_perm, const size_t* b_in_perm,
const permutation_generator_t* restrict a_out_perms,
const permutation_generator_t* restrict b_out_perms);
// Convert from P representation to CG representation.
//
// `cg` isn't required to be initialized, only allocated.
void FromPToCg(const size_t a_out, const size_t b_out, const size_t a_in,
const size_t b_in, data_t* restrict cg,
const data_t* restrict p);
// Swaps the input labels of the two parties, and the output labels of the two
// parties.
//
// This function only makes sense if `a_out == b_out` and `a_in ==
// b_in`. Calling it otherwise may be undefined behaviour. `p` is modified in
// place.
void PSwapParties(const size_t out, const size_t in, data_t* p);
// Debug print a CG row.
void PrintCg(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* cg);
// Debug print a P row.
void PrintP(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* p);
// Print a P row as if it was in the input format.
void PrintPRaw(size_t a_out, size_t b_out, size_t a_in, size_t b_in,
const data_t* p);
#endif