arXiv:cs/9901007v1 [] 15 Jan 1999

Universal Object Oriented Languages and
Computer Algebra
Alexander Yu. Vlasov
Federal Center for Radiology, IRH
197101, Mira Street 8, St.–Petersburg, Russia
E-mail: Alexander.Vlasov@pobox.spbu.ru, alex@protection.spb.su

Extended abstract
Abstract
The universal object oriented languages made programming more simple and efficient. In the article is considered possibilities of using similar
methods in computer algebra. A clear and powerful universal language
is useful if particular problem was not implemented in standard software
packages like REDUCE, MATHEMATICA, etc. and if the using of internal programming languages of the packages looks not very efficient.
Functional languages like LISP had some advantages and traditions
for algebraic and symbolic manipulations. Functional and object oriented
programming are not incompatible ones. An extension of the model of an
object for manipulation with pure functions and algebraic expressions is
considered.

1

Introduction

Despite of existence of many interactive algebra–numerical systems (MatLAB
or MathCAD1 ) and systems of computer algebra (MACSYMA, REDUCE[7],
MATHEMATICA[5], MAPLE, etc.), some kind of algebraic problems related
with numerous difficult and formal manipulation could not be simply rewritten for computer. The systems of computer algebra very useful if the class
of problems under consideration is already has standard implementation. It is
symbolic integration and differentiation, rational and integer number arithmetic
with arbitrary precision[6], etc. .
For implementation of new classes of problems the most of systems of computer algebra (CA) have his own programming languages. Sometime it can
be very universal and powerful languages like LISP. For example, many new
packages was implemented in REDUCE/RLISP by users.
1 Either

can use MAPLE library

1

On the other hand the programming of the new methods in a system of CA
can be even more difficult, than using universal modern languages like Pascal[1],
C++[2], etc. with new powerful techniques like data types or object oriented
programming (OOP).
In the paper are considered possible extensions of the OOP to make possible
of simple implementations to systems of CA. The paper is continue a theme
presented earlier at [4].

2

Object Oriented Programming and Computer
Algebra

The development of big and difficult pieces of software is often related with proliferation of errors and lost of clarity. The problem of effectiveness of programming was one of central point for creation structural languages like Pascal[1] and
new generation of object oriented languages like Java[3]. The LISP, traditional
for CA, is very universal, but the structure of programs is too complicated.
The OOP has possibility of understanding representation of structures in CA
[4]. For example it is possible to define Module 2 :
Module = Object;
operation + (A,B : Module) : Module;
operation − (A,B : Module) : Module;
operation − (A : Module) : Module;
const Zero : Module;
end; { Module }
Then definition of Ring can exploit inheritance in OOP:
Ring = Object(Module)
operation ∗ (A,B : Ring) : Ring;
operation / (A,B : Ring) : Ring;
function Inversion(A : Ring) : Ring;
const Unit : Ring;
end; { Ring }
It is conception of an abstract basic type. They are algebra, module, group,
field, ring etc.. The abstract types do not contain a data. Other objects contain
data. It is integer, real or complex numbers, quaternions, n × n matrices, etc.:
Quaternion = Object(Algebra)
Data : array [0..3] of Number;
function Norm : Number;
operation + (A,B : Quaternion) : Quaternion;
operation ∗ (A,B : Quaternion) : Quaternion;
···
end; { Quaternion }
2 Here

it is additive Abelian group, unit is called “zero”

2

There is a difficulty because in CA it is necessary to work with analytical
expressions associated with each of the object. We can have possibility to write
either z := 2 ∗ i, or z := x + i y. In the work [4] already was discussed some kind
of extensions to the model of an object. It is some synthesis of functional and
object oriented programming.

References
[1] N. Wirth, Algorithms + Data Structures = Programs (Prentice–Hall, Englewood Cliffs, New Jersey, 1976).
[2] B. Stroustrup, The C++ Programming Language (Addison–Wesley, Reading, Massachusetts, 1986).
[3] P. Naughton, The Java Handbook (McGraw–Hill, Osborne, 1996).
[4] A. Vlasov, Object Oriented and Functional Programming for Symbolic Manipulation (Proc. 5th Internat. Workshop on New Computing Techniques in
Physics Research (AIHENP’96), Switzerland, 2–6 September, 1996)
[5] S. Wolfram, Mathematica: A System for Doing Mathematics by Computer
(Addison–Wesley, Redwood City, California, 1988)
[6] A. Akritas, Elements of Computer Algebra with Applications (John Wiley &
Sons, New York, 1989)
[7] J. Davenport, Y. Siret, E. Tournier, Calcul formel: Systèms et algorithmes
de manipulations algébriques (Masson, Paris, 1987)

3

Comments to attached copy of slide presentation

