aboutsummaryrefslogtreecommitdiff
path: root/src/algebra/omdev.spad.pamphlet
blob: ea5dd518425126cb6e941486d2953d923ff0f85f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/algebra omdev.spad}
\author{Vilya Harvey}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{domain OMENC OpenMathEncoding}
<<domain OMENC OpenMathEncoding>>=
)abbrev domain OMENC OpenMathEncoding
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions: 
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description:
++ \spadtype{OpenMathEncoding} is the set of valid OpenMath encodings.
OpenMathEncoding(): SetCategory with
  OMencodingUnknown : () -> %
  ++ OMencodingUnknown() is the constant for unknown encoding types. If this 
  ++ is used on an input device, the encoding will be autodetected.
  ++ It is invalid to use it on an output device.
  OMencodingXML     : () -> %
  ++ OMencodingXML() is the constant for the OpenMath XML encoding.
  OMencodingSGML    : () -> %
  ++ OMencodingSGML() is the constant for the deprecated OpenMath SGML encoding.
  OMencodingBinary  : () -> %
  ++ OMencodingBinary() is the constant for the OpenMath binary encoding.
 == add
  Rep := SingleInteger

  =(u,v) == (u=v)$Rep

  import Rep

  coerce(u) ==
    u::Rep = 0$Rep => "Unknown"::OutputForm
    u::Rep = 1$Rep => "Binary"::OutputForm
    u::Rep = 2::Rep => "XML"::OutputForm
    u::Rep = 3::Rep => "SGML"::OutputForm
    error "Bogus OpenMath Encoding Type"

  OMencodingUnknown(): % == 0::Rep
  OMencodingBinary(): % == 1::Rep
  OMencodingXML(): % == 2::Rep
  OMencodingSGML(): % == 3::Rep

@
\section{domain OMDEV OpenMathDevice}
<<domain OMDEV OpenMathDevice>>=
import Void
import String
import Integer
import DoubleFloat
import String
import Symbol
import OpenMathEncoding
)abbrev domain OMDEV OpenMathDevice
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: \spadtype{OpenMathDevice} provides support for reading
++ and writing openMath objects to files, strings etc.  It also provides
++ access to low-level operations from within the interpreter.


