<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Computer Algebra implemented in Isabelle's Function Package under Lucas-Interpretation - a Case Study</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Walther Neuper</string-name>
          <email>neuper@ist.tugraz.at</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Institute for Software Technology University of Technology Graz</institution>
          ,
          <country country="AT">Austria</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>The relation of this paper to “Theorem-Proving (TP) components for educational software” deserves explanation: TP technology is designed for mechanised justification of formalised facts - so educational software gains a prerequisite for being a “transparent system” [12] which explains itself. Computer Algebra (CA), however, is not designed for justification (and thus leaves full responsibility for interpreting results with the user, which over-strains students frequently), and CA is not designed for “transparency”1. So integration of CA into TP promises to improve justification and “transparency” of CA, provides requisites for step-wise “Lucas-Interpretation” [11], another advantage for interactive educational software.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>but in Isabelle/HOL. The first challenge was to identify, which SML integers represent coefficients of
polynomials, and which represent primes. The latter were represented by HOL’s nat — an instructive
exercise in precise programming.</p>
      <p>The translation took care to use the simplest Isabelle tool possible: definition for non-recursive
functions (which well might comprise fold or map), primrec for primitive recursion and fun otherwise. The
latter resolves all proof obligations automatically and creates a suite of theorems: customized induction
rules *.induct and case rules *.cases required later for proofs in x4 and x5. The simplification rules
*.simps, generated as well, allow immediate testing of functions by value — most important for
programmers’ approaches.</p>
      <p>Only if implementation by fun does not succeed immediately, one expands the definition to
function and resolves the proof obligations explicitly calling by pat completeness auto and postpones the
termination proof by termination sorry. Table.1 gives a survey on all functions implemented so far:
Isabelle’s tool
definition
primrec
fun
function
total of function definitions
tool’s features
no recursion
primitive recursion
automated proofs
interactive proof
number of occurrences
21</p>
      <p>1
10</p>
      <p>9
41</p>
      <p>Defining functions in the FP is almost trivial but not in all cases of 41 above, which seem typical for
CA. The first function which really challenged the programmer was the following one, which decides
divisibility (dvd) for univariate polynomials (up, actually lists of integers, i.e. of exponents). The
identifier for the function is declared as infix with priority 70 in line 01, the function is implemented by two
patterns in line 02 and in line 03:
01 function (sequential) dvd up :: ”unipoly ) unipoly ) bool” (infixl ”%j%” 70) where
List.length rest ^ ds % % rest))
j
:
09 in
10 rest = [] _ (quot 6= 0 ^ List.length ds
12 by pat completeness auto
13 termination sorry
3</p>
    </sec>
    <sec id="sec-2">
      <title>Using Isabelle’s Code Generator</title>
      <p>
        For the working programmer automated code generation for relevant target languages is a major
motivation. And indeed motivating, following the tutorial [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] and executing
export code ”gcd up” (* gcd for *u*nivariate *p*olynomials *) in SML
module name GCD Univariate file ”˜/codegen/gcd univariate.ML”
immediately led to successfully running SML code: just evaluate the two lines in an auxiliary theory
importing GCD Poly FP.thy, which holds gcd up and the preceding definitions. Inspection of the
automatically generated code was the next pleasant surprise: the original SML code (i.e. the model for
translation into Isabelle’s FP) and the generated code are almost identical.2.
      </p>
      <p>Further investigations on the efficiency of the generated code are planned, in particular with respect
to the indefinite precision integers and naturals in comparison with the original SML code.
4</p>
    </sec>
    <sec id="sec-3">
      <title>Proving Termination</title>
      <p>Admittedly, generating code from Isabelle definitions with termination sorry (as done in x2 and x3 above)
is a bad practice in terms of software verification in HOL: On termination, even when stated with sorry,
i.e. omitting a proof, the theorems mentioned in x2 are created and seduce to inappropriate use. However,
as already mentioned, this case study started from a programmers perspective which considers automated
generation of code a major success — while the generated code is not less trustworthy than the original
SML code.</p>
      <p>The obligation to prove termination, as imposed by the FP, marks the transition from naive
programming to software engineering. Isabelle’s FP supports this transition with much automation: Table.1
shows that from 41 functions only 9 require an explicit termination proof:</p>
      <p>Termination proof
not necessary (definition, primrec)
done automatically by FP (fun)
by lexicographic order
by relation measure
by size change
did not yet succeed
total of function definitions
number of occurrences
22
10
1
2
0
6
41</p>
      <p>2The final paper will show some examples.</p>
      <p>The ration between automated proof and interactive proof of termination seems typical for CA:
recursion is not structural with respect to some datatype, rather depends on specific mathematical knowledge.
In this case study the crucial function for proving termination is</p>
      <p>function next prime not dvd :: ”nat ) nat ) nat”