Slide 1
A scientific problem could be resolved with using variety of different ways.
Here is represented using: Standard systems of computer algebra, Universal
programming languages and traditional work with pen and piece of paper.
↓
An application of universal programming languages like C++, Pascal, etc.
is still widely used not only for numerical calculation but for any scientific data
manipulation, including computer algebra. Here is represented an approach
with using Object oriented programming for computer algebra.
↓
An object oriented program for computer algebra consists of Specific structures and algorithms of computer algebra together with Standard structures of
the object oriented language.
↓
It is convenient to merge both types of structures in some Extension of object
oriented language for computer algebra.
↓
Practical realization of such idea could be either standalone translator for
the language or Translator CA → OOP, i.e. convertor of a program for computer algebra to a program on one of widespread object oriented languages (C++,
JAVA, Delphi, etc.). The code generator produces program on the OO language,
standard algorithms of computer algebra also can be included in Libraries in
a standard format accessible for the language. Next, the produced C++ program can be translated to executable module; if it is JAVA program it can be
converted to bytecode for using in WWW applets; etc.. It is the possibility to
make computer algebra more effective, universal, fast, “light” and to include it
as parts in other software projects.

Slide 2
Here is represented good agreement of principles of object oriented programming
with structures of standard algebraic models in mathematics, i.e. inheritance
of methods and properties between such abstract objects as Semigroup, Group,
Module, Ring, Division ring, Field, Algebra and such descendant “actual” objects as Real and Complex numbers or Polynomials.
4

Slide 3
Here is emphasized one of specific property of mathematical language that requires some extension of model of an object in object oriented programming. As
a simple example is considered meaning of same variable x in different contexts:
What does ‘x’ mean?
First meaning is traditional for standard programming language there ‘x’
means value of variable x and nothing else. But another meanings also are
essential and used in mathematics and computer algebra. The second meaning
is ‘x’ as some variable x of given type with value unknown or not essential. The
last, most difficult case is ‘x’ as value of some function with (maybe partially)
unknown arguments or expression like x = a ∗ y + 2.
--------------------------------------------------All three meaning are also used in Pure functional programming languages
there the functions with partially defined arguments are used and could be
described formally as some tree represented on the slide.
--------------------------------------------------The trees are simply described by using usual Structures in object oriented
languages produced by formal inversion of all arrows in diagram above.
--------------------------------------------------But principles of type checking of an object oriented language should be
extended for such a case to make the new structure (an object with pointers to
argument and to method of evaluation of the function) compatible with initial
type of variable x. It require an Extension of object programming: compatibility
of 3 subtypes mentioned above.

5

Universal Object Oriented Languages and Computer Algebra

A. Yu. Vlasov

A scientific problem

H
Standard systems

Universal

of computer

programming

?

languages

algebra

ó

REDUCE

ó

LISP

MATHEMATICA

PROLOG

MAPLE

ALGOL, PASCAL

MACSYMA

C++, JAVA

...

...

2

ß

ê

Object Oriented Programming

Specific structures and algorithms of computer algebra
Standard structures of the object

ê
ê

oriented language

Standalone
translator

Translator CA

ç
à

Extension of

object oriented

languages for computer algebra

OOP

â

An object oriented program for computer algebra

â
â

Code generator

Libraries

à
æ

CASC98 April 20-24, 1998
St.Petersburg, Russia

Program on usual object oriented language
(C++, JAVA, Delphi,

etc.)

C++ translator, JAVA (WWW applet), etc. .

1

Universal Object Oriented Languages and Computer Algebra

A. Yu. Vlasov

Abstract algebraic objects

Semigroup

Data objects

Group

Module

Ring

Polynomials

Division ring

Field

Real numbers
Complex numbers

Algebra

Module = object (Group) {+, -, Abelian := true}

+ (A, B : Module) : Module;
function - (A, B : Module) : Module;
function

constant
zero {0}: Module;
end;

Ring = object (Module)
function

* (A, B : Ring) : Ring;

constant
unit {1}: Ring;
end;

Polynomial = object(Ring)

+ ; overload;
function - ; overload;
function * ; overload;
function

end;

CASC98 April 20-24, 1998
St.Petersburg, Russia

2

Universal Object Oriented Languages and Computer Algebra

A. Yu. Vlasov

x

What does   mean?

x = 5 {Value of x} x : Real {Variable x}

x = A*y {Function}

-------------------------------------------------------------------------------------

Pure Functional Programming
A ¾¾¾®
f

¾¾¾¾®
g

B ¾¾¾®

¾¾¾®

C ¾¾¾®
g( f(A,B),C)

Type~A; B : Type~B) : Type~f;
g : function (F : Type~f; C : Type~C) : Type~g;
f : function (A :

-------------------------------------------------------------------------------------

Structure in Object Oriented Language
g

Type~f
C : Type~C
F :

f
¾¾¾¾®
¾¾®C

Type~A
B : Type~B
A :

¾¾¾®A
¾¾¾®B

-------------------------------------------------------------------------------------

Extension of Object Programming: Compatibility of 3 subtypes

TypeOf(x) = X

variable X

CASC98 April 20-24, 1998
St.Petersburg, Russia

value X

functional X

3

