On Fri, Feb 17, 2012 at 11:03:55AM +0100, Ralf Hemmecke wrote:
>> The matter is the aim:
>> to implement in Spad only one function (dParse):
>> fast parsing from a list of strings to an arbitrary domain
>> potentially built by a certain fixed finite set of constructors:
>> Integer, Fraction, Polynomial, ResidueRing, Vector, Matrix
>> (may be, 3-4 more).
>
> Well, if you start with the goal of just writing one function, then this
> is one of the rare cases where I would suggest to use Any.
>
> The reason for this suggestion lies in the way Any is implemented.
>
> https://github.com/hemmecke/fricas-svn/blob/master/src/algebra/any.spad.pamphlet#L106
>
> Rep := Record(dm: SExpression, ob: None)
> [..]
Thank you for explanation. I shall see.
> Since you actually will most probably send the strings from Haskell to
> FriCAS, I wonder whether it would be a good idea not to do it as a
> typeless string but rather prefix it with a type information string that
> can quickly be parsed. If there is no type information, it will have to
> be _guessed_ by FriCAS (which could be wrong).
>
> How much freedom do you have to prepare your list of strings before you
> send it to fricas?
The Haskell program can send strings like
"<domainDescription> [ <elemInputs> ]",
where
<domainDecription> is the the precise description of a type and
domain in Spad,
<elemInputs> is a sequence of the element inputs for this domain.
Examples: "(Fraction Integer) [1/2, -2/3, 3/4]"
"(Fraction (UP(x, Fraction Integer)) [<f1>/<f2>, <f1>/f3>]",
where <fi> = such and such strings.
But still <domainDecription> is only a String.
The dParse Spad function still needs to compute all domains from string,
without knowing initially which are these domains.
Currently, I tested "(I -2)",
"(Fr (I -2) (I 3)",
and it works. For example, dParse of the latter string yields
2
- --
3 Type: Fraction Integer
(BTW, I though that % + %^2 will work after this, never tried,
may be it would not?).
Seeing the tag "Fr", it knows that domain = Fraction D, where D
needs to be found further. Then, seeing "I", it finds that D = Integer,
and also applies parseInteger "-2".
And the found D1 := Fraction Integer is put to the result record.
The result record also has the value (-2/3) and the remaining lexemes
(dParse processes lexemes : List String).
Domain and its elements are parsed in the same process.
Also after D is defined from "(I -2)", this ready D is used in parsing
"(I 3)".
If the approach FDTE "first -- only domain, then -- its elements"
is better than this, I could apply it.
> I guess the FriCAS parser is not fast enough for you and that is the
> reason to create your own parser. Nevertheless you must end up in
> putting your parsed expression into some FriCAS domain, because
> otherwise you cannot use any function from FriCAS. Even if your result
> domain is "Expression(Integer)" there will then be need for routines
> that coerce your expression to DMP([x,y,z],FRAC INT) which may be
> costly, but are the only way to call concrete FriCAS functions. Note
> that everything in FriCAS is done in a "domain of computation" (domain
> for short). So you need a concrete domain to do the computation. How do
> you currently select this domain?
>
As above. In the above example, the domains Integer and
Fraction Integer are computed from the string "(Fr (I -2) (I 3)".
I am adding UP(x, D) to the syntax, and then shall test various
compositions of Integer, Fraction and UP.
I wonder in what way it will be stuck. And then I shall write a more
concrete report, and may be understand more of what you write above.
Thanks,
------
Sergei
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.