Computer certified efficient exact reals in Coq
|
|
|
- Leonard Howard
- 10 years ago
- Views:
Transcription
1 Computer certified efficient exact reals in Coq Robbert Krebbers and Bas Spitters Radboud University Nijmegen Abstract. Floating point operations are fast, but require continuous effort on the part of the user in order to ensure that the results are correct. This burden can be shifted away from the user by providing a library of exact analysis in which the computer handles the error estimates. We provide an implementation of the exact real numbers in the Coq proof assistant. This improves on the earlier Coq-implementation by O Connor in two ways: we use dyadic rationals built from the machine integers and we optimize computation of power series by using approximate division. Moreover, we use type classes for clean mathematical interfaces. This appears to be the first time that type classes are used in heavy computation. We obtain over a 100 times speed up of the basic operations and indications for improving the Coq system. 1 Introduction Real numbers cannot be represented exactly in a computer. Hence, in constructive analysis [1] one approximates real numbers by rational, or dyadic numbers. The real numbers are the completion of the rationals. This completion construction can be organized in a monad, a familiar construct from functional programming (Section 3). The completion monad provides an efficient combination of proving and computing [2]. In this way, O Connor [3] implements exact real numbers and the transcendental functions on them in Coq. A number of possible improvements in this implementation were already suggested in [4]. First, we can use Coq s new machine integers; see Section 2. Second, we can use dyadic rationals (that are numbers of the shape n 2 e for n, e Z, also known as infinitary floats). Third, the implementation of power series can be improved by using approximate division. Here we carry out all three optimizations. Unfortunately, changing O Connor s implementation to use the new machine integers was far for from trivial, as he used a particular concrete representation of the rationals. To avoid this in the future, we provide an abstract specification of the dense set as approximate rationals; see Section 4. In Section 4 we provide some abstract order theory culminating in the theory of approximate rationals. Section 5 deals with computing power series using dyadics. Section 6 describes Wolfram s algorithm to compute the square root of a real number. We finish with some benchmarks in Section 7. The research leading to these results has received funding from the European Union s 7th Framework Programme under grant agreement nr (ForMath).
2 2 The Coq-system The Coq proof assistant is based on the calculus of inductive constructions [5, 6], a dependent type theory with (co)inductive types; see [7, 8]. In true Curry- Howard fashion, it is both a pure functional programming language with an expressive type system, and a language for mathematical statements and proofs. We highlight some aspects of Coq relevant for our development. Types and propositions. Propositions in Coq are types [9, 10], which themselves have types called sorts. Coq features a distinguished sort called Prop that one may choose to use as the sort for types representing propositions. The distinguishing feature of the Prop sort is that terms of non-prop type may not depend on the values of inhabitants of Prop types (that is, proof terms). This regime of discrimination establishes a weak form of proof irrelevance, in that changing a proof can never affect the result of value computations. On a practical level, this lets Coq safely erase all Prop components when extracting certified programs to Ocaml or Haskell. We should note however, that in practice, Coq s extraction mechanism is still very hard to use for programs with the complexity, in terms of depth of definitions, that we are interested in. Equality, setoids, and rewriting Because the Coq type theory lacks quotient types (as it would make type checking undecidable), one usually bases abstract structures on a setoid ( Bishop set ): a type equipped with an equivalence relation [1, 11]. This leads to a naive set theory as described by Palmgren [12]. When the user attempts to substitute a given (sub)term using an equality, the system keeps track of, resolves, and combines proofs of equivalence [13]. The native notion of equality in Coq, Leibniz equality, is that of terms being convertible, naturally reified as a proposition by the inductive type family eq with single constructor eq refl : (T : Type)(x : T), x x, where a b is notation for eq T a b. Since convertibility is a congruence, a proof of a b lets us substitute b for a anywhere inside a term without further conditions. Our interest is in more complicated equalities, so we diverge from Coq tradition and reserve = for setoid equality. Rewriting with = does give rise to side conditions. For instance, consider formal fractions of integers as a representation of rationals. Rewriting a subterm using such an equality is permitted only if the subterm is an argument of a function that has been proven to respect the equality. Such a function is called Proper, and that property must be proved for each function in whose arguments we wish to enable rewriting. Type classes. Type classes have been a great success story in the Haskell functional programming language, as a means of organizing interfaces of abstract structures. Coq s type classes provide a superset of their functionality, but are implemented in a different way. In Haskell and Isabelle, type classes and their instances are second class. They are handled as specialized syntactic constructs whose semantics are given 2
3 specifically by the type class apparatus. By contrast, the expressivity of dependent types and inductive families as supported in Coq, combined with the use of pre-existing technology in the system (namely proof search and implicit arguments) enable a first class type class implementation [14]: classes are ordinary record types ( dictionaries ), instances are ordinary constants of these record types (registered as hints with the proof search machinery), class constraints are ordinary implicit parameters, and instance resolution is achieved by augmenting the unification algorithm to invoke ordinary proof search for implicit arguments of class type. Thus, type classes in Coq are realized by relatively minor syntactic aids that bring together existing facilities of the theory and the system into a coherent idiom, rather than by introduction of a new category of qualitatively different definitions with their own dedicated semantics. We use the algebraic hierarchy based on type classes and its abstract specification of N, Z and Q [15]. Unfortunately, we should note that we have clearly met the efficiency problems connected to the current implementation of type classes in Coq. Luckily, these efficiency problems are limited to instance resolution which is only performed at compile time. Type classes have only a very minor effect on the computation time of type checked terms due to the absence of code inlining; see Section 7 for timings. Virtual machine and machine integers. Coq includes a virtual machine [16], vm compute, based on Ocaml s virtual machine to allow efficient evaluation. Both the abstract machine and its compilation scheme have been proved correct, in Coq, with respect to the weak reduction semantics. However, we still need to extend our trusted core to a bigger kernel, as the implementation has not been formally verified. Machine integers were also added to the Coq system [17]. The usual evaluation inside Coq (compute) uses a special inductive type for cyclic integers, but the virtual machine uses Ocaml s machine integers. This allows for a big speedup, for which we pay by having to trust (the virtual machine and) that Ocaml treats these integers correctly. The time difference between computation with Coq s int and Ocaml s Big int is about a factor of 20 [18] on primality tests. 3 Metric spaces Having completed our brief description of the Coq-system, we now turn to O Connor s formalization of exact real numbers [2]. Traditionally, a metric space is defined as a set X with a metric function d : X X R + satisfying certain axioms. The usual constructive formulation requires d be a computable function. We use a more relaxed definition of a metric space that does not require the metric be a function. A similar construction can be found in the work by Richman [19]. The metric is represented via a (respectful) ball relation B : Q + X X Prop, where Prop is the type of propositions, satisfying five axioms: msp refl : x ε, B ε x x 3
4 msp sym : x y ε, B ε x y B ε y x msp triangle : x y z ε 1 ε 2, B ε1 x y B ε2 y z B ε1 +ε 2 x z msp closed : x y ε, ( δ, B ε+δ x y) B ε x y msp eq : x y, ( ε, B ε x y) x = y The ball relation B ε x y expresses that the points x and y are within ε of each other. We call this a ball relationship because the partially applied relation B X ε x : X Prop is a predicate that represents the closed ball of radius ε around the point x. For example, the ball relation on Q is B Q ε x y := x y ε. A metric space X is a prelength space if: a b ε δ 1 δ 2, ε < δ1 + δ2 B ε a b c, B δ1 a c B δ2 c b. This property states that if two points a and b within ε of each other, then there exists curve of length d(a, b) in the completion of X that connects a and b. The metric space Q is a prelength space. We will introduce the completion of a prelength space as a monad. In order to do this we will first introduce monads. Monads. Moggi [20] recognized that many non-standard forms of computation may be modeled by monads 1. Wadler [21] popularized their use in functional programming. Monads are now an established tool to structure computation with side-effects. For instance, programs with input X and output Y which have access to a mutable state S can be modeled as functions of type X S Y S, or equivalently X (Y S) S. The type constructor MY := (Y S) S is an example of a monad. Similarly, partial functions may be modeled by maps X Y, where Y := Y + () is a monad. The formal definition of a (strong) monad is a triple (M, return, bind) consisting of a type constructor M and two functions: return : X MX bind : (X MY ) MX MY We will denote return x as ˆx, and bind f as ˇf. These two operations must satisfy the following laws: bind return a = a ˇf â = f a ˇf (ǧ a) = bind ( ˇf g) a Completion monad. Given a metric space X, the completion CX of X is defined by: CX := {f : Q + X ε 1 ε 2, B ε1+ε 2 (f ε 1 ) (f ε 2 )}. Given metric spaces X and Y, a function f : X Y is uniformly continuous with modulus µ f : Q + Q + if: ε x 1 x 2, B µf ε x 1 x 2 B ε (f x 1 ) (f x 2 ). 1 In category theory one would speak about the Kleisli category of a (strong) monad. 4
5 Completion is a monad on the category of prelength spaces with uniformly continuous functions. The function return : X CX defined by λx ε, x is the embedding of a prelength space in its completion. Moreover, a uniformly continuous function f : X CY with modulus µ f can be lifted to operate on ε complete prelength spaces as bind f : CX CY defined by λx ε, f (x (µ f 2 )) ε 2. The restriction to prelength spaces allows the present efficient definition of bind. One advantage of this approach is that it helps us to work with simple representations. Let R := CQ. Then to specify a function from R R, we define a uniformly continuous function f : Q R, and obtain ˇf : R R as the required function. Hence, the completion monad allows us to do in a structured way what was already folklore in constructive mathematics: to work with simple, often decidable, approximations to continuous objects. 4 Abstract interfaces using type classes An important part of this work is to further develop the algebraic hierarchy based on type classes by Spitters and van der Weegen [15]. Especially, we have formalized some order theory and developed interfaces for mathematical operations common in programming languages such as shift and power. This layer of abstraction makes both proof engineering and programming more flexible: it avoids duplication of code, it introduces a canonical way to refer to operations and properties, both by names and notations, and it allows to easily swap different implementations of number representations and their operations. First we will briefly recap the design decisions made in [15]. Algebraic structures are expressed in terms of a number of carrier sets, a number of relations and operations, and a number of laws that the operations satisfy. One way of describing such a structure is by a bundled representation: one uses a dependently typed record that contains the carrier, operations and laws. For example a semigroup can be represented as follows. (The fields sg car and sg proper support our explicit handling of naive set theory in type theory.) Record SemiGroup : Type := { sg car :> Setoid ; sg op : sg car sg car sg car ; sg proper : Proper ((=) = (=) = (=)) sg op ; sg ass : x y z, sg op x (sg op y z) = sg op (sg op x y) z) } However, this approach has some serious limitations, the most important one being a lack of support for sharing components. For example, suppose we group together two CommutativeMonoids in order to create a SemiRing. Now awkward hacks are necessary to establish equality between the carriers. A second problem is that if we stack up these records to represent higher structures the projection paths become increasingly large. Historically these problems have been an acceptable trade-off because unbundled representations, in which the carrier and operations are parameterized, introduce even more problems. Spitters and van der Weegen have proposed a use of Coq s new type class machinery that resolves many of the problems of 5
6 unbundled representations. Our current experiment confirms that this is a viable approach. An operational type class is defined for each operation and relation. Class Equiv A := equiv: relation A. Infix = := equiv: type scope. Class RingPlus A := ring plus: A A A. Infix + := ring plus. Now an algebraic structure is just a type class living in Prop that is parametrized by its carrier, relations and operations. This class contains all laws that the operations should satisfy. Since the operations are unbundled we can easily support sharing. For example let us consider the SemiRing interface. Class SemiRing A {e plus mult zero one} : Prop := { semiring mult monoid A e mult one ; semiring plus monoid A e plus zero ; semiring distr :> Distribute (..) (+) ; semiring left absorb :> LeftAbsorb (..) 0 }. Without type classes it would be a burden to manually carry around the carrier, relations and operations. However, because these parameters are just type class instances, the type class machinery will perform that job for us. For example, Lemma double {SemiRing R} x : 2 x = x + x. The backtick instructs Coq to automatically insert implicit declarations, namely e plus mult zero one. Furthermore, instance resolution will automatically find instances of the operational type classes for the written notations. This approach to interfaces proved useful to formalize a standard algebraic hierarchy. Combined with category theory and universal algebra, N and Z are represented as interfaces specifying an initial SemiRing and initial Ring [15]. These abstract interfaces for the naturals an integers make it easier to change the concrete representation in the future. No such simple specification for Q seems to exists, so we choose to specify it as the field of fractions of Z. More precisely, Q is specified as a Field containing Z that moreover can be embedded into the field of fractions of Z. Inductive Frac R {e : Equiv R} {zero : RingZero R} : Type := frac { num : R ; den : R ; den nonzero : den 0 }. Class RationalsToFrac (A : Type) := rationals to frac : B {Integers B}, A Frac B. Class Rationals A {e plus mult zero one opp inv} {U :!RationalsToFrac A} : Prop := { rationals field A e plus mult zero one opp inv ; rationals frac :> {Integers Z}, Injective (rationals to frac A Z) ; rationals frac mor :> {Integers Z}, SemiRing Morphism (rationals to frac A Z) ; rationals embed ints :> {Integers Z}, Injective (integers to ring Z A) }. 4.1 Order theory To abstract from N, Z, Q and R and their various implementations, we provide a basic library for order theory and its interaction with algebraic structures. For example, 6
7 Class RingOrder {Equiv A} {RingPlus A} {RingMult A} {RingZero A} (o : Order A) := { ringorder partialorder :> PartialOrder ( ) ; ringorder plus :> (OrderPreserving (z +)); ringorder mult : (0 x y, 0 y 0 x y) }. To apply this to N, which is merely a semiring, we introduce the, apparently new, notion of a SemiRingOrder. Every RingOrder is a SemiRingOrder. Class SemiRingOrder {Equiv A} {RingPlus A} {RingMult A} {RingZero A} (o : Order A) := { srorder partialorder :> PartialOrder ( ) ; srorder plus : (x y z, 0 z y = x + z) ; srorder mult : (0 x y, 0 y 0 x y) }. This allows us to refer by canonical names to lemmas as those shown below for N, Z, Q and the dyadics. Lemma plus compat x 1 y 1 x 2 y 2 : x 1 y 1 x 2 y 2 x 1 + x 2 y 1 + y 2. Lemma sprecedes 1 2 : 1 < 2. For instances of N, Z, Q it is easy to define an order satisfying these interfaces: Instance nat precedes {Naturals N} : Order N 10 := λ x y, z, y = x + z. However, often we encounter an a priori different order on a structure, most likely an order defined in Coq s standard library (like Nle on N). Therefore we prove that an arbitrary order satisfying these interfaces while also being a TotalOrder uniquely specifies the order on N, Z and Q. For example: Context {Naturals N} {Naturals N2} {f : N N2} {!SemiRing Morphism f} {o1 : Order N} {!SemiRingOrder o1} {!TotalOrder o1} {o2 : Order N2} {!SemiRingOrder o2} {!TotalOrder o2}. Global Instance: OrderEmbedding f. 4.2 Basic operations The operation nat pow is most commonly defined as repeated multiplication and the operation shiftl is defined as repeated multiplication by 2. However, if we implement these operations that way, they become too slow for the purpose of our work: efficient computation with real numbers. Instead we specify the desired behavior of these operations. This approach allows for different implementations for different number representations and avoids definitions and proofs becoming implementation dependent. We introduce interfaces that specify the behavior of the operations abs, shiftl, shiftr, nat pow, int pow and Euclidean division. Again there are various ways of specifying these interfaces: with Σ-types, bundled or unbundled. In general, Σ-types are convenient for functions whose specification is easy, for example: Class Abs A {Equiv A} {Order A} {RingZero A} {GroupInv A} := abs sig: (x : A), { y : A (0 x y = x) (x 0 y = x)}. Definition abs {Abs A} := λ x : A, (abs sig x). 7
8 However, for more complex operations, such as shiftl, such an interface is different from the usual mathematical specification because we cannot quantify over all possible input values. Now there are two ways: a bundled or an unbundled interface. Since these interfaces are not used for hierarchies the disadvantages of the latter do not apply. Let us first describe the former approach. Class ShiftL A B {Equiv A} {Equiv B} {RingOne A} {RingPlus A} {RingMult A} {RingZero B} {RingOne B} {RingPlus B} := { shiftl : A B A ; shiftl proper : Proper ((=) = (=) = (=)) shiftl ; shiftl 0 :> RightIdentity shiftl 0 ; shiftl S : x n, shiftl x (1 + n) = 2 shiftl x n }. Infix := shiftl (at level 33, left associativity). Although this interface seems reasonable, it does not work well in Coq. The simpl tactic which is used to simplify a goal will unfold occurrences of shiftl to their underlying definition (for example in case of BigN, the expression x n becomes BigN.shiftl x n). This is rather inconvenient because Coq will then be unable to use lemmas concerning for rewriting. This problem is caused because shiftl is a projection of a record, which is in fact a δ-redex that will be unfolded by simpl. Currently there seems to be no way to adjust the behavior of simpl to remove this inconvenience. A similar problem was already observed in Ssreflect [22]. Instead we use an unbundled interface, which has a lot in common with our interfaces for algebraic structures. Now shiftl no longer contains a δ-redex. Class ShiftL A B := shiftl: A B A. Infix := shiftl (at level 33, left associativity). Class ShiftLSpec A B (sl : ShiftL A B) {Equiv A} {Equiv B} {RingOne A} {RingPlus A} {RingMult A} {RingZero B} {RingOne B} {RingPlus B} := { shiftl proper : Proper ((=) = (=) = (=)) ( ) ; shiftl 0 :> RightIdentity ( ) 0 ; shiftl S : x n, x (1 + n) = 2 x n }. We do not specify shiftl as shiftl x n = x 2 ˆ n since on the dyadics we cannot take a negative power while we can shift by a negative integer. 4.3 Decision procedures The Decision type class collects types with a decidable equality [15]. Class Decision P := decide: sumbool P ( P). Using this type class we can declare a parameter { x y, Decision (x y)} to describe a decider for and say decide (x y) to decide whether x y or not. This type class allows to easily define additional deciders, like the one for the strict order. We have to be careful however. Consider the order on the dyadics. Global Instance dy equiv: Equiv Dyadic := λ x y, ZtoQ (mant x) 2 ˆ (expo x) ZtoQ (mant y) 2 ˆ (expo y) Now, decide (x y) is Dyadic (x y) dyadic dec, where dyadic dec is the computational conclusion of the decision. Due to eager evaluation, and 8
9 the absence of dead code removal, the second argument, x y, is also evaluated. Evaluation of this argument results in a conversion of x and y into Q, as described above. But since this argument is just a proposition it is later thrown away. We avoid this problem introducing a λ-abstraction. Definition decide rel (R : relation A) {dec : x y, Decision (R x y)} (x y : A) : Decision (R x y) := dec x y. We can now define: Context {!PartialOrder ( ) } {!TotalOrder ( ) } { x y, Decision (x y)}. Global Program Instance sprecedes dec: x y, Decision (x < y) 9 := λ x y, match decide rel ( ) y x with left E right right E left end. 4.4 Approximate rationals In order to make our implementation of the reals independent of the underlying dense set, we provide an abstract specification of such a set. The interface of this specification is called approximate rationals and is inspired by the notion of approximate fields which is used in the Haskell implementation of the exact reals by Bauer and Kavler [23]. We provide an implementation of this interface by dyadics based on Coq s machine integers. Our interface describes an ordered ring containing Z that is dense in Q. Here Z are the binary integers from Coq s standard library, and Q are the rationals based on these binary integers. We do not parametrize by arbitrary integer and rational implementations because they are hardly used for computation. Also, for efficient computation, this interface contains the operations: approximate division, normalization, an embedding of Z, absolute value, power by N, shift by Z, and decision procedures for both equality and order. Class AppDiv AQ := app div : AQ AQ Z AQ. Class AppApprox AQ := app approx : AQ Z AQ. Class AppRationals AQ {e plus mult zero one inv} {!Order AQ} {AQtoQ : Coerce AQ Q as MetricSpace} {!AppInverse AQtoQ} {ZtoAQ : Coerce Z AQ} {!AppDiv AQ} {!AppApprox AQ} {!Abs AQ} {!Pow AQ N} {!ShiftL AQ Z} { x y : AQ, Decision (x = y)} { x y : AQ, Decision (x y)} : Prop := { aq ring AQ e plus mult zero one inv ; aq order embed :> OrderEmbedding AQtoQ ; aq ring morphism :> SemiRing Morphism AQtoQ ; aq dense embedding :> DenseEmbedding AQtoQ ; aq div : x y k, B 2 k( app div x y k) ( x / y) ; aq approx : x k, B 2 k( app approx x k) ( x) ; aq shift :> ShiftLSpec AQ Z ( ) ; aq nat pow :> NatPowSpec AQ N (ˆ) ; aq ints mor :> SemiRing Morphism ZtoAQ }. 9
10 O Connor s [2] keeps the size of the rational numbers small to avoid efficiency problems. He introduced a function approx x ɛ that yields the simplest rational number between x ɛ and x + ɛ. In our interface we modify the approx function slightly: app approx x k yields an arbitrary element between x 2 k and x +2 k. Using this function we define the compress operation on the real numbers: compress := bind (λ ɛ, app approx x (Qdlog2 ɛ)) such that compress x = x. In Section 5 we will explain our choice of using a power of 2 to specify the precision of app div and app approx. In the remainder of this section we briefly describe our implementation by the dyadics. The dyadic rationals are numbers of the shape n 2 e for n, e Z. In order to remain independent of an integers implementation, we abstract over it. For our eventual implementation of the approximate rationals we use Coq s machine integers, bigz. Now given an arbitrary integer implementation Int it is straightforward to define the dyadics. Here we will just show the ring operations. Notation x p := (exist x p) (at level 20). Record Dyadic := dyadic { mant : Int ; expo : Int }. Infix $ := dyadic (at level 80). Global Instance dy inject: Coerce Int Dyadic := λ x, x $ 0. Global Instance dy opp: GroupInv Dyadic := λ x, mant x $ expo x. Global Instance dy mult: RingMult Dyadic := λ x y, mant x mant y $ expo x + expo y. Global Instance dy 0: RingZero Dyadic := ( 0:Dyadic). Global Instance dy 1: RingOne Dyadic := ( 1:Dyadic). Global Program Instance dy plus: RingPlus Dyadic := λ x y, if decide rel ( ) (expo x) (expo y) then mant x + mant y (expo y expo x) $ min (expo x) (expo y) else mant x (expo x expo y) + mant y $ min (expo x) (expo y). In this code shiftl has type Int Int + Int, where Int + is a Σ-type describing the non-negative elements of Int. Therefore, in the definition of dy plus we have to equip expo y expo x with a proof that it is in fact non-negative. 5 Power series Elementary transcendental functions as exp, sin, ln and arctan can be defined by their power series. A power series is particularly suited for computation if its coefficients are alternating, decreasing and have limit 0. For 1 x 0, exp x = is of this form. To approximate exp x with error ε we take the partial sum until x i i! ε. In order to implement this efficiently we use a stream representing the series and define a function that sums the required number of elements. For example, the series 1, a, a 2, a 3,... is defined by the following stream. CoFixpoint powers help (c : A) : Stream A := Cons c (powers help (c a)). Definition powers : Stream A := powers help 1. i=0 x i i! 10
11 Streams in Coq, like lists in Haskell, are lazy. So, in the example the multiplications are accumulated. Since Coq only allows structural recursion it requires some work to convince Coq that our algorithm terminates. Intuitively, one would describe the limit as an upperbound of the required number of elements using the Exists predicate. Inductive Exists A (P : Stream A Prop) (x : Stream) : Prop := Here : P x Exists P x Further : Exists P (tl x) Exists P x. This approach leads to performance problems. The upperbound, encoded in unary format, may become very large while generally only a few terms are necessary. Due to vm compute s eager evaluation scheme, this unary number will be computed before summing the series. Instead we use LazyExists [24]. Inductive LazyExists A (P : Stream A Prop) (x : Stream A) : Prop := LazyHere : P x LazyExists P x LazyFurther : (unit LazyExists P (tl x)) LazyExists P x. O Connor s InfiniteAlternatingSum s returns the real number represented by the infinite alternating sum over s, where the stream s is decreasing, non-negative and has limit 0. We have extended this in two ways. First, by generalizing some of the work to abstract structures. Second, as we do not have exact division on approximate rationals, we extended his algorithm to work with approximate division. The latter required changing InfiniteAlternatingSum s to InfiniteAlternatingSum n d which computes the infinite alternating sum of the stream λi, ni d i. This allows us to postpone divisions. Also, we have to determine both the length of the partial sum and the required precision of the divisions. To do so we find k such that: B ε (app div n k d 2 k (log ε 2k ) + ε ) 0. (1) 2k Now k is the length of the partial sum, and is the required precision of division. Using O Connor s results we have verified that these values are correct and such a k indeed exists for a decreasing, non-negative stream with limit 0. As noted in Section 4.4, we have specified the precision of division in powers of 2 instead of using a rational value. This is allows us to replace (1) with: B ε 2 (app div n k d k (log ε (k + 1)) + 1 (log ε (k + 1))) 0. Here k is the length of the partial sum, and 2 l, where l = log ε (k + 1), is the required precision of division. This variant can be implemented without any arithmetic on the rationals and is thus much more efficient. This method gives us a fast way to compute the infinite alternating sum, in practice, only few extra terms have to be computed and due to the approximate division the auxiliary results are kept as small as possible. Using this method to compute infinite alternating sums we have so far implemented exp and arctan. Furthermore, we extend the exponential to its complete domain by repeatedly applying the following formula. ε 2k exp x = (exp(x 1)) 2 (2) 11
12 Our tests have shown that reducing the input to a value between 2 k x 0 for 50 k yields major performance improvements as the series will converge much faster. For higher precisions setting it to 75 k gives even better results. By defining arctan on [0, 1), we can define π := 176 arctan arctan 48 arctan arctan Since we do not have exact devision on the approximate rationals, we here see the purpose of parameterizing infinite sums by two streams. 6 Square root We use Wolfram s algorithm [25, p.913] for computing the square root. Its complexity is linear, in fact it provides a new binary digit in each step. We aim to investigate Newton iteration in future work. Context (Pa : 1 a 4). Fixpoint AQroot loop (n : nat) : AQ AQ := match n with O (a, 0) S n let (r, s) := AQroot loop n in if decide rel ( ) (s + 1) r then ((r (s + 1)) (2:Z), (s + 2) (1:Z)) else (r (2:Z), s (1:Z)) end. Three easy invariants allow us to prove this series converges to the square root. Lemma AQroot loop invariant1 (n : nat) : snd (AQroot loop n) snd (AQroot loop n) + 4 fst (AQroot loop n) = 4 4 ˆ n a. Lemma AQroot loop invariant2 (n : nat) : fst (AQroot loop n) 2 snd (AQroot loop n) + 4. Lemma AQroot loop fst bound (n : nat) : fst (AQroot loop n) 2 ˆ (3 + n). 7 Benchmarks The first step in this research was to create a Haskell prototype based on O Connor s implementation of the real numbers in Haskell [2]. The second step was to implement this prototype in Coq. Currently, our Coq development contains the field operations, computation of power series, exp, arctan, π and the square root. Apart from the square root, the correctness of these operations has been verified in the Coq system. In this section we present some benchmarks comparing the old and the new implementation, both in Haskell and Coq. All benchmarks have been carried out on an Intel Core Quad 2.4 GHz with 8GB of memory running 12
13 Expression Decimals O Connor Krebbers/Spitters sin (sin (sin 1)) 10,000 71s 5s cos (10 50 ) 10, s 0.6s tan ( 2) + arctanh (sin 1) s 2.2s Table 1. Haskell, compiled with ghc version , using -O2. Expression Decimals O Connor Krebbers/Spitters π s 0.8s exp (exp (exp ( 1 ))) s 0.23s 2 exp π π 25 52s 0.1s arctan π s 1.0s Table 2. Coq trunk revision Debian GNU/Linux with kernel The sources of our developments can be found at Table 1 shows some benchmarks in Haskell with compiler optimizations enabled (-O2) and Table 2 compares our Coq implementation with O Connor s. More extensive benchmarking shows that our Haskell implementation generally benefits from a 15 times speed up while the speed up in Coq is usually more than a 100 times. This difference is explained by the fact that O Connor s Haskell implementation already used fast integers, while his Coq implementation did not. In the same times as shown in Table 2 for the old implementation, the new implementation is able to compute the first 2,000 decimals of π, 450 decimals of exp (exp (exp ( 1 2 ))), 425 decimals of exp π π and 85 decimals of arctan π. This is an improvement of up to 18 times of the number of decimals. It is interesting to notice that π and arctan benefit the least from our improvements, as we are unaware of an optimization similar to the squaring trick for exp (Section 5, Equation 2). We conclude this section with a comparison between the performance of Wolfram s algorithm in Coq and Haskell. The Haskell prototype (without compiler optimizations) is quite fast, computing 10,000 iterations (giving 3,010 decimals) of 2 takes 0.2s. In Coq it takes 11.6s using type classes and 11.3s without type classes. Here we exclude the time spend on type class resolution. Thus type classes cause only a 3% performance penalty on computations. Unfortunately, the Coq-implementation is slow compared to Haskell. Laurent Théry suggested that this is due to the representation of the fast integers, which uses a tree with a fixed depth and when the size of the integer becomes too big uses a less optimal representation. Increasing the size of the tree representation and avoiding an inefficiency in the implementation of shifts reduces this time to 7.5s. 13
14 8 Conclusions and Related work We have greatly improved the performance of real number computation in Coq using Coq s new machine integers. We produced highly structured and abstract code using type classes with no apparent performance penalty. Moreover, Coq s notation mechanism combined with unicode characters gives nicely readable statements and proofs. Type classes were a great help in our work. However, the current implementation of instance resolution is still experimental and at times too slow (at compile time). The use of canonical structures by the Ssreflect team does not suffer from these efficiency issues [26]. However, their library is currently not suited for setoids which are crucial to us. We hope these issues might be addressed by the integration of unification hints [27] into Coq. We needed to adapt our correctness proofs to prevent the virtual machine from eagerly evaluating them. Lazy evaluation for Prop would have allowed us to use the original proofs. The experimental native compute performs evaluation by compilation to native Ocaml code. This approach uses the Ocaml compiler available and is interesting for heavy compilation. Our first experiments indicate a 10 times speed up with Wolfram iteration. Unfortunately, native compute does not work with Coq trunk yet, so we were unable to test it with our implementation of the reals. The Flocq project [28] formalizes floating-points in Coq. It provides a library of theorems on a multi-radix multi-precision arithmetic and supports efficient numerical computations inside Coq. However, the current library is still too limited for our purposes, but in the future it should be possible to show that they form an instance of our approximate rationals. This may allow us to gain some speed by taking advantage of fine grained algorithms on the floats instead of our more straightforward ones. The encoding of real numbers as streams of bits is potentially interesting. However, currently there is a big difference in performance. The computation of 37 decimals of the square root of 1/2 by Newton iteration [29] took 12s. This should be compared with our use of the Wolfram iteration, which gives only linear convergence, but with which we nevertheless obtain 3,000 decimals in in a similar time. The present work is part of a larger program to use constructive mathematics based on type theory as a programming language for exact analysis. This should culminate in a numerical ODE-solver. 9 Acknowledgements We thank Eelis van der Weegen for many discussions. We thank Pierre Letouzey and Matthieu Sozeau for closing some of our bug reports. References 1. Bishop, E.A.: Foundations of constructive analysis. McGraw-Hill (1967) 14
15 2. O Connor, R.: A Monadic, Functional Implementation of Real Numbers. MSCS 17(1) (2007) O Connor, R.: Certified Exact Transcendental Real Number Computation in Coq. In: TPHOLs Volume 5170 of LNCS. (2008) O Connor, R., Spitters, B.: A computer verified, monadic, functional implementation of the integral. TCS 411(37) (2010) Coquand, T., Huet, G.: The Calculus of Constructions. Information and Computation 76(2-3) (1988) Coquand, T., Paulin, C.: Inductively defined types. In: COLOG-88. Volume 417 of LNCS. Springer (1990) Coq Development Team: The Coq Proof Assistant Reference Manual. INRIA- Rocquencourt (2008) 8. Bertot, Y., Castéran, P.: Interactive Theorem Proving and Program Development. Coq Art: The Calculus of Inductive Constructions. Texts in TCS. Springer (2004) 9. Martin-Löf, P.: An intuitionistic theory of types. In: Twenty-five years of constructive type theory. Volume 36 of Oxford Logic Guides. OUP (1998) Martin-Löf, P.: Constructive Mathematics and Computer Science. In: Logic, Methodology and the Philosophy of Science VI. Volume 104 of Studies in Logic and the Foundations of Mathematics. (1982) Hofmann, M.: Extensional constructs in intensional type theory. CPHC/BCS Distinguished Dissertations. Springer (1997) 12. Palmgren, E.: Constructivist and Structuralist Foundations: Bishop s and Lawvere s Theories of Sets. Technical Report 4, Mittag-Leffler (2009) 13. Sozeau, M.: A New Look at Generalized Rewriting in Type Theory. Journal of Formalized Reasoning 2(1) (2009) Sozeau, M., Oury, N.: First-class type classes. In: TPHOLs Volume 5170 of LNCS. (2008) Spitters, B., van der Weegen, E.: Type classes for mathematics in type theory. MSCS, special issue on Interactive theorem proving and the formalization of mathematics (2011) 16. Grégoire, B., Leroy, X.: A compiled implementation of strong reduction. In: ICFP. (2002) Armand, M., Grégoire, B., Spiwack, A., Théry, L.: Extending Coq with imperative features and its application to SAT verification. In: ITP Volume 6172 of LNCS. (2010) Spiwack, A.: Verified Computing in Homological Algebra, A Journey Exploring the Power and Limits of Dependent Type Theory. PhD thesis, INRIA (2011) 19. Richman, F.: Real numbers and other completions. Mathematical Logic Quarterly 54(1) (2008) Moggi, E.: Computational lambda-calculus and monads. In: LICS. (1989) Wadler, P.: Monads for functional programming. In: Proceedings of the Marktoberdorf Summer School on Program Design Calculi. (August 1992) 22. Gonthier, G., Mahboubi, A., Tassi, E.: A Small Scale Reflection Extension for the Coq system. Technical Report RR-6455, INRIA (2008) 23. Bauer, A., Kavkler, I.: A constructive theory of continuous domains suitable for implementation. Annals of Pure and Applied Logic 159(3) (2009) O Connor, R.: Incompleteness and Completeness: Formalizing Logic and Analysis in Type Theory. PhD thesis, Radboud University Nijmegen (2009) 25. Wolfram, S.: A new kind of science. Wolfram Media (2002) 26. Garillot, F., Gonthier, G., Mahboubi, A., Rideau, L.: Packaging mathematical structures. In: TPHOLs Volume 5674 of LNCS. (2009)
16 27. Asperti, A., Ricciotti, W., Coen, C., Tassi, E.: Hints in Unification. In: TPHOLs Volume 5674 of LNCS. (2009) Boldo, S., Melquiond, G.: Flocq: A unified library for proving floating-point algorithms in Coq. In: Proc 20th IEEE Symposium on Computer Arithmetic. (2011) 29. Julien, N., Pasca, I.: Formal Verification of Exact Computations Using Newton s Method. In: TPHOLs Volume 5674 of LNCS. (2009)
Continued Fractions and the Euclidean Algorithm
Continued Fractions and the Euclidean Algorithm Lecture notes prepared for MATH 326, Spring 997 Department of Mathematics and Statistics University at Albany William F Hammond Table of Contents Introduction
[Refer Slide Time: 05:10]
Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture
Functional Programming. Functional Programming Languages. Chapter 14. Introduction
Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The
Some Polynomial Theorems. John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA 90405 [email protected].
Some Polynomial Theorems by John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA 90405 [email protected] This paper contains a collection of 31 theorems, lemmas,
Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic
Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic Lars Birkedal Rasmus Ejlers Møgelberg Rasmus Lerchedahl Petersen IT University Technical Report Series TR-00-7 ISSN 600 600 February 00
Checking Access to Protected Members in the Java Virtual Machine
Checking Access to Protected Members in the Java Virtual Machine Alessandro Coglio Kestrel Institute 3260 Hillview Avenue, Palo Alto, CA 94304, USA Ph. +1-650-493-6871 Fax +1-650-424-1807 http://www.kestrel.edu/
Termination Checking: Comparing Structural Recursion and Sized Types by Examples
Termination Checking: Comparing Structural Recursion and Sized Types by Examples David Thibodeau Decemer 3, 2011 Abstract Termination is an important property for programs and is necessary for formal proofs
Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test
Math Review for the Quantitative Reasoning Measure of the GRE revised General Test www.ets.org Overview This Math Review will familiarize you with the mathematical skills and concepts that are important
ML for the Working Programmer
ML for the Working Programmer 2nd edition Lawrence C. Paulson University of Cambridge CAMBRIDGE UNIVERSITY PRESS CONTENTS Preface to the Second Edition Preface xiii xv 1 Standard ML 1 Functional Programming
PYTHAGOREAN TRIPLES KEITH CONRAD
PYTHAGOREAN TRIPLES KEITH CONRAD 1. Introduction A Pythagorean triple is a triple of positive integers (a, b, c) where a + b = c. Examples include (3, 4, 5), (5, 1, 13), and (8, 15, 17). Below is an ancient
Chapter 7: Functional Programming Languages
Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language
U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, 2009. Notes on Algebra
U.C. Berkeley CS276: Cryptography Handout 0.1 Luca Trevisan January, 2009 Notes on Algebra These notes contain as little theory as possible, and most results are stated without proof. Any introductory
Functional Programming
FP 2005 1.1 3 Functional Programming WOLFRAM KAHL [email protected] Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative telling
11 Ideals. 11.1 Revisiting Z
11 Ideals The presentation here is somewhat different than the text. In particular, the sections do not match up. We have seen issues with the failure of unique factorization already, e.g., Z[ 5] = O Q(
Mathematics Course 111: Algebra I Part IV: Vector Spaces
Mathematics Course 111: Algebra I Part IV: Vector Spaces D. R. Wilkins Academic Year 1996-7 9 Vector Spaces A vector space over some field K is an algebraic structure consisting of a set V on which are
The Clean programming language. Group 25, Jingui Li, Daren Tuzi
The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was
CHAPTER 5 Round-off errors
CHAPTER 5 Round-off errors In the two previous chapters we have seen how numbers can be represented in the binary numeral system and how this is the basis for representing numbers in computers. Since any
FACTORING POLYNOMIALS IN THE RING OF FORMAL POWER SERIES OVER Z
FACTORING POLYNOMIALS IN THE RING OF FORMAL POWER SERIES OVER Z DANIEL BIRMAJER, JUAN B GIL, AND MICHAEL WEINER Abstract We consider polynomials with integer coefficients and discuss their factorization
Automated Theorem Proving - summary of lecture 1
Automated Theorem Proving - summary of lecture 1 1 Introduction Automated Theorem Proving (ATP) deals with the development of computer programs that show that some statement is a logical consequence of
POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful
POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: [email protected] Homepage: http://www.cs.uu.nl/~ralf/
The Goldberg Rao Algorithm for the Maximum Flow Problem
The Goldberg Rao Algorithm for the Maximum Flow Problem COS 528 class notes October 18, 2006 Scribe: Dávid Papp Main idea: use of the blocking flow paradigm to achieve essentially O(min{m 2/3, n 1/2 }
3. Mathematical Induction
3. MATHEMATICAL INDUCTION 83 3. Mathematical Induction 3.1. First Principle of Mathematical Induction. Let P (n) be a predicate with domain of discourse (over) the natural numbers N = {0, 1,,...}. If (1)
Numerical Analysis Lecture Notes
Numerical Analysis Lecture Notes Peter J. Olver 5. Inner Products and Norms The norm of a vector is a measure of its size. Besides the familiar Euclidean norm based on the dot product, there are a number
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Lecture 3: Finding integer solutions to systems of linear equations
Lecture 3: Finding integer solutions to systems of linear equations Algorithmic Number Theory (Fall 2014) Rutgers University Swastik Kopparty Scribe: Abhishek Bhrushundi 1 Overview The goal of this lecture
How To Know If A Domain Is Unique In An Octempo (Euclidean) Or Not (Ecl)
Subsets of Euclidean domains possessing a unique division algorithm Andrew D. Lewis 2009/03/16 Abstract Subsets of a Euclidean domain are characterised with the following objectives: (1) ensuring uniqueness
9.2 Summation Notation
9. Summation Notation 66 9. Summation Notation In the previous section, we introduced sequences and now we shall present notation and theorems concerning the sum of terms of a sequence. We begin with a
Factoring & Primality
Factoring & Primality Lecturer: Dimitris Papadopoulos In this lecture we will discuss the problem of integer factorization and primality testing, two problems that have been the focus of a great amount
Summary Last Lecture. Automated Reasoning. Outline of the Lecture. Definition sequent calculus. Theorem (Normalisation and Strong Normalisation)
Summary Summary Last Lecture sequent calculus Automated Reasoning Georg Moser Institute of Computer Science @ UIBK Winter 013 (Normalisation and Strong Normalisation) let Π be a proof in minimal logic
Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.
Elementary Number Theory and Methods of Proof CSE 215, Foundations of Computer Science Stony Brook University http://www.cs.stonybrook.edu/~cse215 1 Number theory Properties: 2 Properties of integers (whole
The Notebook Series. The solution of cubic and quartic equations. R.S. Johnson. Professor of Applied Mathematics
The Notebook Series The solution of cubic and quartic equations by R.S. Johnson Professor of Applied Mathematics School of Mathematics & Statistics University of Newcastle upon Tyne R.S.Johnson 006 CONTENTS
A Gentle Introduction to Type Classes and Relations in Coq
A Gentle Introduction to Type Classes and Relations in Coq Pierre Castéran Univ. Bordeaux, LaBRI, UMR 5800, F-33400 Talence, France. CNRS, LaBRI, UMR 5800, F-33400 Talence, France. Matthieu Sozeau INRIA
Chapter 15 Functional Programming Languages
Chapter 15 Functional Programming Languages Introduction - The design of the imperative languages is based directly on the von Neumann architecture Efficiency (at least at first) is the primary concern,
Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions
Grade 7 Mathematics, Quarter 1, Unit 1.1 Integer Operations Overview Number of Instructional Days: 15 (1 day = 45 minutes) Content to Be Learned Describe situations in which opposites combine to make zero.
Lecture 4 Online and streaming algorithms for clustering
CSE 291: Geometric algorithms Spring 2013 Lecture 4 Online and streaming algorithms for clustering 4.1 On-line k-clustering To the extent that clustering takes place in the brain, it happens in an on-line
Jieh Hsiang Department of Computer Science State University of New York Stony brook, NY 11794
ASSOCIATIVE-COMMUTATIVE REWRITING* Nachum Dershowitz University of Illinois Urbana, IL 61801 N. Alan Josephson University of Illinois Urbana, IL 01801 Jieh Hsiang State University of New York Stony brook,
This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers
This Unit: Floating Point Arithmetic CIS 371 Computer Organization and Design Unit 7: Floating Point App App App System software Mem CPU I/O Formats Precision and range IEEE 754 standard Operations Addition
CHAPTER II THE LIMIT OF A SEQUENCE OF NUMBERS DEFINITION OF THE NUMBER e.
CHAPTER II THE LIMIT OF A SEQUENCE OF NUMBERS DEFINITION OF THE NUMBER e. This chapter contains the beginnings of the most important, and probably the most subtle, notion in mathematical analysis, i.e.,
MATH 132: CALCULUS II SYLLABUS
MATH 32: CALCULUS II SYLLABUS Prerequisites: Successful completion of Math 3 (or its equivalent elsewhere). Math 27 is normally not a sufficient prerequisite for Math 32. Required Text: Calculus: Early
The Method of Partial Fractions Math 121 Calculus II Spring 2015
Rational functions. as The Method of Partial Fractions Math 11 Calculus II Spring 015 Recall that a rational function is a quotient of two polynomials such f(x) g(x) = 3x5 + x 3 + 16x x 60. The method
6 EXTENDING ALGEBRA. 6.0 Introduction. 6.1 The cubic equation. Objectives
6 EXTENDING ALGEBRA Chapter 6 Extending Algebra Objectives After studying this chapter you should understand techniques whereby equations of cubic degree and higher can be solved; be able to factorise
Lecture Notes on Polynomials
Lecture Notes on Polynomials Arne Jensen Department of Mathematical Sciences Aalborg University c 008 Introduction These lecture notes give a very short introduction to polynomials with real and complex
The countdown problem
JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON
CONTINUED FRACTIONS AND PELL S EQUATION. Contents 1. Continued Fractions 1 2. Solution to Pell s Equation 9 References 12
CONTINUED FRACTIONS AND PELL S EQUATION SEUNG HYUN YANG Abstract. In this REU paper, I will use some important characteristics of continued fractions to give the complete set of solutions to Pell s equation.
The Ideal Class Group
Chapter 5 The Ideal Class Group We will use Minkowski theory, which belongs to the general area of geometry of numbers, to gain insight into the ideal class group of a number field. We have already mentioned
Integer roots of quadratic and cubic polynomials with integer coefficients
Integer roots of quadratic and cubic polynomials with integer coefficients Konstantine Zelator Mathematics, Computer Science and Statistics 212 Ben Franklin Hall Bloomsburg University 400 East Second Street
InvGen: An Efficient Invariant Generator
InvGen: An Efficient Invariant Generator Ashutosh Gupta and Andrey Rybalchenko Max Planck Institute for Software Systems (MPI-SWS) Abstract. In this paper we present InvGen, an automatic linear arithmetic
RN-Codings: New Insights and Some Applications
RN-Codings: New Insights and Some Applications Abstract During any composite computation there is a constant need for rounding intermediate results before they can participate in further processing. Recently
Copyrighted Material. Chapter 1 DEGREE OF A CURVE
Chapter 1 DEGREE OF A CURVE Road Map The idea of degree is a fundamental concept, which will take us several chapters to explore in depth. We begin by explaining what an algebraic curve is, and offer two
Notes on Factoring. MA 206 Kurt Bryan
The General Approach Notes on Factoring MA 26 Kurt Bryan Suppose I hand you n, a 2 digit integer and tell you that n is composite, with smallest prime factor around 5 digits. Finding a nontrivial factor
3. INNER PRODUCT SPACES
. INNER PRODUCT SPACES.. Definition So far we have studied abstract vector spaces. These are a generalisation of the geometric spaces R and R. But these have more structure than just that of a vector space.
Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay
Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay Lecture - 17 Shannon-Fano-Elias Coding and Introduction to Arithmetic Coding
discuss how to describe points, lines and planes in 3 space.
Chapter 2 3 Space: lines and planes In this chapter we discuss how to describe points, lines and planes in 3 space. introduce the language of vectors. discuss various matters concerning the relative position
PURSUITS IN MATHEMATICS often produce elementary functions as solutions that need to be
Fast Approximation of the Tangent, Hyperbolic Tangent, Exponential and Logarithmic Functions 2007 Ron Doerfler http://www.myreckonings.com June 27, 2007 Abstract There are some of us who enjoy using our
Verifying Specifications with Proof Scores in CafeOBJ
Verifying Specifications with Proof Scores in CafeOBJ FUTATSUGI, Kokichi 二 木 厚 吉 Chair of Language Design Graduate School of Information Science Japan Advanced Institute of Science and Technology (JAIST)
MOP 2007 Black Group Integer Polynomials Yufei Zhao. Integer Polynomials. June 29, 2007 Yufei Zhao [email protected]
Integer Polynomials June 9, 007 Yufei Zhao [email protected] We will use Z[x] to denote the ring of polynomials with integer coefficients. We begin by summarizing some of the common approaches used in dealing
A simple criterion on degree sequences of graphs
Discrete Applied Mathematics 156 (2008) 3513 3517 Contents lists available at ScienceDirect Discrete Applied Mathematics journal homepage: www.elsevier.com/locate/dam Note A simple criterion on degree
Lecture 6 Online and streaming algorithms for clustering
CSE 291: Unsupervised learning Spring 2008 Lecture 6 Online and streaming algorithms for clustering 6.1 On-line k-clustering To the extent that clustering takes place in the brain, it happens in an on-line
Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1
Recursion Slides by Christopher M Bourke Instructor: Berthe Y Choueiry Fall 007 Computer Science & Engineering 35 Introduction to Discrete Mathematics Sections 71-7 of Rosen cse35@cseunledu Recursive Algorithms
Faster deterministic integer factorisation
David Harvey (joint work with Edgar Costa, NYU) University of New South Wales 25th October 2011 The obvious mathematical breakthrough would be the development of an easy way to factor large prime numbers
WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT?
WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT? introduction Many students seem to have trouble with the notion of a mathematical proof. People that come to a course like Math 216, who certainly
Set theory as a foundation for mathematics
V I I I : Set theory as a foundation for mathematics This material is basically supplementary, and it was not covered in the course. In the first section we discuss the basic axioms of set theory and the
Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:
CSE341T 08/31/2015 Lecture 3 Cost Model: Work, Span and Parallelism In this lecture, we will look at how one analyze a parallel program written using Cilk Plus. When we analyze the cost of an algorithm
Integer Factorization using the Quadratic Sieve
Integer Factorization using the Quadratic Sieve Chad Seibert* Division of Science and Mathematics University of Minnesota, Morris Morris, MN 56567 [email protected] March 16, 2011 Abstract We give
7. Some irreducible polynomials
7. Some irreducible polynomials 7.1 Irreducibles over a finite field 7.2 Worked examples Linear factors x α of a polynomial P (x) with coefficients in a field k correspond precisely to roots α k [1] of
First-Class Type Classes
First-Class Type Classes Matthieu Sozeau 1 and Nicolas Oury 2 1 Univ. Paris Sud, CNRS, Laboratoire LRI, UMR 8623, Orsay, F-91405 INRIA Saclay, ProVal, Parc Orsay Université, F-91893 [email protected] 2 University
CHAPTER 7 GENERAL PROOF SYSTEMS
CHAPTER 7 GENERAL PROOF SYSTEMS 1 Introduction Proof systems are built to prove statements. They can be thought as an inference machine with special statements, called provable statements, or sometimes
Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics
Undergraduate Notes in Mathematics Arkansas Tech University Department of Mathematics An Introductory Single Variable Real Analysis: A Learning Approach through Problem Solving Marcel B. Finan c All Rights
P NP for the Reals with various Analytic Functions
P NP for the Reals with various Analytic Functions Mihai Prunescu Abstract We show that non-deterministic machines in the sense of [BSS] defined over wide classes of real analytic structures are more powerful
a 11 x 1 + a 12 x 2 + + a 1n x n = b 1 a 21 x 1 + a 22 x 2 + + a 2n x n = b 2.
Chapter 1 LINEAR EQUATIONS 1.1 Introduction to linear equations A linear equation in n unknowns x 1, x,, x n is an equation of the form a 1 x 1 + a x + + a n x n = b, where a 1, a,..., a n, b are given
Chapter 21: The Discounted Utility Model
Chapter 21: The Discounted Utility Model 21.1: Introduction This is an important chapter in that it introduces, and explores the implications of, an empirically relevant utility function representing intertemporal
Continued Fractions. Darren C. Collins
Continued Fractions Darren C Collins Abstract In this paper, we discuss continued fractions First, we discuss the definition and notation Second, we discuss the development of the subject throughout history
OPERATIONAL TYPE THEORY by Adam Petcher Prepared under the direction of Professor Aaron Stump A thesis presented to the School of Engineering of
WASHINGTON NIVERSITY SCHOOL OF ENGINEERING AND APPLIED SCIENCE DEPARTMENT OF COMPTER SCIENCE AND ENGINEERING DECIDING JOINABILITY MODLO GROND EQATIONS IN OPERATIONAL TYPE THEORY by Adam Petcher Prepared
THREE DIMENSIONAL GEOMETRY
Chapter 8 THREE DIMENSIONAL GEOMETRY 8.1 Introduction In this chapter we present a vector algebra approach to three dimensional geometry. The aim is to present standard properties of lines and planes,
A Static Analyzer for Large Safety-Critical Software. Considered Programs and Semantics. Automatic Program Verification by Abstract Interpretation
PLDI 03 A Static Analyzer for Large Safety-Critical Software B. Blanchet, P. Cousot, R. Cousot, J. Feret L. Mauborgne, A. Miné, D. Monniaux,. Rival CNRS École normale supérieure École polytechnique Paris
Formal Verification Coverage: Computing the Coverage Gap between Temporal Specifications
Formal Verification Coverage: Computing the Coverage Gap between Temporal Specifications Sayantan Das Prasenjit Basu Ansuman Banerjee Pallab Dasgupta P.P. Chakrabarti Department of Computer Science & Engineering
CONTINUED FRACTIONS AND FACTORING. Niels Lauritzen
CONTINUED FRACTIONS AND FACTORING Niels Lauritzen ii NIELS LAURITZEN DEPARTMENT OF MATHEMATICAL SCIENCES UNIVERSITY OF AARHUS, DENMARK EMAIL: [email protected] URL: http://home.imf.au.dk/niels/ Contents
Adaptive Online Gradient Descent
Adaptive Online Gradient Descent Peter L Bartlett Division of Computer Science Department of Statistics UC Berkeley Berkeley, CA 94709 bartlett@csberkeleyedu Elad Hazan IBM Almaden Research Center 650
26. Determinants I. 1. Prehistory
26. Determinants I 26.1 Prehistory 26.2 Definitions 26.3 Uniqueness and other properties 26.4 Existence Both as a careful review of a more pedestrian viewpoint, and as a transition to a coordinate-independent
9 More on differentiation
Tel Aviv University, 2013 Measure and category 75 9 More on differentiation 9a Finite Taylor expansion............... 75 9b Continuous and nowhere differentiable..... 78 9c Differentiable and nowhere monotone......
8 Divisibility and prime numbers
8 Divisibility and prime numbers 8.1 Divisibility In this short section we extend the concept of a multiple from the natural numbers to the integers. We also summarize several other terms that express
Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2
CS 70 Discrete Mathematics and Probability Theory Fall 2009 Satish Rao, David Tse Note 2 Proofs Intuitively, the concept of proof should already be familiar We all like to assert things, and few of us
BANACH AND HILBERT SPACE REVIEW
BANACH AND HILBET SPACE EVIEW CHISTOPHE HEIL These notes will briefly review some basic concepts related to the theory of Banach and Hilbert spaces. We are not trying to give a complete development, but
Lectures 5-6: Taylor Series
Math 1d Instructor: Padraic Bartlett Lectures 5-: Taylor Series Weeks 5- Caltech 213 1 Taylor Polynomials and Series As we saw in week 4, power series are remarkably nice objects to work with. In particular,
Notes on Determinant
ENGG2012B Advanced Engineering Mathematics Notes on Determinant Lecturer: Kenneth Shum Lecture 9-18/02/2013 The determinant of a system of linear equations determines whether the solution is unique, without
Regular Expressions and Automata using Haskell
Regular Expressions and Automata using Haskell Simon Thompson Computing Laboratory University of Kent at Canterbury January 2000 Contents 1 Introduction 2 2 Regular Expressions 2 3 Matching regular expressions
Section 1.1. Introduction to R n
The Calculus of Functions of Several Variables Section. Introduction to R n Calculus is the study of functional relationships and how related quantities change with each other. In your first exposure to
Type Classes with Functional Dependencies
Appears in Proceedings of the 9th European Symposium on Programming, ESOP 2000, Berlin, Germany, March 2000, Springer-Verlag LNCS 1782. Type Classes with Functional Dependencies Mark P. Jones Department
JUST THE MATHS UNIT NUMBER 1.8. ALGEBRA 8 (Polynomials) A.J.Hobson
JUST THE MATHS UNIT NUMBER 1.8 ALGEBRA 8 (Polynomials) by A.J.Hobson 1.8.1 The factor theorem 1.8.2 Application to quadratic and cubic expressions 1.8.3 Cubic equations 1.8.4 Long division of polynomials
The Trip Scheduling Problem
The Trip Scheduling Problem Claudia Archetti Department of Quantitative Methods, University of Brescia Contrada Santa Chiara 50, 25122 Brescia, Italy Martin Savelsbergh School of Industrial and Systems
Overview. Essential Questions. Precalculus, Quarter 4, Unit 4.5 Build Arithmetic and Geometric Sequences and Series
Sequences and Series Overview Number of instruction days: 4 6 (1 day = 53 minutes) Content to Be Learned Write arithmetic and geometric sequences both recursively and with an explicit formula, use them
Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit
Decimal Division Remember 4th grade long division? 43 // quotient 12 521 // divisor dividend -480 41-36 5 // remainder Shift divisor left (multiply by 10) until MSB lines up with dividend s Repeat until
24. The Branch and Bound Method
24. The Branch and Bound Method It has serious practical consequences if it is known that a combinatorial problem is NP-complete. Then one can conclude according to the present state of science that no
