Algebraic.unique - Maple Programming Help

Home : Support : Online Help : Programming : OpenMaple : Java Application Programming Interface : Algebraic Class : OpenMaple/Java/Algebraic/unique

Algebraic.unique

get the unique representation of a Maple expression

 Calling Sequence Algebraic unique() throws MapleException

Description

 • The unique function returns the unique representation of the current Maple expression.
 • Most Maple expressions have a unique representation within Maple.  Sometimes working with the unique representation is useful (two expressions can be compared very efficiently, see dagEquals) and sometimes it is not (while adding elements to a list or expression sequence it is very inefficient to unique each intermediate stage).  Most functions in Java OpenMaple return objects already using their unique representation; however, in some cases the object returned is not unique.
 • The Algebraic objects returned by newList and newExpseq are not in their unique representation.  Once they have been initialized, unique should be called on them to obtain the unique representation.  Failing to do so can lead to unpredictable results.
 • The current Algebraic object is unchanged by this call.
 • Calling unique on an Algebraic that already stores a unique representation returns a reference to the same Algebraic object.
 • If a unique representation for the current Maple expression does not exist, the current Maple expression becomes that unique representation.  Therefore the Algebraic returned by unique may refer to the same Maple object as the original. The dagEquals function can be used to determine if they refer to the same Maple object.

Examples

 import com.maplesoft.openmaple.*; import com.maplesoft.externalcall.MapleException; class Example { public static void main( String notused[] ) throws MapleException { String mapleArgs[]; Engine engine; List original, unique, global; mapleArgs = new String[1]; mapleArgs[0] = "java"; engine = new Engine( mapleArgs, new EngineCallBacksDefault(), null, null ); global = (List)engine.evaluate( "[100]:" ); original = engine.newList( 1 ); original.assign( 1, engine.newNumeric( 100 ) ); unique = (List)original.unique(); if ( !original.dagEquals( unique ) ) { System.out.println( "unique not equal to original" ); } if ( !original.dagEquals( global ) ) { System.out.println( "global not equal to original" ); } if ( unique.dagEquals( global ) ) { System.out.println( "unique and global are equal" ); } } }

Executing this code produces the following output.

 unique not equal to original global not equal to original unique and global are equal