aboutsummaryrefslogtreecommitdiff
path: root/src/algebra/ituple.spad.pamphlet
blob: 2babee588718c87b8905b0724b9fe5ddad86fc2a (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
\documentclass{article}
\usepackage{open-axiom}
\begin{document}
\title{src/algebra ituple.spad}
\author{Clifton J. Williamson}
\maketitle

\begin{abstract}
\end{abstract}
\tableofcontents
\eject

\section{domain ITUPLE InfiniteTuple}

<<domain ITUPLE InfiniteTuple>>=
import Type
import CoercibleTo OutputForm
import Boolean
import Stream
)abbrev domain ITUPLE InfiniteTuple
++ Infinite tuples for the interpreter
++ Author: Clifton J. Williamson
++ Date Created: 16 February 1990
++ Date Last Updated: 16 February 1990
++ Keywords:
++ Examples:
++ References:
InfiniteTuple(S:Type): Exports == Implementation where
  ++ This package implements 'infinite tuples' for the interpreter.
  ++ The representation is a stream.

  Exports ==> CoercibleTo OutputForm with
    map: (S -> S, %) -> %
      ++ map(f,t) replaces the tuple t
      ++ by \spad{[f(x) for x in t]}.
    filterWhile: (S -> Boolean, %) -> %
      ++ filterWhile(p,t) returns \spad{[x for x in t while p(x)]}.
    filterUntil: (S -> Boolean, %) -> %
      ++ filterUntil(p,t) returns \spad{[x for x in t while not p(x)]}.
    select: (S -> Boolean, %) -> %
      ++ select(p,t) returns \spad{[x for x in t | p(x)]}.
    generate: (S -> S,S) -> %
      ++ generate(f,s) returns \spad{[s,f(s),f(f(s)),...]}.
    construct: % -> Stream S
      ++ construct(t) converts an infinite tuple to a stream.

  Implementation ==> Stream S add
    generate(f,x) == per generate(f,x)$Stream(S)
    filterWhile(f, x) == per filterWhile(f,rep x)$Stream(S)
    filterUntil(f, x) == per filterUntil(f,rep x)$Stream(S)
    select(f, x) == per select(f,rep x)$Stream(S)
    construct x == rep x

@

\section{package ITFUN2 InfiniteTupleFunctions2}

<<package ITFUN2 InfiniteTupleFunctions2>>=
import Type
import InfiniteTuple
import Stream
)abbrev package ITFUN2 InfiniteTupleFunctions2
InfiniteTupleFunctions2(A:Type,B:Type): Exports == Implementation where
  ++ Functions defined on streams with entries in two sets.
  IT   ==> InfiniteTuple

  Exports ==> with
    map: ((A -> B),IT A) -> IT B
      ++ \spad{map(f,[x0,x1,x2,...])} returns \spad{[f(x0),f(x1),f(x2),..]}.

  Implementation ==> add

    map(f,x) ==
      map(f,x pretend Stream(A))$StreamFunctions2(A,B) pretend IT(B)

@

\section{package ITFUN3 InfiniteTupleFunctions3}

<<package ITFUN3 InfiniteTupleFunctions3>>=
import Type
import InfiniteTuple
import Stream
)abbrev package ITFUN3 InfiniteTupleFunctions3
InfiniteTupleFunctions3(A:Type, B:Type,C:Type): Exports
 == Implementation where
   ++ Functions defined on streams with entries in two sets.
   IT   ==> InfiniteTuple
   ST   ==> Stream
   SF3  ==> StreamFunctions3(A,B,C)
   FUN  ==> ((A,B)->C)
   Exports ==> with
     map: (((A,B)->C), IT A, IT B) -> IT C
	++ map(f,a,b) \undocumented
     map: (((A,B)->C), ST A, IT B) -> ST C
	++ map(f,a,b) \undocumented
     map: (((A,B)->C), IT A, ST B) -> ST C
	++ map(f,a,b) \undocumented

   Implementation ==> add

     map(f:FUN, s1:IT A, s2:IT B):IT C ==
       map(f, s1 pretend Stream(A), s2 pretend Stream(B))$SF3 pretend IT(C)
     map(f:FUN, s1:ST A, s2:IT B):ST C ==
       map(f, s1, s2 pretend Stream(B))$SF3
     map(f:FUN, s1:IT A, s2:ST B):ST C ==
       map(f, s1 pretend Stream(A), s2)$SF3

@

\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 ITUPLE InfiniteTuple>>
<<package ITFUN2 InfiniteTupleFunctions2>>
<<package ITFUN3 InfiniteTupleFunctions3>>
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}