From 1e6400bd90760d34cc3a28d7c7c32be31b75babf Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Wed, 14 Feb 2018 14:46:12 -0500 Subject: Add a file to parse taps with Coq notations --- src/Util/ParseTaps.v | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Util/ParseTaps.v (limited to 'src/Util/ParseTaps.v') diff --git a/src/Util/ParseTaps.v b/src/Util/ParseTaps.v new file mode 100644 index 000000000..35bc380fd --- /dev/null +++ b/src/Util/ParseTaps.v @@ -0,0 +1,40 @@ +Require Import Coq.Lists.List. +Require Import Coq.ZArith.BinInt. +Require Import Crypto.Util.Notations. +Import ListNotations. + +Local Open Scope list_scope. +Local Open Scope Z_scope. + +Definition tap := (Z * Z)%type. +Definition taps := list tap. +Delimit Scope tap_scope with tap. +Delimit Scope taps_scope with taps. +Bind Scope tap_scope with tap. +Bind Scope taps_scope with taps. + +Coercion Z_to_tap (v : Z) : tap := (v, 0). +Coercion tap_to_taps (v : tap) : taps := [v]. +Definition make_tap (b e : Z) : tap := (b, e). + +Definition scmul_tap (c : Z) (t : tap) : tap + := let '(c', e) := t in (c * c', e). +Definition neg_tap (t : tap) : tap + := let '(c, e) := t in (-c, e). +Definition add_taps : taps -> taps -> taps := @List.app _. + +Notation "b ^ e" := (make_tap (Z.log2 b) e) : tap_scope. +Notation "2 ^ e" := [(1, e%Z)] (only printing) : tap_scope. +Notation "x * y" := (scmul_tap x y) : tap_scope. +Notation "- a" := (neg_tap a) : tap_scope. + +Notation "b ^ e" := (b^e)%tap (only printing) : taps_scope. +Notation "x * y" := (x * y)%tap (only printing) : taps_scope. +Notation "- a" := (-a)%tap (only printing) : taps_scope. +Notation "b ^ e" := (tap_to_taps (b ^ e)) : taps_scope. +Notation "x * y" := (tap_to_taps (x * y)) : taps_scope. +Notation "- a" := (tap_to_taps (-a)) : taps_scope. + +Notation "a + b" := (add_taps a b) : taps_scope. +Notation "a - b" := (add_taps a (neg_tap (Z_to_tap (Zpos b)))) : taps_scope. +Notation "a - b" := (add_taps a (- b)) : taps_scope. -- cgit v1.2.3