Improving Performance of Computer Algebra Systems

Computer Algebra Systems have been extensively used in higher education. The reasons are many e.g., visualize mathematical problems, correlate real-world problems on a conceptual level, are flexible, simple to use, accessible from anywhere, etc. However, there is still room for improvement. Computer algebra system (CAS) optimization is the set of best practices and techniques to keep the CAS running optimally. Best practices are related to how to carry out a mathematical task or configure your system. In this paper, we are going to examine these techniques. The documentation sheets of CASs are the source of data that we used to compare them and examine their characteristics. The research results reveal that there are many tips that we can follow to accelerate performance.


Introduction
The field of Mathematics is found in many disciplines such as Biology, Physics, Economics, Chemistry and many more.Computer technology has completely affected many scientific fields, facilitating people's daily lives.In this light, the field of Mathematics could not remain unaffected by the rise of technology.In recent decades, a variety of mathematical software have been created, which improve the learning experience of the understanding and familiarity of the interested users.
It is difficult to compare CASs.There are few studies in the literature that dare to compare them.This happens because each one specializes in a field of Ma-thematics and has a different philosophical approach.So, it would be a mistake to say which of them is the best or what is wrong or right.Therefore, the aim of the paper could not be to find the best CAS but to present techniques to improve the existing ones.
Different devices, platforms, and web browsers may have distinctive necessities, limitations, and features that affect how CAS runs.Huge scale numerical calculations can put overwhelming requests of computer memory and processing power.Some CASs analysts believe that do not have to optimize CASs performance because computer hardware is progressing so quickly.On the other hand, software engineers and researchers are ordinarily less tolerant of poorly designed software.In technical markets, the general philosophy is the gains of performance to rise continuously.In this paper, we will not criticize these opinions which are all partly correct, but we are going to combine them and present some tips and techniques to improve the performance of CASs.
The rest of the paper is organized as follows: Section 2 provides a general overview of Computer Algebra Systems.In Section 3, we are going to examine some tips for better performance.Next (Section 4), the results are presented and discussed whereas in the final section (Section 5) some conclusions are drawn.

Basic Characteristics of Famous Computer Algebra Systems
Computer Algebra Systems are software packages, which are used in manipulation of mathematical formulas.The primary goal of a Computer Algebra System is to automate tedious and sometimes difficult algebraic manipulation tasks.
There are many publications that show the positive impact of CAS on students [1].Today, they exist over fifty Computer Algebra Systems on the market.The most famous are Mathematica, Maple, MATLAB, Maxima, SageMath, SymPy, GNU Octave, Magma and MathStudio.In this paper, we will focus on MATLAB, Mathematica and Maple.The documentation sheets of these three CASs are the source of data that we used to compare them and examine their characteristics.
So, the basic features of them are the following: Despite the advantages of having a common core, unfortunately there are also some disadvantages, such as quite slow processing speed (compared to pure programming languages), program instability and increased memory requirements.The low speed is mainly seen when the repeated execution of a series of commands (e.g.Loops) is requested and is mainly due to the fact that Mathematica uses an interpreter and not a compiler like classical programming languages (e.g.C, Pascal, Visual basic).

• MATLAB-MathWorks
It is a modern integrated mathematical package used extensively in academia and industry.It is an interactive program for numerical calculations and graphing, but it also provides programming capability, which makes it a useful tool for all sciences.Unlike the Maple and Mathematica software, MATLAB in its initial versions did not perform symbolic calculations.In its newer versions, the package includes toolkits that allow symbolic computations.
As its name suggests, MATLAB is specially designed for matrix calculations, such as solving linear systems, finding eigenvalues and eigenvectors, inverting a quadratic matrix, etc.In addition, this mathematical package is equipped with many options for graphics and programs written in its own programming language to solve other problems such as finding the roots of a non-linear equation, solving non-linear systems, solving initial value problems with ordinary differential equations, etc.Finally, there are tools for creating custom graphical user interfaces and interactive tools for iterative exploration, design, and problem-solving [4].
According to Shacham and Cutlip (1998), the comparison of mathematical software packages ensures the selection of a system, which will fully meet the needs of each user.However, in order to achieve the comparison, these software packages should be investigated with a comparative eye based on specific objective criteria [5].These criteria are summarized as follows: • Numerical performance