which determines a prime with a certain property greater than a given number. Isabelle2013 lacks
respective knowledge, however, the Isabelle development already started to fill this gap3. So we look forward
to have completed all termination proofs at the end of the case study.
5</p>
    </sec>
    <sec id="sec-4">
      <title>Verifying CA Algorithms in Isabelle</title>
      <p>This task has not begun at the time of writing this extended abstract. For sake of efficiency in development
and of coherence of Isabelle’s knowledge the first step of this task will be to adopt Isabelle’s multivariate
Polynomials4 — from the side of Isabelle development respective tools are already under construction5
for supporting this task.</p>
      <p>Transferring the gcd algorithm completely to Isabelle’s FP and verifying it seems essential: there
seems no way to produce a certificate for the property of being the greatest common divisor. Thus,
in order to get a computable gcd into the Isabelle distribution, verification of some algorithm seems
necessary.
6</p>
    </sec>
    <sec id="sec-5">
      <title>Making CA transparent by Lucas-Interpretation</title>
      <p>
        Lucas-Interpretation [
        <xref ref-type="bibr" rid="ref10">11</xref>
        ] is a TP-based technology, which maintains both, an environment (for
computation) and a logical context (for deduction) and thus allows step-wise execution of algorithms, where a
student is free at any step to investigate the underlying knowledge, to suggest a next step (where
derivability is proved automatically from the context) or to ask the system for a next step.
      </p>
      <p>While the benefits for education seem evident, the benefits for implementing CA are not. On
completion the case study is expected to produce detailed requirements for debugging (with inspection of
environment and context) and experiences, how Lucas-Interpretation might support verification of the
underlying CA algorithm.
7</p>
    </sec>
    <sec id="sec-6">
      <title>Conclusion</title>
      <p>
        The steps already done in this case study suggest, that Isabelle’s function package is ready for
implementation of comprehensive algorithms in Computer Algebra. Furthermore, the experiences with
“programming in Isabelle” are promising such, that integrative support for “Domain Engineering” (as an offspring
of Formal Methods) [
        <xref ref-type="bibr" rid="ref1 ref2 ref3">1, 2, 3</xref>
        ] might come into sight within some years.
      </p>
      <p>About advantages of Lucas-Interpretation for the implementation of CA nothing can be said at the
time of writing this extended abstract; results are expected on completion of the case study for the final
publication in autumn 2013.</p>
      <p>3See the development branch at http://isabelle.in.tum.de/reports/Isabelle/rev/7f864f2219a9.
