text stringlengths 128 2.05k |
|---|
CASE II [MATH] is not singularized: In this case the inductive claim is an immediate consequence of the following proposition: Proposition 5.4 |
Assuming induction hypothesis ( ), if [MATH] is not singularized, then [MATH] so that [MATH] [MATH] and [MATH] It now suffices to consider singularized [MATH] |
Definition 5.5 Define the width of [MATH] to be [MATH] An interval [MATH] with height [MATH] is called narrow if [MATH] We say [MATH] is narrow if all its intervals are narrow. (Observe that every [MATH] is narrow.) |
If [MATH] singularized but not narrow, it can also be improved. CASE III [MATH] is singularized but not narrow: In this case the inductive claim is an immediate consequence of the following proposition: |
Proposition 5.6 If [MATH] is singularized but not narrow, then [MATH] so that [MATH] [MATH] and [MATH] Finally, we consider the remaining case that [MATH] is singularized, narrow, and not in [MATH] |
CASE IV [MATH] but [MATH] is both singularized and narrow: In this case the inductive claim is an immediate consequence of the following proposition: |
Proposition 5.7 Assuming induction hypothesis ( ), for [MATH] if [MATH] is singularized and narrow, then [MATH] so that [MATH] [MATH] and [MATH] |
Now, assuming Propositions 5.4 5.6 and 5.7 , which we prove in the following sections, and putting Cases II, III, and IV together, we immediately derive Claim 5.2 |
From Case I if [MATH] then [MATH] which is sufficient. Otherwise, we apply Claim 5.2 to obtain [MATH] so that [MATH] [MATH] and [MATH] By the induction hypothesis ( ), |
[MATH] Therefore [EQUATION] as required and the lemma follows by induction. We now finish the overall argument by proving each of the Propositions 5.4 5.6 and 5.7 in each of the following subsections. |
5.1 Singularization In this subsection we prove Proposition 5.4 Proof of Proposition 5.4 We claim that the following algorithm on input [MATH] that is not singularized, outputs [MATH] so that [MATH] |
[MATH] and [MATH] Input: [MATH] Output: Singularized [MATH] for [MATH] do Compute [MATH] Compute [MATH] so that [MATH] /* Here we use the fact that [MATH] */ |
[MATH] [MATH] for [MATH] do [MATH] Algorithm 3 Singularization First, inside each original group [MATH] we always have [MATH] by construction. Moreover, between groups we have |
[EQUATION] and therefore [MATH] Now let us consider [MATH] for [MATH] By the algorithm and definition 4.1 we have [EQUATION] so, |
[EQUATION] This is the place where we can use the induction hypothesis. Notice that [MATH] Consider the configuration [MATH] Then [MATH] Moreover, |
[MATH] So by ( ) we have [EQUATION] which gives [EQUATION] This holds for every original interval. So in total we have [MATH] Also, the construction clearly gives us |
[EQUATION] Let [MATH] be the first original interval that is not singularized. Then by construction we can see that [MATH] for [MATH] If [MATH] then clearly [MATH] Otherwise [MATH] because [MATH] is not singularized. Again we have [MATH] So [MATH] is strictly lexicographically larger than [MATH] which implies [MATH] |
5.2 Transposing In this subsection we prove Proposition 5.6 For convenience of notations, we use [MATH] which we call the [MATH] -th order width of [MATH] |
Proof of Proposition 5.6 We claim that the following algorithm on input [MATH] that is not narrow, outputs [MATH] so that [MATH] |
[MATH] and [MATH] Input: Singularized [MATH] Output: [MATH] Let [MATH] be the smallest integer so that [MATH] is not narrow. for |
[MATH] do if [MATH] then /* We do not change numbers before [MATH] -th group */ [MATH] else /* first set [MATH] */ [MATH] [MATH] |
for [MATH] do 10 [MATH] 11 12 for [MATH] do 13 [MATH] Algorithm 4 Transposing We first argue that [MATH] Notice that [MATH] is a decreasing function on [MATH] By construction, for [MATH] |
[MATH] When [MATH] clearly [MATH] When [MATH] we claim that [MATH] must be 0. This is because for contradiction assume [MATH] for some [MATH] then by setting [MATH] we have [MATH] while [MATH] which implies [MATH] So [MATH] We conclude that when [MATH] |
[MATH] If [MATH] because [MATH] we have [MATH] when [MATH] So we only need to show that [MATH] To see this, because [MATH] is narrow, we have [MATH] Also, |
[MATH] otherwise we will not have the next group. So [EQUATION] Therefore [MATH] . Then we argue that [MATH] This is because for singularized [MATH] |
[EQUATION] On the other hand, [EQUATION] But we have [EQUATION] Notice that when [MATH] , we have [MATH] so [EQUATION] and [EQUATION] |
Here we use the fact that [MATH] is not narrow, hence [MATH] Combining these lines gives us [MATH] We next argue that [MATH] is lexicographically larger than [MATH] For [MATH] we have [MATH] But since [MATH] is not narrow, we have |
[EQUATION] Therefore [MATH] . We finally show that [MATH] We have [EQUATION] On the other hand, we have for [MATH] [MATH] So [EQUATION] |
Comparing the two expressions, it is sufficient to show that [EQUATION] Indeed, we have [EQUATION] where we use the fact that [MATH] when [MATH] |
5.3 Repacking In this section we prove Proposition 5.7 We need one auxiliary lemma. Lemma 5.8 Assuming induction hypothesis ( ), then for all integers [MATH] so that [MATH] , for every integer [MATH] |
[EQUATION] Proof. Without loss of generality assume that [MATH] Then consider [MATH] We can verify that [MATH] and [MATH] Hence [MATH] Now, by Corollary 4.5 |
[MATH] therefore [EQUATION] Now consider [MATH] that is singularized and narrow. Vectors in [MATH] are very structured in the sense that they can have at most 3 heights. Inspired by the definition of [MATH] we have the following definition. |
Definition 5.9 An interval [MATH] is called [MATH] -packed if one of the following happens: [MATH] and [MATH] where [MATH] or [MATH] so that [MATH] [MATH] [MATH] and [MATH] |
Interval [MATH] is called packed if there exists a [MATH] so that [MATH] is [MATH] -packed. With this definition, we can verify that [MATH] |
[MATH] is [MATH] -packed on [MATH] Since [MATH] let [MATH] be the smallest integer so that [MATH] is packed; then either [MATH] or [MATH] is [MATH] -packed for some [MATH] We are going to rearrange [MATH] so that it is [MATH] -packed to improve [MATH] |
Proof of Proposition 5.7 We claim that the following operation on input [MATH] that is singularized and narrow, outputs [MATH] so that [MATH] |
[MATH] and [MATH] We first select the smallest [MATH] so that [MATH] is packed. Then [MATH] is [MATH] -packed where [MATH] is the height of the interval [MATH] Then we set [MATH] for all [MATH] that is, we only “repack” the interval [MATH] We compute [MATH] then compute [MATH] and [MATH] Then we set [MATH] for [MATH] s... |
We first argue that [MATH] Here we use the fact that [MATH] is singularized, therefore when [MATH] [MATH] for all [MATH] If [MATH] then we have [MATH] because when [MATH] |
[MATH] is of the form [MATH] if [MATH] we can see that [MATH] is also packed, which contradicts the assumption of [MATH] Now we are ready to prove properties of [MATH] First we show that [MATH] This is obvious if [MATH] Otherwise, by construction we only need to show that [MATH] Since [MATH] we have [MATH] So [MATH] |
By construction, we can see [MATH] Now we argue that [MATH] If [MATH] this is obvious from construction. Otherwise if [MATH] first we must have [MATH] otherwise since [MATH] |
[MATH] But by the choice of [MATH] we must have [MATH] and [MATH] otherwise we could choose [MATH] So [MATH] which implies that [MATH] |
The proposition is immediate from the following claim whose proof is somewhat tedious. Claim 5.10 Let [MATH] be the vector obtained by repacking. Assuming induction hypothesis ( ), we have |
[MATH] It remains to prove this claim. By construction, when [MATH] [MATH] hence [EQUATION] To prove the claim, we will expand the [MATH] function in the summations. We will see that those summations have many terms in common, so we can do a lot of cancellation. Furthermore, we will use Corollary 4.4 which allows us to... |
Since [MATH] is singularized and [MATH] is packed, without losing generality we may assume [MATH] is of the form [EQUATION] Here, [MATH] is the height of the interval [MATH] |
and [MATH] is the height of the interval [MATH] To avoid unnecessary special cases, we set [MATH] if [MATH] then we can view all four of these cases as occurring. |
Notice that in ( ), all the terms in the summations start with [MATH] To simplify notation, we shift the indices so that we start from [MATH] For [MATH] we set [MATH] and [MATH] Then [MATH] is a vector of length [MATH] Let [MATH] and [MATH] Also in order to drop messy subscripts, we set |
[MATH] [MATH] [MATH] and [MATH] By replacing symbols, we have [EQUATION] Hence we can compute [MATH] Also, since [MATH] is narrow, by Definition 5.5 |
[MATH] Recall that [MATH] We argue that [MATH] Indeed, since [EQUATION] we get [MATH] On the other hand, if [MATH] then [MATH] which is equivalent to |
[EQUATION] But this cannot be true, since [MATH] and [MATH] So we know that [MATH] can only be [MATH] or [MATH] Observe that [EQUATION] |
and [EQUATION] These two summations are very similar in the sense that we can break them into two parts: one structured summation where the input of the [MATH] function is some power of [MATH] and another part where the input is quite irregular. If [MATH] then we can “align” the structured part; otherwise, there will b... |
Case 1 [MATH] : If this happens, we must have [MATH] which is equivalent to [EQUATION] Notice that for [MATH] , by Definition 4.1 we have |
[EQUATION] Together with ( 5.3 ) and ( ), ( ) becomes [EQUATION] Since we have [EQUATION] and since [MATH] and [MATH] by Definition 4.1 we have |
[EQUATION] Now, because we have [EQUATION] ) can be simplified further to [EQUATION] Notice that [MATH] so, by Corollary 4.5 [MATH] Hence we can apply Lemma 5.8 by using [MATH] [MATH] to get |
[EQUATION] which leads to [MATH] Case 2 [MATH] : In this case, we must have [MATH] which is equivalent to [EQUATION] So [MATH] In this case, ) becomes |
[EQUATION] We observe here that [MATH] and let [MATH] Because [MATH] we have [MATH] Letting [MATH] then we have [EQUATION] Notice that [MATH] and [MATH] , hence [MATH] , so |
[EQUATION] So we can plug ( 5.3 ) and ( ) into ) to get [EQUATION] We now break this case into sub-cases depending on the relationship between [MATH] and [MATH] |
Sub-Case 2a [MATH] : Since [MATH] [MATH] So by Corollary 4.4 we have [EQUATION] So ( ) can be reduced as [EQUATION] First suppose that [MATH] : Since [MATH] and [MATH] this can only happen when [MATH] and [MATH] For notational convenience, let [MATH] then we only need to argue that |
[EQUATION] where [MATH] To see this, let [MATH] and [MATH] and note that [MATH] By Corollary 4.4 [MATH] Therefore [EQUATION] Now, consider the induction hypothesis applied to [MATH] since [MATH] we have [MATH] This implies |
[EQUATION] which gives the result. Alternatively, assume that [MATH] : Notice that [MATH] so [MATH] Hence [EQUATION] Now, [MATH] and [MATH] so we can apply Corollary 4.4 to get |
[EQUATION] Plugging into ( ), we get [EQUATION] If [MATH] then we can apply Lemma 5.8 to show that [MATH] Otherwise, if [MATH] then we are back to inequality in the form of ( ), which also gives us [MATH] as required. |
Case 2b [MATH] : Notice that [MATH] and [MATH] so [EQUATION] and [EQUATION] Therefore ) can be rewritten as [EQUATION] Notice that [MATH] so, by the fact that |
[MATH] we actually have [EQUATION] So, we have [EQUATION] This is a somewhat familiar expression. Actually, the right-hand side of ( ) is of the same form as ( ). With a similar argument we can also conclude that [MATH] |
# Source: arxiv 1806.07041 # Title: Reasoning about Polymorphic Manifest Contracts # Sections: all # Downloaded: 2026-03-03T02:30:45.840997+00:00 |
Reasoning About Polymorphic Manifest Contracts Abstract. Manifest contract calculi, which integrate cast-based dynamic contract checking and refinement type systems, have been studied as foundations for hybrid contract checking. In this article, we study techniques to reasoning about a polymorphic manifest contract cal... |
types and prove that a term obtained by eliminating upcasts—casts from one type to a supertype of it—is logically related and so contextually equivalent to the original one. We also justify two other program transformations for casts: selfification and static cast decomposition, which help upcast elimination. A challen... |
semityped relations: only one side of the relations is required to be well typed and the other side may be ill typed. 1. Introduction |
1.1. Software contracts Software contracts Meyer_1988_book are a promising program verification tool to develop robust, dependable software. Contracts are agreements between a supplier and a client of software components. On one hand, contracts are what the supplier guarantees. On the other hand, they are what the clie... |
Contracts can be verified by two complementary approaches: static and dynamic verification. Dynamic verification is possible due to executability of contracts—the run-time system can confirm that a contract holds by evaluating it. Since Eiffel advocated “Design by Contracts” Meyer_1988_book , there has been extensive w... |
is another, complementary approach to program verification with contracts. It causes no run-time overhead and guarantees that contracts are always satisfied at run time, while it is difficult to use—it often requires heavy annotations in programs, gives complicated error messages, and restricts the expressive power of ... |
1.2. Manifest contracts To take the best of both, hybrid contract verification—where contracts are verified statically if possible and, otherwise, dynamically—was proposed by Flanagan Flanagan_2006_POPL , and calculi of manifest contracts |
have been studied as its theoretical foundation. Manifest contracts refer to contract systems where contract information occurs as part of types. In particular, contracts are embedded into types by refinement types |
[MATH] which denote a set of values [MATH] of [MATH] such that [MATH] satisfies Boolean expression [MATH] (which is called a contract or a refinement ), that is, [MATH] evaluates to [MATH] For example, using refinement types, a type of positive numbers is represented by [MATH] |
Dynamic verification in manifest contracts is performed by dynamic type conversion, called casts A cast [MATH] checks that, when applied to value [MATH] of source type |
[MATH] [MATH] can behave as target type [MATH] In particular, if [MATH] is a refinement type, the cast checks that [MATH] satisfies the contract of [MATH] If the contract check succeeds, the cast returns [MATH] ; otherwise, if it fails, an uncatchable exception, called blame , will be raised. For example, let us consid... |
Static contract verification is formalized as subtyping , which statically checks that any value of a subtype behaves as a supertype. In particular, a refinement type [MATH] is a subtype of another |
[MATH] if any value of [MATH] satisfying [MATH] behaves as [MATH] and satisfies [MATH] For example, [MATH] is a subtype of [MATH] |
because all prime numbers should be positive. Hybrid contract verification integrates these two verification mechanisms of contracts. In the hybrid approach, for every program point where a type |
[MATH] is required to be a subtype of [MATH] , a type checker first tries to solve the instance of the subtyping problem statically. Unfortunately, since contracts are arbitrary Boolean expressions in a Turing-complete language, the subtyping problem is undecidable in general. Thus, the type checker may not be able to ... |
[MATH] are given types [MATH] and [MATH] , respectively. Given this expression, the type checker tries to see if [MATH] is a subtype of |
[MATH] If the checker is strong enough, it will find out that values of [MATH] are only three, five, and seven and that the subtyping relation holds and accept [MATH] ; otherwise, cast [MATH] is inserted to check [MATH] satisfies contract [MATH] at run time and the resulting expression [MATH] will be evaluated. |
1.3. Our work In this article, we study program reasoning in manifest contracts. The first goal of the reasoning is to justify hybrid contract verification. As described in Section 1.2 , a cast is inserted if an instance of the subtyping problem is not solved statically. Unfortunately, due to undecidability of the subt... |
In fact, the upcast elimination has been studied in the prior work on manifest contracts Flanagan_2006_POPL Knowles/Flanagan_2010_TOPLAS Belo/Greenberg/Igarashi/Pierce_2011_ESOP but it is not satisfactory. Flanagan Flanagan_2006_POPL and Belo et al. Belo/Greenberg/Igarashi/Pierce_2011_ESOP studied the upcast eliminatio... |
We introduce a subsumption-free polymorphic manifest contract calculus [MATH] and show the upcast elimination for it. [MATH] is subsumption-free in the sense that it lacks a typing rule of subsumption, that is, to promote the type of an expression to a supertype (in fact, subtyping is not even part of the calculus) and... |
Sekiyama/Igarashi/Greenberg_2016_TOPLAS For example, given [MATH] , our “fussy” semantics checks both [MATH] and [MATH] , while Belo et al.’s “sloppy” semantics checks only [MATH] because [MATH] is ensured by the source type. Our fussy semantics resolves the issue of type soundness in Belo et al. and is arguably simple... |
In addition to the upcast elimination, we study reasoning about casts to make static contract verification more effective. In particular, this work studies two additional reasoning techniques. The first is selfification |
Ou/Tan/Mandelbaum/Walker_2004_TCS which embeds information of expressions into their types. For example, it gives expression [MATH] of integer type [MATH] more informative refinement type [MATH] (where |
[MATH] is a Boolean equality operator on integers). The selfification is easily extensible to higher-order types, and it is especially useful when given type information is not sufficient to solve subtyping instances; see Section LABEL:sec:reasoning-self for an example. We formalize the selfification by casts: given [M... |
[MATH] is equivalent to a cast application [MATH] , where [MATH] is the resulting type of embedding [MATH] into [MATH] In other words, [MATH] behaves as an expression of [MATH] The second is static cast decomposition , which leads to elimination of more upcasts obtained by reducing nonredundant casts. |
We show correctness of three reasoning techniques about casts—the upcast elimination, the selfification, and the cast decomposition—based on contextual equivalence: we prove that (1) an upcast is contextually equivalent to an identity function, (2) a cast application [MATH] is to |
[MATH] , and (3) a cast is to its static decomposition. We have to note that contextual equivalence that relates only terms of the same type (except for the case of type variables) is useless in this work because we want to show contextual equivalence between terms of different types For example, an upcast and an ident... |
contextual equivalence—we introduce semityped contextual equivalence, where a well-typed term and a possibly ill-typed term can be related, and show correctness of cast reasoning based on it. |
Since, as is well known, it is difficult to prove contextual equivalence of programs directly, we apply a proof technique based on logical relations |
Plotkin_1980_TODO Reynolds_1983_IFIP We develop a logical relation for manifest contracts and show its soundness with respect to semityped contextual equivalence. We also show completeness of our logical relation with respect to well-typed terms in semityped contextual equivalence, via semityped CIU-equivalence Mason/T... |
1.4. Organization and proofs The rest of this paper is organized as follows. We define our polymorphic manifest contract calculus [MATH] equipped with fussy cast semantics in Section Section introduces semityped contextual equivalence and Section develops a logical relation for [MATH] We show that the logical relation ... |
Most of our proofs are written in the pencil-and-paper style, but the proof of cotermination, which is a key, but often flawed, property of manifest contracts, is given by Coq proof script coterm.v at |
2. Polymorphic Manifest Contract Calculus [MATH] This section formalizes a polymorphic manifest contract calculus [MATH] and proves its type soundness. As described in Section 1.3 , our run-time system checks even refinements which have been ensured already, which enables us to prove cotermination a key property to sho... |
2.1. Syntax Figure shows the syntax of [MATH] , which is based on Belo et al. Belo/Greenberg/Igarashi/Pierce_2011_ESOP Types, ranged over by [MATH] , are from the standard polymorphic lambda calculus except dependent function types and refinement types. Base types, denoted by [MATH] , are parameterized, but we suppose ... |
[MATH] such that [MATH] evaluates to [MATH] As the prior work Belo/Greenberg/Igarashi/Pierce_2011_ESOP Sekiyama/Nishida/Igarashi_2015_POPL Sekiyama/Igarashi/Greenberg_2016_TOPLAS our refinement types are general in the sense that any type |
[MATH] can be refined, while some work Ou/Tan/Mandelbaum/Walker_2004_TCS Flanagan_2006_POPL allows only base types to be refined. Dependent function types [MATH] bind variable [MATH] of domain type |
[MATH] in codomain type [MATH] , and universal types [MATH] bind type variable [MATH] in [MATH] Typing contexts [MATH] are a sequence of type variables and bindings of the form [MATH] , and we suppose that term and type variables bound in a typing context are distinct. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.