Sage ANC A Note on Coercion

Study the following sequence of commands, while cognizant of the failure to specify a number system for x.









None of this should be too much of a surprise, and the results should be what we would have expected. Though for x we never specified if 1, 2, 3 are integers, rationals, reals, complexes, or …? Let us dig a little deeper and examine the parents of the five vectors involved.













So x and u belong to something called an “ambient free module,” whatever that is. What is important here is that the parent of x uses the integers as its number system. How about u, v, y, w, z? All but the first has a parent that uses the rationals for its number system.

Three of the final four vectors are examples of a process that Sage calls “coercion.” Mathematical elements get converted to a new parent, as necessary, when the conversion is totally unambiguous. In the examples above:

The coercion above is automatic, but we can also usually force it to happen without employing an operation.











So the syntax is to use the name of the parent like a function and coerce the element into the new parent. This can fail if there is no natural way to make the conversion.





Coercion is one of the more mysterious aspects of Sage, and the above discussion may not be very clear the first time though. But if you get an error (like the one above) talking about coercion, you know to come back here and have another read through. For now, be sure to create all your vectors and matrices over QQ and you should not have any difficulties.