add.mlw 21.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
module Add

  use import int.Int
  use import mach.int.Int32
  use import mach.int.UInt64GMP as Limb
  use import int.Power
  use import ref.Ref
  use import mach.c.C
  use import array.Array
  use import map.Map
  use import types.Types
  use import lemmas.Lemmas

14 15 16
  (** `add_limb r x y sz` adds to `x` the value of the limb `y`,
      writes the result in `r` and returns the carry. `r` and `x`
      have size `sz`. This corresponds to the function `mpn_add_1` *)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
  (* r and x must be separated. This is enforced by Why3 regions in typing *)
  let add_limb (r x:t) (y:limb) (sz:int32) : limb
    requires { valid x sz }
    requires { valid r sz }
    requires { sz > 0 } (* ? GMP does the same for 0 and 1*)
    ensures { value r sz + (power radix sz) * result =
              value x sz + y }
    ensures { 0 <= result <= 1 }
    ensures { forall j. (j < offset r \/ offset r + sz <= j)
              -> (pelts r)[j] = old (pelts r)[j] }
    writes { r.data.elts }
  =
    let limb_zero = Limb.of_int 0 in
    let c = ref y in
    let lx = ref limb_zero in
    let i = ref (Int32.of_int 0) in
    while Int32.(<) !i sz && (not (Limb.(=) !c limb_zero)) do
      invariant { 0 <= !i <= sz }
      invariant { !i > 0 -> 0 <= !c <= 1 }
      invariant { value r !i + (power radix !i) * !c =
                  value x !i + y }
      invariant { forall j. (j < offset r \/ offset r + sz <= j)
                -> (pelts r)[j] = old (pelts r)[j] }
      variant { sz - !i }
      label StartLoop in
      lx := get_ofs x !i;
      let (res, carry) = add_with_carry !lx !c limb_zero in
      set_ofs r !i res;
      assert { value r !i + (power radix !i) * !c =
                  value x !i + y };
      c := carry;
      value_tail r !i;
      value_tail x !i;
      assert { value r (!i+1) + (power radix (!i+1)) * !c
             = value x (!i+1) + y
             (* by
             value r !i + (power radix !i) * !c
             = value r k + (power radix k) * res
                               + (power radix !i) * !c
             = value r k + (power radix k) * res
                               + (power radix k) * radix * !c
             = value r k + (power radix k) * (res + radix * !c)
             = value r k +
               (power radix k) * (!lx + (!c at StartLoop))
             = value r k + (power radix k) * (!c at StartLoop)
                               + (power radix k) * !lx
             = value x k + y + (power radix k) * !lx
             = value x !i + y*) };
      i := Int32.(+) !i (Int32.of_int 1);
    done;
    if Int32.(=) !i sz then !c
    else begin
    while Int32.(<) !i sz do
      invariant { !c  = 0 }
      invariant { 0 <= !i <= sz }
      invariant { value r !i + (power radix !i) * !c =
                  value x !i + y }
      invariant { forall j. (j < offset r \/ offset r + sz <= j)
                -> (pelts r)[j] = old (pelts r)[j] }
      variant { sz - !i }
      lx := get_ofs x !i;
      set_ofs r !i !lx;
      assert { value r !i + (power radix !i) * !c =
                  value x !i + y };
      let ghost k = p2i !i in
      i := Int32.(+) !i (Int32.of_int 1);
      value_sub_tail (pelts r) r.offset (r.offset + k);
      value_sub_tail (pelts x) x.offset (x.offset + k);
    done;
    !c
    end


