Recusion bounds

View: New views
4 Messages — Rating Filter:   Alert me  

Recusion bounds

by Dr. James J. Hunt-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Colleagues,

Why has @decreasing not been defined to apply to recursive methods as
well as loop statements?  One would have to define, whether to it terms
of recursion depth or breadth.  Otherwise, I would expect it to be
analogous the loop case.

Sincerely,
James

--
Dr. James J. Hunt      * CEO aicas group       * Tel: +49 721 663968 22

aicas incorporated
69 West Rock Ave.      * New Haven, CT 06515   * USA
http://www.aicas.com   * Tel: +1 203 676 9807  *

Business Filing Number: 0002879819, State of Connecticut
President: Dr. James J. Hunt, Secretary/Treasurer: David P. Reddy

aicas --- allerton interworks computer automated systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe     * Deutschland (Germany)
http://www.aicas.com   * Tel: +49 721 663968 0 * FAX: +49 721 663968 99

USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim
Geschäftsführer: Dr. James J. Hunt


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Jmlspecs-interest mailing list
Jmlspecs-interest@...
https://lists.sourceforge.net/lists/listinfo/jmlspecs-interest

Parent Message unknown Re: Recusion bounds

by Dr. James J. Hunt-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Gary,

I do not think measured by really would help.  I am interested in
determining the number of times a given method would be called in a
recursion.  In a simple recursion, there is no difference between width
and breath.  By breath, I mean the total number of times a method is
called in a recursion, not just the depth of the recursion.  For
instance in the fibonacci double recursion algorithm, fibonacci itself
is call much more often than the depth of the recursion.  In general, a
depth approach would both suffice and be simpler to analyze.

We are currently working on binding our data flow analysis tool on
AbsInt's WCETA analysis tool.  We have successfully used the normal
@decreasing clause to determine the concrete loop bounds needed by the
AbsInt tool.  I would like to be able to do the same for recursion.

I do not really like any of the annotations in JML for timing analysis,
because they are too simple.  For dynamically bound loops, concrete loop
bounds only apply to a very restricted set of usages.  I and some
colleagues wrote a paper for JTRES 2006 about proving the correctness of
@decreases classes using KeY.  Now, we are working on one about using
data flow analysis to convert @decreases into concrete loop bounds for a
given application.

Sincerely,
James

P.S. In general, I am interested in a JSR on converting JML to Metadata
Annotations, since our data flow analysis tool works with byte code.

On Wed, 2008-06-04 at 11:51 -0400, Gary T. Leavens wrote:

> Hi James,
>
> We haven't looked into generalizing the decreasing clause to methods.
> JML does have a measured_by clause that can be used for termination
> arguments for recursive methods.
>
> But a simplification is worth thinking about.  What do you mean by recursion breadth?
>
> On Wed, 4 Jun 2008, Dr. James J. Hunt wrote:
>
> > Dear Colleagues,
> > Why has @decreasing not been defined to apply to recursive methods
> aswell as loop statements?  One would have to define, whether to it
> termsof recursion depth or breadth.  Otherwise, I would expect it to
> beanalogous the loop case.
> > Sincerely,James
> >
>
>
>          Gary T. Leavens
>          210 Harris Center (Bldg. 116)
>          School of EECS, University of Central Florida
>          4000 Central Florida Blvd., Orlando, FL 32816-2362 USA
>          http://www.eecs.ucf.edu/~leavens  phone: +1-407-823-4758
>          leavens@...
--
Dr. James J. Hunt      * CEO aicas group       * Tel: +49 721 663968 22

aicas incorporated
69 West Rock Ave.      * New Haven, CT 06515   * USA
http://www.aicas.com   * Tel: +1 203 676 9807  *

Business Filing Number: 0002879819, State of Connecticut
President: Dr. James J. Hunt, Secretary/Treasurer: David P. Reddy

aicas --- allerton interworks computer automated systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe     * Deutschland (Germany)
http://www.aicas.com   * Tel: +49 721 663968 0 * FAX: +49 721 663968 99

USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim
Geschäftsführer: Dr. James J. Hunt


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Jmlspecs-interest mailing list
Jmlspecs-interest@...
https://lists.sourceforge.net/lists/listinfo/jmlspecs-interest

Parent Message unknown Re: Recusion bounds

by Dr. James J. Hunt-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Gary,

Please forgive the delay in answering.

On Wed, 2008-06-04 at 13:12 -0400, Gary T. Leavens wrote:

