<s> """<STR_LIT>""" <EOL> from __future__ import print_function , division <EOL> from sympy . printing . codeprinter import CodePrinter <EOL> from sympy . printing . str import StrPrinter <EOL> from sympy . printing . precedence import precedence <EOL> known_functions = { <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> "<STR_LIT>" : [ ( lambda x : True , "<STR_LIT>" ) ] , <EOL> } <EOL> class MCodePrinter ( CodePrinter ) : <EOL> """<STR_LIT>""" <EOL> printmethod = "<STR_LIT>" <EOL> _default_settings = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:15> , <EOL> '<STR_LIT>' : { } , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> _number_symbols = set ( ) <EOL> _not_supported = set ( ) <EOL> def __init__ ( self , settings = { } ) : <EOL> """<STR_LIT>""" <EOL> CodePrinter . __init__ ( self , settings ) <EOL> self . known_functions = dict ( known_functions ) <EOL> userfuncs = settings . get ( '<STR_LIT>' , { } ) <EOL> for k , v in userfuncs . items ( ) : <EOL> if not isinstance ( v , list ) : <EOL> userfuncs [ k ] = [ ( lambda * x : True , v ) ] <EOL> self . known_functions . update ( userfuncs ) <EOL> doprint = StrPrinter . doprint <EOL> def _print_Pow ( self , expr ) : <EOL> PREC = precedence ( expr ) <EOL> return '<STR_LIT>' % ( self . parenthesize ( expr . base , PREC ) , <EOL> self . parenthesize ( expr . exp , PREC ) ) <EOL> def _print_Mul ( self , expr ) : <EOL> PREC = precedence ( expr ) <EOL> c , nc = expr . args_cnc ( ) <EOL> res = super ( MCodePrinter , self ) . _print_Mul ( expr . func ( * c ) ) <EOL> if nc : <EOL> res += '<STR_LIT:*>' <EOL> res += '<STR_LIT>' . join ( self . parenthesize ( a , PREC ) for a in nc ) <EOL> return res <EOL> def _print_Pi ( self , expr ) : <EOL> return '<STR_LIT>' <EOL> def _print_Infinity ( self , expr ) : <EOL> return '<STR_LIT>' <EOL> def _print_NegativeInfinity ( self , expr ) : <EOL> return '<STR_LIT>' <EOL> def _print_list ( self , expr ) : <EOL> return '<STR_LIT:{>' + '<STR_LIT:U+002CU+0020>' . join ( self . doprint ( a ) for a in expr ) + '<STR_LIT:}>' <EOL> _print_tuple = _print_list <EOL> _print_Tuple = _print_list <EOL> def _print_Function ( self , expr ) : <EOL> if expr . func . __name__ in self . known_functions : <EOL> cond_mfunc = self . known_functions [ expr . func . __name__ ] <EOL> for cond , mfunc in cond_mfunc : <EOL> if cond ( * expr . args ) : <EOL> return "<STR_LIT>" % ( mfunc , self . stringify ( expr . args , "<STR_LIT:U+002CU+0020>" ) ) <EOL> return expr . func . __name__ + "<STR_LIT>" % self . stringify ( expr . args , "<STR_LIT:U+002CU+0020>" ) <EOL> def _print_Integral ( self , expr ) : <EOL> if len ( expr . variables ) == <NUM_LIT:1> and not expr . limits [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] : <EOL> args = [ expr . args [ <NUM_LIT:0> ] , expr . variables [ <NUM_LIT:0> ] ] <EOL> else : <EOL> args = expr . args <EOL> return "<STR_LIT>" + '<STR_LIT:U+002CU+0020>' . join ( self . doprint ( a ) for a in args ) + "<STR_LIT>" <EOL> def _print_Sum ( self , expr ) : <EOL> return "<STR_LIT>" + '<STR_LIT:U+002CU+0020>' . join ( self . doprint ( a ) for a in expr . args ) + "<STR_LIT>" <EOL> def mathematica_code ( expr , ** settings ) : <EOL> r"""<STR_LIT>""" <EOL> return MCodePrinter ( settings ) . doprint ( expr ) </s>