4http://isabelle.in.tum.de/dist/library/HOL/HOL-Library/Polynomial.html
5See the development branch at http://isabelle.in.tum.de/reports/Isabelle/rev/3cc46b8cca5e.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Dines</given-names>
            <surname>Bjørner</surname>
          </string-name>
          (
          <year>2006</year>
          )
          <article-title>: Software Engineering</article-title>
          . Texts in Theoretical Computer Science 3, Springer, Berlin, Heidelberg.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>Dines</given-names>
            <surname>Bjørner</surname>
          </string-name>
          (
          <year>2009</year>
          )
          <article-title>: Domain Engineering</article-title>
          . Technology Management, Research and Engineering.
          <source>COE Research Monograph Series 4</source>
          , JAIST Press, Nomi, Japan.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Dines</given-names>
            <surname>Bjørner</surname>
          </string-name>
          (
          <year>2013</year>
          )
          <article-title>: Domain Science and Engineering as a Foundation for Computation for Humanity, chapter 7</article-title>
          , pp.
          <fpage>159</fpage>
          -
          <lpage>177</lpage>
          . Francis &amp; Taylor. In: J.
          <string-name>
            <surname>Zander</surname>
          </string-name>
          &amp; P.J.Mosterman (eds.),
          <source>Computational Analysis, Synthesis, and Design of Dynamic Systems.</source>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Florian</given-names>
            <surname>Haftmann</surname>
          </string-name>
          (
          <year>2013</year>
          ):
          <article-title>Code generation from Isabelle/HOL theories</article-title>
          . Theorem Proving Group at TUM, Munich. Available at http://isabelle.in.tum.de/dist/Isabelle2013/doc/codegen. pdf.
          <article-title>Part of the Isabelle distribution</article-title>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>John</given-names>
            <surname>Harrison</surname>
          </string-name>
          &amp; Laurent The`ry (
          <year>1998</year>
          )
          <article-title>: A sceptic's approach to combining HOL and Maple</article-title>
          .
          <source>J. of Automated Reasoning 21</source>
          , pp.
          <fpage>279</fpage>
          -
          <lpage>294</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Alexander</given-names>
            <surname>Krauss</surname>
          </string-name>
          (
          <year>2006</year>
          ):
          <article-title>Partial recursive functions in higher-order logic</article-title>
          . In Ulrich Furbach &amp; Natarajan Shankar, editors:
          <source>Automated Reasoning (IJCAR 2006), Lecture Notes in Artificial Intelligence 4130</source>
          , Springer Verlag, pp.
          <fpage>589</fpage>
          -
          <lpage>603</lpage>
          , doi:10.1007/11814771 48.
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>Alexander</given-names>
            <surname>Krauss</surname>
          </string-name>
          (
          <year>2010</year>
          )
          <article-title>: Partial and Nested Recursive Function Definitions in Higher-order Logic</article-title>
          .
          <source>J. Autom. Reasoning</source>
          <volume>44</volume>
          (
          <issue>4</issue>
          ), pp.
          <fpage>303</fpage>
          -
          <lpage>336</lpage>
          , doi:10.1007/s10817-009-9157-2.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>Alexander</given-names>
            <surname>Krauss</surname>
          </string-name>
          (
          <year>2013</year>
          )
          <article-title>: Defining Recursive Functions in Isabelle/HOL</article-title>
          . Theorem Proving Group TUM, Munich. Available at http://isabelle.in.tum.de/dist/Isabelle2013/doc/functions. pdf.
          <article-title>Part of the Isabelle distribution</article-title>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>Douglas</given-names>
            <surname>Meade</surname>
          </string-name>
          (
          <year>2009</year>
          )
          <article-title>: Getting Started with Maple</article-title>
          , 3rd ed. Wiley.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>Walther</given-names>
            <surname>Neuper</surname>
          </string-name>
          (
          <year>2012</year>
          )
          <article-title>: Automated Generation of User Guidance by Combining Computation and Deduction</article-title>
          .
          <source>Electronic Proceedings in Theoretical Computer Science</source>
          <volume>79</volume>
          , Open Publishing Association, pp.
          <fpage>82</fpage>
          -
          <lpage>101</lpage>
          , doi:10.4204/EPTCS.79.5.
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>Walther</given-names>
            <surname>Neuper</surname>
          </string-name>
          (
          <year>2013</year>
          ):
          <article-title>On the Emergence of TP-based</article-title>
          <source>Educational Math Assistants. 7</source>
          , pp.
          <fpage>110</fpage>
          -
          <lpage>129</lpage>
          . Available at https://php.radford.edu/˜ejmt/ContentIndex.php#v7n2. Special Issue “
          <article-title>TPbased Systems</article-title>
          and Education”.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>