On 07.08.21 18:41, Neven Sajko wrote: > The title basically says it all. I am referring to the lack of > appropriate coerce or convert operations that make it impossible to > convert the simpler type to the more complex type with only :: in Spad > code.
The interpreter guesses what you want, when you type ::Polynomial(FRAC(INT)). The compiler isn't allowed to do that. So *you* must call the right function yourself. http://fricas.github.io/api/PolynomialFunctions2.html?highlight=polynomialfunctions (10) -> p := x+2*y*x+3*x*y*z (10) 3 x y z + 2 x y + x Type: Polynomial(Integer) (11) -> map(c+->c::FRAC(INT),p)$PolynomialFunctions2(INT, FRAC INT) (11) 3 x y z + 2 x y + x Type: Polynomial(Fraction(Integer)) > Also, the situation is the same with, e.g., UnivariatePolynomial (as > with Polynomial). For that I only know this package. http://fricas.github.io/api/PolynomialCategoryLifting.html?highlight=polynomialcategorylifting That's pretty generic and thus a bit difficult to apply. > I guess that it's possible to convert between polynomials with such > differing coefficient types by disassembling into coefficients, > converting coefficients, and then reassembling into a polynomial. But > why isn't this built into the library as a coerce or convert > operation? Simple answer. It is implemented as you see from the links above, but it is by nature of FriCAS not as simple as you would like it. Think about it. Suppose you want to write a function coerce: Polynomial R -> Polynomial S In order for this coerce to work nicely, it should either live in Polynomial(R) or Polynomial(S). OK, that means it should live in the code of the Polynomial constructor. But wait, the definition goes Polynomial(R: Ring): with ... == add ... Ooops. How would you specify the second type? You could do it this way: Polynomial(R: Ring): with ... coerce: (S: Ring) -> % -> Polynomial S ... == add ... coerce(S: Ring): % -> Polynomial S == (x: %): Polynomial S +-> -- here you program the conversion into Polynomial S But look closer at that definition. You are about to define the domain "Polynomial". Inside of it you use the constructor "Polynomial(S)". That's a recursive definition. And the above coerce has a dependent type, i.e., its result type depends on the input. Pretty involve, hey? So the original AXIOM developers chose to put that function into a package, with the consequence that it is quite a bit harder to call. > Also, how come that the interpreter has this functionality > automatically? How is it achieved in the interpreter? The interpreter is a magician. In order to understand how FriCAS works, do little steps with the compiler and learn explicitly what functions you have to call. When I started with AXIOM, I got quite frustrated when I translated my .input files into .spad files. You seem to be exactly at that stage. Yes, that's pretty frustrating, but you have been warned that the interpreter does some magic which you cannot rely on when you write .spad files. Hope that helps Ralf -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/af3d2e0d-9b16-9cb4-aaf5-dbd8138c313f%40hemmecke.org.
