oldk1331
2018-11-15 12:00:17 UTC
I try to make the meaning of 'children' accurate and consistent:
return value of 'children' should not contain empty aggregate.
diff --git a/ChangeLog b/ChangeLog
index cb3e6139..bd671a6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-15 Qian Yun <***@gmail.com>
+
+ * src/algebra/aggcat.spad, src/algebra/stream.spad,
+ src/algebra/tree.spad: fix 'children' in List, Stream and Tree
+
2018-11-14 Qian Yun <***@gmail.com>
* src/algebra/aggcat.spad: fix 'children' in BRAGG
diff --git a/src/algebra/aggcat.spad b/src/algebra/aggcat.spad
index e16526d6..f7cf5ecb 100644
--- a/src/algebra/aggcat.spad
+++ b/src/algebra/aggcat.spad
@@ -1054,13 +1054,14 @@
++ a directed graph containing values of type S.
++ Recursively, a recursive aggregate is either empty or a {\em node}
++ consisting of a \spadfun{value} from S and 0 or more \spadfun{children}
-++ which are recursive aggregates.
+++ which are also nodes.
++ A node with no children is called a \spadfun{leaf} node.
++ A recursive aggregate may be cyclic for which some operations as noted
++ may go into an infinite loop.
RecursiveAggregate(S : Type) : Category == HomogeneousAggregate(S) with
children : % -> List %
++ children(u) returns a list of the children of aggregate u.
+ ++ Returns \spad{empty()} if u is empty aggregate.
-- should be % -> %* and also needs children: % -> Iterator(S, S)
nodes : % -> List %
++ nodes(u) returns a list of all of the nodes of aggregate u.
@@ -1299,7 +1300,6 @@
++ A node with one children models a non-empty list, with the
++ \spadfun{value} of the list designating the head, or
\spadfun{first}, of the
++ list, and the child designating the tail, or \spadfun{rest}, of the
list.
-++ A node with no child then designates the empty list.
++ Since these aggregates are recursive aggregates, they may be cyclic.
UnaryRecursiveAggregate(S : Type) : Category == RecursiveAggregate S with
concat : (%, %) -> %
@@ -1421,7 +1421,7 @@
reverse! l
children x ==
- empty? x => empty()
+ empty? x or empty? rest x => empty()
[rest x]
leaf? x ==
diff --git a/src/algebra/stream.spad b/src/algebra/stream.spad
index 33cffce1..c21cc581 100644
--- a/src/algebra/stream.spad
+++ b/src/algebra/stream.spad
@@ -325,7 +325,7 @@
x = rst y
children x ==
- empty? x => error "children: no children"
+ empty? x or empty? rst x => empty()
[rst x]
distance(x, z) ==
diff --git a/src/algebra/tree.spad b/src/algebra/tree.spad
index c58aae21..213b20c1 100644
--- a/src/algebra/tree.spad
+++ b/src/algebra/tree.spad
@@ -42,7 +42,7 @@
empty() == ["empty"]
children t ==
- t case empty => error "cannot take the children of an empty tree"
+ t case empty => empty()
(t.node.args)@List(%)
setchildren!(t, lt) ==
t case empty => error "cannot set children of an empty tree"
diff --git a/src/input/bugs2018.input b/src/input/bugs2018.input
index e08adf3d..adfb8054 100644
--- a/src/input/bugs2018.input
+++ b/src/input/bugs2018.input
@@ -199,4 +199,12 @@
testTrue("empty? children binarySearchTree [1]")
+testcase "'children' in List, Stream and Tree"
+
+testTrue("empty? children [1]")
+
+testTrue("empty? children([1]@Stream Integer)")
+
+testTrue("empty? children(empty()$Tree Integer)")
+
statistics()
return value of 'children' should not contain empty aggregate.
diff --git a/ChangeLog b/ChangeLog
index cb3e6139..bd671a6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-15 Qian Yun <***@gmail.com>
+
+ * src/algebra/aggcat.spad, src/algebra/stream.spad,
+ src/algebra/tree.spad: fix 'children' in List, Stream and Tree
+
2018-11-14 Qian Yun <***@gmail.com>
* src/algebra/aggcat.spad: fix 'children' in BRAGG
diff --git a/src/algebra/aggcat.spad b/src/algebra/aggcat.spad
index e16526d6..f7cf5ecb 100644
--- a/src/algebra/aggcat.spad
+++ b/src/algebra/aggcat.spad
@@ -1054,13 +1054,14 @@
++ a directed graph containing values of type S.
++ Recursively, a recursive aggregate is either empty or a {\em node}
++ consisting of a \spadfun{value} from S and 0 or more \spadfun{children}
-++ which are recursive aggregates.
+++ which are also nodes.
++ A node with no children is called a \spadfun{leaf} node.
++ A recursive aggregate may be cyclic for which some operations as noted
++ may go into an infinite loop.
RecursiveAggregate(S : Type) : Category == HomogeneousAggregate(S) with
children : % -> List %
++ children(u) returns a list of the children of aggregate u.
+ ++ Returns \spad{empty()} if u is empty aggregate.
-- should be % -> %* and also needs children: % -> Iterator(S, S)
nodes : % -> List %
++ nodes(u) returns a list of all of the nodes of aggregate u.
@@ -1299,7 +1300,6 @@
++ A node with one children models a non-empty list, with the
++ \spadfun{value} of the list designating the head, or
\spadfun{first}, of the
++ list, and the child designating the tail, or \spadfun{rest}, of the
list.
-++ A node with no child then designates the empty list.
++ Since these aggregates are recursive aggregates, they may be cyclic.
UnaryRecursiveAggregate(S : Type) : Category == RecursiveAggregate S with
concat : (%, %) -> %
@@ -1421,7 +1421,7 @@
reverse! l
children x ==
- empty? x => empty()
+ empty? x or empty? rest x => empty()
[rest x]
leaf? x ==
diff --git a/src/algebra/stream.spad b/src/algebra/stream.spad
index 33cffce1..c21cc581 100644
--- a/src/algebra/stream.spad
+++ b/src/algebra/stream.spad
@@ -325,7 +325,7 @@
x = rst y
children x ==
- empty? x => error "children: no children"
+ empty? x or empty? rst x => empty()
[rst x]
distance(x, z) ==
diff --git a/src/algebra/tree.spad b/src/algebra/tree.spad
index c58aae21..213b20c1 100644
--- a/src/algebra/tree.spad
+++ b/src/algebra/tree.spad
@@ -42,7 +42,7 @@
empty() == ["empty"]
children t ==
- t case empty => error "cannot take the children of an empty tree"
+ t case empty => empty()
(t.node.args)@List(%)
setchildren!(t, lt) ==
t case empty => error "cannot set children of an empty tree"
diff --git a/src/input/bugs2018.input b/src/input/bugs2018.input
index e08adf3d..adfb8054 100644
--- a/src/input/bugs2018.input
+++ b/src/input/bugs2018.input
@@ -199,4 +199,12 @@
testTrue("empty? children binarySearchTree [1]")
+testcase "'children' in List, Stream and Tree"
+
+testTrue("empty? children [1]")
+
+testTrue("empty? children([1]@Stream Integer)")
+
+testTrue("empty? children(empty()$Tree Integer)")
+
statistics()
--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel+***@googlegroups.com.
To post to this group, send email to fricas-***@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.