ebook img

Essays on Yacas PDF

51 Pages·0.593 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Essays on Yacas

Essays on Yacas by the Yacas team 1 Yacas version: 1.3.1 generated on November 23, 2011 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 GNUFreeDocumentationLicense,Version1.1oranylaterversionpublishedbytheFreeSoftwareFoundation;withnoInvariant 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 4 Why −x−1 and −1 are not the same in Yacas 16 x 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 Amuchshorterandmorepolishedversionofthispaperis similarlytoPrologB86,andincludesexpressiontransformation publishedas: AyalZ.PinkusandSergeWinitzki,“YACAS: (term rewriting) as a basic feature of the language. ado-it-yourselfcomputeralgebrasystem”,LectureNotesin 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). Yacasscriptlibraryisinactivedevelopmentandatthepresent stagedoesnotoffertherichfunctionalityofindustrial-strength systems such as Mathematica or Maple. Extensive implementa- by Ayal Zwi Pinkus and Serge Winitzki tion of algorithms of symbolic computation is one of the future development goals. Abstract YacashandlesinputandoutputinplainASCII,eitherinter- activelyorinbatchmode. (Agraphicalinterfaceisunderdevel- We describe the design and implementation of Yacas, a opment.) There is also an optional plugin mechanism whereby freecomputeralgebrasystemcurrentlyunderdevelopment. 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 scriptsthatimplementsymbolicalgebrafunctionality. 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- 1.2 Basic design bra algorithms, but the language is suitable for all kinds 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. formationrules,arbitrary-precisionnumericalcalculations, TheYacasenginehasbeenimplementedinasubsetofC++ 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 symbolicalgebrafunctionality, suchaspolynomialsandel- (no dependence on extra libraries or packages), ease of imple- ementary functions, limits, derivatives and (limited) inte- mentingalgorithms,codetransparency,andflexibility. TheYa- 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 thanintothe“axiom/algebraic”category,accordingtotheter- easy-to-use programming language with a comfortable and minology of Fateman F90. There are relatively few specific de- signdecisionsrelatedtomathematics,butinsteadtheemphasis adjustable syntax; cross-platform portability and small re- is made on extensibility. source requirements; and extensibility. The kernel offers sufficiently rich but basic functionality throughalimitednumberofcorefunctions. Thiscorefunction- 1.1 Introduction alityincludessubstitutionsandrewritingofsymbolicexpression trees, an infix syntax parser, and arbitrary precision numerics. The kernel does not contain any definitions of symbolic mathe- Yacasisacomputeralgebrasystem(CAS)whichhasbeen maticaloperationsandtriestobeasgeneralandfreeaspossible in development since the beginning of 1999. The goal was ofpredefinednotionsorpoliciesinthedomainofsymboliccom- tomakeasmallsystemthatallowstoeasilyprototypeand 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- easyexplorationandprototypingofalgorithmsofsymbolic ternalfunctionsappearinYacasasnewcorefunctions. 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 relatedtoLISPWH89buthasarecursivedescentinfixgrammar compiled either statically or dynamically as shared libraries to parserASU86whichsupportsdefininginfixoperatorsatruntime be loaded at runtime from Yacas scripts. In addition, Yacas 2 scripts can be compiled to C++ code for further compilation Oncesuchinfixoperatorsaredefined,itispossibletodescribe intoaplugin. Systemsthatdon’tsupportpluginscanthenlink new transformation rules directly using the new syntax. This these modules in statically. The system can also be run with- makesiteasytodevelopsimplificationorevaluationprocedures out the plugins, for debugging and development purposes. The adapted to a particular problem. scripts will be interpreted in that case. Supposetheuserneedstoreorderexpressionscontainingnon- The script library contains declarations of transformation commutative creation and annihilation operators of quantum rulesandoffunctionsyntax(prefix,infixetc.). Theintentionis field theory. It takes about 20 lines of Yacas script code to that all symbolic manipulation algorithms, definitions of math- defineaninfixoperation“**”toexpressnon-commutativemul- 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 automaticallynormal-orderallexpressionsinvolvingthesesym- numberofmathematicalorutilityfunctionsthatarefrequently 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 the left hand side. Since all transformation rules are applied ronments, Psion organizers (EPOC32), Ipaq PDAs, BeOS, and recursively, these two lines of code are enough for the Yacas Apple iMacs. Creating an executable for another platform (in- engine to expand all brackets in any expression containing the cluding embedded platforms) should not be difficult. infix operators ** and +. Rule-basedprogrammingisnottheonlymethodthatcanbe 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 mumsupportfromotheroperatingsystemcomponents. Yacas for the convenience of users. takesinputandoutputinplainASCII,eitherinteractivelyorin Standard patterns of procedural programming, such as sub- batch mode. (An optional graphical interface is under develop- routines that return values, with code blocks and temporary ment.) Thesystemcomeswithitsown(unoptimized)arbitrary local variables, are also available. (A “subroutine” is imple- precision arithmetic module but could be compiled to use an- mented as a new “ground term” with a single rule defined for otherarbitraryprecisionarithmeticlibrary;currentlylinkingto it.) Users may freely combine rules with C-like procedures or gmp is experimentally supported. There is also an optional plu- LISP-like list processing primitives such as Head(), Tail(). ginmechanismwherebyexternallibrariescanbelinkedintothe system to provide extra functionality. Self-containmentisarequirementiftheprogramistobeeasy Code clarity vs. speed to port. A dependency on libraries that might not be available onotherplatformswouldreduceportability. Ontheotherhand, Speed is obviously an important factor. For Yacas, where a Yacascanbecompiledwithacomplementofexternallibraries choice had to be made between speed and clarity of code, clar- on “production” platforms. ity was chosen. Yacas is mainly a prototyping system and its future maintainability is more important. Thismeansthatspecial-purposesystemsdesignedforspecific Ease of use types of calculations, as well as heavily optimized industrial- strength computer algebra systems, will outperform Yacas. Yacas is used mainly by executing programs written in the However,special-purposeoroptimizedexternallibrariescanbe Yacas script language. A design goal is to create a high-level dynamically linked into Yacas using the plugin mechanism. language that allows the user to conveniently express symbolic algorithms. A few lines of user code should go a long way. Onemajoradvantageof Yacasistheflexibilityofitssyntax. Flexible, “policy-free” engine Although Yacas works internally as a LISP-style interpreter, alluserinteractionisthroughtheYacasscriptlanguagewhich ThecoreengineoftheYacassysteminterpretstheYacasscript has a flexible infix grammar. Infix operators are defined by the language. ThereasontoimplementyetanotherLISP-basedcus- user and may contain non-alphabetic characters such as “=” or tom language interpreter instead of taking an already existing “#”. This means that the user interacts with Yacas using a one was to have full control over the design of the system and comfortable and adjustable infix syntax, rather than a LISP- to make it self-contained. While most of the features of the stylesyntax. Theusercanintroducesuchsyntacticconventions Yacas script language are “syntactic sugar” on top of a LISP as are most convenient for a given problem. interpreter,somefeaturesnotcommonlyfoundinLISPsystems Forexample,theYacasscriptlibrarydefinesinfixoperators were added. “+”, ”*” and so on with conventional precedence, so that an The script library contains declarations of transformation algebraic expression can be entered in the familiar infix form rulesandoffunctionsyntax(prefix,infixetc.). Theintentionis such as that all symbolic manipulation algorithms, definitions of math- ematicalfunctionsandsoonshouldbeheldinthescriptlibrary (x+1)^2 - (y-2*z)/(y+3) + Sin(x*Pi/2) and not in the kernel. The only exception so far is for a very 3 small number of mathematical or utility functions that are fre- term,theargumentsareevaluatedfirstandthenthefunctionis quently used; they are compiled into the core for speed. applied to these values. Forexample,themathematicaloperator“+”isaninfixoper- AHoldArg()primitiveisprovidedtonotevaluatecertainar- ator defined in the library scripts. To the kernel, this operator guments of certain functions before passing them on as param- isonthesamefootingasanyotherfunctiondefinedbytheuser eters to these functions. The Hold() and Eval() primitives, and can be redefined. The Yacas kernel itself does not store similarly to LISP’s QUOTE and EVAL, can be used to stop the anypropertiesforthisoperator. Insteaditreliesentirelyonthe recursive application of rules at a certain point and obtain an script library to provide transformation rules for manipulating unevaluated expression, or to initiate evaluation of an expres- expressions involving the operator “+”. In this way, the kernel sion which was previously held unevaluated. doesnotneedtoanticipateallpossiblemeaningsoftheoperator Whenanexpressioncannotbetransformedanyfurther,that “+” that users might need in their calculations. is, when no more rules apply to it, the expression is returned This policy-free scheme means that Yacas is highly config- unevaluated. For instance, a variable that is not assigned a urable through its scripting language. It is possible to create value will return unevaluated. This is a desired behavior in a anentirelydifferentsymbolicmanipulationenginebasedonthe symbolic manipulation system. Evaluation is treated as a form same C++ kernel, with different syntax and different naming of “simplification”, in that evaluating an expression returns a conventions, by simply using another script library instead of simplified form of the input expression. the current library scripts. An example of the flexibility of the Rulesarematchedbyapatternexpressionwhichcancontain Yacas system is a sample script wordproblems.ys that comes patternvariables,i.e. atomsmarkedbythe“ ”operator. During with the distribution. It contains a set of rule definitions that matching, each pattern variable atom becomes a local variable make Yacas recognize simple English sentences, such as “Tom and is tentatively assigned the subexpression being matched. has 3 apples” or “Jane gave an apple to Tom”, as valid Yacas Forexample,thepattern x + ycanmatchanexpressiona*x+b expressions. Yacascanthen“evaluate”thesesentencestoTrue and then the pattern variable x will be assigned the value a*x orFalseaccordingtothesemanticsofthecurrentsituationde- (unevaluated) and the variable y will have the value b. scribed in them. This type of semantic matching has been frequently imple- The “policy-free” concept extends to typing: strong typing mented before in various term rewriting systems (see, e.g., is not required by the kernel, but can be easily enforced by the [C86]). However, the Yacas language offers its users an ability scripts if needed for a particular problem. The language offers tocreateamuchmoreflexibleandpowerfultermrewritingsys- features, but does not enforce their use. Here is an example of temthanonebasedonafixedsetofrules. Herearesomeofthe a policy implemented in the script library: features: 61 # x_IsPositiveNumber ^ y_IsPositiveNumber First,transformationrulesinYacashavepredicatesthatcon- <-- MathPower(x,y); trol whether a rule should be applied to an expression. Predi- catescanbeany Yacasexpressionsthatevaluatetotheatoms By this rule, expressions of the form x^y (representing powers True or False and are typically functions of pattern variables. xy)areevaluatedandreplacedbyanumberifandonlyif xand A predicate could check the types or values of certain subex- y are positive numerical constants. (The function MathPower is pressions of the matching context (see the x ^ y example in defined in the kernel.) If this simplification by default is not the previous subsection). desirable, the user could erase this rule from the library and Second,rulesareassignedaprecedencevalue(apositiveinte- have a CAS without this feature. ger)thatcontrolstheorderofrulestobeattempted. ThusYa- casprovidessomewhatbettercontrolovertheautomaticrecur- 1.3 The Yacas kernel functionality sion than the pattern-matching system of Mathematica which doesnotallowforruleprecedence. Theinterpreterwillfirstap- Yacas script is a functional language based on various ideas ply the rule that matches the argument pattern, for which the that seemed useful for an implementation of CAS: list-based predicate returns True, and which has the least precedence. datastructures,objectproperties,andfunctionalprogramming Third, new rules can be defined dynamically as a side-effect (alaLISP);termrewriting[BN98]withpatternmatchingsome- of evaluation. This means that there is no predefined “ranking what along the lines of Mathematica; user-defined infix oper- alphabet”of“groundterms”(intheterminologyof[TATA99]), ators a la PROLOG; delayed evaluation of expressions; and inotherwords,nofixedsetoffunctionswithpredefinedarities. arbitrary-precision arithmetic. Garbage collection is imple- It is also possible to define a “rule closure” that defines rules mented through reference counting. depending on its arguments, or to erase rules. Thus, a Ya- Thekernelprovidesthreebasicdatatypes: numbers,strings, cas script library (although it is read-only) does not represent and atoms, and two container types: list and static array (for a fixed tree rewriting automaton. An implementation of ma- speed). Atomsareimplementedasstringsthatcanbeassigned chine learning is possible in Yacas (among other things). For values and evaluated. Boolean values are simply atoms True example,whenthemodulewordproblems.ys(mentionedinthe andFalse. Numbersarerepresentedbyobjectsonwhicharith- previous subsection) ”learns” from the user input that apple metic can be performed immediately. Expression trees, associ- is a countable object, it defines a new postfix operator apples ation(hash)tables,stacks,andclosures(purefunctions)areall andaruleforitsevaluation,sotheexpression3 applesislater implemented using nested lists. In addition, more data types parsed as a function apples(3) and evaluated according to the can be provided by plugins. Kernel primitives are available for rule. arbitrary-precision arithmetic, string manipulation, array and Fourth, Yacas expressions can be “tagged” (assigned a list access and manipulation, for basic control flow, for assign- “property object” a la LISP) and tags can be checked by pred- ingvariables(atoms)andfordefiningrulesforfunctions(atoms icates in rules or used in the evaluation. with a function syntax). Fifth, the scope of variables can be controlled. In addition The interpreter engine recursively evaluates expression trees to having its own local variables, a function can be allowed to accordingtouser-definedtransformationrulesfromthescriptli- access local variables of its calling environment (the UnFence() brary. Evaluationproceedsbottom-up,thatis,foreachfunction primitive). Itisalsopossibletoencapsulateagroupofvariables 4 and functions into a “module”, making some of them inacces- Here the rules have precedence 10 and 20, so that the first rule sible from the outside (the LocalSymbols() primitive). The will be tried first and the recursion will stop when n = 0 is scoping of variables is a “policy decision”, to be enforced by reached. the script which defines the function. This flexibility is by de- Rule-based programming can be freely combined with pro- signandallowstoeasilymodifythebehavioroftheinterpreter, cedural programming when the latter is a more appropri- effectively changing the language as needed. ate method. For example, here is a function that computes (xn modm) efficiently: 1.4 The Yacas scripting language powermod(x_IsPositiveInteger, n_IsPositiveInteger, The Yacas interpreter is sufficiently powerful so that the func- m_IsPositiveInteger) <-- tions For, ForEach, if, else etc., as well as the convenient [ shorthand “...<--...” for defining new rules, can be defined in Local(result); the script library itself rather than in the kernel. This power result:=1; is fully given to the user, since the library scripts are on the x:=Mod(x,m); same footing as any user-defined code. Some library functions While(n != 0) areintendedmainlyastoolsavailabletoaYacasusertomake [ algorithm implementation more comfortable. Below are some if ((n&1) = 1) examplesofthefeaturesprovidedbytheYacasscriptlanguage. [ Yacas supports “function overloading”: it allows a user to result := Mod(result*x,m); declarefunctionsf(x)andf(x,y),eachhavingtheirownsetof ]; transformation rules. Of course, different rules can be defined x := Mod(x*x,m); forthesamefunctionnamewiththesamenumberofarguments n := n>>1; (arity) but with different argument patterns or different predi- ]; cates. result; Simple transformations on expressions can be performed us- ]; ing rules. For instance, if we need to expand the natural loga- Interaction with the function powermod(x,n,m) would then rithm in an expression, we could use the following rules: look like this: log(_x * _y) <-- log(x) + log(y); In> powermod(2,10,100) log(_x ^ _n) <-- n * log(x); Out> 24; These two rules define a new symbolic function log which will In> Mod(2^10,100) not be evaluated but only transformed if one of these two rules Out> 24; are applicable. The symbol , as before, indicates that the fol- In> powermod(23234234,2342424234,232423424) lowing atom is a pattern variable that matches subexpressions. Out> 210599936; After entering these two rules, the following interactive ses- sion is possible: 1.5 Currently supported CAS fea- In> log(a*x^2) tures log( a ) + 2 * log( x ) Yacas consists of approximately 22000 lines of C++ code and Integrationofthenewfunctionlogcanbedefinedbyadding 13000 lines of scripting code, with 170 functions defined in the a rule for the AntiDeriv function atom, C++kerneland600functionsdefinedinthescriptinglanguage. These numbers are deceptively small. The program is written AntiDeriv(_x,log(_x)) <-- x*log(x)-x; in clean and simple style to keep it maintainable. Excessive NowYacascandointegrationsinvolvingthenewlydefinedlog optimization tends to bloat software and make it less readable. function, for example: A base of mathematical capabilities has already been imple- mented in the script library (the primary sources of inspiration In> Integrate(x)log(a*x^n) were the books [K98], [GG99] and [B86]). The script library is currently under active development. The following section log( a ) * x + n * ( x * log( x ) - x ) + C18 demonstrates a few facilities already offered in the current sys- tem. In> Integrate(x,B,C)log(a*x^n) Basic operations of elementary calculus have been imple- mented: log( a ) * C + n * ( C * log( C ) - C ) - In> Limit(n,Infinity)(1+(1/n))^n ( log( a ) * B + n * ( B * log( B ) - B ) ) Exp( 1 ) Rules are applied when their associated patterns match and when their predicates return True. Rules also have precedence, In> Limit(h,0) (Sin(x+h)-Sin(x))/h anintegervaluetoindicatewhichrulesneedtobeappliedfirst. Using these features, a recursive implementation of the integer factorial function may look like this in Yacas script, Cos( x ) 10 # Factorial(_n) _ (n=0) <-- 1; In> Taylor(x,0,5)ArcSin(x) 20 # Factorial(n_IsInteger) _ (n>0) <-- n*Factorial(n-1); 3 5 5 x 3 * x In> RadSimp(Sqrt(9+4*Sqrt(2))) x + -- + ------ 6 40 Sqrt( 8 ) + 1 In> InverseTaylor(x,0,5)Sin(x) In> TrigSimpCombine(Sin(x)^2+Cos(x)^2) 5 3 1 3 * x x ------ + -- + x In> TrigSimpCombine(Cos(x/2)^2-Sin(x/2)^2) 40 6 Cos( x ) In> Integrate(x,a,b)Ln(x)+x In> GcdReduce((x^2+2*x+1)/(x^2-1),x) 2 / 2 \ b | a | x + 1 b * Ln( b ) - b + -- - | a * Ln( a ) - a + -- | ----- 2 \ 2 / x - 1 Univariate polynomials are supported in a dense representa- In> Integrate(x)1/(x^2-1) tion, and multivariate polynomials in a sparse representation: Ln( 2 * ( x - 1 ) ) Ln( 2 * ( x + 1 ) ) In> Factor(x^6+9*x^5+21*x^4-5*x^3-54*x^2-12*x+40) ------------------- - ------------------- + C38 2 2 3 2 ( x + 2 ) * ( x - 1 ) * ( x + 5 ) In> Integrate(x)Sin(a*x)^2*Cos(b*x) In> Apart(1/(x^2-x-2)) Sin( b * x ) Sin( -2 * x * a + b * x ) ------------ - ------------------------- - 1 1 2 * b 4 * ( -2 * a + b ) ------------- - ------------- 3 * ( x - 2 ) 3 * ( x + 1 ) Sin( -2 * x * a - b * x ) ------------------------- + C39 In> Together(%) 4 * ( -2 * a - b ) 9 In> OdeSolve(y’’==4*y) ------------------- 2 C193 * Exp( -2 * x ) + C195 * Exp( 2 * x ) 9 * x - 9 * x - 18 Solving systems of equations has been implemented using a generalized Gaussian elimination scheme: In> Simplify(%) In> Solve( {x+y+z==6, 2*x+y+2*z==10, \ 1 In> x+3*y+z==10}, \ ---------- In> {x,y,z} ) [1] 2 Out> {4-z,2,z}; x - x - 2 (The solution of this underdetermined system is returned as a vector, so x=4−z, y=2, and z remains arbitrary.) Various“syntacticsugar”functionsaredefinedtomoreeasily A small theorem prover [B86] using a resolution principle is enter expressions: offered: In> Ln(x*y) /: { Ln(_a*_b) <- Ln(a) + Ln(b) } In> CanProve(P Or (Not P And Not Q)) Ln( x ) + Ln( y ) Not( Q ) Or P In> CanProve(a > 3 And a < 2) In> Add(x^(1 .. 5)) False 2 3 4 5 x + x + x + x + x Various exact and arbitrary-precision numerical algorithms have been implemented: In> Select("IsPrime", 1 .. 15) In> N(1/7,40); // evaluate to 40 digits Out> {2,3,5,7,11,13}; Out> 0.1428571428571428571428571428571428571428; In> Decimal(1/7); // obtain decimal period Out> {0,{1,4,2,8,5,7}}; Groebner bases [GG99] have been implemented: In> N(LnGamma(1.234+2.345*I)); // gamma-function In> Groebner({x*(y-1),y*(x-1)}) Out> Complex(-2.13255691127918,0.70978922847121); Various domain-specific expression simplifiers are available: / \ 6 | x * y - x | prototyping of various methods of symbolic calculations. Ya- | | casismeanttobearepositoryandatestbedforsuchalgorithm | x * y - y | prototypes. | | The plugin facility will be extended in the future, so that a | y - x | rich set of extra additional libraries (especially free software li- | | braries),system-specificaswellasmathematics-oriented,should | 2 | be loadable from the Yacas system. The issue of speed is also | y - y | continuously being addressed. \ / (From this it follows that x=y, and x2 =x so x is 0 or 1.) 1.9 References Symbolic inverses of matrices: [ASU86]A.Aho,R.SethiandJ.Ullman,Compilers(Principles, In> Inverse({{a,b},{c,d}}) Techniques and Tools), Addison-Wesley, 1986. [B86] I. Bratko, Prolog (Programming for Artificial Intelli- / \ gence), Addison-Wesley, 1986. | / d \ / -( b ) \ | [BN98] F. Baader and T. Nipkow, Term rewriting and all | | ------------- | | ------------- | | that, Cambridge University Press, 1998. | \ a * d - b * c / \ a * d - b * c / | [C86]G.Cooperman,Asemanticmatcherforcomputeralge- | | bra,inProceedingsofthesymposiumonsymbolicandalgebraic | / -( c ) \ / a \ | computation (1986), Waterloo, Ontario, Canada (ACM Press, | | ------------- | | ------------- | | NY). | \ a * d - b * c / \ a * d - b * c / | [F90]R.Fateman,Onthedesignandconstructionofalgebraic \ / manipulation systems, also published as: ACM Proceedings of the ISSAC-90, Tokyo, Japan. This list of features is not exhaustive. [GG99]J.vonzurGathenandJ.Gerhard,ModernComputer Algebra, Cambridge University Press, 1999. [K98]D.Knuth,TheArtofComputerProgramming(Volume 1.6 Interface 2, Seminumerical Algorithms), Addison-Wesley, 1998. [TATA99] H. Comon, M. Dauchet, R. Gilleron, F. Jacque- Currently, Yacas is primarily a text-oriented application with mard, D. Lugiez, S. Tison, and M. Tommasi, Tree Au- interactive interface through the text console. Commands are tomata Techniques and Applications, 1999, online book: entered and evaluated line by line; files containing longer code http://www.grappa.univ-lille3.fr/tata maybeloadedandevaluated. A“notebook”interfaceunderthe [W96] S. Wolfram, The Mathematica book, Wolfram Media, GNU Emacs editor is available. There is also an experimental Champain, 1996. graphical interface (proteus) for Unix and Windows environ- [WH89] P. Winston and B. Horn, LISP, Addison-Wesley, ments. 1989. Debugging facilities are implemented, allowing to trace exe- cution of a function, trace application of a given rule pattern, examine the stack when recursion did not terminate, or an on- line debugger from the command line. An experimental debug version of the Yacas executable that provides more detailed information can be compiled. 1.7 Documentation The documentation for the Yacas is extensive and is actively updated,followingthedevelopmentofthesystem. Documenta- tioncurrentlyconsistsoftwotutorialguides(user’sintroduction and programmer’s introduction), a collection of essays that de- scribesomeadvancedfeaturesinmoredetail,andafullreference manual. Yacas currently comes with its own document formatting module that allows maintenance of documentation in a special plain text format with a minimal markup. This text format is automatically converted to HTML, LATEX, PostScript and PDF formats. The HTML version of the documentation is hy- perlinked and is used as online help available from the Yacas prompt. 1.8 Future plans The long-term goal for Yacas is to become an industrial- strength CAS and to remain a flexible research tool for easy 7 Chapter 2 M. Wester’s CAS benchmark and Yacas In his 1994 paper Review of CAS mathematical capabilities, 12. (NO) Hypothesis testing with t-distribution. MichaelWesterhasputforward123problemsthatareasonable 13. (NO) Hypothesis testing with normal distribution (M. computeralgebrasystemshouldbeabletosolveandtestedthe Wester probably meant the χ2 distribution). then current versions of various commercial CAS on this list. Below is the list of Wester’s problems with the correspond- 14. (OK) x2x+24−x4+4 = xx−+22. ing Yacas code. “OK” means a satisfactory solution, “BUG” Verify(GcdReduce((x^2-4)/(x^2+4*x+4),x), meansthatYacasgivesawrongsolutionorbreaksdown,“NO” (x-2)/(x+2)); means that the relevant functionality is not yet implemented. Yacas version: 1.3.1 15. (NO) exp(x)−1 =exp(cid:0)x(cid:1)−1. exp(x)+1 2 2 1. (OK) 50! 16. (OK) Expand (1+x)20, take derivative and factorize. Verify(25!, 15511210043330985984000000); Factor(D(x) Expand((1+x)^20)); Verify(50!, (26***50)*25!); 17. (BUG/NO) Factorize x100−1. 2. (OK) Factorize 50! Factor(x^100-1); Verify(Factors(50!), {{2,47},{3,22},{5,12}, (returns the same expression unfactorized) {7,8},{11,4},{13,3},{17,2},{19,2},{23,2}, {29,1},{31,1},{37,1},{41,1},{43,1},{47,1}}); 18. (NO)Factorizex4−3x2+1inthefieldofrationalnumbers extended by roots of x2−x−1. 3. (OK) 1 +...+ 1 = 4861 2 10 2520 19. (NO) Factorize x4−3x2+1 mod 5. Verify(Sum(n,2,10,1/n) , 4861/2520); 20. (BUG) Partial fraction decomposition of x2+2x+3 . √ x3+4x2+5x+2 4. (OK) Evaluate eπ 163 to 50 decimal digits Apart((x^2+2*x+3)/(x^3+4*x^2+5*x+2), x); Verify(N(1000000000000*(-262537412640768744 + (does not obtain full partial fraction representation for Exp(Pi*Sqrt(163))), 50)> -0.75, True); higher-degree polynomials, e.g. p(x)/(x+a)n) 5. (OK) Evaluate the Bessel function J2 numerically at z = 21. (NO) Assuming x≥y, y≥z, z≥x, deduce x=z. 1+ı. 22. (NO) Assuming x>y, y>0, deduce 2x2 >2y2. NumericEqual(N(BesselJ(2, 1+I)), 23. (NO) Solve the inequality |x−1|>2. 0.4157988694e-1+I*0.2473976415,Builtin’Precision’Get()); 24. (NO) Solve the inequality (x−1)...(x−5)<0. 6. (OK) Obtain period of decimal fraction 1/7=0.(142857). 25. (NO) cos3x =(cosx)2−3(sinx)2orsimilarequivalentcom- cosx Verify(Decimal(1/7), {0,{1,4,2,8,5,7}}); bination. 26. (NO) cos3x =2cos2x−1. 7. Continued fraction of 3.1415926535. cosx 27. (OK) Define rewrite rules to match cos3x = (cosx)2 − Verify([Local(p,r);p:=Builtin’Precision’Get();Builtin’Precision’Set(12);r:=ContFracLiscots(x3.1415926535, 6);Builtin’Precision’Set(p);r;], 3(sinx)2. {3,7,15,1,292,1}); (cid:112) √ √ Cos(3*_x)/Cos(_x) <-- Cos(x)^2-3*Sin(x)^2; 8. (OK) 2 3+4=1+ 3. √ √ 28. (OK) 997− 69973 =0 Verify(RadSimp(Sqrt(2*Sqrt(3)+4)), 1+Sqrt(3)); Verify(RadSimp(Sqrt(997)-(997^3)^(1/6)), 0); (cid:115) (cid:114) (cid:113) (cid:112) √ √ 29. (OK) √99983−√6999833 =0 9. (OK) 14+3 3+2 5−12 3−2 2=3+ 2. Verify(RadSimp(Sqrt(99983)-(99983^3)^(1/6)) Verify(RadSimp(Sqrt(14+3*Sqrt(3+2*Sqrt(5-12 , 0); *Sqrt(3-2*Sqrt(2)))))), 3+Sqrt(2)); 30. (OK) (cid:0)√32+√34(cid:1)2−6(cid:0)√32+√34(cid:1)−6=0 10. (OK) 2∞−3=∞. Verify(RadSimp((2^(1/3)+4^(1/3))^3-6*(2^(1/3)+ Verify(2*Infinity-3, Infinity); 4^(1/3))-6), 0); (cid:0) (cid:1) 11. (NO) Standard deviation of the sample (1, 2, 3, 4, 5). 31. (NO) lntan x + π −arcsinh tanx=0 2 4 8 (cid:0) (cid:1) 32. (NO) Numerically, the expression lntan x + π − Verify(Simplify(Integrate(x) Abs(x)), 2 4 arcsinh tanx=0 and its derivative at x=0 are zero. Abs(x)*x/2); Ln(Tan(x/2+Pi/4))-ArcSinh(Tan(x)); 1. (OK) Compute derivative of |x|, piecewise defined. D(x)(Ln(Tan(x/2+Pi/4))-ArcSinh(Tan(x))); Verify(D(x)if(x<0) (-x) else x, √ 33. (NO) ln√2 r+1 =0. Simplify(if(x<0) -1 else 1)); √ 4r+4 r+1 34. (NO) (cid:0)4r+4√r+1(cid:1)2√√rr+1 (cid:0)2√r+1(cid:1)(2√r+1)−1 − 2√r − 2. (OK) Integrate |x|, piecewise defined. Verify(Simplify(Integrate(x) 1=0, assuming r>0. if(x<0) (-x) else x), 35. (OK) Obtain real and imaginary parts of ln(3+4ı). Simplify(if(x<0) (-x^2/2) else x^2/2)); Verify( 3. (OK) Taylor series of (cid:112)1 at v=0. Hold({ {x}, {Re(x), Im(x)}}) @ Ln(3+4*I) 1−vc22 , {Ln(5),ArcTan(4/3)}); S := Taylor(v,0,4) 1/Sqrt(1-v^2/c^2); TestYacas(S, 1+v^2/(2*c^2)+3/8*v^4/c^4); 36. (BUG) Obtain real and imaginary parts of tan(x+ıy). Note: The result of Taylor is not in convenient form but Hold({ {x}, {Re(x), Im(x)}}) @ Tan(x+I*y); is equivalent. 37. (BUG) Simplify lnexp(z) to z for −π<Im(z)≤π. 4. (OK)ComputetheTaylorexpansionoftheinversesquare of the above. Verify(Simplify(Ln(Exp(z))), z); TestYacas(Taylor(v,0,4) 1/S^2, 1-v^2/c^2); (no conditions on z are used) √ √ 38. (NO) Assuming Re(x) > 0, Re(y) > 0, deduce nxny− Note: The result of Taylor is not in convenient form but √ nxy=0. is equivalent. 39. (NO) Transform equations, x=2 +(1=1)⇒ x +1=2. 5. (OK) (Taylor expansion of sinx)/(Taylor expansion of 2 2 cosx) = (Taylor expansion of tanx). 40. (BUG) Solve exp(x)=1 and get all solutions. TestYacas(Taylor(x,0,5)(Taylor(x,0,5)Sin(x))/ Verify(Solve(Exp(x)==1,x), {x==0}); (Taylor(x,0,5)Cos(x)), Taylor(x,0,5)Tan(x)); (get only one solution) 6. (BUG) Taylor expansion of (lnx)aexp(−bx) at x=1. 41. (BUG) Solve tanx=1 and get all solutions. //Taylor(x,1,3)(Ln(x))^a*Exp(-b*x); Verify(Solve(Tan(x)==1,x), {x==Pi/4}); (bugs in Deriv manipulation) (get only one solution) 7. (BUG) Taylor expansion of lnsinx at x=0. x 42. (OK) Solve a degenerate 3x3 linear system. //Taylor(x,0,5) Ln(Sin(x)/x); Verify(Simplify({x+y+z==6,2*x+y+2*z==10,x+3*y+z==10}(nWehveerrestoSpols)ve({x+y+z==6, 2*x+y+2*z==10,x+3*y+z==10}, {x,y,z})), {{0==0,0==0,0==0}}); (the new routine Solve cannot do this yet) 8. (NO) Compute n-th term of the Taylor series of lnsinxx at x=0. 43. (OK) Invert a 2x2 symbolic matrix. 9. (NO) Compute n-th term of the Taylor series of Verify(Simplify(Inverse({{a,b},{1,a*b}})), exp(−x)sinx at x=0. {{a/(a^2-1), -1/(a^2-1)}, 10. (OK) Solve x=siny+cosy for y as Taylor series in x at {-1/(b*(a^2-1)), a/(b*(a^2-1))}}); x=1. 44. (BUG)Computethedeterminantofthe4x4Vandermonde TestYacas(InverseTaylor(y,0,4) Sin(y)+Cos(y), matrix. (y-1)+(y-1)^2/2+2*(y-1)^3/3+(y-1)^4); Factor(Determinant(VandermondeMatrix NotethatInverseTaylordoesnotgivetheseriesinterms ({a,b,c,d}))); of x but in terms of y which is semantically wrong. But (this does not factor correctly) other CAS do the same. 11. (OK) Compute Legendre polynomials directly from Ro- 45. (OK) Find eigenvalues of a 3x3 integer matrix. drigues’s formula, P = 1 (cid:0) ∂n (cid:0)x2−1(cid:1)n(cid:1). n (2n)!! ∂xn Verify(EigenValues({{5,-3,-7},{-2,1,2}, P(n,x) := Simplify( 1/(2*n)!! * {2,-3,-4}}) , {1,3,-2}); Deriv(x,n) (x^2-1)^n ); 46. (OK) Verify some standard limits found by L’Hopital’s TestYacas(P(4,x), (35*x^4)/8+(-15*x^2)/4+3/8); rule: 12. (OK) Compute Legendre polynomials P recursively. n Verify(Limit(x,Infinity) (1+1/x)^x, Exp(1)); Verify(OrthoP(4,x) Verify(Limit(x,0) (1-Cos(x))/x^2, 1/2); , 3/8+((35*x^2)/8-15/4)*x^2); 47. (OK) Sign(x) 13. (OK) Compute Legendre polynomial P at x=1. 4 Verify(D(x) Abs(x), Sign(x)); Verify(OrthoP(4,1), 1); (cid:82) 48. (OK) |x|dx=|x|x2 14. (OK) Define the polynomial p=(cid:80)5i=1aixi. 9

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.