90 91
  (** `add_limbs r x y sz` adds `x[0..sz-1]` and `y[0..sz-1]` and writes the result in `r`.
      Returns the carry, either `0` or `1`. Corresponds to the function `mpn_add_n`. *)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

  let add_limbs (r x y:t) (sz:int32) : limb
    requires { valid x sz }
    requires { valid y sz }
    requires { valid r sz }
    ensures { 0 <= result <= 1 }
    ensures { value r sz + (power radix sz) * result =
            value x sz + value y sz }
    ensures { forall j. (j < offset r \/ offset r + sz <= j)
              -> (pelts r)[j] = old (pelts r)[j] }
    writes { r.data.elts }
    =
    let limb_zero = Limb.of_int 0 in
    let lx = ref limb_zero in
    let ly = ref limb_zero in
    let c = ref limb_zero in
    let i = ref (Int32.of_int 0) in
    while Int32.(<) !i sz do
      variant { sz - !i }
      invariant { 0 <= !i <= sz }
      invariant { value r !i + (power radix !i) * !c =
                value x !i + value y !i }
      invariant { 0 <= !c <= 1 }
      invariant { forall j. (j < offset r \/ offset r + sz <= j)
                -> (pelts r)[j] = old (pelts r)[j] }
      label StartLoop in
      lx := get_ofs x !i;
      ly := get_ofs y !i;
      let res, carry = add_with_carry !lx !ly !c in
      set_ofs r !i res;
      assert { value r !i + (power radix !i) * !c =
                value x !i + value y !i
               by value r !i = (value r !i at StartLoop) };
      c := carry;
      value_tail r !i;
      value_tail x !i;
      value_tail y !i;
      assert { value r (!i+1) + (power radix (!i+1)) * !c =
                value x (!i+1) + value y (!i+1)
              (*by
              value r !i + (power radix !i) * !c
              = value r k + (power radix k) * res
                   + (power radix !i) * !c
              = value r k + (power radix k) * res
                   + (power radix k) * radix * !c
              = value r k + (power radix k) * (res + radix * !c)
              = value r k +
                  (power radix k) * (!lx + !ly + (!c at StartLoop))
              = value r k + (power radix k) * (!c at StartLoop)
                 + (power radix k) * (!lx + !ly)
              = value x k + value y k
                 + (power radix k) * (!lx + !ly)
              = value x k + (power radix k) * !lx
                 + value y k + (power radix k) * !ly
              = value x !i
                 + value y k + (power radix k) * !ly
              = value x !i
                 + (value y k + (power radix k) * !ly)
              = value x !i + value y !i*) };
      i := Int32.(+) !i (Int32.of_int 1);
    done;
    !c

