Feature #1243
New function: Read a string into a list (of RingElem) -- CoCoA-5
Description
Ange asked whether it would be possible to have a function like ReadExpr
but which reads a list of ringelem (or a list of lists of ringelem).
Is this a good idea? Is it feasible?
Discuss, and possibly implement.
2020-02 The function is called RingElems.
Example: RingElems(R, "x-1, y^3-2, x*z")
Related issues
History
#1 Updated by John Abbott about 5 years ago
Presumably the list syntax should be the same as what CoCoA prints: ","-separated entries inside square brackets [].
An empty list is allowed.
Ange has a workaround: she has changed the input so that it is simply a succession of polynomials (one per line), with a zero polynomial to mark the end of the list.
#2 Updated by Anna Maria Bigatti about 5 years ago
I admit I would have found this useful in a number of occasions.
I had followed the same workaround as Ange...
#3 Updated by John Abbott about 5 years ago
- Status changed from New to In Progress
- % Done changed from 0 to 10
- in the current (prototype) implementation the natural way to read inputs is line-by-line; this could be awkward if the input is split over several lines?
- a nice "modular" design would be to have a function which reads just strings, and then another which takes a string and splits it into pieces; BUT this means that the function which splits the string into pieces needs to know how to "parse" the string (and this could be tricky). Consider this example
[x+y, a[1,2], [[[a[2,1]]]]]
- a special function which reads a list-of-ringelem should solve the parsing problem (but it is rather an ad hoc approach); would we also want a function which reads list-of-list-of-ringelem?
- is it reasonable to force external programs to use the CoCoA-5 syntax for lists?
- what happens if the sender forgets the close square-bracket at the end of the list? The receiver would keep on waiting for more input. This seems to be a problem whatever system we adopt: how to handle truncated input?
- It might be nice for the receiver to read first the number of values in the list, and then read the values one-by-one...?
#4 Updated by John Abbott about 5 years ago
After lunch (rather disappointing fish-and-chips in the mensa), I now think that trying to impose a "list syntax" is not a good idea. The main reason is that we must write a parser (how?), and we must handle syntax errors (tedious).
It should be easy to write a function for reading a list, perhaps something like this:
define ReadListOfRingElem(Istream, R, EndMarker) ans := []; repeat str := GetLine(Istream); if str = EndMarker then return ans; endif; append(ref ans, RingElem(R, str)); endrepeat; enddefine;
Maybe we could make the string "00"
a default end marker? Does it even make sense to have a default?
#5 Updated by Anna Maria Bigatti about 5 years ago
- Assignee set to Anna Maria Bigatti
- % Done changed from 10 to 30
John Abbott wrote:
After lunch (rather disappointing fish-and-chips in the mensa), I now think that trying to impose a "list syntax" is not a good idea. The main reason is that we must write a parser (how?), and we must handle syntax errors (tedious).
True.
I was thinking of just [ , , , ]
(in CoCoALib)
but indeed, that's very tedious.
In CoCoALib we also have ReadExprSemicolon
which we may export to CoCoA.
And I think a function to read a sequence of polys would be very useful in CoCoALib too.
So I should do this in CoCoALib (RingElemInput.C
).
It should be easy to write a function for reading a list, perhaps something like this:
[...]
I'll think about this.
Maybe we could make the string
"00"
a default end marker? Does it even make sense to have a default?
Better no default, I think. Might induce in errors.
#6 Updated by John Abbott about 5 years ago
At the moment, input is only via GetLine
, which naturally reads a whole line as a string.
Currently we cannot easily handle the case where a single ringlem is spread over several lines, or if there are several ringelems in one line.
Consider these examples:
How many ringelems are here?
x+y -z
How many ringelems are here?
x -y -z
#7 Updated by John Abbott about 5 years ago
ReadExprSemicolon
in reserve, and adopting a KISS approach now:
- KISS the ringelems must be written exactly one per line (effectively "newline" functions as "semicolon")
- the advantage of
ReadExprSemicolon
is that lines and ringelems are essentially independent (one ringelem may span several lines, and one line may contain (parts of) several ringelems) - if we do choose to use
ReadExprSemicolon
, I would suggest changing its name and allowing the user to specify what terminating character to expect (with some restrictons, probably)
#8 Updated by John Abbott over 4 years ago
- Related to Feature #1332: New function: vector of RingElem from string -- in CoCoALib added
#9 Updated by Anna Maria Bigatti over 4 years ago
- Target version changed from CoCoA-5.?.? to CoCoA-5.3.0
- % Done changed from 30 to 50
I think I've done it. ... after lots of tedious little mistakes!
Called ReadExprVector(ring, string)
in RingElemInput.[CH]
Now testing and applying where useful for CoCoA-5, then we can think of a good name...
#10 Updated by Anna Maria Bigatti over 4 years ago
- Related to Feature #1330: New syntax for NewQuotientRing added
#11 Updated by Anna Maria Bigatti over 4 years ago
- Related to Feature #1329: New syntax for creating homomorphisms (PolyAlgebraHom) added
#12 Updated by Anna Maria Bigatti over 4 years ago
- Subject changed from Read a string into a list (of RingElem) to New function: Read a string into a list (of RingElem) -- CoCoA-5
#13 Updated by Anna Maria Bigatti over 4 years ago
- Related to deleted (Feature #1330: New syntax for NewQuotientRing)
#14 Updated by Anna Maria Bigatti over 4 years ago
- Related to deleted (Feature #1329: New syntax for creating homomorphisms (PolyAlgebraHom))
#15 Updated by John Abbott over 4 years ago
- Related to Slug #1238: ReadExpr is too slow on long lists of monomial with many indets: ---> use RingElems instead added
#16 Updated by Anna Maria Bigatti over 4 years ago
For the moment called (also in CoCoA) ReadExprVector(ring, string)
.
Example ReadExprVector(R, "x-1, y^3-2, x*z")
Think of a good name fast!
#17 Updated by Anna Maria Bigatti over 4 years ago
reminder: choose name and write doc for cocoa-5
#18 Updated by Anna Maria Bigatti over 4 years ago
- Status changed from In Progress to Resolved
- % Done changed from 50 to 60
what about RingElems(ring, string)
?
Similar to RingElem(ring, string)
... or too similar?
One thing I do not like of BlaBlaVector
is that in CoCoA-5 it should be BlaBlaList
.
#19 Updated by John Abbott over 4 years ago
One "advantage" of BlaBlaVector
and BlaBlaList
is that it help reminds the programmer that indices in the first case start from 0, and in the second case start from 1. Of course, the parts of code which much be changed to get the indices right are almost certainly not the lines in which BlaBlaVector
appears... :-/
It could also be that the interface in C++ is a bit different. For example, it may be more convenient in C++ to read a succession of values from a stringstream
rather than read them all in one go into a vector (not too sure about this, but it should be considered).
#20 Updated by Anna Maria Bigatti over 4 years ago
- Related to Design #1391: RingElems: syntax with [ and ] ? added
#21 Updated by Anna Maria Bigatti over 4 years ago
As discussed in #1931, there are now two functions:
(A) RingElems(RING, STRING)
example RingElems(P, "x*y,z")
and
(B) RingElemList(RING, STRING)
example RingElems(P, "[x*y,z]")
I prefer (A) and it is also implemented in cocoalib.
Not yet documented (neither)
#22 Updated by Anna Maria Bigatti about 4 years ago
- % Done changed from 60 to 80
I prefer A, John prefers B, so we'll have them both.
Write documentation.
#23 Updated by Anna Maria Bigatti about 4 years ago
- Status changed from Resolved to Feedback
- % Done changed from 80 to 90
- Estimated time set to 5.00 h
#24 Updated by Anna Maria Bigatti about 4 years ago
- Description updated (diff)
- Status changed from Feedback to Closed
- % Done changed from 90 to 100
#25 Updated by Anna Maria Bigatti about 4 years ago
documented