Martin,

Without trying to solve the more general problem of rationalizing
InputForm and unparse in FriCAS, attached is a patch to 'axiom.py'
(relative to sage-3.1.2 +  Mike's patches (trac_4036.patch
trac_4036-2.patch  trac_4036-3.patch  trac_4036-fixes.patch)) that
solves the problem of parsing 'sin x' so that now we get:

sage: axiom(sin(x)).sage()
sin(x)

@@ -693,7 +731,11 @@ in unparse_input_form

+        if r:
+            # juxtaposition is always function application
+            if axiom.get(self.type()) != "String": # except in strings
+                return re.sub(r'([^ ]+) ([^ ]+)',r'\1(\2)', r.groups(0)[0])
+            else:
+                return r.groups(0)[0]
+        else:
+            return s

adds the missing parenthesis. We need to deal here with the special
case of a String.

@@ -761,7 +803,8 @@ in _sage_

+        if type == "String":
+            return self.unparsed_input_form()

handles conversion of Axiom strings to Sage strings.

@@ -559,13 +595,15 @@ is a minor fix to axiom.type so that calls 'typeOf'.

@@ -820,17 +867,17 @@ changes the hack for the ! and ? suffix in Axiom
function names form xxx_e and xxx_q to what I consider a more common
convention of set_xxx and is_xxx.

This patch also includes the necessary code to compile spad files @@
-362,6 +362,41 @@

Regards,
Bill Page.

On Sat, Sep 13, 2008 at 7:07 PM, Martin Rubey wrote:
>>
>> I think the following *should* work...
>>
>> sage: a = axiom.sin(x)
>
> I hacked around axiom.py a little, and came up with the following:
>
>        #If all else fails, try using the unparsed input form
>        try:
>            import sage.misc.sage_eval
>            try:
>                vars = str(self.variables())[1:-1]
>                return 
> sage.misc.sage_eval.sage_eval(self.unparsed_input_form(),cmds='var(\''+vars+'\')')
>            except:
>                return 
> sage.misc.sage_eval.sage_eval(self.unparsed_input_form())
>        except:
>            raise NotImplementedError
>
> This takes into account the fact that in sage we have to introduce all
> variables...
>
> Unfortunately, we are still not there, because unparsed_input_form returns
>
> 'sin x'
>
> (In FriCAS, one can omit parentheses, if a function takes only a single
> argument.)
>
> Is there an easy way to massage this string in python, or should I rather do 
> it
> in FriCAS?  (I guess I should...)
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Attachment: axiom.py.patch
Description: Binary data

Reply via email to