val indexing (#b: _) (vb:buffer b) (i:nat{i < length vb})
  : Lemma (let n = View?.n (get_view vb) in
           let vlen = length vb in
           n * (i / n) < vlen  /\
           n * (i / n) + n <= vlen)
val indexing (#b: _) (vb:buffer b) (i:nat{i < length vb})
  : Lemma (let n = View?.n (get_view vb) in
           let vlen = length vb in
           n * (i / n) < vlen  /\
           n * (i / n) + n <= vlen)
let indexing #b vb i = indexing' (get_view vb) (B.length (as_buffer vb)) i
(*
   Copyright 2008-2018 Microsoft Research

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*)
module LowStar.BufferView.Down
open LowStar.Monotonic.Buffer
open FStar.Mul
module HS=FStar.HyperStack
module B=LowStar.Monotonic.Buffer
module Math=FStar.Math.Lemmas

#set-options "--smtencoding.elim_box true"
#set-options "--smtencoding.l_arith_repr native"
#set-options "--smtencoding.nl_arith_repr wrapped"
#set-options "--z3rlimit_factor 4" //just being conservative
#set-options "--initial_fuel 1 --max_fuel 1"

noeq
type buffer_view (src:Type0) (rrel rel:B.srel src) (dest:Type u#b) : Type u#b =
  | BufferView: buf:B.mbuffer src rrel rel
              -> v:view src dest
              -> buffer_view src rrel rel dest

let mk_buffer_view (#src:Type0) (#rrel #rel:B.srel src) (#dest:Type)
                   (b:B.mbuffer src rrel rel)
                   (v:view src dest)
   : GTot (buffer dest)
   = (| src, rrel, rel, BufferView b v |)

let as_buffer (#b:Type) (v:buffer b) =
  let (| _, _, _, BufferView b _ |) = v in
  b

let as_buffer_mk_buffer_view
       (#src:Type0) (#rrel #rel:B.srel src) (#dest:Type)
       (b:B.mbuffer src rrel rel)
       (v:view src dest) =
   ()

let get_view  (#b : Type) (bv:buffer b) =
  let (| _, _, _, BufferView _ v |) = bv in
  v

let get_view_mk_buffer_view
       (#src:Type0) (#rrel #rel:B.srel src) (#dest:Type)
       (b:B.mbuffer src rrel rel)
       (v:view src dest)
  = ()

let length (#b: _) (vb:buffer b) =
  let b = as_buffer vb in
  let v = get_view vb in
  B.length b * View?.n v

let length_eq (#b: _) (vb:buffer b) = ()

let indexing' (#a #b: _) (v:view a b) (len_as:nat) (i:nat{i < len_as * View?.n v})
  : Lemma (let n = View?.n v in
           let vlen = len_as * n in
           n * (i / n) < vlen  /\
           n * (i / n) + n <= vlen)
  = let n = View?.n v in
    let vlen = len_as * n in
    assert (n * (i / n) < vlen);
    assert (i / n <= len_as - 1)
/
prims.fst.checked LowStar.Monotonic.Buffer.fsti.checked FStar.Seq.fst.checked FStar.Pervasives.fsti.checked FStar.Mul.fst.checked FStar.Math.Lemmas.fst.checked FStar.HyperStack.ST.fsti.checked FStar.HyperStack.fst.checked FStar.Classical.fsti.checked
LowStar.BufferView.Down.fst
vb: LowStar.BufferView.Down.buffer b -> i: Prims.nat{i < LowStar.BufferView.Down.length vb}
  -> FStar.Pervasives.Lemma
    (ensures
      (let n = View?.n (LowStar.BufferView.Down.get_view vb) in
        let vlen = LowStar.BufferView.Down.length vb in
        n * (i / n) < vlen /\ n * (i / n) + n <= vlen))
LowStar.BufferView.Down.buffer Prims.nat Prims.b2t Prims.op_LessThan LowStar.BufferView.Down.length LowStar.BufferView.Down.indexing' FStar.Pervasives.__proj__Mkdtuple4__item___1 LowStar.Monotonic.Buffer.srel LowStar.BufferView.Down.buffer_view LowStar.BufferView.Down.get_view LowStar.Monotonic.Buffer.length FStar.Pervasives.__proj__Mkdtuple4__item___2 FStar.Pervasives.__proj__Mkdtuple4__item___3 LowStar.BufferView.Down.as_buffer Prims.unit
let indexing #b vb i =
  
indexing' (get_view vb) (B.length (as_buffer vb)) i