OpenMathDevice(): with
  OMopenFile    : (String, String, OpenMathEncoding) -> %
  ++ OMopenFile(f,mode,enc) opens file \axiom{f} for reading or writing
  ++ OpenMath objects (depending on \axiom{mode} which can be "r", "w"
  ++ or "a" for read, write and append respectively), in the encoding
  ++ \axiom{enc}.
  OMopenString  : (String, OpenMathEncoding) -> %
  ++ OMopenString(s,mode) opens the string \axiom{s} for reading or writing 
  ++ OpenMath objects in encoding \axiom{enc}.
  OMclose       : % -> Void
  ++ OMclose(dev) closes \axiom{dev}, flushing output if necessary.
  OMsetEncoding : (%, OpenMathEncoding) -> Void
  ++ OMsetEncoding(dev,enc) sets the encoding used for reading or writing
  ++ OpenMath objects to or from \axiom{dev} to \axiom{enc}.
  OMputApp      : % -> Void
  ++ OMputApp(dev) writes a begin application token to \axiom{dev}.
  OMputAtp      : % -> Void
  ++ OMputAtp(dev) writes a begin attribute pair token to \axiom{dev}.
  OMputAttr     : % -> Void
  ++ OMputAttr(dev) writes a begin attribute token to \axiom{dev}.
  OMputBind     : % -> Void
  ++ OMputBind(dev) writes a begin binder token to \axiom{dev}.
  OMputBVar     : % -> Void
  ++ OMputBVar(dev) writes a begin bound variable list token to \axiom{dev}.
  OMputError    : % -> Void
  ++ OMputError(dev) writes a begin error token to \axiom{dev}.
  OMputObject   : % -> Void
  ++ OMputObject(dev) writes a begin object token to \axiom{dev}.
  OMputEndApp   : % -> Void
  ++ OMputEndApp(dev) writes an end application token to \axiom{dev}.
  OMputEndAtp   : % -> Void
  ++ OMputEndAtp(dev) writes an end attribute pair token to \axiom{dev}.
  OMputEndAttr  : % -> Void
  ++ OMputEndAttr(dev) writes an end attribute token to \axiom{dev}.
  OMputEndBind  : % -> Void
  ++ OMputEndBind(dev) writes an end binder token to \axiom{dev}.
  OMputEndBVar  : % -> Void
  ++ OMputEndBVar(dev) writes an end bound variable list token to \axiom{dev}.
  OMputEndError : % -> Void
  ++ OMputEndError(dev) writes an end error token to \axiom{dev}.
  OMputEndObject: % -> Void
  ++ OMputEndObject(dev) writes an end object token to \axiom{dev}.
  OMputInteger  : (%, Integer) -> Void
  ++ OMputInteger(dev,i) writes the integer \axiom{i} to \axiom{dev}.
  OMputFloat    : (%, DoubleFloat) -> Void
  ++ OMputFloat(dev,i) writes the float \axiom{i} to \axiom{dev}.
  OMputVariable : (%, Symbol) -> Void
  ++ OMputVariable(dev,i) writes the variable \axiom{i} to \axiom{dev}.
  OMputString   : (%, String) -> Void
  ++ OMputString(dev,i) writes the string \axiom{i} to \axiom{dev}.
  OMputSymbol   : (%, String, String) -> Void
  ++ OMputSymbol(dev,cd,s) writes the symbol \axiom{s} from CD \axiom{cd}
  ++ to \axiom{dev}.

  OMgetApp      : % -> Void
  ++ OMgetApp(dev) reads a begin application token from \axiom{dev}.
  OMgetAtp      : % -> Void
  ++ OMgetAtp(dev) reads a begin attribute pair token from \axiom{dev}.
  OMgetAttr     : % -> Void
  ++ OMgetAttr(dev) reads a begin attribute token from \axiom{dev}.
  OMgetBind     : % -> Void
  ++ OMgetBind(dev) reads a begin binder token from \axiom{dev}.
  OMgetBVar     : % -> Void
  ++ OMgetBVar(dev) reads a begin bound variable list token from \axiom{dev}.
  OMgetError    : % -> Void
  ++ OMgetError(dev) reads a begin error token from \axiom{dev}.
  OMgetObject   : % -> Void
  ++ OMgetObject(dev) reads a begin object token from \axiom{dev}.
  OMgetEndApp   : % -> Void
  ++ OMgetEndApp(dev) reads an end application token from \axiom{dev}.
  OMgetEndAtp   : % -> Void
  ++ OMgetEndAtp(dev) reads an end attribute pair token from \axiom{dev}.
  OMgetEndAttr  : % -> Void
  ++ OMgetEndAttr(dev) reads an end attribute token from \axiom{dev}.
  OMgetEndBind  : % -> Void
  ++ OMgetEndBind(dev) reads an end binder token from \axiom{dev}.
  OMgetEndBVar  : % -> Void
  ++ OMgetEndBVar(dev) reads an end bound variable list token from \axiom{dev}.
  OMgetEndError : % -> Void
  ++ OMgetEndError(dev) reads an end error token from \axiom{dev}.
  OMgetEndObject: % -> Void
  ++ OMgetEndObject(dev) reads an end object token from \axiom{dev}.
  OMgetInteger  : % -> Integer
  ++ OMgetInteger(dev) reads an integer from \axiom{dev}.
  OMgetFloat    : % -> DoubleFloat
  ++ OMgetFloat(dev) reads a float from \axiom{dev}.
  OMgetVariable : % -> Symbol
  ++ OMgetVariable(dev) reads a variable from \axiom{dev}.
  OMgetString   : % -> String
  ++ OMgetString(dev) reads a string from \axiom{dev}.
  OMgetSymbol   : % -> Record(cd:String, name:String)
  ++ OMgetSymbol(dev) reads a symbol from \axiom{dev}.

  OMgetType     : % -> Symbol
  ++ OMgetType(dev) returns the type of the next object on \axiom{dev}.
 == add
  OMopenFile(fname: String, fmode: String, enc: OpenMathEncoding): % ==
    OM_-OPENFILEDEV(fname, fmode, enc)$Lisp
  OMopenString(str: String, enc: OpenMathEncoding): % ==
    OM_-OPENSTRINGDEV(str, enc)$Lisp
  OMclose(dev: %): Void ==
    OM_-CLOSEDEV(dev)$Lisp
  OMsetEncoding(dev: %, enc: OpenMathEncoding): Void ==
    OM_-SETDEVENCODING(dev, enc)$Lisp

  OMputApp(dev: %): Void == OM_-PUTAPP(dev)$Lisp
  OMputAtp(dev: %): Void == OM_-PUTATP(dev)$Lisp
  OMputAttr(dev: %): Void == OM_-PUTATTR(dev)$Lisp
  OMputBind(dev: %): Void == OM_-PUTBIND(dev)$Lisp
  OMputBVar(dev: %): Void == OM_-PUTBVAR(dev)$Lisp
  OMputError(dev: %): Void == OM_-PUTERROR(dev)$Lisp
  OMputObject(dev: %): Void == OM_-PUTOBJECT(dev)$Lisp
  OMputEndApp(dev: %): Void == OM_-PUTENDAPP(dev)$Lisp
  OMputEndAtp(dev: %): Void == OM_-PUTENDATP(dev)$Lisp
  OMputEndAttr(dev: %): Void == OM_-PUTENDATTR(dev)$Lisp
  OMputEndBind(dev: %): Void == OM_-PUTENDBIND(dev)$Lisp
  OMputEndBVar(dev: %): Void == OM_-PUTENDBVAR(dev)$Lisp
  OMputEndError(dev: %): Void == OM_-PUTENDERROR(dev)$Lisp
  OMputEndObject(dev: %): Void == OM_-PUTENDOBJECT(dev)$Lisp
  OMputInteger(dev: %, i: Integer): Void == OM_-PUTINT(dev, i)$Lisp
  OMputFloat(dev: %, f: DoubleFloat): Void == OM_-PUTFLOAT(dev, f)$Lisp
  --OMputByteArray(dev: %, b: Array Byte): Void == OM_-PUTBYTEARRAY(dev, b)$Lisp
  OMputVariable(dev: %, v: Symbol): Void == OM_-PUTVAR(dev, v)$Lisp
  OMputString(dev: %, s: String): Void == OM_-PUTSTRING(dev, s)$Lisp
  OMputSymbol(dev: %, cd: String, nm: String): Void == OM_-PUTSYMBOL(dev, cd, nm)$Lisp

  OMgetApp(dev: %): Void == OM_-GETAPP(dev)$Lisp
  OMgetAtp(dev: %): Void == OM_-GETATP(dev)$Lisp
  OMgetAttr(dev: %): Void == OM_-GETATTR(dev)$Lisp
  OMgetBind(dev: %): Void == OM_-GETBIND(dev)$Lisp
  OMgetBVar(dev: %): Void == OM_-GETBVAR(dev)$Lisp
  OMgetError(dev: %): Void == OM_-GETERROR(dev)$Lisp
  OMgetObject(dev: %): Void == OM_-GETOBJECT(dev)$Lisp
  OMgetEndApp(dev: %): Void == OM_-GETENDAPP(dev)$Lisp
  OMgetEndAtp(dev: %): Void == OM_-GETENDATP(dev)$Lisp
  OMgetEndAttr(dev: %): Void == OM_-GETENDATTR(dev)$Lisp
  OMgetEndBind(dev: %): Void == OM_-GETENDBIND(dev)$Lisp
  OMgetEndBVar(dev: %): Void == OM_-GETENDBVAR(dev)$Lisp
  OMgetEndError(dev: %): Void == OM_-GETENDERROR(dev)$Lisp
  OMgetEndObject(dev: %): Void == OM_-GETENDOBJECT(dev)$Lisp
  OMgetInteger(dev: %): Integer == OM_-GETINT(dev)$Lisp
  OMgetFloat(dev: %): DoubleFloat == OM_-GETFLOAT(dev)$Lisp
  --OMgetByteArray(dev: %): Array Byte == OM_-GETBYTEARRAY(dev)$Lisp
  OMgetVariable(dev: %): Symbol == OM_-GETVAR(dev)$Lisp
  OMgetString(dev: %): String == OM_-GETSTRING(dev)$Lisp
  OMgetSymbol(dev: %): Record(cd:String, name:String) == OM_-GETSYMBOL(dev)$Lisp

  OMgetType(dev: %): Symbol == OM_-GETTYPE(dev)$Lisp

