[BACK]Return to om.rr CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-contrib / packages / src

File: [local] / OpenXM / src / asir-contrib / packages / src / om.rr (download)

Revision 1.2, Wed Apr 13 23:19:54 2005 UTC (19 years, 2 months ago) by takayama
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.1: +4 -4 lines

Forgot to commit it in the previous commit.

/*$OpenXM: OpenXM/src/asir-contrib/packages/src/om.rr,v 1.2 2005/04/13 23:19:54 takayama Exp $ */
/* Old: om, see Attic */

Om_proc = -1$
#define OM_FIND_PROC(P)  P = getopt(proc);\
                          if (type(P) == -1) {\
                             P = om_find_proc();\
                          }

def om_find_proc() {
  extern Om_proc;
  if (Om_proc == -1) {
     A = ox_get_serverinfo();
     /* Look for OMproxy. Not yet written */
     /* Start java OMproxy automatically if there is not ox_sm1 */
     Om_proc = om_start();
  }
  return(Om_proc);
}
/*&C
@node OpenMath Functions,,, Top
*/
/*&ja
@chapter OpenMath $BH!?t(B(1999$BHG(B)

@file{om.rr}$B$K$3$N@a$GDj5A$5$l$F$$$k4X?t$,Dj5A$5$l$F$$$k(B.
Java $B$N<B9T4D6-$,@_Dj$5$l$F$$$k$3$H$,I,MW$G$"$k(B.
*/
/*&en
@chapter OpenMath Functions(Version 1999)

The functions in this section is defined in the file @file{om.rr}.
An environment to execute Java codes must be set to call the functions
described in this section.
*/

/*&C

@noindent
Author of OMproxy : Yasushi Tamura.

*/

/*&C
@menu
* om_start::
* om_xml::
* om_xml_to_cmo::
@end menu
*/
/*&en
@node om_start,,, OpenMath Functions
@subsection @code{om_start}
@findex om_start
@table @t
@item om_start()
::  Start @code{OMproxy} server to make a translation between CMO and OpenMath XML (CD's in 1999) expressions.
@end table

@table @var
@item return
Number
@end table
*/
/*&ja
@node om_start,,, OpenMath Functions
@subsection @code{om_start}
@findex om_start
@table @t
@item om_start()
::  @code{OMproxy} $B$r%9%?!<%H$9$k(B. $B$3$N%5!<%P$O(B CMO $B$H(B OpenMath XML (CD's in 1999)
$B$H$N4V$NJQ49$r$*$3$J$&(B.
@end table

@table @var
@item return
$B?t(B
@end table
*/
/*&C
@example
[155] load("om.rr");
1
[160] om_start();
control: wait OX
Trying to connect to the server... Done.
0
[161] om_xml(<<1,0>>+2*<<0,1>>);
<OMOBJ><OMA><OMS name="DMP" cd="poly"/>
<OMA><OMS name="PolyRing" cd="poly"/>
 <OMI>2</OMI></OMA><OMA>
 <OMS name="SDMP" cd="poly"/>
 <OMA><OMS name="Monom" cd="poly"/><OMI>1</OMI><OMI>1</OMI><OMI>0</OMI></OMA>
 <OMA><OMS name="Monom" cd="poly"/><OMI>2</OMI><OMI>0</OMI><OMI>1</OMI></OMA>
</OMA></OMA></OMOBJ>
[162] om_xml_to_cmo(@@);
(1)*<<1,0>>+(2)*<<0,1>>
@end example
*/
def om_start() {
  extern Xm_unix;
  if (ox_ostype()[0] == "windows" && Xm_unix == 0)
    return om_start_windows(0);
  else
    return om_start_unix();
}

def om_start_unix() {
  extern Om_proc;
 /* ctrl("ox_check",0);   for buggy mathcap of OMproxy */
  CPort = generate_port();
  SPort = generate_port();
 
  Outfile = " > /dev/null ";
  Lib = ox_getenv("OpenXM_HOME")+"/lib/java-support"$
  Com = "java OMproxy -data "+ rtostr(SPort) +" -control "+ rtostr(CPort);
 /* Com = Com +" -nohup || "+ Com;	for not to stop by CTRL-C */
  Com = "cd "+ Lib +";"+ Com;
  Com = "/bin/csh -c \""+ Com +"\"";
  Com = "/bin/csh -c '(oxlog xterm -iconic -T OMproxy -n OMproxy -e "+ Com +">&/dev/null)"
	+"||"+ Com + Outfile +"' &";
 /* print(Com +"\n"); */
  shell(Com);
  shell("sleep 5");
  print("Trying to connect to the server...",0)$
  CSocket = try_connect("localhost",CPort);
  SSocket = try_connect("localhost",SPort);
  A = register_server(CSocket,CPort,SSocket,SPort);
  print(" Done.");
  Om_proc = A;
  return(A);
}

