On 8/15/07, Paul-Olivier Dehaye <[EMAIL PROTECTED]> wrote: > Hi, > How do I do some of the more advanced examples given at > http://wiki.axiom-developer.org/GuessingFormulasForSequences > under SAGE?
> If tmp is a sequence of SAGE rational functions, I tried: > > sage: tmp_axiom = axiom(tmp) > sage: tmp_axiom.guessRec() > [] This is just telling you the guess found no answer to the problem you gave it terms of a recursive formula. Here is an example that will yield a simple result: sage: tmp=[1/x^i for i in range(5)] sage: tmp? Type: list Base Class: <type 'list'> String Form: [1, 1/x, 1/x^2, 1/x^3, 1/x^4] Namespace: Interactive Length: 5 Docstring: list() -> new list list(sequence) -> new list initialized from sequence's items The more interesting way of interacting with Axiom is by having Sage automatically convert Sage expressions to Axiom expressions. This is what happens when you leave out the quotes. sage: tmp_axiom=axiom(tmp) sage: tmp_axiom? Type: AxiomElement Base Class: <class 'sage.interfaces.axiom.AxiomElement'> String Form: [1,1/x,1/(x*x),1/x**3,1/x**4] Namespace: Interactive Length: 5 Docstring: [1,1/x,1/(x*x),1/x**3,1/x**4] So 'tmp' above is a Sage list, but when we pass it to axiom as far as Sage is concerned it becomes an AxiomElement. But inside Axiom it a member of a specific Axiom domain (type): sage: tmp_axiom.type() List Fraction Polynomial Integer 'List Fraction Polynomial Integer' is the domain of rational functions with integer coefficients. Now we can operate on it using guessRec: sage: tmp_axiom.guessRec() [[function= [f(n): - x f(n + 1) + f(n)= 0,f(0)= 1],order= 0]] > > sage: tmp_axiom.guess([guessRat], [guessSum, guessProduct]) > --------------------------------------------------------------------------- > <type ' exceptions.NameError'> Traceback (most recent call last) > > /Users/pdehaye/<ipython console> in <module>() > > <type 'exceptions.NameError'>: name 'guessRat' is not defined > > It s not clear to me how the syntax works... > The problem here is to keep track of when you are talking directly to Axiom and when you are using native Sage syntax. Of course any expression that is acceptable to Axiom can be passed between quotes like this: axiom(' ... ') The quotes tell Sage not to interpret the contents, but rather just pass it directly to Axiom. Axiom does some computation and creates a Sage object which Sage then asks Axiom to display (or saves it a variable without displaying it). guessRat, guessSum and guessProduct are names known to Axiom but not to Sage, so they must appear inside quotes ' ... '. We can define these names for Sage like this: sage: guessRat=axiom('guessRat') sage: guessSum=axiom('guessSum') sage: guessProduct=axiom('guessProduct') Now we can call Axiom just as you wrote above: sage: tmp_guess = tmp_axiom.guess([guessRat], [guessSum, guessProduct]) sage: tmp_guess - n [[function= x ,order= 0]] sage: tmp_guess? Type: AxiomElement Base Class: <class 'sage.interfaces.axiom.AxiomElement'> Namespace: Interactive Length: 1 sage: tmp_guess.type() List Record(function: Expression Integer,order: NonNegativeInteger) sage: Notice that the result is a rather complex Axiom domain consisting of a list of records consisting of two fields named, 'function' and 'order'. Currently there are some limitations in Sage concerning convenient access to fields within an Axiom Record but this is Python so we can easily extend the AxiomElement class: sage: def Record(self,n): ....: return axiom('%s.%s'%(self.name(),n)) ....: sage: setattr(sage.interfaces.axiom.AxiomElement,'Record', Record) Then we can write: sage: tmp_guess[1].Record('function') - n x Or as a property: sage: sage.interfaces.axiom.AxiomElement.function = property(fget=lambda self: axiom('%s.function'%self.name())) which is less generic but perhaps looks nicer: sage: tmp_guess[1].function - n x As this becomes more clear, I hope that we will be able to write some documentation about how to use Guess and some of the other packages in Axiom. > Also: > sage: axiom.help('guess') > AXIOM shell variable has no value. using current directory > unable to find the file compress.daase > Help system not available. > > but that s on your todo list, right? > Yes it is. Axiom has several ways to do this and I am experimenting. I will have an new update for 'axiom.py' in the next few days that has something that works. Regards, Bill Page. _______________________________________________ Axiom-mail mailing list Axiom-mail@nongnu.org http://lists.nongnu.org/mailman/listinfo/axiom-mail