155 156 157
  (** `add r x y sx sy` adds `(x, sx)` to `(y, sy)` and writes the
      result in `(r, sx)`.  `sx` must be greater than or equal to
      `sy`. Returns carry, either 0 or 1. Corresponds to `mpn_add`. *)
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
  let add (r x y:t) (sx sy:int32) : limb
    requires { 0 <= sy <= sx }
    requires { valid x sx }
    requires { valid y sy }
    requires { valid r sx }
    ensures { value r sx + (power radix sx) * result =
              value x sx + value y sy }
    ensures { forall j. (j < offset r \/ offset r + sx <= j)
              -> (pelts r)[j] = old (pelts r)[j] }
    ensures { 0 <= result <= 1 }
    writes { r.data.elts }
 =
    let limb_zero = Limb.of_int 0 in
    let lx = ref limb_zero in
    let ly = ref limb_zero in
    let c = ref limb_zero in
    let i = ref (Int32.of_int 0) in
    while Int32.(<) !i sy do
      variant { sy - !i }
      invariant { 0 <= !i <= sy }
      invariant { value r !i + (power radix !i) * !c =
                value x !i + value y !i }
      invariant { 0 <= !c <= 1 }
      invariant { forall j. (j < offset r \/ offset r + sx <= j)
                -> (pelts r)[j] = old (pelts r)[j] }
      label StartLoop in
      lx := get_ofs x !i;
      ly := get_ofs y !i;
      let res, carry = add_with_carry !lx !ly !c in
      set_ofs r !i res;
      assert { value r !i + (power radix !i) * !c =
                value x !i + value y !i };
      c := carry;
      value_tail r !i;
      value_tail x !i;
      value_tail y !i;
      assert { value r (!i+1) + (power radix (!i+1)) * !c =
                value x (!i+1) + value y (!i+1)
              (*by
              value r !i + (power radix !i) * !c
              = value r k + (power radix k) * res
                   + (power radix !i) * !c
              = value r k + (power radix k) * res
                   + (power radix k) * radix * !c
              = value r k + (power radix k) * (res + radix * !c)
              = value r k +
                  (power radix k) * (!lx + !ly + (!c at StartLoop))
              = value r k + (power radix k) * (!c at StartLoop)
                 + (power radix k) * (!lx + !ly)
              = value x k + value y k
                 + (power radix k) * (!lx + !ly)
              = value x k + (power radix k) * !lx
                 + value y k + (power radix k) * !ly
              = value x !i
                 + value y k + (power radix k) * !ly
              = value x !i
                 + (value y k + (power radix k) * !ly)
              = value x !i + value y !i*) };
      i := Int32.(+) !i (Int32.of_int 1);
    done;
    try
    begin while Int32.(<) !i sx do
      variant { sx - !i }
      invariant { sy <= !i <= sx }
      invariant { value r !i + (power radix !i) * !c =
                value x !i + value y sy }
      invariant { 0 <= !c <= 1 }
      invariant { forall j. (j < offset r \/ offset r + sx <= j)
                -> (pelts r)[j] = old (pelts r)[j] }
      (if (Limb.(=) !c (Limb.of_int 0)) then raise Break);
      label StartLoop2 in
      lx := get_ofs x !i;
      let res, carry = add_with_carry !lx limb_zero !c in
      set_ofs r !i res;
      assert { value r !i + (power radix !i) * !c =
                value x !i + value y sy };
      c := carry;
      value_tail r !i;
      value_tail x !i;
      assert { value r (!i+1) + (power radix (!i+1)) * !c =
                value x (!i+1) + value y sy
              (*by
              value r !i + (power radix !i) * !c
              = value r k + (power radix k) * res
                   + (power radix !i) * !c
              = value r k + (power radix k) * res
                   + (power radix k) * radix * !c
              = value r k + (power radix k) * (res + radix * !c)
              = value r k +
                  (power radix k) * (!lx + 0 + (!c at StartLoop2))
              = value r k + (power radix k) * (!c at StartLoop2)
                 + (power radix k) * !lx
              = value x k + value y sy
                 + (power radix k) * !lx
              = value x !i
                 + value y sy*) };
      i := Int32.(+) !i (Int32.of_int 1);
    done;
    assert { !i = sx }
    end
    with Break -> assert { !c = 0 }
    end;
    while Int32.(<) !i sx do
      variant { sx - !i }
      invariant { sy <= !i <= sx }
      invariant { !i = sx \/ !c = 0 }
      invariant { value r !i + power radix !i * !c =
                value x !i + value y sy }
      invariant { forall j. (j < offset r \/ offset r + sx <= j)
                -> (pelts r)[j] = old (pelts r)[j] }
      assert { !c = 0 by !i < sx };
      lx := get_ofs x !i;
      set_ofs r !i !lx;
      value_tail r !i;
      value_tail x !i;
      assert { value r !i = value x !i + value y sy }; (* true with this, should not be needed *)
      assert { value r (!i+1) + power radix (!i+1) * !c
               = value x (!i+1) + value y sy
               (*
               by
               value r !i + power radix !i * !c
                 = value r !i
                 = value r k + power radix k * !lx
               so value x !i
                  = value x k + power radix k * !lx
               so value r k
                  = value r k + power radix k * !c
                  = value x k + value y sy*) };
      i := Int32.(+) !i (Int32.of_int 1);
    done;
    !c

  let add_in_place (x y:t) (sx sy:int32) : limb
    requires { 0 <= sy <= sx }
    requires { valid x sx }
    requires { valid y sy }
    ensures  { value x sx + (power radix sx) * result
               = value (old x) sx + value y sy }
    ensures  { 0 <= result <= 1 }
    ensures { forall j. j < x.offset \/ x.offset + sx <= j ->
              (pelts x)[j] = (pelts (old x))[j] }
    writes   { x.data.elts }
  =
    let ghost ox = { x } in
    let limb_zero = Limb.of_int 0 in
    let lx = ref limb_zero in
    let ly = ref limb_zero in
    let c = ref limb_zero in
    let i = ref (Int32.of_int 0) in
    while Int32.(<) !i sy do
      variant   { sy - !i }
      invariant { 0 <= !i <= sy }
      invariant { value x !i + (power radix !i) * !c =
                  value ox !i + value y !i }
      invariant { 0 <= !c <= 1 }
      invariant { forall j. !i <= j < sx ->
                  (pelts x)[x.offset + j] = (pelts ox)[x.offset + j] }
      invariant { forall j. j < x.offset \/ x.offset + sx <= j ->
                  (pelts x)[j] = (pelts (old x))[j] }
      label StartLoop in
      lx := get_ofs x !i;
      assert { !lx = (pelts ox)[ox.offset + !i] };
      ly := get_ofs y !i;
      let res, carry = add_with_carry !lx !ly !c in
      set_ofs x !i res;
      assert { forall j. !i < j < sx ->
                 (pelts x)[x.offset + j]
                 = (pelts ox)[x.offset + j]
                 by (pelts x)[x.offset + j]
                 = (pelts (x at StartLoop))[x.offset + j]
                 = (pelts ox)[x.offset + j]};
      assert { value x !i + (power radix !i) * !c = value ox !i + value y !i };
      c := carry;
      value_tail x !i;
      value_tail ox !i;
      value_tail y !i;
      assert { value x (!i+1) + (power radix (!i+1)) * !c =
                value ox (!i+1) + value y (!i+1)
              (*by value ox k + (power radix k) * !lx
                 = value ox !i
              so value x !i + (power radix !i) * !c
              = value x k + (power radix k) * res
                   + (power radix !i) * !c
              = value x k + (power radix k) * res
                   + (power radix k) * radix * !c
              = value x k + (power radix k) * (res + radix * !c)
              = value x k +
                  (power radix k) * (!lx + !ly + (!c at StartLoop))
              = value x k + (power radix k) * (!c at StartLoop)
                 + (power radix k) * (!lx + !ly)
              = value ox k + value y k
                 + (power radix k) * (!lx + !ly)
              = (value ox k + (power radix k) * !lx)
                 + (value y k + (power radix k) * !ly)
              = value ox !i
                 + (value y k + (power radix k) * !ly)
              = value ox !i
                 + (value y k + (power radix k) * !ly)
              = value ox !i + value y !i*) };
      i := Int32.(+) !i (Int32.of_int 1);
    done;
    try
    while Int32.(<) !i sx do
      variant   { sx - !i }
      invariant { sy <= !i <= sx }
      invariant { value x !i + (power radix !i) * !c =
                  value ox !i + value y sy }
      invariant { 0 <= !c <= 1 }
      invariant { forall j. !i <= j < sx ->
                  (pelts x)[x.offset + j] = (pelts ox) [x.offset + j] }
      invariant { forall j. j < x.offset \/ x.offset + sx <= j ->
                  (pelts x)[j] = (pelts (old x))[j] }
      (if (Limb.(=) !c limb_zero) then raise ReturnLimb limb_zero);
      label StartLoop2 in
      lx := get_ofs x !i;
      assert { !lx = (pelts ox)[ox.offset + !i] };
      let res, carry = add_with_carry !lx limb_zero !c in
      value_sub_update_no_change (pelts x) (x.offset + p2i !i)
                                           (x.offset + p2i !i + 1)
                                           (x.offset + p2i sx) res;
      set_ofs x !i res;
      assert { value x !i + (power radix !i) * !c = value ox !i + value y sy };
      c := carry;
      assert { forall j. !i < j < sx ->
                  (pelts x)[x.offset + j] = (pelts ox) [x.offset + j] };
      value_tail ox !i;
      value_tail x !i;
      assert { value x (!i+1) + (power radix (!i+1)) * !c =
                value ox (!i+1) + value y sy
              (*by value ox k + (power radix k) * !lx
                 = value ox !i
              so
              value x !i + (power radix !i) * !c
              = value x k + (power radix k) * res
                   + (power radix !i) * !c
              = value x k + (power radix k) * res
                   + (power radix k) * radix * !c
              = value x k + (power radix k) * (res + radix * !c)
              = value x k +
                  (power radix k) * (!lx + 0 + (!c at StartLoop2))
              = value x k + (power radix k) * (!c at StartLoop2)
                 + (power radix k) * !lx
              = value ox k + value y sy
                 + (power radix k) * !lx
              = value ox !i
                 + value y sy*) };
      i := Int32.(+) !i (Int32.of_int 1);
    done;
    assert { !i = sx };
    !c
    with ReturnLimb n -> begin
      assert { n = 0 = !c };
      assert { forall j. x.offset + !i <= j < x.offset + sx
               -> (pelts x)[j] = (pelts ox)[j]
               by !i <= j - x.offset < sx
               so (pelts x)[x.offset + (j - x.offset)]
                  = (pelts ox)[x.offset + (j - x.offset)] };
      value_sub_frame (pelts x) (pelts ox) (x.offset + p2i !i) (x.offset + p2i sx);
      value_sub_concat (pelts x) x.offset (x.offset + p2i !i) (x.offset + p2i sx);
      value_sub_concat (pelts ox) x.offset (x.offset + p2i !i) (x.offset + p2i sx);
      assert { value x sx = value (old x) sx + value y sy };
      n
      end
    end

  use import int.EuclideanDivision

