up

Simplification test. Comparison between Maple and Mathemtica

Updated March 12, 2007 by Nasser M. Abbasi

Change History

# Change History

March 12, 2007: Added more tests using Maple simplify() command with option called size. I learned about this new option for simplify, which is designed to reduce the size of the expression, from Maple help:

The simplify(expr, size) calling sequence is used to attempt simplifying the expression size, performing only collections and simple decomposition of fractional powers in the coefficients - sometimes taking advantage of linear factors when they exist. No other mathematical simplifications of the expression or its subexpressions is performed. These operations, while simple and with low computational cost, may remarkably structure the expression and reduce its size.

The concept of size used by these routines is close to the concept of length, but function calls and radicals are considered of bigger size than mathematically simpler objects of the same length. In this framework size partly includes the idea of mathematical complexity (for advanced users, see the routines `simplify/size/size` and `simplify/size/size/object`).

The approach used consists of collecting subexpressions using an ordering based on size, then searching for possible fractional decompositions or linear factors that lead to coefficients of smaller size. Functions are handled by first simplifying in size their arguments, followed by re-evaluating the function when the simplification leads to simpler arguments. To avoid re-evaluating the functions, use the optional argument evaluate_known_functions=false.

Expressions given as a ratio between two subexpressions have the numerator and denominator simplified in size separately, and the returned result constructed by dividing the expressions obtained (whenever this result is simpler than the given expression).

The simplification of the expression size is not performed automatically by the simplify command. To perform it, invoke the routines by calling simplify with the extra argument size. Alternatively, the simplification of size is an option in the context menu. To activate this menu, highlight Maple output and right-click with the mouse.

# Introduction

This is result of doing informal simplification measure on expressions using Maple and Mathematica based on script posted on sci.math.symbolic by Dr Carlos and slightly changed by me for formatting purposes and to add a new calculation for the percentage of the size of the expression after simplification to that before the simplification.

# System and software used

Maple used: Version 11 on Windows XP

Mathematica used: Version 5.2 on Windows XP

PC:  Intel P4, 2.4 GHz, 750 MB RAM.

For the Mathematica tests, one test used Simplify[] and the second used FullSimplify[]. Both tested used LeafCount[] command to count the size of the expression. Before start of each test, the Mathematic Kernel was restarted.

For Maple, 2 tests are done, Both use the length() command as a measure of size of expression. In one test simplify() was called, and in the second test simplify() with the option size, which is designed to reduce the size of the expression.

# File used

Mathematica notebook

# Test results

Maple simplify(expr,size)

Test1

 Size before Size after % of original CPU 555 198 36% 0.031

Test2

 Size before Size after % of original CPU 1245 372 30% 0.047

Test3

 Size before Size after % of original CPU 11905 3316 28% 0.078

Test4

 Size before Size after % of original CPU 3509 956 28% 0.031

Test5

 Size before Size after % of original CPU 47654 14960 32% 0.328

Maple simplify(expr)

Test1

 Size before Size after % of original CPU 555 1 0% 0.250

Test2

 Size before Size after % of original CPU 1245 521 42% 1.845

Test3

 Size before Size after % of original CPU 11905 5784 49% 17.390

Test4

 Size before Size after % of original CPU 3509 1570 45% 4.985

Test5

 Size before Size after % of original CPU 47654 24909 53% 14.671

Mathematica Simplify[expr]

Test1

 Size before Size after % of original CPU 230 80 35% 0.093

Test2

 Size before Size after % of original CPU 507 149 29% 0.141

Test3

 Size before Size after % of original CPU 1394 362 26% 0.359

Test4

 Size before Size after % of original CPU 4500 1052 23% 1.016

Test5

 Size before Size after % of original CPU 16040 3533 22% 3.562

Mathematica FullSimplify[expr]

Test1

 Size before Size after % of original CPU 230 60 26% 1.765

Test2

 Size before Size after % of original CPU 507 90 18% 3.672