@
\section{domain OMCONN OpenMathConnection}
<<domain OMCONN OpenMathConnection>>=
import Void
import Boolean
import SingleInteger
import String
import OpenMathDevice
)abbrev domain OMCONN OpenMathConnection
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: \spadtype{OpenMathConnection} provides low-level functions
++ for handling connections to and from \spadtype{OpenMathDevice}s.


OpenMathConnection(): with
  OMmakeConn    : SingleInteger -> % ++ \spad{OMmakeConn}
  OMcloseConn   : % -> Void ++ \spad{OMcloseConn}
  OMconnInDevice: %-> OpenMathDevice ++ \spad{OMconnInDevice:}
  OMconnOutDevice: %-> OpenMathDevice ++ \spad{OMconnOutDevice:}
  OMconnectTCP  : (%, String, SingleInteger) -> Boolean ++ \spad{OMconnectTCP}
  OMbindTCP     : (%, SingleInteger) -> Boolean ++ \spad{OMbindTCP}
 == add
  OMmakeConn(timeout: SingleInteger): % == OM_-MAKECONN(timeout)$Lisp
  OMcloseConn(conn: %): Void == OM_-CLOSECONN(conn)$Lisp

  OMconnInDevice(conn: %): OpenMathDevice ==
    OM_-GETCONNINDEV(conn)$Lisp
  OMconnOutDevice(conn: %): OpenMathDevice ==
    OM_-GETCONNOUTDEV(conn)$Lisp

  OMconnectTCP(conn: %, host: String, port: SingleInteger): Boolean ==
    OM_-CONNECTTCP(conn, host, port)$Lisp
  OMbindTCP(conn: %, port: SingleInteger): Boolean ==
    OM_-BINDTCP(conn, port)$Lisp

