Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

3 Expressions
 3.1 Constructors
 3.2 Attributes
 3.3 Operations
 3.4 Global Functions
 3.5 Examples
 3.6 GAP Categories

3 Expressions

3.1 Constructors

3.1-1 Expression
‣ Expression( variables, string )( operation )

Returns: an expression

Create an expression from a list of variables and a string representation.

3.1-2 ConstantExpression
‣ ConstantExpression( string )( operation )

Returns: a constant expression

Create a constant expression from a string. The expression will have no variables and will also be registered as a global constant.

3.2 Attributes

3.2-1 Variables
‣ Variables( e )( attribute )

Returns: a list of strings

The list of variables of an expression.

3.2-2 String
‣ String( e )( attribute )

Returns: a string

The string representation of an expression.

3.2-3 AsFunction
‣ AsFunction( e )( attribute )

Returns: a function

Convert an expression to a GAP function that can be evaluated numerically.

3.3 Operations

3.3-1 DummyInput
‣ DummyInput( var, n )( operation )

Returns: a list of expressions

Generate a list of dummy input expressions using base name var with indices from 1 to n. For example, DummyInput("x", 3) returns a list of three expressions x1, x2, x3. Those can be used as input to smooth morphisms constructed from expressions.

3.4 Global Functions

3.4-1 ConvertToConstantExpressions
‣ ConvertToConstantExpressions( constants )( function )

Returns: a list of constant expressions

Assign to each string in constants a global constant expression defined by that string. The variables of these expressions will be empty. For example, ConvertToConstantExpressions( ["Pi"] ) returns [ Pi ], and Variables(Pi)=[].

3.4-2 CreateContextualVariables
‣ CreateContextualVariables( variables )( function )

Returns: a list of expressions

Assigns to each string in variables an expression with the same name. The variables of these expressions equals the list variables itself. After that, one would be able for example to construct more complex expressions using these variables, e.g., x1 + Sin(x2). For example, ConvertToExpressions( ["x1", "x2"] ) returns a pair [ x1, x2 ], where x1 and x2 are expressions with string representations "x1" and "x2", and Variables(x1) = ["x1", "x2"], Variables(x2) = ["x1", "x2"].

3.4-3 AssignExpressions
‣ AssignExpressions( vars )( function )

Assign each expression in vars to a global variable with the same name. For example, if vars = [ x1, x2 ], this function will create global variables x1 and x2 corresponding to the expressions in the list.

3.5 Examples

gap> e1 := Expression( ["x", "y"], "x + Sin( y )" );
x + Sin( y )
gap> e2 := Expression( ["y", "z"], "( y + Sin( z ) ) ^ 2" );
(y + Sin( z )) ^ 2
gap> CategoriesOfObject( e1 );
[ "IsExtAElement", "IsNearAdditiveElement", "IsNearAdditiveElementWithZero",
  "IsNearAdditiveElementWithInverse", "IsAdditiveElement", "IsExtLElement",
  "IsExtRElement", "IsMultiplicativeElement", "IsExpression" ]
gap> KnownAttributesOfObject( e1 );
[ "String", "Variables" ]
gap> String( e1 );
"x + Sin( y )"
gap> Variables( e1 );
[ "x", "y" ]
gap> Variables( e2 );
[ "y", "z" ]
gap> e1 + e2;
x + Sin( y ) + (y + Sin( z )) ^ 2
gap> e1 * e2;
(x + Sin( y )) * (y + Sin( z )) ^ 2
gap> e := Sin( e1 ) / e2;
Sin( x + Sin( y ) ) / (y + Sin( z )) ^ 2
gap> Variables( e );
[ "x", "y", "z" ]
gap> ConstantExpression( "tau" );
#I  MakeReadWriteGlobal: tau already read-write
tau
gap> Variables( tau );
[  ]
gap> e3 := e1 * Sin( tau );
(x + Sin( y )) * Sin( tau )
gap> Variables( e3 );
[ "x", "y" ]
gap> f := AsFunction( e );
function( vec ) ... end
gap> Display( f );
function ( vec )
    local x, y, z;
    Assert( 0, IsDenseList( vec ) and Length( vec ) = 3 );
    x := vec[1];
    y := vec[2];
    z := vec[3];
    return Sin( x + Sin( y ) ) / (y + Sin( z )) ^ 2;
end
gap> x := [ 3, 2, 4 ];
[ 3, 2, 4 ]
gap> f( x );
-0.449348
gap> dummy_input := CreateContextualVariables( [ "x1", "x2", "x3" ] );
[ x1, x2, x3 ]
gap> f( dummy_input );
Sin( x1 + Sin( x2 ) ) / (x2 + Sin( x3 )) ^ 2
gap> AssignExpressions( dummy_input );
#I  MakeReadWriteGlobal: x1 already read-write
#I  MakeReadWriteGlobal: x2 already read-write
#I  MakeReadWriteGlobal: x3 already read-write
gap> x1;
x1
gap> Variables( x1 );
[ "x1", "x2", "x3" ]
gap> [ [ x1, x2 ] ] * [ [ x3 ], [ -x3 ] ];
[ [ x1 * x3 + x2 * (- x3) ] ]

3.6 GAP Categories

3.6-1 IsExpression
‣ IsExpression( e )( filter )

Returns: true or false

The GAP category of symbolic expressions. Expressions are used to represent mathematical formulas symbolically, allowing operations like differentiation to be performed symbolically before evaluation.

3.6-2 IsConstantExpression
‣ IsConstantExpression( e )( filter )

Returns: true or false

The GAP category of constant expressions (expressions with no variables). Constant expressions represent fixed numerical values and can be evaluated directly.

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 Ind

generated by GAPDoc2HTML