> Hi James,
>
> On Wed, 4 Jun 2008, Dr. James J. Hunt wrote:
>
> > I do not think measured by really would help.  I am interested in
> > determining the number of times a given method would be called in a
> > recursion.  In a simple recursion, there is no difference between width
> > and breath.  By breath, I mean the total number of times a method is
> > called in a recursion, not just the depth of the recursion.  For
> > instance in the fibonacci double recursion algorithm, fibonacci itself
> > is call much more often than the depth of the recursion.  In general, a
> > depth approach would both suffice and be simpler to analyze.
> >
> > We are currently working on binding our data flow analysis tool on
> > AbsInt's WCETA analysis tool.  We have successfully used the normal
> > @decreasing clause to determine the concrete loop bounds needed by the
> > AbsInt tool.  I would like to be able to do the same for recursion.
>
> I see.  The intent of the measured_by clause is described in section
> 9.9.12 of the JML Reference Manual as "A measured by clause can be
> used in a termination argument for a recursive specification."  (There
> isn't much else about it in the reference manual, however.)  But it's
> essentially the same idea as the decreasing clause on loops: it
> provides a termination measure.
The nice thing about the decreasing clause is that its initial value
gives an upper bound on the number of times a loop executes.  In fact,
in most cases, it is that number.  With data flow analysis, one can
determine the complete set of possible initial values.  I do not see how
this is necessarily so for measured_by, but I may be missing something,
as the documentation is less than illuminating on this point.

> I don't think any of our tools use measured_by however, and thus
> changing the name to decreasing would perhaps be sensible.

If the intent really is the same, i.e., that it has an integer value
that decreases by at least one for each recursive call (depth) and the
iteration terminates when it becomes zero, than this would be probably
be clearer.

> > I do not really like any of the annotations in JML for timing analysis,
> > because they are too simple.  For dynamically bound loops, concrete loop
> > bounds only apply to a very restricted set of usages.  I and some
> > colleagues wrote a paper for JTRES 2006 about proving the correctness of
> > @decreases classes using KeY.  Now, we are working on one about using
> > data flow analysis to convert @decreases into concrete loop bounds for a
> > given application.
>
> I'll have to look that up, can you send details (e.g., a bibtex entry)
> for the paper?
Please find it attached.

> > P.S. In general, I am interested in a JSR on converting JML to Metadata
> > Annotations, since our data flow analysis tool works with byte code.
>
> See the following TR for our design of this:
>
> Kristina Taylor's MS thesis at Iowa State this year discussed a design
> for this.  You can get it from:
>
>    ftp://ftp.cs.iastate.edu/pub/techreports/TR08-03
>
> Comments on that are welcome.
I do not think the paper makes a convincing case for the level of
encoding in annotations that she chose.  What makes annotations
interesting is that they are carried into the byte code.  To make this
useful, they must drastically limit the parsing necessary.  In
particular, one needs to know what are the Java variables referenced in
the clauses from the current method.  I opine that to take anything but
the most radical approach she outlined will make it too difficult to
relate JML code fragments back to the byte code.

For example, to analyze the initial value of a decreasing clause, we
inline the clause into the application code.

Thus

 // @decreasing a.length() - i
 for (int i = 0; i < a.length(); i++)
 {
   ...
 }

can be transformed into

 {
   int i = 0; // obtainable from the JML parser.
   Do.nothing(a.length() - i);
 }
 for (int i = 0; i < a.length(); i++)
 {
   ...
 }

The value set for the Do.Nothing method gives the bound set for the
loop.  Note that if a.length() grows in the loop, that the bound is
incorrect, but this can be shown with a deductive verifier tool such as
KeY.

This trick does not work at the byte code level.  It would very
difficult to parse the example and generate the equivalent byte code
without support form the annotations.  Not to mention that the more
radical approach would benefit from better type and syntax checking from
javac.

Sincerely,
James

