Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346<Chapter Label="OpenMathFunctionality">1<Heading>&OpenMath; functionality in &GAP;</Heading>234<Section Label="ViewOpenMath">5<Heading>Viewing &OpenMath; representation of an object</Heading>67<#Include Label="OMPrint">89Producing &OpenMath; representation of polynomials, one may get a warning:1011<Log>12<![CDATA[13gap> x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;14gap> OMPrint(x^2+y);15#I Warning : polynomial will be printed using its default ring16#I because the default OpenMath polynomial ring is not specified17#I or it is not contained in the default OpenMath polynomial ring.18#I You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.19<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">20<OMA>21<OMS cd="polyd1" name="DMP"/>22<OMA id="polyring9qiY2oOaiITWUORb" >23<OMS cd="polyd1" name="poly_ring_d"/>24<OMS cd="setname1" name="Q"/>25<OMI>2</OMI>26</OMA>27<OMA>28<OMS cd="polyd1" name="SDMP"/>29<OMA>30<OMS cd="polyd1" name="term"/>31<OMI>1</OMI>32<OMI>0</OMI>33<OMI>1</OMI>34</OMA>35<OMA>36<OMS cd="polyd1" name="term"/>37<OMI>1</OMI>38<OMI>2</OMI>39<OMI>0</OMI>40</OMA>41</OMA>42</OMA>43</OMOBJ>44]]>45</Log>46Indeed, now when another polynomial will be printed, it will belong to a47ring with a different identifier (despite &GAP; will be able to perform48arithmetical operations on these polynomials like when they belong to the49same ground ring):50<Log>51<![CDATA[52gap> OMPrint(x+1);53#I Warning : polynomial will be printed using its default ring54#I because the default OpenMath polynomial ring is not specified55#I or it is not contained in the default OpenMath polynomial ring.56#I You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.57<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">58<OMA>59<OMS cd="polyd1" name="DMP"/>60<OMA id="polyring0LqlkhnCyLldcoBl" >61<OMS cd="polyd1" name="poly_ring_d_named"/>62<OMS cd="setname1" name="Q"/>63<OMV name="x"/>64</OMA>65<OMA>66<OMS cd="polyd1" name="SDMP"/>67<OMA>68<OMS cd="polyd1" name="term"/>69<OMI>1</OMI>70<OMI>1</OMI>71</OMA>72<OMA>73<OMS cd="polyd1" name="term"/>74<OMI>1</OMI>75<OMI>0</OMI>76</OMA>77</OMA>78</OMA>79</OMOBJ>80]]>81</Log>82Thus, the warning means that it is not guaranteed that the polynomial ring83will have the same identifier <C><OMA id="polyring..." ></C> when84another or same polynomial from this ring will be printed next time.85If this may constitute a problem, for example, if a list of polynomial86is being exchanged with another system and it is crucial that all of87them will belong to the same ring, then such ring must be created88explicitly and then <C>SetOpenMathDefaultPolynomialRing</C> must be89called:90<Log>91<![CDATA[92gap> x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;93gap> R:=PolynomialRing(Rationals,[x,y]);;94gap> SetOpenMathDefaultPolynomialRing(R);95gap> OMPrint(x^2+y);96<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">97<OMA>98<OMS cd="polyd1" name="DMP"/>99<OMA id="polyring9eNcBGFHXkjl2kWh" >100<OMS cd="polyd1" name="poly_ring_d"/>101<OMS cd="setname1" name="Q"/>102<OMI>2</OMI>103</OMA>104<OMA>105<OMS cd="polyd1" name="SDMP"/>106<OMA>107<OMS cd="polyd1" name="term"/>108<OMI>1</OMI>109<OMI>0</OMI>110<OMI>0</OMI>111</OMA>112<OMA>113<OMS cd="polyd1" name="term"/>114<OMI>1</OMI>115<OMI>0</OMI>116<OMI>0</OMI>117</OMA>118</OMA>119</OMA>120</OMOBJ>121]]>122</Log>123Now we can see that both polynomials belong to the ring with the same124identifier, and the &OpenMath; representation of the 2nd polynomial125properly reflects that it belongs to a polynomial ring with two variables.126<Log>127<![CDATA[128gap> OMPrint(x+1);129<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">130<OMA>131<OMS cd="polyd1" name="DMP"/>132<OMR href="#polyring9eNcBGFHXkjl2kWh" />133<OMA>134<OMS cd="polyd1" name="SDMP"/>135<OMA>136<OMS cd="polyd1" name="term"/>137<OMI>1</OMI>138<OMI>0</OMI>139<OMI>0</OMI>140</OMA>141<OMA>142<OMS cd="polyd1" name="term"/>143<OMI>1</OMI>144<OMI>0</OMI>145<OMI>0</OMI>146</OMA>147</OMA>148</OMA>149</OMOBJ>150]]>151</Log>152153<#Include Label="OMString">154155</Section>156157158<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->159160<Section Label="Reading OpenMath from streams">161<Heading>Reading &OpenMath; code from streams and strings</Heading>162163<#Include Label="OMGetObject">164<#Include Label="EvalOMString">165166</Section>167168169<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->170171<Section Label="Writing OpenMath to streams">172<Heading>Writing &OpenMath; code to streams</Heading>173174While it is possible to read &OpenMath; code directly from a stream,175writing &OpenMath; to streams uses a different setup. It requires176special objects called &OpenMath; <E>writers</E>, which encapsulate177streams and may be viewed as transducers accepting &GAP; objects and178writing them to a stream in the XML or binary &OpenMath;179<P/>180Such setup makes it possible to re-use the same stream for both binary181and XML &OpenMath; communication, using different &OpenMath; writers182in different calls. It also allows to re-use most of the high-level183code for &GAP; to &OpenMath; conversion, having separate methods for184generating binary and XML &OpenMath; only for low-level output185(&OpenMath; tags and basic objects). This makes easier adding support186to new mathematical objects and private content dictionaries as described187in Chapter <Ref Chap="ExtendingOpenMath"/> since it does not require188changing the low-level functionality.189<P/>190191<#Include Label="IsOpenMathWriter">192<#Include Label="OpenMathXMLWriter">193<#Include Label="OpenMathBinaryWriter">194<#Include Label="OMPutObject">195<#Include Label="OMPlainString">196197</Section>198199200<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->201202<Section Label="Utilities">203<Heading>Utilities</Heading>204205<#Include Label="OMTestXML">206<#Include Label="OMTestBinary">207208</Section>209210</Chapter>211212