Moderators: phlip, Moderators General, Prelates
Berengal wrote:What would e.g. "int div(int a, int b){return a / b;}" look like?
/*
ensures
there exists: a, b, c integer
c = #a / #b
*/
headprogrammingczar wrote:The concept of RESOLVE sounds like substituting a fancy compiler for bug-fixing to me. If, in fact, it is actually useful, then it is probably something similar to interfaces in Java, where all it does is enforce a naming convention. Mathematics on computers tends to end up becoming a language all its own, so if you really had this all-singing and all-dancing math-language, why the hell aren't you coding in that? RESOLVE/C++ itself seems useful in that it formalizes certain types of comments, but it isn't any more revolutionary than javadoc.exe.
Lase wrote:Just as it would in C++. Unless you mean math language. In math language it would be something like
Berengal wrote:Lase wrote:Just as it would in C++. Unless you mean math language. In math language it would be something like
That doesn't really say much about its behaviour, does it? The same holds for +, -, * and several other arithmetic operators as well.
Except that there's no integer c such that a / 0 = c.
/*
requires
#b /= 0
ensures
c = #a / #b
*/ math definition HEIGHT (
t: tree of Item
): integer satisfies
there exists x: Item, str: string of tree of Item
(t = compose (x, str) and
HEIGHT (t) = 1 + STRING_HEIGHT (str))
math definition STRING_HEIGHT (
str: string of tree of Item
): integer satisfies
if str = empty_string
then STRING_HEIGHT (str) = 0
else there exists t: tree of Item,
rest: string of tree of Item
(str = <t> * rest and
STRING_HEIGHT (str) =
max (HEIGHT (t), STRING_HEIGHT (rest)))
stephentyrone wrote:Am I the only one who would rather just have a clearly written english paragraph explaining the function?
stephentyrone wrote:Am I the only one who would rather just have a clearly written english paragraph explaining the function?
Rysto wrote:The goal is not to make the function easier to comprehend by humans. The goal is to have the compiler understand the intent of the function, so that the compiler can check that the function does what you claim it does.
prop_quotRem a b =
let (q, r) = quotRem a b
in b /= 0 ==> q*b + r == a
ghci> quickCheck prop_quotRem
+++ OK, passed 100 tests.headprogrammingczar wrote:But it makes you write the function twice!
Learn to do unit testing and you will see how incredibly useless this is.
It uses mathematical models and loop invariants to describe what programs should do, and they get compiled along with the RESOLVE code. The catch is, your program will not compile unless it does exactly what the math says it should do. This leads to the idea that if you can write in this mathy jargon, you can describe to anyone what operation you'd like done, and whoever implements it has to have it exactly correct for it to ever work.
I have to agree that this seems like a poor substitute for testing. In Haskell, for example, I can write tests for my monads that look suspiciously similar to the definition of the monad laws. To see if the standard implementation of the function quotRem was correct, I can test it like:
ComputerAnalysis wrote:First the mathematical language is actually much easier to understand than English paragraphs once you get used to it. It's much shorter and easier to write than English, and it's mathematical rigorous and clear.
However they are working on a special compiler that uses to mathematical models to prove that your code is correct. No amount of testing can prove that code is correct, but imagine a compiler that can prove that all your code works as intended. This feature is well worth writing the mathematical models. On an ending note, @ headprogrammingczar, while you may be OK with partially working code, some of us aren't.
stephentyrone wrote:No, it isn't. If you read any paper in a mathematical journal, you'll see that it is not composed entirely of mathematical notation. The vast majority of the body of a good article is in relatively simple English prose, with technical mathematical terms and symbols mixed in. This is for readability. I am a professional mathematician, and I would much rather read a paragraph of english comments than one line of symbolic asserts in an obscure technical language.
stephentyrone wrote:You're still left with the problem that the C++ compiler hasn't been proved correct (and likely never will be, given the complexity of C++). Neither has the runtime, the OS, or the system libraries that the program is sitting on top of. Neither has the physical processor hardware been proven correct, or the caches, memory, busses, etc.
ComputerAnalysis wrote:Techniques exist that can prove programs correct.
The field of software verification is a prominent one. It's an obvious step to take these techniques and combined them with compiler theory, just as AI was to create smarter optimizing compilers. All you need to do is break down the requirement of procedures into a set of logical conditions that need to be fulfilled, just as in any theorem prover.
stephentyrone wrote:What motivated the choice of C++?
Users browsing this forum: No registered users and 0 guests