425 426 427
  (** `incr x y sz` adds to `x` the value of the limb `y` in place.
      `x` has size `sz`. The addition must not overflow. This corresponds
      to `mpn_incr` *)
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
  let incr (x:t) (y:limb) (ghost sz:int32) : unit
    requires { valid x sz }
    requires { sz > 0 }
    requires { value x sz + y < power radix sz }
    ensures  { value x sz = value (old x) sz + y }
    ensures { forall j. j < x.offset \/ x.offset + sz <= j ->
              (pelts x)[j] = (pelts (old x))[j] }
    writes   { x.data.elts }
  =
    let ghost ox = { x } in
    let c = ref y in
    let lx : ref limb = ref 0 in
    let i : ref int32 = ref 0 in
    while not (Limb.(=) !c 0) do
      invariant { 0 <= !i <= sz }
      invariant { !i = sz -> !c = 0 }
      invariant { !i > 0 -> 0 <= !c <= 1 }
      invariant { value x !i + (power radix !i) * !c
                  = value ox !i + y }
      invariant { forall j. !i <= j < sz ->
                  (pelts x)[x.offset + j] = (pelts ox)[x.offset + j] }
      invariant { forall j. j < x.offset \/ x.offset + sz <= j ->
                  (pelts x)[j] = (pelts ox)[j] }
      variant   { sz - !i }
      label StartLoop in
      lx := get_ofs x !i;
      assert { !lx = (pelts ox)[ox.offset + !i] };
      let (res, carry) = add_with_carry !lx !c 0 in (*TODO*)
      assert { res + radix * carry = !lx + !c }; (* TODO remove this *)
      value_sub_update_no_change (pelts x) (x.offset + p2i !i)
                                           (x.offset + p2i !i + 1)
                                           (x.offset + p2i sz) res;
      set_ofs x !i res;
      assert { forall j. !i < j < sz ->
                 (pelts x)[x.offset + j]
                 = (pelts ox)[x.offset + j] };
      assert { value x !i + (power radix !i) * !c = value ox !i + y };
      c := carry;
      value_tail x !i;
      value_tail ox !i;
      assert { value x (!i+1) + power radix (!i+1) * !c =
               value ox (!i+1) + y };
      i := Int32.(+) !i 1;
      assert { !i = sz -> !c = 0
               by value x sz + power radix sz * !c = value ox sz + y
                  so value ox sz + y < power radix sz
                  so 0 <= !c <= 1};
    done;
    value_concat x !i sz;
    value_concat ox !i sz;
    assert { forall j. x.offset + !i <= j < x.offset + sz ->
             (pelts x)[j] = (pelts ox)[j]
             by let k = j - x.offset in
                !i <= k < sz
                so (pelts x)[x.offset + k] = (pelts ox)[x.offset + k]};
    value_sub_frame (pelts x) (pelts ox) (x.offset + p2i !i) (x.offset + p2i sz)

