Case analysis in Isabelle - isabelle

How do I apply case analysis in Isabelle? I was looking for something similar to apply (induct x) (which is used for induction).

Case analysis is usually performed with the cases method (also see "cases (method)" in the index of the Isabelle/Isar Reference manual of Isabelle2014). If you are a beginner, I recommend the tutorial Programming and Proving in Isabelle/HOL.
Note that since Isabelle 2014, the documentation is also available in the Isabelle/jEdit IDE in the Documentation panel.

Related

Isabelle/HOL with HOL-Z and ZETA

I have seen some papers that describe how to use the Z notation with Isabelle/HOL using the tools HOL-Z and ZETA. I was not able to find these tools, have they ever been published? Are there other ways to use Isabelle with the Z notation?
If you are prepared to substitute Isabelle/HOL for one of the HOL theorem provers (which also adopt the LCF approach to soundness) then you should consider ProofPower, which also embeds the Z notation in HOL. ProofPower-Z has been used on large industrial examples for many years, in particular to discharge verification conditions to show the correctness of Ada source code.

Are there any examples of isabelle sources for academic papers?

I’ve completed the better part of a major development in Isabelle, and is wondering how best to go about writing the corresponding academic paper.
From Isabelle sources I can generate a somewhat idiosyncratic take on such a paper. However, the default rendering of theorems, lemmas and definitions seems almost certain to alienate reviewers.
The LaTeX-sugar theories help, but apparently only if I manually restate the entire theory using anti-quotations.
Are there examples of Isabelle developments underpinning publications that I can look to for inspiration on how best to proceed here?
I have done that in the past (for my master's thesis), there is only one case where you should do that: the documentation of Isabelle and the documentation of Isabelle developments (like the AFP).
There are some people who do that (Makarius Wenzel, e.g., https://sketis.net/2019/11), similarly the "Concrete Semantics". However, this is not a great solution.
The reasons not to do that:
The compilation takes much longer than using pdflatex, even if you base your work on an image of your development.
Unless you type LaTeX macros directly, you are much more limited in what you can do (LaTeX wise). And if you do type latex macros directly, you cannot produce HMTL output anymore. So the gain of Isabelle is limited.
Many conferences want to see LaTeX sources and they don't run Isabelle, so you will have to generate LaTeX at some point anyhow (and even possibly do some post-productions effects because Isabelle is not able to do some things).
You rarely want to use the exact theorem of Isabelle (LaTeXsugar can help, but it is not perfect).
What if you write the paper now and discover a typo you want to fix in 5 years? In 5 years, latex will still work. Isabelle2020 probably not.
Do all your co-authors use Isabelle on all their computers, including your laptop if you are on vacation and have an emergency fix to do?
And you will fight Isabelle a lot, for example:
text "
\begin{counterexample}
"
lemma True
by auto
text "
\end{counterexample}
"
does not work, because text is its own environment, so you need post-production effects.
Basically, use the snippets mechanism to extract LaTeX out of the theories and then use your favorite LaTeX editor.

What is the difference between "fold" and "unfold"?

I'm doing an exercise using Isabelle recently and don't know the difference between fold and unfold. What I know is to apply the rules which contain inference symbol, we should use rule and those without inference symbol, we should use unfold. But when should we use fold? Some examples will be much appreciated.

How to describe a MATLAB function using mathematical notation?

Basically I have created two MATLAB functions which involve some basic signal processing and I need to describe how these functions work in a written report. It specifically requires me to describe the algorithms using mathematical notation.
Maths really isn't my strong point at all, in fact I'm quite surprised I've even been able to develop the functions in the first place. I'm quite worried about the situation at the moment, it's the last section of writing I need to complete but it is crucially important.
What I want to know is whether I'm going to have to grab a book and teach myself mathematical notation in a very short space of time or is there possibly an easier/quicker way to learn? (Yes I know reading a book should be simple enough, but maths + short time frame = major headache + stress)
I've searched through some threads on here already but I really don't know where to start!
Although your question is rather vague, and I have no idea what sorts of algorithms you have coded that you are trying to describe in equation form, here are a few pointers that may help:
Check the MATLAB documentation: If you are using built-in MATLAB functions, they will sometimes give an equation in the documentation that describes what they are doing internally. Some examples are the functions CONV, CORRCOEF, and FFT. If the function is rather complicated, it may not have an equation but instead have links to some papers describing the algorithm, which may themselves have equations for the algorithm. An example is the function HILBERT (which you can also find equations for on Wikipedia).
Find some lists of common mathematical symbols: Some standard symbols used to represent common mathematical operations can be found here.
Look at some sample pseudocode to see how it's done: For algorithms you yourself have coded up, you'll have to write them out in equation or pseudocode form. A paper that I've used often in my work is Templates for the Solution of Linear Systems, and it has some examples of pseudocode that may be helpful to you. I would suggest first looking at the list of symbols used in that paper (on page iv) to see some typical notations used to represent various mathematical operations. You can then look at some of the examples of pseudocode throughout the rest of the document, such as in the box on page 8.
I suggest that you learn a little bit of LaTeX and investigate Matlab's publish feature. You only need to learn enough LaTeX to write mathematical expressions. Then you have to write Matlab comments in your source file in LaTeX, but only for the bits you want to look like high-quality maths. Finally, open the Matlab editor on your .m file, and select File | Publish.
See Very Quick Intro to LaTeX and check your Matlab documentation for publish.
In addition to the answers already here, I would strongly advise using words in addition to forumlae in your report to describe the maths that you are presenting.
If I were marking a student's report and they explained the concepts of what they were doing correctly, but had poor or incorrect mathematical notation to back it up: this would lose them some marks, but would hopefully not impede my understanding of the hard work they've put in.
If they had poor/wrong maths, with no explanation of what they meant to say, this could jeapordise my understanding of their entire project and cost them a passing grade.
The reason you haven't found any useful threads is because most of the time, people are trying to turn maths into algorithms, not vice versa!
Starting from an arbitrary algorithm, sometimes pseudo-code, along with suitable comments, is the clearest (and possibly only) representation.

Representing code algebraically

I have a number of small algorithms that I would like to write up in a paper. They are relatively short, and concise. However, instead of writing them in pseudo-code (à la Cormen or even Knuth), I would like to write an algebraic representation of them (more linear and better LaTeX rendering) . However, I cannot find resources as to the best notation for this, if there is anything: e.g. how do I represent a loop? If? The addition of a tuple to a list?
Has any of you encountered this problem, and somehow solved it?
Thanks.
EDIT: Thanks, people. I think I did a poor job at phrasing the question. Here goes again, hoping I make it clearer: what is the common notation for talking about loops and if-then clauses in a mathematical notation? For instance, I can use $acc \leftarrow acc \cup \langle i,i+1 \rangle$ to represent the "add" method of a list.
Don't do this. You are deviating from what people expect to see when they read a paper about algorithms. You should follow expected practices; your ideas are more likely to get the attention that they deserve. When in Rome, do as the Romans do.
Formatting code (or pseudocode as it may be) in a LaTeXed paper is very easy. See, for example, Formatting code in LaTeX.
I see if-expressions in mathematical notation fairly often. The usual thing for a loop is a recurrence relation, or equivalently, a function defined recursively.
Here's how the Ackermann function is defined on Wikipedia, for instance:
This picture is nice because it feels mathematical in flavor and yet you could clearly type it in almost exactly as written and have an implementation. It is not always possible to achieve that.
Other mathematical notations that correspond to loops include ∑-notation for summation and set-builder notation.
I hope this answers your question! But if your aim is to describe how something is done and have someone understand, I think it is probably a mistake to assume that mathematicians would prefer to see equations. I don't think they're interchangeable tools (despite Turing equivalence). If your algorithm involves mutable data structures, procedural code is probably going to be better than equations for explaining it.
I'd copy Knuth. Few know how to communicate better than him in a computer science setting.
A symbol for general loops does not exist; usually you will use the summation operator. "if" is represented using implications, and to "add a tuple to a list" you would use union.
However, in general, a bit of verbosity is not necessarily a bad thing - sometimes, especially for complex algorithms, it is best to spell it out in plain English, using examples and diagrams. This is doubly-true for non-coders.
Think about it: when you read a math text-book on Euclid's algorithm for GCD, or the sieve of Eratosthenes, how is it written? Usually, the algorithm itself is in prose, while the proof of the algorithm is where the mathematical symbols lie.
You might take a look at Haskell. Haskell formats well in latex, has a nice algebraic syntax, and you can even compile a latex file with Haskell in it, provided the code is wrapped in \begin{code} and \end{code}. See here: http://www.haskell.org/haskellwiki/Literate_programming. There are probably literate programming tools for other languages.
Lisp started out as a mathematical notation of a computing model so that the lecturer would have a better tool than turing machines. By accident, it turns out that it can be implemented in assembly - thus lisp, the programming language was born.
But I don't think this is really what you are looking for since the computing model that lisp describes doesn't have loops: recursion is used instead. The syntax derives from algebra where braces denote evaluate-this-and-substitute-the-result. Indeed, lisp's model of computing is basically substitution - what algebra essentially is.
Indeed, most functional languages like Lisp, Haskell and Erlang are derived from mathematics. Haskell is actually a result of proving that lambda calculus can be used to implement type systems. So Haskell, like Lisp was born out of pure mathematics. But again, the syntax is not what you would probably be used to.
You can certainly explain Lisp and Haskell syntax to mathematicians and they would treat it as a "game". Language constructs like loops, recursion and conditionals can be proven out of the rules of the game rather than blindly implemented like in other languages. This would lead you into the realms of combinatronics, another branch of mathematics. Indeed, in combinatronics, even the concept of numbers can be constructed out of the rules of the game rather than being a native part of the language (google Church Numerals).
So have a look at Lisp/Scheme, Erlang and Haskell if you want. Erlang especially has syntax close to what you want:
add(a,b) -> a + b
But my recommendation is to write in C-like pseudocode. It's sort of the lowest common denominator in programming languages. Has a syntax that is fairly easy to understand and clean. And the function syntax even derives from functions in mathematics. Remember f(x)?
As a plus, mathematicians are used to writing C, statisticians are used to writing C (though generally they prefer R), physicists are used to writing C, programmers are used to at least looking at C (I know a few who've never touched C).
Actually, scratch that. You mention that your target audience are statisticians. Write in R
Something like this website describes?
APL? The only problem is that few people can read it.

Resources