> > On Wed, 2008-06-04 at 11:51 -0400, Gary T. Leavens wrote:
> >> Hi James,
> >>
> >> We haven't looked into generalizing the decreasing clause to methods.
> >> JML does have a measured_by clause that can be used for termination
> >> arguments for recursive methods.
> >>
> >> But a simplification is worth thinking about.  What do you mean by recursion breadth?
> >>
> >> On Wed, 4 Jun 2008, Dr. James J. Hunt wrote:
> >>
> >>> Dear Colleagues,
> >>> Why has @decreasing not been defined to apply to recursive methods
> >> aswell as loop statements?  One would have to define, whether to it
> >> termsof recursion depth or breadth.  Otherwise, I would expect it to
> >> beanalogous the loop case.
> >>> Sincerely,James
> >>>
> >>
> >>
> >>          Gary T. Leavens
> >>          210 Harris Center (Bldg. 116)
> >>          School of EECS, University of Central Florida
> >>          4000 Central Florida Blvd., Orlando, FL 32816-2362 USA
> >>          http://www.eecs.ucf.edu/~leavens  phone: +1-407-823-4758
> >>          leavens@...
> > --
> > Dr. James J. Hunt      * CEO aicas group       * Tel: +49 721 663968 22
> >
> > aicas incorporated
> > 69 West Rock Ave.      * New Haven, CT 06515   * USA
> > http://www.aicas.com   * Tel: +1 203 676 9807  *
> >
> > Business Filing Number: 0002879819, State of Connecticut
> > President: Dr. James J. Hunt, Secretary/Treasurer: David P. Reddy
> >
> > aicas --- allerton interworks computer automated systems GmbH
> > Haid-und-Neu-Straße 18 * D-76131 Karlsruhe     * Deutschland (Germany)
> > http://www.aicas.com   * Tel: +49 721 663968 0 * FAX: +49 721 663968 99
> >
> > USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim
> > Geschäftsführer: Dr. James J. Hunt
> >
>
>
>          Gary T. Leavens
>          210 Harris Center (Bldg. 116)
>          School of EECS, University of Central Florida
>          4000 Central Florida Blvd., Orlando, FL 32816-2362 USA
>          http://www.eecs.ucf.edu/~leavens  phone: +1-407-823-4758
>          leavens@...
--
Dr. James J. Hunt      * CEO aicas group       * Tel: +49 721 663968 22

aicas incorporated
69 West Rock Ave.      * New Haven, CT 06515   * USA
http://www.aicas.com   * Tel: +1 203 676 9807  *

Business Filing Number: 0002879819, State of Connecticut
President: Dr. James J. Hunt, Secretary/Treasurer: David P. Reddy

aicas --- allerton interworks computer automated systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe     * Deutschland (Germany)
http://www.aicas.com   * Tel: +49 721 663968 0 * FAX: +49 721 663968 99

USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim
Geschäftsführer: Dr. James J. Hunt


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Jmlspecs-interest mailing list
Jmlspecs-interest@...
https://lists.sourceforge.net/lists/listinfo/jmlspecs-interest

hunt-bounds.pdf (177K) Download Attachment

Parent Message unknown Re: Recusion bounds

by Dr. James J. Hunt-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear Gary,

On Sun, 2008-06-08 at 20:45 -0400, Gary T. Leavens wrote:

> Hi James,
>
> On Fri, 6 Jun 2008, Dr. James J. Hunt wrote:
>
> > Please forgive the delay in answering.
>
> No problem and likewise.
>
> > On Wed, 2008-06-04 at 13:12 -0400, Gary T. Leavens wrote:
> >> Hi James,
> >>
> >> On Wed, 4 Jun 2008, Dr. James J. Hunt wrote:
> >>
> >>> P.S. In general, I am interested in a JSR on converting JML to Metadata
> >>> Annotations, since our data flow analysis tool works with byte code.
> >>
> >> See the following TR for our design of this:
> >>
> >> Kristina Taylor's MS thesis at Iowa State this year discussed a design
> >> for this.  You can get it from:
> >>
> >>    ftp://ftp.cs.iastate.edu/pub/techreports/TR08-03
> >>
> >> Comments on that are welcome.
> >
> > I do not think the paper makes a convincing case for the level of
> > encoding in annotations that she chose.  What makes annotations
> > interesting is that they are carried into the byte code.  To make this
> > useful, they must drastically limit the parsing necessary.  In
> > particular, one needs to know what are the Java variables referenced in
> > the clauses from the current method.  I opine that to take anything but
> > the most radical approach she outlined will make it too difficult to
> > relate JML code fragments back to the byte code.
>
> Yes, I agree that having them in the byte code is important.  I wish
> Java allowed interesting sturctures in annotations, but perhaps some
> more parsed form can be stored in the byte code.

Recursive annotation definitions would help a lot.

> But which do you mean by "the most radical approach"?  Presumably not
> the middle one that she picked; I'm guessing you prefer the one that
> has the most fields fleshed out, what she calls the "clausal
> annotation".  Is that right?

Yes

> Do you have a preferred way to relate the annotations to the variables
> in the Java code at the byte ode level?

This is a bit tricky, since the variable names do not necessarily exist
in the byte code and the registers in the byte code can not be
referenced at the source level.  One way to do this would be to write
all expressions as methods.  For example,

//@ descreasing a.size() - i;

whould become

@Decreasing("int foo(Collection a, int i) { return a.size() - i; }")

another would be to have a parameter list such as

@Decreasing(values="(Collection a, int i)", expression="a.size() - i")

or using annotation array syntax

