Skip to content

IAST IASTMutable and IASTAppendable

Axel Kramer edited this page Aug 8, 2024 · 4 revisions

IAST, IASTMutable, and IASTAppendable interfaces for immutable, mutable and appendable function argument representations

Overview

In the Symja library, expressions are represented using the IExpr interface. This interface has several sub-interfaces to handle different types of expressions, for representing functions with arguments the interfaces IAST, IASTMutable and IASTAppendablecan be used.

IAST

IAST stands for "Abstract Syntax Tree" interface. It is an interface that represents an immutable list of IExpr elements. This means that once an IAST object is created, its state cannot be changed.

Here is an example of how to create an IAST object:

IAST function = F.Plus(F.x, F.y);

In this example, F.Plus(F.x, F.y) creates an IAST object that represents the function expression x + y.

IASTMutable

IASTMutable is a sub-interface of IAST that represents a mutable list of IExpr elements. This means that you can change the state of an IASTMutable object after it is created.

Here is an example of how to create and modify an IASTMutable object:

IASTMutable function = F.Times(F.x, F.y);
function.set(1, F.z);

In this example, F.Times(F.x, F.y) creates an IASTMutable object that represents the expression x * y. The set method is then used to change the first element of the list to z, so the expression becomes z * y.

IASTAppendable

IASTAppendable is another sub-interface of IAST that represents a function-list of IExpr elements to which new elements can be appended.

Here is an example of how to create and append to an IASTAppendable object:

IASTAppendable function = F.PlusAlloc(8);
function.append(F.x);
function.append(F.y);

In this example, F.PlusAlloc(8) creates an IASTAppendable object with Plus as the head of the function and memory allocated for 8 arguments. The append method is then used to add x and y to the list, so the expression becomes x + y.

Conclusion

The IAST, IASTMutable, and IASTAppendable interfaces provide a flexible way to represent and manipulate expressions in the Symja library. By understanding these interfaces, you can effectively create and manipulate mathematical expressions in your code.

Clone this wiki locally