val lemma_g_upd_with_same_seq
      (#a: Type0)
      (#rrel #rel: srel a)
      (b: mbuffer a rrel rel)
      (h: HS.mem{B.live h b})
      (s: _)
    : Lemma (Seq.equal s (B.as_seq h b) ==> B.g_upd_seq b s h == h)
let lemma_g_upd_with_same_seq (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (h:HS.mem{B.live h b}) (s:_)
  : Lemma (Seq.equal s (B.as_seq h b) ==>
           B.g_upd_seq b s h == h)
  = B.lemma_g_upd_with_same_seq b h
val lemma_g_upd_with_same_seq
      (#a: Type0)
      (#rrel #rel: srel a)
      (b: mbuffer a rrel rel)
      (h: HS.mem{B.live h b})
      (s: _)
    : Lemma (Seq.equal s (B.as_seq h b) ==> B.g_upd_seq b s h == h)
let lemma_g_upd_with_same_seq
      (#a: Type0)
      (#rrel #rel: srel a)
      (b: mbuffer a rrel rel)
      (h: HS.mem{B.live h b})
      (s: _)
    : Lemma (Seq.equal s (B.as_seq h b) ==> B.g_upd_seq b s h == h) =
B.lemma_g_upd_with_same_seq b h
LowStar.BufferView.Down.fst.checked
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
LowStar.Monotonic.Buffer.srel LowStar.Monotonic.Buffer.mbuffer FStar.Monotonic.HyperStack.mem LowStar.Monotonic.Buffer.live FStar.Seq.Base.seq Prims.eq2 Prims.nat FStar.Seq.Base.length LowStar.Monotonic.Buffer.length LowStar.Monotonic.Buffer.lemma_g_upd_with_same_seq Prims.unit Prims.l_True Prims.squash Prims.l_imp FStar.Seq.Base.equal LowStar.Monotonic.Buffer.as_seq LowStar.Monotonic.Buffer.g_upd_seq Prims.Nil FStar.Pervasives.pattern
(*
   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)

let indexing #b vb i = indexing' (get_view vb) (B.length (as_buffer vb)) i

let sel' (#a #b: _) (v:view a b)
         (es:Seq.seq a)
         (i:nat{i / View?.n v < Seq.length es})
   : GTot b
   = let n = View?.n v in
     let a_i = i / n in
     let bs = View?.get v (Seq.index es a_i) in
     Seq.index bs (i % n)

let sel (#b: _)
        (h:HS.mem)
        (vb:buffer b)
        (i:nat{i < length vb})
   : GTot b
   = indexing vb i;
     let es = B.as_seq h (as_buffer vb) in
     let v = get_view vb in
     sel' v es i

let lemma_g_upd_with_same_seq (#a:Type0) (#rrel #rel:srel a) (b:mbuffer a rrel rel) (h:HS.mem{B.live h b}) (s:_)
  : Lemma (Seq.equal s (B.as_seq h b) ==>
val lemma_g_upd_with_same_seq
      (#a: Type0)
      (#rrel #rel: srel a)
      (b: mbuffer a rrel rel)
      (h: HS.mem{B.live h b})
      (s: _)
    : Lemma (Seq.equal s (B.as_seq h b) ==> B.g_upd_seq b s h == h)

    b: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
    h: FStar.Monotonic.HyperStack.mem{LowStar.Monotonic.Buffer.live h b} ->
    s: FStar.Seq.Base.seq a {FStar.Seq.Base.length s == LowStar.Monotonic.Buffer.length b}
  -> FStar.Pervasives.Lemma
    (ensures
      FStar.Seq.Base.equal s (LowStar.Monotonic.Buffer.as_seq h b) ==>
      LowStar.Monotonic.Buffer.g_upd_seq b s h == h)