@
\section{package OMPKG OpenMathPackage}
<<package OMPKG OpenMathPackage>>=
)abbrev package OMPKG OpenMathPackage
++ Author: Vilya Harvey
++ Date Created:
++ Date Last Updated:
++ Basic Functions:
++ Related Constructors:
++ Also See:
++ AMS Classifications:
++ Keywords:
++ References:
++ Description: \spadtype{OpenMathPackage} provides some simple utilities 
++ to make reading OpenMath objects easier.

OpenMathPackage(): with
  OMread            : OpenMathDevice -> Any
  ++ OMread(dev) reads an OpenMath object from \axiom{dev} and passes it
  ++ to AXIOM.
  OMreadFile        : String -> Any
  ++ OMreadFile(f) reads an OpenMath object from \axiom{f} and passes it
  ++ to AXIOM.
  OMreadStr         : String -> Any
  ++ OMreadStr(f) reads an OpenMath object from \axiom{f} and passes it
  ++ to AXIOM.
  OMlistCDs         : () -> List(String)
  ++ OMlistCDs() lists all the CDs supported by AXIOM.
  OMlistSymbols     : String -> List(String)
  ++ OMlistSymbols(cd) lists all the symbols in \axiom{cd}.
  OMsupportsCD?      : String -> Boolean
  ++ OMsupportsCD?(cd) returns true if AXIOM supports \axiom{cd}, false 
  ++ otherwise.
  OMsupportsSymbol? : (String, String) -> Boolean
  ++ OMsupportsSymbol?(s,cd) returns true if AXIOM supports symbol \axiom{s}
  ++ from CD \axiom{cd}, false otherwise.
  OMunhandledSymbol : (String, String) -> Exit
  ++ OMunhandledSymbol(s,cd) raises an error if AXIOM reads a symbol which it
  ++ is unable to handle.  Note that this is different from an unexpected
  ++ symbol.
 == add
  import OpenMathEncoding
  import OpenMathDevice
  import String

  OMunhandledSymbol(u,v) ==
    error concat ["AXIOM is unable to process the symbol ",u," from CD ",v,"."]

  OMread(dev: OpenMathDevice): Any ==
    interpret(OM_-READ(dev)$Lisp :: InputForm)

  OMreadFile(filename: String): Any ==
    dev := OMopenFile(filename, "r", OMencodingUnknown())
    res: Any := interpret(OM_-READ(dev)$Lisp :: InputForm)
    OMclose(dev)
    res

  OMreadStr(str: String): Any ==
    strp := OM_-STRINGTOSTRINGPTR(str)$Lisp
    dev := OMopenString(strp pretend String, OMencodingUnknown())
    res: Any := interpret(OM_-READ(dev)$Lisp :: InputForm)
    OMclose(dev)
    res

  OMlistCDs(): List(String) ==
    OM_-LISTCDS()$Lisp pretend List(String)

  OMlistSymbols(cd: String): List(String) ==
    OM_-LISTSYMBOLS(cd)$Lisp pretend List(String)

  import SExpression

  OMsupportsCD?(cd: String): Boolean ==
    not null? OM_-SUPPORTSCD(cd)$Lisp 

  OMsupportsSymbol?(cd: String, name: String): Boolean ==
    not null? OM_-SUPPORTSSYMBOL(cd, name)$Lisp

@
\section{License}
<<license>>=
--Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd.
--All rights reserved.
--
--Redistribution and use in source and binary forms, with or without
--modification, are permitted provided that the following conditions are
--met:
--
--    - Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    - Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in
--      the documentation and/or other materials provided with the
--      distribution.
--
--    - Neither the name of The Numerical ALgorithms Group Ltd. nor the
--      names of its contributors may be used to endorse or promote products
--      derived from this software without specific prior written permission.
--
--THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
--IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
--TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
--PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
--OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
--EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
--PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@
<<*>>=
<<license>>

<<domain OMENC OpenMathEncoding>>
<<domain OMDEV OpenMathDevice>>
<<domain OMCONN OpenMathConnection>>
<<package OMPKG OpenMathPackage>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}