def om_start_windows(S) {
  extern Xm_debug_on_win_1;
  if (!Xm_debug_on_win_1) {
    error("The component phc has not yet been implemented on Windows(native).");
  }
}
/*&en
@node om_xml,,, OpenMath Functions
@subsection @code{om_xml}
@findex om_xml
@table @t
@item om_xml(@var{s}|proc=@var{p})
::  Translate CMO expression of  @var{s} to a XML expression of OpenMath(CD's in 1999).
@end table

@table @var
@item return
String
@item p
Number
@item s
Object
@end table

@itemize @bullet
@item  
Translate CMO @var{s} to a XML expression of OpenMath(CD's in 1999).
@end itemize
*/
/*&ja
@node om_xml,,, OpenMath Functions
@subsection @code{om_xml}
@findex om_xml
@table @t
@item om_xml(@var{s}|proc=@var{p})
::  @var{s} $B$N(B CMO $BI=8=$r(B OpenMath $B$N(B XML (CD's in 1999) $BI=8=$K$J$*$9(B.
@end table

@table @var
@item return
$BJ8;zNs(B
@item p
$B?t(B
@item s
$B%*%V%8%'%/%H(B
@end table

@itemize @bullet
@item   @var{s} $B$N(B CMO $BI=8=$r(B OpenMath $B$N(B XML (CD's in 1999) $BI=8=$K$J$*$9(B.
@end itemize
*/
/*&C
@example
For (I=0; I<10; I++) @{
   A = 2^I;
   B = om_xml(A);
   C = om_xml_to_cmo(B);
   print(A == C);
@}
@end example
*/

def om_xml(F) {
  OM_FIND_PROC(P);
  ox_push_cmo(P,F);
  ox_push_cmo(P,ntoint32(1));
  ox_push_cmo(P,"CMO2OMXML");
  ox_push_cmd(P,269);  /* SM_executeFunction */
  return(ox_pop_cmo(P));
}

/*&en
@node om_xml_to_cmo,,, OpenMath Functions
@subsection @code{om_xml_to_cmo}
@findex om_xml_to_cmo
@table @t
@item om_xml_to_cmo(@var{s}|proc=@var{p})
::  Translate XML expression (CD's in 1999) @var{s} of OpenMath to a CMO.
@end table

@table @var
@item return
Object
@item p
Number
@item s
String
@end table

@itemize @bullet
@item  
Translate XML expression (CD's in 1999) @var{s} of OpenMath to a CMO.
@end itemize
*/
/*&ja
@node om_xml_to_cmo,,, OpenMath Functions
@subsection @code{om_xml_to_cmo}
@findex om_xml_to_cmo
@table @t
@item om_xml_to_cmo(@var{s}|proc=@var{p})
::  OpenMath $B$N(B XML (CD's in 1999) $BI=8=(B @var{s} $B$r(B CMO $B$K$J$*$9(B.
@end table

@table @var
@item return
$B%*%V%8%'%/%H(B
@item p
$B?t(B
@item s
$BJ8;zNs(B
@end table

@itemize @bullet
@item   OpenMath $B$N(B XML (CD's in 1999) $BI=8=(B @var{s} $B$r(B CMO $B$KJQ49$9$k(B.
@end itemize
*/

def om_xml_to_cmo(F) {
  OM_FIND_PROC(P);
  ox_push_cmo(P,F);
  ox_push_cmo(P,ntoint32(1));
  ox_push_cmo(P,"OMXML2CMO");
  ox_push_cmd(P,269);  /* SM_executeFunction */
  return(ox_pop_cmo(P));
}

def om_test(A){
	print(A);

	B = om_xml(A);
	C = om_xml_to_cmo(B);

	if(A!=C){
		print(B);
		print(C);
		print("difference found.\n");
		debug;
	}else{
		print("OK!");
	}
	return 0;
}

def om_test_with_tree(A){
	print(A);

	B = om_xml(A);
	/* C = om_xml_to_cmo(B); */
	C = eval_str(sm1_xml_tree_to_prefix_string(B));

	if(A!=C){
		print(B);
		print(C);
		print("difference found.\n");
		debug;
	}else{
		print("OK!");
	}
	return 0;
}

def om_test_taylor(F,X,P,N){
        R = 0;
        A = F;

        for(I=0;I<N;I++){
                R += subst(A,X,P) * x^I;
                A = diff(A,X)/(I+1);
        }
        return R;
}

def om_test_auto(){
	for(I=0;I<50;I+=1){
		om_test((I%3-1)*random());
	}

	for(I=-2^35;I<2^35;I+=random()){
		om_test(I);
	}

	for(I=0;I<20;I+=1){
		om_test((I%3-1)*random()/random());
	}

	for(I=-100;I<100;I+=random()/random()){
		om_test(I);
	}

	/* load("taylor"); */
	/* om_test(taylor(exp(z),z,0,10));
	om_test_with_tree(taylor(sin(z),z,0,10));
	om_test_with_tree(taylor(cos(z),z,0,10));
        om_test_with_tree(taylor(cos(z),z,1,10)); */

        om_test_with_tree(om_test_taylor(1/(1-z),z,0,10));
        om_test_with_tree(om_test_taylor(1/(1-z),z,2,10));
        om_test_with_tree(om_test_taylor(1/(1-z),z,3,10));

	/* om_test_with_tree(taylor((1-z)^(1/2),z,0,10));
        om_test_with_tree(taylor((1-z)^(1/2),z,2,10)); */

	for(I=0;I<14;I+=1){
	        om_test_with_tree((x+y)^I);
	        om_test_with_tree((x+y+I)^I);
	}

}

Loaded_om = 1 $

end$