Debian Codegraph @

src/Util/ParseTaps.v

raw
1 From Coq Require Import List.
2 From Coq Require Import BinInt.
3 Require Import Crypto.Util.Notations.
4 Import ListNotations.
5
6 Local Open Scope list_scope.
7 Local Open Scope Z_scope.
8
9 Definition tap := (Z * Z)%type.
10 Definition taps := list tap.
11 Declare Scope tap_scope.
12 Declare Scope taps_scope.
13 Delimit Scope tap_scope with tap.
14 Delimit Scope taps_scope with taps.
15 Bind Scope tap_scope with tap.
16 Bind Scope taps_scope with taps.
17
18 Coercion Z_to_tap (v : Z) : tap := (v, 0).
19 Coercion tap_to_taps (v : tap) : taps := [v].
20 Definition make_tap (b e : Z) : tap := (b, e).
21
22 Definition scmul_tap (c : Z) (t : tap) : tap
23 := let '(c', e) := t in (c * c', e).
24 Definition neg_tap (t : tap) : tap
25 := let '(c, e) := t in (-c, e).
26 Definition add_taps : taps -> taps -> taps := @List.app _.
27
28 Notation "b ^ e" := (make_tap (Z.log2 b) e) : tap_scope.
29 Notation "2 ^ e" := [(1, e%Z)] (only printing) : tap_scope.
30 Notation "x * y" := (scmul_tap x y) : tap_scope.
31 Notation "- a" := (neg_tap a) : tap_scope.
32
33 Notation "b ^ e" := (b^e)%tap (only printing) : taps_scope.
34 Notation "x * y" := (x * y)%tap (only printing) : taps_scope.
35 Notation "- a" := (-a)%tap (only printing) : taps_scope.
36 Notation "b ^ e" := (tap_to_taps (b ^ e)) : taps_scope.
37 Notation "x * y" := (tap_to_taps (x * y)) : taps_scope.
38 Notation "- a" := (tap_to_taps (-a)) : taps_scope.
39
40 Notation "a + b" := (add_taps a b) : taps_scope.
41 Notation "a - b" := (add_taps a (neg_tap (Z_to_tap (Zpos b)))) : taps_scope.
42 Notation "a - b" := (add_taps a (- b)) : taps_scope.