forked from fricas/fricas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ituple.spad
104 lines (94 loc) · 4.31 KB
/
ituple.spad
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
)abbrev domain ITUPLE InfiniteTuple
++ Infinite tuples for the interpreter
++ Author: Clifton J. Williamson
++ Date Created: 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)]}.
stream : (S -> S, S) -> %
++ stream(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
stream(f, x) == stream(f, x)$Stream(S) pretend %
filterWhile(f, x) == filterWhile(f, x pretend Stream(S))$Stream(S) pretend %
filterUntil(f, x) == filterUntil(f, x pretend Stream(S))$Stream(S) pretend %
select(f, x) == select(f, x pretend Stream(S))$Stream(S) pretend %
construct x == x pretend Stream(S)
-- coerce x ==
-- coerce(x)$Stream(S)
)abbrev package ITFUN2 InfiniteTupleFunctions2
++ Functions defined on streams with entries in two sets.
InfiniteTupleFunctions2(A : Type, B : Type) : Exports == Implementation where
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)
)abbrev package ITFUN3 InfiniteTupleFunctions3
++ Functions defined on streams with entries in three sets.
InfiniteTupleFunctions3(A : Type, B : Type, C : Type) : Exports
== Implementation where
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
--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.