Essays on Yacas
Total Page:16
File Type:pdf, Size:1020Kb
Essays on Yacas by the Yacas team 1 Yacas version: 1.3.6 generated on November 25, 2014 This is a book of essays on Yacas. It covers various topics, from using the Yacas system for specific calculations to general issues related to the Yacas system development and maintenance. 1This text is part of the Yacas software package. Copyright 2000{2002. Principal documentation authors: Ayal Zwi Pinkus, Serge Winitzki, Jitse Niesen. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". Contents 1 Yacas: A do-it-yourself symbolic algebra environment 2 1.1 Introduction . 2 1.2 Basic design . 2 1.3 The Yacas kernel functionality . 4 1.4 The Yacas scripting language . 5 1.5 Currently supported CAS features . 5 1.6 Interface . 7 1.7 Documentation . 7 1.8 Future plans . 7 1.9 References . 7 2 M. Wester's CAS benchmark and Yacas 8 3 On Yacas programming 11 3.1 Example: implementing a formal grammar . 11 3.2 Example: Using rules with special syntax operators creatively . 12 −1 1 4 Why −x and − x are not the same in Yacas 16 4.1 Canonical and normal representations . 16 4.2 But how can we then build a powerful CAS? . 17 4.3 Conclusion . 17 5 For Yacas developers 18 5.1 A crash course in Yacas maintenance for developers . 18 5.2 Preparing and maintaining Yacas documentation . 19 5.3 The Yacas build system . 28 6 Designing modules in the Yacas scripting language 32 6.1 Introduction . 32 6.2 Demonstration of the problem . 32 6.3 Declaring resources to be local to the module . 32 6.4 When to use and when not to use LocalSymbols ................................ 33 7 The Yacas arithmetic library 34 7.1 Introduction . 34 7.2 The link between the interpreter and the arithmetic library . 34 7.3 Interface of the BigNumber class ......................................... 34 7.4 Precision of arithmetic operations . 37 7.5 Implementation notes . 44 8 GNU Free Documentation License 47 1 Chapter 1 Yacas: A do-it-yourself symbolic algebra environment A much shorter and more polished version of this paper is similarly to Prolog B86, and includes expression transformation published as: Ayal Z. Pinkus and Serge Winitzki, \YACAS: (term rewriting) as a basic feature of the language. a do-it-yourself computer algebra system", Lecture Notes in The Yacas language interpreter comes with a library of Artificial Intelligence 2385, pp. 332 - 336 (Springer-Verlag, scripts that implement a set of computer algebra features. The 2002). Yacas script library is in active development and at the present stage does not offer the rich functionality of industrial-strength by Ayal Zwi Pinkus and Serge Winitzki systems such as Mathematica or Maple. Extensive implementa- tion of algorithms of symbolic computation is one of the future development goals. Abstract Yacas handles input and output in plain ASCII, either inter- actively or in batch mode. (A graphical interface is under devel- We describe the design and implementation of Yacas, a opment.) There is also an optional plugin mechanism whereby free computer algebra system currently under development. external libraries can be linked into the system to provide ex- The system consists of a core interpreter and a library of tra functionality. Basic facilities are in place to compile Yacas scripts that implement symbolic algebra functionality. The scripts to C++ so they can be compiled into plugins. interpreter provides a high-level weakly typed functional language designed for quick prototyping of computer alge- bra algorithms, but the language is suitable for all kinds 1.2 Basic design of symbolic manipulation. It supports conditional term Yacas consists of a \core engine" (kernel), which is an inter- rewriting of symbolic expression trees, closures (pure func- preter for the Yacas scripting language, and a library of script tions) and delayed evaluation, dynamic creation of trans- code. formation rules, arbitrary-precision numerical calculations, The Yacas engine has been implemented in a subset of C++ and flexible user-defined syntax using infix notation. The which is supported by almost all C++ compilers. The design library of scripts currently provides basic numerical and goals for Yacas core engine are: portability, self-containment symbolic algebra functionality, such as polynomials and el- (no dependence on extra libraries or packages), ease of imple- ementary functions, limits, derivatives and (limited) inte- menting algorithms, code transparency, and flexibility. The Ya- gration, solution of (simple) equations. The main advan- cas system as a whole falls into the \prototype/hacker" rather tages of Yacas are: free (GPL) software; a flexible and than into the \axiom/algebraic" category, according to the ter- easy-to-use programming language with a comfortable and minology of Fateman F90. There are relatively few specific de- adjustable syntax; cross-platform portability and small re- sign decisions related to mathematics, but instead the emphasis is made on extensibility. source requirements; and extensibility. The kernel offers sufficiently rich but basic functionality through a limited number of core functions. This core function- ality includes substitutions and rewriting of symbolic expression 1.1 Introduction trees, an infix syntax parser, and arbitrary precision numerics. The kernel does not contain any definitions of symbolic mathe- is a computer algebra system (CAS) which has been Yacas matical operations and tries to be as general and free as possible in development since the beginning of 1999. The goal was of predefined notions or policies in the domain of symbolic com- to make a small system that allows to easily prototype and putation. research symbolic mathematics algorithms. A secondary The plugin inter-operability mechanism allows extension of future goal is to evolve Yacas into a full-blown general the Yacas kernel and the use of external libraries, e.g. GUI purpose CAS. toolkits or implementations of special-purpose algorithms. A Yacas is primarily intended to be a research tool for simple C++ API is provided for writing \stubs" that make ex- easy exploration and prototyping of algorithms of symbolic ternal functions appear in Yacas as new core functions. Plugins computation. The main advantage of Yacas is its rich are on the same footing as the Yacas kernel and can in prin- and flexible scripting language. The language is closely ciple manipulate all Yacas internal structures. Plugins can be related to LISP WH89 but has a recursive descent infix grammar compiled either statically or dynamically as shared libraries to parser ASU86 which supports defining infix operators at run time be loaded at runtime from Yacas scripts. In addition, Yacas 2 scripts can be compiled to C++ code for further compilation Once such infix operators are defined, it is possible to describe into a plugin. Systems that don't support plugins can then link new transformation rules directly using the new syntax. This these modules in statically. The system can also be run with- makes it easy to develop simplification or evaluation procedures out the plugins, for debugging and development purposes. The adapted to a particular problem. scripts will be interpreted in that case. Suppose the user needs to reorder expressions containing non- The script library contains declarations of transformation commutative creation and annihilation operators of quantum rules and of function syntax (prefix, infix etc.). The intention is field theory. It takes about 20 lines of Yacas script code to that all symbolic manipulation algorithms, definitions of math- define an infix operation \**" to express non-commutative mul- ematical functions etc. should be held in the script library and tiplication with the appropriate commutation relations and to not in the kernel. The only exception so far is for a very small automatically normal-order all expressions involving these sym- number of mathematical or utility functions that are frequently bols and other (commutative) factors. Once the operator ** is used; they are compiled into the core for speed. defined (with precedence 40), Infix("**", 40); Portability the rules that express distributivity of the operation ** with Yacas is designed to be as platform-independent as possible. respect to addition may look like this: All platform-specific parts have been clearly separated to facil- 15 # (_x + _y) ** _z <-- x ** z + y ** z; itate porting. Even the standard C++ library is considered to 15 # _z ** (_x + _y) <-- z ** x + z ** y; be platform-specific, as there exist platforms without support for the standard C++ library (e.g. the EPOC32 platform). Here, 15 # is a specification of the rule precedence, x denotes The primary development platform is GNU/Linux. Cur- a pattern-matching variable x and the expression to the right rently Yacas runs under various Unix variants, Windows envi- of <-- is to be substituted instead of a matched expression on ronments, Psion organizers (EPOC32), Ipaq PDAs, BeOS, and the left hand side. Since all transformation rules are applied Apple iMacs. Creating an executable for another platform (in- recursively, these two lines of code are enough for the Yacas cluding embedded platforms) should not be difficult. engine to expand all brackets in any expression containing the infix operators ** and +. Rule-based programming is not the only method that can be A self-contained system used in Yacas scripts; there are alternatives that may be more useful in some situations. For example, the familiar if / else Yacas should work as a standalone package, requiring mini- constructs, For, ForEach loops are defined in the script library mum support from other operating system components. Yacas for the convenience of users.