GithubHelp home page GithubHelp logo

affeldt-aist / infotheo Goto Github PK

View Code? Open in Web Editor NEW
61.0 61.0 15.0 4.18 MB

A Coq formalization of information theory and linear error-correcting codes

License: GNU Lesser General Public License v2.1

Coq 99.76% OCaml 0.19% Makefile 0.04%
convexity error-correcting-codes information-theory math-comp mathcomp probability ssreflect

infotheo's People

Contributors

affeldt-aist avatar erikmd avatar gares avatar garrigue avatar hoheinzollern avatar t6s avatar yoshihiro503 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

infotheo's Issues

Unable to install using GNU make. Error: Unable to locate library Rstruct with prefix mathcomp.

Ubuntu 20.04.2 LTS
Release: 20.04

opam --version
2.0.5

coqc --version
The Coq Proof Assistant, version 8.13.1 (March 2021)
compiled on Mar 8 2021 11:40:26 with OCaml 4.08.1

opam list mathcomp
Name Installed Synopsis
coq-mathcomp-algebra 1.12.0 Mathematical Components Library on Algebra
coq-mathcomp-analysis 0.3.6 An analysis library for mathematical components
coq-mathcomp-bigenough 1.0.0 A small library to do epsilon - N reasonning
coq-mathcomp-field 1.12.0 Mathematical Components Library on Fields
coq-mathcomp-fingroup 1.12.0 Mathematical Components Library on finite groups
coq-mathcomp-finmap 1.5.1 Finite sets, finite maps, finitely supported functions
coq-mathcomp-solvable 1.12.0 Mathematical Components Library on finite groups (II)
coq-mathcomp-ssreflect 1.12.0 Small Scale Reflection

Running:
git clone https://github.com/affeldt-aist/infotheo.git
cd infotheo
make

Outputs:
make -f Makefile.coq all
make[1]: Entering directory '/home/user/Documents/infotheo'
COQC lib/ssrR.v
File "./lib/ssrR.v", line 5, characters 29-36:
Error: Unable to locate library Rstruct with prefix mathcomp.

make[2]: *** [Makefile.coq:720: lib/ssrR.vo] Error 1
make[1]: *** [Makefile.coq:343: all] Error 2
make[1]: Leaving directory '/home/user/Documents/infotheo'
make: *** [Makefile:2: all] Error 2

Could anyone help to figure out and solve the issue?

Top-level Makefile?

As discussed in coq/opam#1003, it's usually a good idea to have a top-level Makefile that issues the critical coq_makefile command for a build. The main advantage is that users (and other build systems such as OPAM and Nix) need only issue make to build the project from scratch - and one can even change to another build approach based on, say, dune, without changing this build command.

The typical Coq project top-level Makefile currently looks as follows:

all: Makefile.coq
        +$(MAKE) -f Makefile.coq all

clean: Makefile.coq
        +$(MAKE) -f Makefile.coq cleanall
        rm -f Makefile.coq Makefile.coq.conf

Makefile.coq: _CoqProject
        coq_makefile -f _CoqProject -o Makefile.coq

_CoqProject Makefile: ;

%: Makefile.coq
        +$(MAKE) -f Makefile.coq $@

.PHONY: all clean

Note that this mostly just defers actions to the makefile generated by coq_makefile.

If this sounds like a good idea, I can make a pull request.

generalize to fieldType

infotheo/probability/convex.v

Lines 1626 to 1669 in d17cdb2