@Decreasing(values={"Collection a", "int i"}, expression="a.size() - i")

One could even separate the types:

@Decreasing(types={"Collection", "int"},
            names={"a", "i"},
            value="a.size() - i")
but this gets rather verbose.

Perhaps a general expression would be best:

@Expression(type=decreasing,
            values={"Collection a", "int i"},
            body="a.size() - i")

where decreasing is a member of an ExpressionType enumeration.

In any case, the types are necessary to make it easy to generate a
synthetic class, calls to which could then be inject back into the byte
code.

> > For example, to analyze the initial value of a decreasing clause, we
> > inline the clause into the application code.
> >
> > Thus
> >
> > // @decreasing a.length() - i
> > for (int i = 0; i < a.length(); i++)
> > {
> >   ...
> > }
>
> A minor but important confusion. In JML the // and the @ must be
> together, as in
>
>    //@ decreasing a.length() - i;
>    for (int i = 0; i < a.length(); i++)
>    {
>      // ...
>    }
>
> Kristina's proposal uses Java 5 annotations, which unfortunately don't
> apply to statements.  If they did, she would write this as (I believe):
>
>    @Decreasing("a.length() - i")
>    for (int i = 0; i < a.length(); i++)
>    {
>      // ...
>    }

I opine that we should target JSR 308.  Perhaps we can persuade the
group to add statement annotations.  The alternative is to annotate the
loop variable, but that could get quite messy.

for (@Expression(type=decreasing,
                 values={"Collection a", "int i"},
                 body="a.size() - i")
     int i = 0; i < a.size(); i++)
{
  //...
}


> But perhaps better is to use your trick, transforming the JML in the
> bytecode to a call of some standard method:
>
> > can be transformed into
> >
> > {
> >   int i = 0; // obtainable from the JML parser.
> >   Do.nothing(a.length() - i);
> > }
> > for (int i = 0; i < a.length(); i++)
> > {
> >   ...
> > }
> >
> > The value set for the Do.Nothing method gives the bound set for the
> > loop.  Note that if a.length() grows in the loop, that the bound is
> > incorrect, but this can be shown with a deductive verifier tool such as
> > KeY.
>
> Good.
>
> > This trick does not work at the byte code level.  It would very
> > difficult to parse the example and generate the equivalent byte code
> > without support form the annotations.  Not to mention that the more
> > radical approach would benefit from better type and syntax checking from
> > javac.
>
> Again, I'm a bit clear on what you mean.  I understand that you don't
> want to parse the bytecodes to recover this kind of structure.  The
> alternative would be to have a table somewhere in the bytecode's
> auxiliary annotations that points out what byte codes are related to
> loop bounds.  Thus a bytecode analyzer would just have to recover this information.
> Again, it's not clear how the radical aproach could help in Java 5 (or
> 6), since we can't attach annotaions to statements at all.
>
> Another possibililty, however, is to use some stereotyped declaration
> as a placeholder to add annotations to loops.  For example, we've
> thought of something like transforming:
>
>    //@ decreasing a.length() - i;
>    for (int i = 0; i < a.length(); i++)
>    {
>      // ...
>    }
>
> into:
>
>    {
>      int i=0;
>      while (true) {
>        long vf$0 = a.length() - i;  // from the deccreasing clause
>        if (i < a.length()) { break; }
>        // ...
>        i++;
>        //@ assert 0 <= vf$0;
>        //@ assert (a.length() - i) < vf$0;
>      }
>    }
>
> where vf$0 is the special name that could be searched for.  We also
> had an encoding that is a bit more complex that keeps the loop as a
> for loop.  (See earlier emails on the jmlspecs-interest list, which
> should be available on sourceforge.net in the archives; but there have
> been some problems with mailing list archives, so if you can't find
> that, let me know.)

Let us not be too tricky.

Sincerely,
James

--
Dr. James J. Hunt      * CEO aicas group       * Tel: +49 721 663968 22

aicas incorporated
69 West Rock Ave.      * New Haven, CT 06515   * USA
http://www.aicas.com   * Tel: +1 203 676 9807  *

Business Filing Number: 0002879819, State of Connecticut
President: Dr. James J. Hunt, Secretary/Treasurer: David P. Reddy

aicas --- allerton interworks computer automated systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe     * Deutschland (Germany)
http://www.aicas.com   * Tel: +49 721 663968 0 * FAX: +49 721 663968 99

USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim
Geschäftsführer: Dr. James J. Hunt


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Jmlspecs-interest mailing list
Jmlspecs-interest@...
https://lists.sourceforge.net/lists/listinfo/jmlspecs-interest
LightInTheBox - Buy quality products at wholesale price