485 486 487
  (** `incr_1 x sz` adds 1 to `x` in place.
      `x` has size `sz`. The addition must not overflow.
      This corresponds to `mpn_incr` *)
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
  let incr_1 (x:t) (ghost sz:int32) : unit
    requires { valid x sz }
    requires { sz > 0 }
    requires { value x sz + 1 < power radix sz }
    ensures  { value x sz = value (old x) sz + 1 }
    ensures { forall j. j < x.offset \/ x.offset + sz <= j ->
              (pelts x)[j] = (pelts (old x))[j] }
    writes   { x.data.elts }
  =
    let ghost ox = { x } in
    let r : ref limb = ref 0 in
    let ghost c : ref limb = ref 1 in
    let lx : ref limb = ref 0 in
    let i : ref int32 = ref 0 in
    while (Limb.(=) !r 0) do
      invariant { 0 <= !i <= sz }
      invariant { !i = sz -> !r <> 0 }
      invariant { !r <> 0 <-> !c = 0 }
      invariant { 0 <= !c <= 1 }
      invariant { value x !i + (power radix !i) * !c
                  = value ox !i + 1 }
      invariant { forall j. !i <= j < sz ->
                  (pelts x)[x.offset + j] = (pelts ox)[x.offset + j] }
      invariant { forall j. j < x.offset \/ x.offset + sz <= j ->
                  (pelts x)[j] = (pelts ox)[j] }
      variant   { sz - !i }
      label StartLoop in
      lx := get_ofs x !i;
      assert { !lx = (pelts ox)[ox.offset + !i] };
      let res = add_mod !lx 1 in
      r := res;
      ghost (if Limb.(=) res 0 then c := 1 else c := 0);
      assert { res + radix * !c = !lx + 1 };
      value_sub_update_no_change (pelts x) (x.offset + p2i !i)
                                           (x.offset + p2i !i + 1)
                                           (x.offset + p2i sz) res;
      set_ofs x !i res;
      assert { forall j. !i < j < sz ->
                 (pelts x)[x.offset + j]
                 = (pelts ox)[x.offset + j] };
      assert { value x !i + (power radix !i) * (!c at StartLoop) = value ox !i + 1 };
      value_tail x !i;
      value_tail ox !i;
      assert { value x (!i+1) + power radix (!i+1) * !c =
               value ox (!i+1) + 1 };
      i := Int32.(+) !i 1;
      assert { !i = sz -> !c = 0
               by value x sz + power radix sz * !c = value ox sz + 1
                  so value ox sz + 1 < power radix sz
                  so 0 <= !c <= 1};
    done;
    value_concat x !i sz;
    value_concat ox !i sz;
    assert { forall j. x.offset + !i <= j < x.offset + sz ->
             (pelts x)[j] = (pelts ox)[j]
             by let k = j - x.offset in
                !i <= k < sz
                so (pelts x)[x.offset + k] = (pelts ox)[x.offset + k]};
    value_sub_frame (pelts x) (pelts ox) (x.offset + p2i !i) (x.offset + p2i sz)

548
end