Section freeN_combination.
Import ssrnum vector.
Import Order.POrderTheory Num.Theory.
Variable E : vectType R.
Local Open Scope ring_scope.
Local Open Scope classical_set_scope.
Import GRing.
Lemma freeN_combination n (s : n.-tuple E) : ~~ free s ->
exists k : 'I_n -> R, (\sum_i k i *: s`_i = 0) /\ exists i, k i != 0.
Proof.
rewrite freeNE => /existsP[[i ilt] /coord_span /=].
move: (ilt) s.
have ne : (n = i.+1 + (n - i.+1))%nat by rewrite subnKC.
rewrite ne => ilt' s sin.
have hk m : (m < n - i.+1 -> m < i.+1 + (n - i.+1) - i.+1)%nat.
by move=> mni; rewrite -addnBAC// subnn add0n.
pose k (x : 'I_(i.+1 + (n - i.+1))) :=
match fintype.split x with
| inl (@Ordinal _ m _) => if m == i then 1%R else 0%R
| inr (@Ordinal _ m i0) => - coord (drop_tuple i.+1 s) (Ordinal (hk m i0)) s`_i
end.
exists k; split; last first.
exists (Ordinal ilt'); rewrite /k; case: splitP.
by case=> j ji/= <-; rewrite eqxx; exact/eqP/R1_neq_R0.
by case=> j jni/= /eqP; rewrite lt_eqF// ltEnat/= addSn ltnS leq_addr.
rewrite big_split_ord big_ord_recr/= big1 ?add0r; last first.
case=> j ji _; rewrite /k; case: splitP.
by case=> m mi /= jm; rewrite -jm lt_eqF ?ltEnat// !scale0r.
by case=> m mni /= jim; move: ji; rewrite jim addSnnS -ltn_subRL subnn.
rewrite {1}/k /=; case: splitP => /=; last first.
by move=> m /eqP; rewrite lt_eqF// ltEnat/= addSn ltnS leq_addr.
case=> j/= ji ij; rewrite [in j == i]ij eqxx scale1r.
apply/eqP; rewrite addrC addr_eq0 sin -sumrN; apply/eqP.
have {}ne : (i.+1 + (n - i.+1) - i.+1 = n - i.+1)%nat by rewrite -addnBAC// subnn.
rewrite (index_enum_cast_ord ne) big_map; apply congr_big=>// [[x xlt]] _.
rewrite nth_drop -scaleNr; congr (_ *: _).
rewrite /k; case: splitP.
by case=> m + /= ixm; rewrite -ixm -ltn_subRL subnn.
case=> m/= mni /eqP; rewrite eqn_add2l => /eqP kl.
by congr (- coord _ _ _); exact/val_inj.
Qed.
End freeN_combination.

generalize to realType

infotheo/probability/convex.v

Lines 2561 to 2570 in 8a67187

(* TODO: move to mathcomp *)
Lemma preimage_add_ker (f : {linear T -> U}) (A: set U) :
[set a + b | a in f @^-1` A & b in f @^-1` [set 0]] = f @^-1` A.
Proof.
rewrite eqEsubset; split.
- move=> x [a /= aA] [b /= bker] xe; subst x.
by rewrite GRing.linearD bker GRing.addr0.
- move=> x /= fx; exists x=>//.
by exists 0; [ apply GRing.linear0 | apply GRing.addr0].
Qed.

new lemmas for infotheo

Dear infotheo authors, I want to point out that my co-authors and I have a paper on the formalization of bounds on the trimmed mean algorithm that uses infotheo. It has been accepted at PPDP this year (https://ppdp2021.github.io/#accepted, the paper is called "Trimming Data Sets: a Verified Algorithm for Robust Mean Estimation", soon to be available) and you can find the source code of the formalization here: https://github.com/ieva-itu/robustmean/blob/main/robustmean.v

We are thankful for the all the development of probability theory that we used in our paper, and we think you might appreciate some lemmas that should belong to infotheo more than our development.
As we are all novice Coq programmers and not used to the mathcomp style, I'd appreciate if you could take a look at the code and see whether you're interested in integrating it here, and maybe help us match the style of the infotheo package. This is also why I'm not making a pull request yet.

duplicate definitions

Rstruct.R_eqType and ssrR.R_eqType

Lemma eqRstruct_eqR (m n : R) : (m == n :> Rstruct.R_eqType) = (m == n :> ssrR.R_eqType).
Proof.
Fail reflexivity.
case/boolP: (m == n).
by move/eqP ->; rewrite eqxx.
by move/eqP=> H; apply esym; rewrite -/(is_true _); apply/eqP.
Qed.

@t6s

prob interface

Definition mk_ (q : R) (Oq1 : 0 <= q <= 1) := mk (introT (@leR2P _ _ _) Oq1).

Since we're favoring a structure with an inequality in bool for prob, the constructor mk_ might turn out to be superfluous after all. Investigate its removal.

Cc: @t6s

error when building ecc_modern

I tried to build infotheo using make:

COQC ecc_modern/ldpc_algo.v
File "./ecc_modern/ldpc_algo.v", line 175, characters 0-76:
Error: ConstructiveCauchyReals.CReal is not an inductive type.

interface consistency

mulRV : forall x : R, x != 0 -> x * / x = 1
invRM : forall r1 r2 : R, r1 <> 0 -> r2 <> 0 -> / (r1 * r2) = / r1 * / r2

@t6s

Notations for random variables conflict between infotheo and mathcomp-analysis

The following expression fails to be parsed after importing both proba.v (infotheo) and probability.v (mathcomp-analysis):

Local Open Scope form_scope.
Variables (d : measure_display) (T : measurableType d) (R : realType) (P : probability T R).
Variable (X : {RV P >-> R}).

>>> Error: Syntax error: '->' expected after [term] (in [term]).

A similar reserved notation in proba.v seems to be confusing the parser:

Reserved Notation "{ 'RV' d -> T }" (at level 0, d, T at next level,
  format "{ 'RV'  d  ->  T }").

`prob` may have two eqType structures, leading to failures in rewriting / applying lemmas.

I experienced this issue when trying to use prob_lt0. The lemma takes as its argument _ : p != 0 and it did not match my goal because of a mismatch between two eqType structures.

One solution would be to change the interface of prob to

Module Prob.
Record t := mk_ {
  p :> R ;
  Op1 : (0 <b= p <b= 1)%R }.
Definition O1 (p : t) : 0 <= p <= 1 :=
  match andP (Op1 p) with conj Op p1 => conj (leRP _ _ Op) (leRP _ _ p1) end.
Arguments O1 : simpl never.
Definition mk (q : R) (Oq1 : 0 <= q <= 1) : t.
Proof.
refine (@mk_ q (match Oq1 with conj Oq q1 => _ end)).
by move/leRP: Oq ->; move/leRP: q1 ->.
Defined.
Module Exports.
Notation prob := t.
Notation "q %:pr" := (@mk q (@O1 _)).
Canonical prob_subType := Eval hnf in [subType for p].
Definition prob_eqMixin := [eqMixin of prob by <:].
Canonical prob_eqType := Eval hnf in EqType _ prob_eqMixin.
End Exports.
End Prob.
Export Prob.Exports.
Coercion Prob.p : prob >-> R.

This seems to almost work, but failing at inferring the canonical structure for onem.

I nixified this: https://github.com/jorsn/infotheo/tree/nixify

Hi!
I am excited to see a formal proof lib for information theory!

If I manage to find the time, I will try to apply it to some proofs about multi-user identification.
Therefore I nixified this: https://github.com/jorsn/infotheo/tree/nixify.
The most recent build from there is also cached in my cachix cache (run cachix use jorsn).

If you are interested in using nix, I can create a PR and perhaps write a usage note for the README.
If not, feel free to close this issue.
Whether I can maintain the nix stuff (and add it to nixpkgs) depends on whether I will expect to really use it for longer.

typo

ltR_subl_addr: forall x y z : R, x - y < z <-> x < z + y
ltr_subl_addl: forall x y z : R, x - y < z <-> x < y + z

@t6s

Generalize fdists

fdists are currently defined over the R type of the standard library. Some developments would like to rely on this library but use structures from the mathcomp library. So we would like to have them generalized (maybe to numFieldType).

submit to mathcomp-analysis

infotheo/probability/convex.v

Lines 2458 to 2465 in 8231da9

(* TODO: move to mathcomp-analysis *)
Lemma image2_subset {aT bT rT : Type} [f : aT -> bT -> rT] [A B: set aT] [C D : set bT] :
(A `<=` B)%classic -> (C `<=` D)%classic ->
([set f x y | x in A & y in C] `<=` [set f x y | x in B & y in D])%classic.
Proof.
move=> AB CD x [a aA [c cC xe]]; subst x; exists a; (try by apply AB).
by exists c; (try by apply CD).
Qed.

it looks like this lemma should better be in MathComp-Analysis' classical_sets.v file

ssrZ missing lemmas

Lemma intRD (n m : nat) : (n + m)%:Z = (n%:Z + m%:Z)%Z.
Proof. exact: Nat2Z.inj_add. Qed.

Lemma leZ0n (n : nat) : (0 <= n%:Z)%Z.
Proof. exact: Zle_0_nat. Qed.

RV_ring

We are missing the following: definition of multiplication of random variables and ring structure for RVs.

Definition mul_RV (U : finType) (P : {fdist U}) (X Y : {RV P -> R}) : {RV P -> R} := fun x => X x * Y x.
Notation "X `* Y" := (mul_RV X Y) : proba_scope.
Arguments mul_RV /.

and

Section RV_ring.
Variables (U : finType) (P : fdist U).
Import topology.
Import GRing.Theory.

Lemma add_RV_addr (X Y : {RV P -> R}) : X `+ Y = (X + Y)%ring.
Proof. reflexivity. Qed.

Lemma sub_RV_subr (X Y : {RV P -> R}) : X `- Y = (X - Y)%ring.
Proof. reflexivity. Qed.

Lemma trans_min_RV_subr (X : {RV P -> R}) (y : R) :
  X `-cst y = (X - cst y)%ring.
Proof. reflexivity. Qed.
Definition fdist_supp_choice : U.
by move/set0Pn/xchoose:(fdist_supp_neq0 P).
Defined.

Canonical fdist_supp_pointedType :=
  @classical_sets.Pointed.pack U fdist_supp_choice _ _ idfun.

Lemma mul_RV_mulr (X Y : {RV P -> R}) : X `* Y = (X * Y)%ring.
Proof. reflexivity. Qed.

Lemma sq_RV_sqrr (X : {RV P -> R}) : X `^2 = (X ^+ 2)%ring.
Proof. by rewrite /sq_RV/comp_RV; apply boolp.funext => u /=; rewrite mulR1. Qed.

Definition RV_ringE :=
  (add_RV_addr, sub_RV_subr, trans_min_RV_subr, mul_RV_mulr, sq_RV_sqrr).
End RV_ring.

Unable to install using opam. ERROR while compiling coq-infotheo.0.3.1

Ubuntu 20.04.2 LTS
Release: 20.04

opam --version
2.0.5

coqc --version
The Coq Proof Assistant, version 8.13.1 (March 2021)
compiled on Mar 8 2021 11:40:26 with OCaml 4.08.1

opam list mathcomp

Name Installed Synopsis
coq-mathcomp-algebra 1.12.0 Mathematical Components Library on Algebra
coq-mathcomp-analysis 0.3.6 An analysis library for mathematical components
coq-mathcomp-bigenough 1.0.0 A small library to do epsilon - N reasonning
coq-mathcomp-field 1.12.0 Mathematical Components Library on Fields
coq-mathcomp-fingroup 1.12.0 Mathematical Components Library on finite groups
coq-mathcomp-finmap 1.5.1 Finite sets, finite maps, finitely supported functions
coq-mathcomp-solvable 1.12.0 Mathematical Components Library on finite groups (II)
coq-mathcomp-ssreflect 1.12.0 Small Scale Reflection

Running:
opam repo add coq-released https://coq.inria.fr/opam/released
opam install coq-infotheo

Outputs:

``
The following actions will be performed:
∗ install coq-infotheo 0.3.1

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[coq-infotheo.0.3.1] found in cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of coq-infotheo failed at "/home/user/.opam/opam-init/hooks/sandbox.sh build make -j1".

#=== ERROR while compiling coq-infotheo.0.3.1 =================================#
# context 2.0.5 | linux/x86_64 | ocaml-base-compiler.4.11.1 | https://coq.inria.fr/opam/released#2021-03-22 11:00
# path ~/.opam/with-coq/.opam-switch/build/coq-infotheo.0.3.1
# command ~/.opam/opam-init/hooks/sandbox.sh build make -j1
# exit-code 2
# env-file ~/.opam/log/coq-infotheo-51929-d2c37b.env
# output-file ~/.opam/log/coq-infotheo-51929-d2c37b.out
### output ###
# [...]
# Warning: filter_index_enum is deprecated; use big_enumP instead
# Warning: filter_index_enum is deprecated; use big_enumP instead
# Warning: filter_index_enum is deprecated; use big_enumP instead
# COQC toy_examples/expected_value_variance.v
# COQC toy_examples/expected_value_variance_ordn.v
# COQC toy_examples/expected_value_variance_tuple.v
# COQC toy_examples/conditional_entropy.v
# Killed
# make[2]: *** [Makefile.coq:720: toy_examples/conditional_entropy.vo] Error 137
# make[1]: *** [Makefile.coq:343: all] Error 2
# make[1]: Leaving directory '/home/user/.opam/with-coq/.opam-switch/build/coq-infotheo.0.3.1'
# make: *** [Makefile:2: all] Error 2

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build coq-infotheo 0.3.1
└─
╶─ No changes have been performed
# Run eval $(opam env) to update the current shell environment

``
Could anyone help to figure out and solve the issue?

gmake

mention that make is actually gmake in the readme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.