# The variables are explained in the file gap/data.g
# name := number;

IF_mathematica := 120;


##############################################################################
# Administrative data


IF_SUBPACKAGE_VERSION[IF_mathematica] := "dev";


IF_CAS_DESCRIPTION[IF_mathematica] :=
[ "Mathematica",
"Mathematica is a computer algebra system originally developed by Stephen Wolfram and sold by his \
company Wolfram Research.",
"http://www.wolfram.com/products/mathematica/index.html" ];


##############################################################################
# Low level data


IF_EXEC_NAME[IF_mathematica] := "math";
#IF_EXEC_FULL_PATH[IF_mathematica] := "";
IF_EXEC_OPTIONS[IF_mathematica] := [];


IF_QUIT_COMMAND[IF_mathematica] := "Quit[]";
IF_DISPLAY_VERSION[IF_mathematica] := "$Version";


IF_FIRST_COMMAND[IF_mathematica] := "$PrePrint=ToString";

if not IsBound( IF_PROMPT_NR[IF_mathematica] )  then
    IF_PROMPT_NR[IF_mathematica]:= 1;
fi;
IF_FIRST_PROMPT[IF_mathematica] := "\n\nIn[1]:= ";

IF_PROMPTS[IF_mathematica] :=
function ( OUT )
    local  prompt;
    prompt := Concatenation( "\nIn[", String( IF_PROMPT_NR[IF_mathematica] + 1 ), "]:= " );
    return PositionSublist( OUT, prompt ) <> fail;
end;

IF_FUNC_REMOVE_PROMPT[IF_mathematica] := 
function ( OUT )
    local  prompt;
    prompt := Concatenation( "\nIn[", String( IF_PROMPT_NR[IF_mathematica] + 1 ), "]:= " );
    OUT := OUT{[ 1 .. Length( OUT ) - Length( prompt ) ]};
    if Length( OUT ) > 8 and OUT{[ 1 .. 5 ]} = "\nOut["  then
        OUT := OUT{[ 9 + Length( String( IF_PROMPT_NR[IF_mathematica] ) ) .. Length( OUT ) - 1 ]};
    else
        Info( InfoInterfaces, 2, "Mathematica prompt: ", OUT );
    fi;

    if Length( OUT ) > 17 and OUT{[ 1 .. 17 ]} = "FullForm= \n \n>   "  then
        OUT := OUT{[ 18 .. Length( OUT ) ]};
    
    elif Length( OUT ) > 10 and OUT{[ 1 .. 10 ]} = "FullForm= "  then
        OUT := OUT{[ 11 .. Length( OUT ) ]};
    fi;

    IF_PROMPT_NR[IF_mathematica] := IF_PROMPT_NR[IF_mathematica] + 1;
    return OUT;
end;

IF_IS_THERE_PROMPT[IF_mathematica] := true;


##############################################################################
# High level data


IF_BRACKETS[IF_mathematica] := [ "[", "]" ];
IF_ASSIGN[IF_mathematica] := "=";
IF_END_COMMAND[IF_mathematica] := "";
IF_END_COMMAND_NO_OUTPUT[IF_mathematica] := ";";
IF_FUNC_TYPE[IF_mathematica] := "Head";
IF_TYPE_IS_QUOTED[IF_mathematica] := false;

IF_FUNC_DISPLAY[IF_mathematica] := "FullForm";

IF_STRING_ARE_QUOTED[IF_mathematica] := true;
IF_FUNC_STRING[IF_mathematica] := "ToString"; # StringForm?
IF_PROHIBITED_CHARS[IF_mathematica] := [  ];


##############################################################################
# data types data


# Documentation available at
# http://documents.wolfram.com/mathematica/
# see also HelpBrowserNotebook[ ]


IF_DATA_TYPES[IF_mathematica] := rec(


# A.1.4 Atomic Objects
# from http://documents.wolfram.com/mathematica/book/section-A.1.4


Symbol := [
"symbol (extract name using SymbolName)",
,
,
IdFunc
],



String := [
"character string \"cccc\" (extract characters using Characters)",
IsString and IsStringRep,
IF_ParseGapString,
IF_EvalString
],



Integer := [
"integer (extract digits using IntegerDigits)",
IsInt,
String,
obj -> Int( Filtered( obj, x -> IsDigitChar( x ) or x = '-' ) )
],



Real := [
"approximate real number (extract digits using RealDigits)",
],



Rational := [
"rational number (extract parts using Numerator and Denominator)",
IsRat,
String,
function ( obj, name )
    IF_LowLevelInterface( IF_mathematica, "num", "Numerator", name );
    IF_LowLevelInterface( IF_mathematica, "den", "Denominator", name );
    return IF_GetCasOutput( IF_mathematica, "num" ) / IF_GetCasOutput( IF_mathematica, "den" );
end
],



Complex := [
"complex number (extract parts using Re and Im)",
IsGaussRat,
function ( obj )
    local  real, imaginary;
    real := x -> (x + ComplexConjugate( x )) / 2;
    imaginary := x -> (x - ComplexConjugate( x )) * -1 / 2 * E( 4 );
    return Concatenation( "( ", IF_ConvertFromGap( IF_mathematica, real( obj ) ),
        " + I*(", IF_ConvertFromGap( IF_mathematica, imaginary( obj ) ), ") )" );
end,
function ( obj, name )
    IF_LowLevelInterface( IF_mathematica, "re", "Re", name );
    IF_LowLevelInterface( IF_mathematica, "im", "Im", name );
    return IF_GetCasOutput( IF_mathematica, "re" ) + E( 4 ) * IF_GetCasOutput( IF_mathematica, "im" );
end
],
 


# Non-atomic Objects



List := [
"{e1, e2, ... } is a list of elements",
obj -> IsDenseList( obj ) and ForAll( obj, y -> IF_Type(IF_mathematica, y) <> fail ),
obj -> IF_ParseGapList( IF_mathematica, obj, "{", "}" ),
function( obj, name ) return IF_Maple_op( IF_mathematica, obj, name, Add ); end
]



);