Test3

 Size before Size after % of original CPU 1394 234 17% 27.390

Test4

 Size before Size after % of original CPU 4500 1043 23% 83.391

Test5

 Size before Size after % of original CPU 16040 3525 22% 520.04

# Observations

For N=1, Maple, using simplify() without the size option, was able to obtain a size=1 after simplification. This is good. For tests N=2,3,4,5 (i.e. as the expression size is increasing), the size of the expression after simplification was about 42% to about 50% compared to the size of the expression before simplification.

Mathematica was not able to obtain size=1 using either Simplify[] nor FullSimplify[] for N=1, but on average, the final size of the expression was about half that of Maple final size of expression when Maple test was done using simplify().

However, when using Maple simplify() command with the size option, Maple was able to reduce the size of the expression to about the same size as Mathematica (few percentage off) and Maple did this in an amazing speed.

However, since with Maple, the length() function was used to determine the size of the expression, and with Mathematica, the function LeafCount[] was used, it is not clear to me that this is a completely valid comparison as the complexity reduction of the expression might not be reflected similarly. This is why I included an image of each test output for comparison so as to allow one to visually see for themselves.

For Mathematica, Using Simplify[], Mathematica achieved a simplification in range of 22% to 35%. While using FullSimplify[], the simplification ranged from 17% to 26%. This shows that FullSimplify[] can achieve about 10% more simplification than Simplify[].

It is also interesting to notice that with Mathematica, as the size of the expression increased (N=4 and N=5), FullSimplify[] achieved the same simplification reduction as Simplify[] did, but using much more CPU time. For N=5, FullSimplify[] CPU usage increased dramatically. One might conclude that using FullSimplify[] for larger expression is not as efficient as using it for smaller expressions.  It looks like FullSimplify might needs to be tuned up more for larger expressions?

Using FullSimplify[] was most productive for N=1 and N=2, where percentage simplification improved by more than 10%

For the CPU time used by Simplification. Maple simplify() was much faster than Mathematica FullSimplify[] as expected since FullSimplify[] is designed to do more simplification on expressions. Maple simplify()  CPU time ranged from 0.2 to 18.5 seconds. While Mathematica FullSimplify[] CPU time ranged from about 1.8 seconds to 518 seconds.  Mathematica Simplify[] command on the other hand used less than 1 second.

# Code

## Maple code

This is Maple implementation of simplification test posted on the internet

sci.symbolic news group. The original test was written in Mathematica by Dr Carlos.

For Maple, I run this test twice, once using simpify() and once using simplify() with the size option.

>

restart;

#names of indexes into matrix which collects the data into

ID:=1: BEFORE_COUNT:=2: AFTER_COUNT:=3: SIMPLIFY_CPU:=5:

PERCENT_SIMPLIFICATION:=4:

xnum:=((6-4*sqrt(2))*ln(3-2*sqrt(2))+(3-2*sqrt(2))*ln(17-12*sqrt(2))+32-24*sqrt(2));

xden:=(48*sqrt(2)-72)*(ln(sqrt(2)+1)+sqrt(2))/3;

x:=xnum/xden;

print("check:",evalf(x,300));

n:=5:

stab:=Matrix(5,5,0):  #Matrix where to keep track of stats

xtab:=expand({x,x^2,x^4,x^8,x^16,x^32}):

s:=Vector(5,0);

for i from 1 to n do

stab[i,ID]:=i:

stab[i,BEFORE_COUNT]:=length(xtab[i]):

startingTime :=time():

s[i]:=simplify(xtab[i]);

#s[i]:=simplify(xtab[i],size):

stab[i,SIMPLIFY_CPU]:=time()-startingTime:

stab[i,AFTER_COUNT]:=length(s[i]):

stab[i,PERCENT_SIMPLIFICATION]:=ceil(100.*stab[i,AFTER_COUNT]/stab[i,BEFORE_COUNT]):

od:

stab;

>