Tips for Better CAS Performance
Computational optimization means that a system, whether software or hardware, runs as fast and stable as possible.Computer Algebra System optimization is the set of best practices and techniques to keep the CAS running optimally.This section provides some tips to help you handle CAS in a way that accelerate performance.Most of this material is general and applies to all CASs, but there are tips which apply only to specific CASs.So, if you want to have better performance follow these points: • Pre-allocate when appropriate.Pre-allocation ensures that matrix elements will be stored in contiguous locations in memory and therefore incurs the cost of memory allocation just once [5].• Place independent operations outside loops, use vector operations instead of loops.Some CASs use processor-optimized libraries for matrix and vector computations and therefore you can accelerate performance by vectorizing code [7].When you can't vectorize something and need to use a loop don't forget to pre-allocate.Most uses of loops can be replaced by calls to faster (built-in) procedures that perform an iteration [8].
• Make the mathematical operations simpler.For example, the partial correlation coefficient can be computed via regression models, or via the simple correlation matrix.The second one is much faster [9].
• Use profiling to measure memory and time complexity of your program and analyze the frequency/duration of function calls.With a profiler, you can easily determine which functions use a significant amount of time or which of them are called most [10].
• Avoid overloading built-ins functions.In some CASs there is a warning that informs you about the existence of a built-in function.
• Sometimes using a functional style (that avoids difficult to optimize side-effects) instead of an imperative style gives higher efficiency.
• Create new variables if data type changes.Avoid code that generates variables, it's better to load them from files, you should avoid using "data as code".Missing arguments, bracket matching, excess arguments.
• Avoid global variables.Choose local functions over nested functions.
• Use functions instead of scripts.• Use sparse arrays when appropriate and numeric arrays when possible.
• You can speed-up applications performing parallel computing.An increasing amount of CAS operations will automatically parallelize over local cores.
• Some CASs, like MATLAB, is designed to solve problems numerically, not symbolically.Therefore, it's better for a symbolic computation to select the appropriate tool, for example Mathematica, which is faster in symbolic computations.Keep in mind that compiled languages are less prone to runtime failures than interpreted languages due to type system adherence [12].
• In matrices, it is faster to scan down columns than over rows.Column-major order implies that elements along a column are sequential in RAM while elements along a row are separated.Scanning down columns promotes cache effectiveness [13].
• Use the advanced IDEs of CASs because they offer you the capability to easily edit and navigate code in an integrated workgroup environment with a specialized editor (code folding, bracket highlighting, syntax coloring, error reporting, command completion etc.) [14].
• Listen code analyzer suggestions.
• Avoid unnecessary I/O.This means avoiding unnecessary reads and writes of files or data.
• Organize and avoid losing data.Use a unique folder for every project to keep all related files together.Use comments (especially header comments).
Avoid using dangerous commands like clear all (MATLAB) in a script.Beware of CAS crash.By applying some of the previous techniques the measurements show a spectacular improvement in performance.For example, according to Mathworks [16] preallocation and vectorization can speed up code by several orders of magnitude.In Maple, the new algorithms preallocate memory and run in place, which makes them faster (approximately twice comparing to previous edition) when multiple extensions are present [17].The use of Mathematica built-in functions can make the code run sometimes4 times faster [18] and the use of efficient built-in data structures (such as packed arrays or sparse arrays that can be used in many more situations than it may appear from their stated main purpose) gives us better execution time.All these are some examples, there are many other experiments that show us in detail how efficient is to follow the tips that are presented above.

Results
Computer Algebra Systems (CAS) have become increasingly popular for students and teachers.The reasons are numerous e.g., are more flexible, simple to use, accessible from anywhere etc.However, as with any instructive software, they too have a few impediments that we ought to know and optimize them.
Computer algebra system optimization is the set of best practices and techniques to keep the CAS running optimally.Different devices, platforms, and web browsers may have distinctive necessities, limitations, and features that affect how CAS runs.It's very difficult to optimize CAS performance in the same level for every environment.There are many factors such as the processing power, memory and the operating system that significantly determine the performance.
Most of the techniques referred in this paper are general and applies to all CASs, but there are tips which apply only to specific CASs.The basic of them are summarized in the following lines: • It's a very good practice to run profiler on your code and improve performance by changing lines of code or functions that use a significant amount of time.This advice is maybe the most important of all.
• Listen code analyzer suggestions.
• Make sure that your problem and the goals are clear in order to select the appropriate mathematical tool.
• Automate as much as you can.
• Make the mathematical operations simpler.Place independent operations outside loops and use vector operations instead of loops.
• Use modular programming (separate program functions into independent pieces).
• Organize and use the advanced IDEs (Integrated Development Environments) of CASs.
• Use the appropriate built-in function and method to solve a problem.Avoid overloading built-ins functions.Don't spend time to write functions that al- MATLAB is more focused on numerical computing, while Wolfram Mathematica is more focused on symbolic computation.Both are powerful tools, but they are designed for different types of tasks.Maple is best for users who want a good tool basically for Mathematics and Engineering.Maple isn't supported as widely as other mathematical software (e.g.MATLAB and Mathematica).In the following Table1, we can see some of the basic characteristics of Maple, Mathematica and MATLAB.From this table we can understand why these three CASs are on the top and how difficult is to pick out only one.Τhere are many other features (not so important) that for reasons of brevity and space are not listed in the following Table1.
thematica is only about three times slower than C++ (after a considerable rewriting of the code).Julia has the best performance (approximately 2.70 times slower than the best C++ executable)[6].

Table 1 .
Basic characteristics of Maple, Mathematica and MATLAB.
because this increases the work of the garbage collector and therefore the time to complete the work.• Use modular programming.Separate program functions into independent pieces.• Use short-circuits operators (for example & and ||), it's more efficient [11].
• Write clean code, do not create garbage (allocated storage that's not re-DOI: 10.4236/jsea.2023.1610026526 Journal of Software Engineering and Applications quired)

•
Automate as much as you can.Use the appropriate tools, don't spend time to write functions that already exist in your CAS.You don't need to reinvent the wheel.Test early and test often with automation.According to a 2020-21 World Quality Report, automation testing tools can save time and minimize human errors [15].• If your computer doesn't meet the basic requirements (in RAM, processing power etc.) of desktop CAS version use online version.With these online platforms you can make mathematical computations even when your computer doesn't meet the required standards of desktop version.With a simple PC you can perform any mathematical computation directly in your browser and collaborate with other CAS users by giving them the appropriate privileges (read, write, and run) that you want and share files directly.You can store files in your CAS Cloud Drive and synchronize your important math files with the Cloud Drive.Moreover, you could access the latest version of CAS without any downloads, installation, or maintenance and with all the latest features available.