forked from AdaCore/learn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystems_programming.rst
More file actions
920 lines (591 loc) · 21.9 KB
/
systems_programming.rst
File metadata and controls
920 lines (591 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
90
91
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
155
156
157
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
425
426
427
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
485
486
487
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
Systems Programming
=====================================================================
.. include:: ../../global.txt
Type Contracts in Ada 2012 and SPARK 2014
---------------------------------------------------------------------
Systems Programming – What is it?
---------------------------------------------------------------------
- Bare metal programming
- bare board applications (no Operating System)
- Operating Systems (ex: Muen separation kernel)
- device drivers (ex: Ada Drivers Library)
- communication stacks (ex: AdaCore TCP/IP stack)
- Specifics of Systems Programming
- direct access to hardware: registers, memory, etc.
- side-effects (yes!)
- efficiency is paramount (sometimes real-time even)
- hard/impossible to debug
Systems Programming – How can SPARK help?
---------------------------------------------------------------------
- SPARK is a Systems Programming language
- same features as Ada for accessing hardware (representation clauses,
address clauses)
- as efficient as Ada or C
- Side-effects can be modeled in SPARK
- reads and writes to memory-mapped devices are modeled
- concurrent interactions with environment are modeled
- SPARK can help catch problems by static analysis
- correct flows, initialization, concurrent accesses
- absence of run-time errors and preservation of invariants
Systems Programming – A trivial example
---------------------------------------------------------------------
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Trivial_Sys_Prog
package Show_Trivial_Sys_Prog is
Y : Integer;
-- Y'Address could be replaced by any
-- external address
X : Integer with Volatile,
Address => Y'Address;
procedure Get (Val : out Integer)
with Global => (In_Out => X),
Depends => (Val => X,
X => X);
end Show_Trivial_Sys_Prog;
package body Show_Trivial_Sys_Prog is
procedure Get (Val : out Integer) is
begin
Val := X;
end Get;
end Show_Trivial_Sys_Prog;
- Comments:
- ``X`` is volatile
- ``X`` is also an output; output ``X`` depends on input ``X``
- ``X`` is only read
Volatile Variables and Volatile Types
---------------------------------------------------------------------
- Variables whose reads/writes cannot be optimized away
- Identified through multiple aspects (or pragmas)
- aspect :ada:`Volatile`
- but also aspect :ada:`Atomic`
- and GNAT aspect :ada:`Volatile_Full_Access`
- all the above aspects can be set on type or object
- Other aspects are useful on volatile variables
- aspect :ada:`Address` to specify location in memory
- aspect :ada:`Import` to skip definition/initialization
.. code-block:: ada
type T is new Integer with Volatile;
X : Integer with Atomic, Import, Address => ... ;
Flavors of Volatile Variables
---------------------------------------------------------------------
Using ``Async_Readers`` / ``Async_Writers``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Boolean aspects describing asynchronous behavior
- :ada:`Async_Readers` if variable may be read asynchronously
- :ada:`Async_Writers` if variable may be written asynchronously
- Effect of :ada:`Async_Readers` on flow analysis
- Effect of :ada:`Async_Writers` on flow analysis & proof
- always initialized, always has an unknown value
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
package Volatile_Vars is
pragma Elaborate_Body;
Ext : array (1 .. 2) of Integer;
X : Integer with Volatile,
Address => Ext (1)'Address,
Async_Readers;
Y : Integer with Volatile,
Address => Ext (2)'Address,
Async_Writers;
procedure Set;
end Volatile_Vars;
package body Volatile_Vars is
procedure Set is
U, V : constant Integer := Y;
begin
pragma Assert (U = V);
X := 0;
X := 1;
end Set;
begin
Ext := (others => 0);
end Volatile_Vars;
.. code:: ada run_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
with Volatile_Vars;
procedure Show_Volatile_Vars is
begin
Volatile_Vars.Set;
end Show_Volatile_Vars;
Using ``Effective_Reads`` / ``Effective_Writes``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Boolean aspects distinguishing values & sequences
- :ada:`Effective_Reads` if reading the variable has an effect on its
value
- :ada:`Effective_Writes` if writing the variable has an effect on its
value
- Effect of both on proof and flow dependencies
- Final value of variable is seen as a sequence of values it took
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
package Volatile_Vars is
pragma Elaborate_Body;
Ext : array (1 .. 2) of Integer;
X : Integer with Volatile,
Address => Ext (1)'Address,
Async_Readers,
Effective_Writes;
Y : Integer with Volatile,
Address => Ext (2)'Address,
Async_Writers,
Effective_Reads;
procedure Set with
Depends => (X => Y,
Y => Y);
end Volatile_Vars;
package body Volatile_Vars is
procedure Set is
begin
X := Y;
X := 0;
end Set;
begin
Ext := (others => 0);
end Volatile_Vars;
.. code:: ada run_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
with Volatile_Vars;
procedure Show_Volatile_Vars is
begin
Volatile_Vars.Set;
end Show_Volatile_Vars;
Combinations of Flavors of Volatile Variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- All four flavors can be set independently
- Default for Volatile/Atomic is all four :ada:`True`
- When some aspects set, all others default to :ada:`False`
- Only half the possible combinations are legal
- :ada:`Async_Readers` and/or :ada:`Async_Writers` is set
- :ada:`Effective_Reads = True` forces :ada:`Async_Writers = True`
- :ada:`Effective_Writes = True` forces :ada:`Async_Readers = True`
- sensor: :ada:`AW=True`
- actuator: :ada:`AR=True`
- input port: :ada:`AW=True`, :ada:`ER=True`
- output port: :ada:`AR=True`, :ada:`EW=True`
Constraints on Volatile Variables
---------------------------------------------------------------------
- Volatile variables must be defined at library level
- Expressions (and functions) cannot have side-effects
- read of variable with :ada:`AW=True` must appear alone on *rhs* of
assign
- a function cannot read a variable with :ada:`ER=True`
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
package Volatile_Vars is
pragma Elaborate_Body;
Ext : array (1 .. 4) of Integer;
AR : Integer with Volatile,
Address => Ext (1)'Address,
Async_Readers;
AW : Integer with Volatile,
Address => Ext (2)'Address,
Async_Writers;
ER : Integer with Volatile,
Address => Ext (3)'Address,
Async_Writers,
Effective_Reads;
EW : Integer with Volatile,
Address => Ext (4)'Address,
Async_Readers,
Effective_Writes;
procedure Read_All;
function Read_ER return Integer;
procedure Set (V : Integer);
end Volatile_Vars;
package body Volatile_Vars is
procedure Read_All is
Tmp : Integer := 0;
begin
Tmp := Tmp + AR;
Tmp := Tmp + AW;
EW := Tmp;
Set (ER);
end Read_All;
function Read_ER return Integer is
Tmp : Integer := ER;
begin
return Tmp;
end Read_ER;
procedure Set (V : Integer) is
begin
AW := V;
end Set;
begin
Ext := (others => 0);
end Volatile_Vars;
.. code:: ada run_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
with Volatile_Vars;
procedure Show_Volatile_Vars is
V : Integer;
begin
Volatile_Vars.Read_All;
V := Volatile_Vars.Read_ER;
end Show_Volatile_Vars;
- Comments:
- AW not alone on rhs
- ER not alone on rhs
- ER output of Read_ER
Constraints on Volatile Functions
---------------------------------------------------------------------
- Functions should have mathematical interpretation
- a function reading a variable with :ada:`AW=True` is marked as
volatile with aspect :ada:`Volatile_Function`
- calls to volatile functions are restricted like reads of
:ada:`Async_Writers`
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
package Volatile_Vars is
pragma Elaborate_Body;
Ext : array (1 .. 4) of Integer;
AR : Integer with Volatile,
Address => Ext (1)'Address,
Async_Readers;
AW : Integer with Volatile,
Address => Ext (2)'Address,
Async_Writers;
ER : Integer with Volatile,
Address => Ext (3)'Address,
Async_Writers,
Effective_Reads;
EW : Integer with Volatile,
Address => Ext (4)'Address,
Async_Readers,
Effective_Writes;
function Read_Non_Volatile
return Integer;
function Read_Volatile
return Integer
with Volatile_Function;
function Read_ER
return Integer
with Volatile_Function;
end Volatile_Vars;
package body Volatile_Vars is
function Read_Non_Volatile
return Integer is
Tmp : Integer := 0;
begin
-- reads AR, AW, EW
-- ERROR: not a volatile function
Tmp := Tmp + AR;
Tmp := Tmp + AW;
Tmp := Tmp + EW;
return Tmp;
end Read_Non_Volatile;
function Read_Volatile
return Integer is
Tmp : Integer := 0;
begin
-- reads AR, AW, EW
-- OK for volatile function
Tmp := Tmp + AR;
Tmp := Tmp + AW;
Tmp := Tmp + EW;
return Tmp;
end Read_Volatile;
function Read_ER
return Integer is
Tmp : Integer := ER;
begin
-- reads ER
-- ERROR: ER output of Read_ER
return Tmp;
end Read_ER;
begin
Ext := (others => 0);
end Volatile_Vars;
.. code:: ada run_button project=Courses.Advanced_SPARK.Systems_Programming.Volatile_Vars
with Volatile_Vars;
procedure Show_Volatile_Vars is
V : Integer;
begin
V := Volatile_Vars.Read_Non_Volatile;
V := Volatile_Vars.Read_Volatile;
V := Volatile_Vars.Read_ER;
end Show_Volatile_Vars;
State Abstraction on Volatile Variables
---------------------------------------------------------------------
- Abstract state needs to be identified as :ada:`External`
- Flavors of volatility can be specified
- Default if none specified is all True
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.State_Abstraction_1
package P1 with
Abstract_State => (S with External)
is
procedure Process (Data : out Integer) with
Global => (In_Out => S);
end P1;
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.State_Abstraction_2
package P2 with
Abstract_State => (S with External =>
(Async_Writers,
-- OK if refined into AW, ER
Effective_Reads)
-- not OK if refined into AR, EW
)
is
procedure Process (Data : out Integer) with
Global => (In_Out => S);
end P2;
Constraints on Address Attribute
---------------------------------------------------------------------
- Address of volatile variable can be specified
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Address_Attribute
package Show_Address_Attribute is
Ext : array (1 .. 2) of Integer;
X : Integer with Volatile,
Address => Ext (1)'Address;
Y : Integer with Volatile;
for Y'Address use Ext (2)'Address;
end Show_Address_Attribute;
- Address attribute not allowed in expressions
- Overlays are allowed
- GNATprove does not check absence of overlays
- GNATprove does not model the resulting aliasing
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Address_Overlay
procedure Show_Address_Overlay is
X : Integer := 1;
Y : Integer := 0
with Address => X'Address;
pragma Assert (X = 1);
-- assertion wrongly proved
begin
null;
end Show_Address_Overlay;
Can something be known of volatile variables?
---------------------------------------------------------------------
- Variables with :ada:`Async_Writers` have no known value
- ... but they have a known type!
- type range, ex: :ada:`0 .. 360`
- type predicate, ex: :ada:`0 .. 15 | 17 .. 42 | 43 .. 360`
- Variables without :ada:`Async_Writers` have a known value
- GNATprove also assumes all values are valid (:ada:`X'Valid`)
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Provable_Volatile_Var
package Show_Provable_Volatile_Var is
X : Integer with Volatile, Async_Readers;
procedure Read_Value;
end Show_Provable_Volatile_Var;
package body Show_Provable_Volatile_Var is
procedure Read_Value is
begin
X := 42;
pragma Assert (X = 42);
-- proved!
end Read_Value;
end Show_Provable_Volatile_Var;
Other Concerns in Systems Programming
---------------------------------------------------------------------
- Software startup state ⟶ elaboration rules
- SPARK follows Ada static elaboration model
- ... with additional constraints for ensuring correct initialization
- ... but GNATprove follows the relaxed GNAT static elaboration
- Handling of faults ⟶ exception handling
- raising exceptions is allowed in SPARK
- ... but exception handlers are :ada:`SPARK_Mode => Off`
- ... typically the last-chance-handler is used instead
- Concurrency inside the application ⟶ tasking support
- Ravenscar and Extended_Ravenscar profiles supported in SPARK
Code Examples / Pitfalls
---------------------------------------------------------------------
Example #1
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_01
:class: ada-expect-compile-error
package Example_01 is
Ext : Integer;
X : Integer with Volatile,
Address => Ext'Address;
procedure Get (Val : out Integer)
with Global => (Input => X),
Depends => (Val => X);
end Example_01;
package body Example_01 is
procedure Get (Val : out Integer) is
begin
Val := X;
end Get;
end Example_01;
This code is not correct. ``X`` has :ada:`Effective_Reads` set by default,
hence it is also an output.
Example #2
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_02
:class: ada-expect-compile-error
package Example_02 is
Ext : Integer;
X : Integer with Volatile, Address => Ext'Address,
Async_Readers, Async_Writers, Effective_Writes;
procedure Get (Val : out Integer)
with Global => (Input => X),
Depends => (Val => X);
end Example_02;
package body Example_02 is
procedure Get (Val : out Integer) is
begin
Val := X;
end Get;
end Example_02;
This code is correct. ``X`` has :ada:`Effective_Reads = False`, hence it
is only an input.
Example #3
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_03
package Example_03 is
Speed : Float with Volatile, Async_Writers;
Motor : Float with Volatile, Async_Readers;
procedure Adjust with
Depends => (Motor =>+ Speed);
end Example_03;
package body Example_03 is
procedure Adjust is
Cur_Speed : constant Float := Speed;
begin
if abs Cur_Speed > 100.0 then
Motor := Motor - 1.0;
end if;
end Adjust;
end Example_03;
This code is correct. ``Speed`` is an input only, ``Motor`` is both an
input and output. Note how the current value of ``Speed`` is first copied
to be tested in a larger expression.
Example #4
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_04
package Example_04 is
Raw_Data : Float with Volatile,
Async_Writers, Effective_Reads;
Data : Float with Volatile,
Async_Readers, Effective_Writes;
procedure Smooth with
Depends => (Data => Raw_Data);
end Example_04;
package body Example_04 is
procedure Smooth is
Data1 : constant Float := Raw_Data;
Data2 : constant Float := Raw_Data;
begin
Data := Data1;
Data := (Data1 + Data2) / 2.0;
Data := Data2;
end Smooth;
end Example_04;
This code is not correct. ``Raw_Data`` has :ada:`Effective_Reads` set,
hence it is also an output.
Example #5
~~~~~~~~~~
.. code:: ada no_button project=Courses.Advanced_SPARK.Systems_Programming.Example_05
package Example_05 is
type Regval is new Integer with Volatile;
type Regnum is range 1 .. 32;
type Registers is array (Regnum) of Regval;
Regs : Registers with Async_Writers, Async_Readers;
function Reg (R : Regnum) return Integer is
(Integer (Regs (R))) with Volatile_Function;
end Example_05;
This code is not correct. ``Regs`` has :ada:`Async_Writers` set, hence it
cannot appear as the expression in an expression function.
Example #6
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_06
package Example_06 is
type Regval is new Integer with Volatile;
type Regnum is range 1 .. 32;
type Registers is array (Regnum) of Regval;
Regs : Registers with Async_Writers, Async_Readers;
function Reg (R : Regnum) return Integer
with Volatile_Function;
end Example_06;
package body Example_06 is
function Reg (R : Regnum) return Integer is
V : Regval := Regs (R);
begin
return Integer (V);
end Reg;
end Example_06;
This code is not correct. ``Regval`` is a volatile type, hence variable
``V`` is volatile and cannot be declared locally.
Example #7
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_07
package Example_07 is
type Regval is new Integer with Volatile;
type Regnum is range 1 .. 32;
type Registers is array (Regnum) of Regval;
Regs : Registers with Async_Writers, Async_Readers;
function Reg (R : Regnum) return Integer
with Volatile_Function;
end Example_07;
package body Example_07 is
function Reg (R : Regnum) return Integer is
begin
return Integer (Regs (R));
end Reg;
end Example_07;
This code is correct. ``Regs`` has :ada:`Effective_Reads = False` hence
can be read in a function. Function ``Reg`` is marked as volatile with
aspect :ada:`Volatile_Function`. No volatile variable is declared locally.
Example #8
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_08
package Example_08 with
Abstract_State => (State with External),
Initializes => State
is
procedure Dummy;
end Example_08;
package body Example_08 with
Refined_State => (State => (X, Y, Z))
is
X : Integer with Volatile, Async_Readers;
Y : Integer with Volatile, Async_Writers;
Z : Integer := 0;
procedure Dummy is
begin
null;
end Dummy;
end Example_08;
This code is not correct. ``X`` has :ada:`Async_Writers = False`, hence is
not considered as always initialized. As aspect :ada:`Initializes`
specifies that ``State`` should be initialized after elaboration, this is
an error. Note that is allowed to bundle volatile and non-volatile
variables in an external abstract state.
Example #9
~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_09
package Example_09 is
type Pair is record
U, V : Natural;
end record
with Predicate => U /= V;
X : Pair with Atomic, Async_Readers, Async_Writers;
function Max return Integer with
Volatile_Function,
Post => Max'Result /= 0;
end Example_09;
package body Example_09 is
function Max return Integer is
Val1 : constant Natural := X.U;
Val2 : constant Natural := X.V;
begin
return Natural'Max (Val1, Val2);
end Max;
end Example_09;
This code is not correct. ``X`` has :ada:`Async_Writers` set, hence it may
have been written between the successive reads of ``X.U`` and ``X.V``.
Example #10
~~~~~~~~~~~
.. code:: ada compile_button project=Courses.Advanced_SPARK.Systems_Programming.Example_10
package Example_10 is
type Pair is record
U, V : Natural;
end record
with Predicate => U /= V;
X : Pair with Atomic, Async_Readers, Async_Writers;
function Max return Integer with
Volatile_Function,
Post => Max'Result /= 0;
end Example_10;
package body Example_10 is
function Max return Integer is
P : constant Pair := X;
Val1 : constant Natural := P.U;
Val2 : constant Natural := P.V;
begin
return Natural'Max (Val1, Val2);
end Max;
end Example_10;
This code is correct. Values of ``P.U`` and ``P.V`` are provably
different, and the postcondition is proved.