CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Views: 418346
1
<Chapter Label="OpenMathFunctionality">
2
<Heading>&OpenMath; functionality in &GAP;</Heading>
3
4
5
<Section Label="ViewOpenMath">
6
<Heading>Viewing &OpenMath; representation of an object</Heading>
7
8
<#Include Label="OMPrint">
9
10
Producing &OpenMath; representation of polynomials, one may get a warning:
11
12
<Log>
13
<![CDATA[
14
gap> x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;
15
gap> OMPrint(x^2+y);
16
#I Warning : polynomial will be printed using its default ring
17
#I because the default OpenMath polynomial ring is not specified
18
#I or it is not contained in the default OpenMath polynomial ring.
19
#I You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.
20
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
21
<OMA>
22
<OMS cd="polyd1" name="DMP"/>
23
<OMA id="polyring9qiY2oOaiITWUORb" >
24
<OMS cd="polyd1" name="poly_ring_d"/>
25
<OMS cd="setname1" name="Q"/>
26
<OMI>2</OMI>
27
</OMA>
28
<OMA>
29
<OMS cd="polyd1" name="SDMP"/>
30
<OMA>
31
<OMS cd="polyd1" name="term"/>
32
<OMI>1</OMI>
33
<OMI>0</OMI>
34
<OMI>1</OMI>
35
</OMA>
36
<OMA>
37
<OMS cd="polyd1" name="term"/>
38
<OMI>1</OMI>
39
<OMI>2</OMI>
40
<OMI>0</OMI>
41
</OMA>
42
</OMA>
43
</OMA>
44
</OMOBJ>
45
]]>
46
</Log>
47
Indeed, now when another polynomial will be printed, it will belong to a
48
ring with a different identifier (despite &GAP; will be able to perform
49
arithmetical operations on these polynomials like when they belong to the
50
same ground ring):
51
<Log>
52
<![CDATA[
53
gap> OMPrint(x+1);
54
#I Warning : polynomial will be printed using its default ring
55
#I because the default OpenMath polynomial ring is not specified
56
#I or it is not contained in the default OpenMath polynomial ring.
57
#I You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.
58
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
59
<OMA>
60
<OMS cd="polyd1" name="DMP"/>
61
<OMA id="polyring0LqlkhnCyLldcoBl" >
62
<OMS cd="polyd1" name="poly_ring_d_named"/>
63
<OMS cd="setname1" name="Q"/>
64
<OMV name="x"/>
65
</OMA>
66
<OMA>
67
<OMS cd="polyd1" name="SDMP"/>
68
<OMA>
69
<OMS cd="polyd1" name="term"/>
70
<OMI>1</OMI>
71
<OMI>1</OMI>
72
</OMA>
73
<OMA>
74
<OMS cd="polyd1" name="term"/>
75
<OMI>1</OMI>
76
<OMI>0</OMI>
77
</OMA>
78
</OMA>
79
</OMA>
80
</OMOBJ>
81
]]>
82
</Log>
83
Thus, the warning means that it is not guaranteed that the polynomial ring
84
will have the same identifier <C>&lt;OMA id="polyring..." ></C> when
85
another or same polynomial from this ring will be printed next time.
86
If this may constitute a problem, for example, if a list of polynomial
87
is being exchanged with another system and it is crucial that all of
88
them will belong to the same ring, then such ring must be created
89
explicitly and then <C>SetOpenMathDefaultPolynomialRing</C> must be
90
called:
91
<Log>
92
<![CDATA[
93
gap> x:=Indeterminate(Rationals,"x");; y:=Indeterminate(Rationals,"y");;
94
gap> R:=PolynomialRing(Rationals,[x,y]);;
95
gap> SetOpenMathDefaultPolynomialRing(R);
96
gap> OMPrint(x^2+y);
97
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
98
<OMA>
99
<OMS cd="polyd1" name="DMP"/>
100
<OMA id="polyring9eNcBGFHXkjl2kWh" >
101
<OMS cd="polyd1" name="poly_ring_d"/>
102
<OMS cd="setname1" name="Q"/>
103
<OMI>2</OMI>
104
</OMA>
105
<OMA>
106
<OMS cd="polyd1" name="SDMP"/>
107
<OMA>
108
<OMS cd="polyd1" name="term"/>
109
<OMI>1</OMI>
110
<OMI>0</OMI>
111
<OMI>0</OMI>
112
</OMA>
113
<OMA>
114
<OMS cd="polyd1" name="term"/>
115
<OMI>1</OMI>
116
<OMI>0</OMI>
117
<OMI>0</OMI>
118
</OMA>
119
</OMA>
120
</OMA>
121
</OMOBJ>
122
]]>
123
</Log>
124
Now we can see that both polynomials belong to the ring with the same
125
identifier, and the &OpenMath; representation of the 2nd polynomial
126
properly reflects that it belongs to a polynomial ring with two variables.
127
<Log>
128
<![CDATA[
129
gap> OMPrint(x+1);
130
<OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0">
131
<OMA>
132
<OMS cd="polyd1" name="DMP"/>
133
<OMR href="#polyring9eNcBGFHXkjl2kWh" />
134
<OMA>
135
<OMS cd="polyd1" name="SDMP"/>
136
<OMA>
137
<OMS cd="polyd1" name="term"/>
138
<OMI>1</OMI>
139
<OMI>0</OMI>
140
<OMI>0</OMI>
141
</OMA>
142
<OMA>
143
<OMS cd="polyd1" name="term"/>
144
<OMI>1</OMI>
145
<OMI>0</OMI>
146
<OMI>0</OMI>
147
</OMA>
148
</OMA>
149
</OMA>
150
</OMOBJ>
151
]]>
152
</Log>
153
154
<#Include Label="OMString">
155
156
</Section>
157
158
159
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
160
161
<Section Label="Reading OpenMath from streams">
162
<Heading>Reading &OpenMath; code from streams and strings</Heading>
163
164
<#Include Label="OMGetObject">
165
<#Include Label="EvalOMString">
166
167
</Section>
168
169
170
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
171
172
<Section Label="Writing OpenMath to streams">
173
<Heading>Writing &OpenMath; code to streams</Heading>
174
175
While it is possible to read &OpenMath; code directly from a stream,
176
writing &OpenMath; to streams uses a different setup. It requires
177
special objects called &OpenMath; <E>writers</E>, which encapsulate
178
streams and may be viewed as transducers accepting &GAP; objects and
179
writing them to a stream in the XML or binary &OpenMath;
180
<P/>
181
Such setup makes it possible to re-use the same stream for both binary
182
and XML &OpenMath; communication, using different &OpenMath; writers
183
in different calls. It also allows to re-use most of the high-level
184
code for &GAP; to &OpenMath; conversion, having separate methods for
185
generating binary and XML &OpenMath; only for low-level output
186
(&OpenMath; tags and basic objects). This makes easier adding support
187
to new mathematical objects and private content dictionaries as described
188
in Chapter <Ref Chap="ExtendingOpenMath"/> since it does not require
189
changing the low-level functionality.
190
<P/>
191
192
<#Include Label="IsOpenMathWriter">
193
<#Include Label="OpenMathXMLWriter">
194
<#Include Label="OpenMathBinaryWriter">
195
<#Include Label="OMPutObject">
196
<#Include Label="OMPlainString">
197
198
</Section>
199
200
201
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
202
203
<Section Label="Utilities">
204
<Heading>Utilities</Heading>
205
206
<#Include Label="OMTestXML">
207
<#Include Label="OMTestBinary">
208
209
</Section>
210
211
</Chapter>
212