# This is a file of SAGE commands to find the roots of a function that # appears in Mas-Colell, Whinston, and Green, Microeconomic Theory, # example 15.B.2, pp. 521. The code was proposed by William Stein # in September 2007 and updated by Mike Hansen in April 2008 to work with # SAGE version 2.11. The code can be read and executed in a SAGE session # by typing the following line: # load "MWG15b2.sage" # # RDF() is shorthand for RealDoubleField(), a function that converts its # argument into a real double-precision number. For example, RDF(pi/e) # returns 1.15572734979 and RDF(8^(2/3)-8^(1/3)) returns 2.0. # A polynomial ring is a set of polynomials with coefficients of a specified # type -- e.g., integers, rationals, or double-precision reals. # PolynomialRing() is a function that returns a polynomial ring with # properties determined by its arguments. The variable or variables can be # named and readied for use by listing them in diamond brackets following # the name assigned to the ring. For example, R. = PolynomialRing(RDF) # defines a univariate polynomial ring R in a variable y with real # double-precision coefficients. Similarly, P. = PolynomialRing(QQ,2) # defines a bivariate polynomial ring P in variables w and x with rational # coefficients. If f is a univariate polynomial, f.roots() is a vector. # If the elements of this vector are scalars, they are roots; if the elements # of the vector are ordered pairs, the left member of a pair is a root and # the right member is its multiplicity. To indicate which type of output is # desired we can specify f.roots(multiplicities=False) or # f.roots(multiplicities=True). The default option may vary from case to case. # In our case, the default is True, which means that f.roots() is a vector of # ordered pairs. The left member of each pair is indexed as 0, the right # member as 1. # # The function in example 15.B.2 is not a polynomial because it involves # exponents that are not positive integers. To convert it into a polynomial # we replace x = p1/p2 with y = x^(1/9). After finding the roots of the # polynomial in y, we obtain the roots of the function in x by # calculating x = y^9. # R. = PolynomialRing(RDF) # Let y be x^(1/9). f = y + RDF(2^(8/9) - 2^(1/9))*(y^9-1) - y^8 v = f.roots(); v print [a[0]^9 for a in v]