#6245: make a custom infix operator decorator
-------------------------------------------------------+--------------------
Reporter: jason | Owner: cwitty
Type: enhancement | Status:
needs_review
Priority: major | Milestone: sage-4.4
Component: misc | Keywords:
Author: Jason Grout, Carl Witty, Florent Hivert | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
-------------------------------------------------------+--------------------
Comment(by rossk):
Can confirm all examples work as indicated and all tests passed for me
{{{
sage: def dot(a,b):
sage: return a.dot_product(b)
sage: dot=infix_operator('multiply')(dot)
sage: u=vector([1,2,3])
sage: v=vector([5,4,3])
sage: u *dot* v
22
# Also these examples here show precedence works as
# expected (i.e. * before +)
#
sage: def eadd(a,b):
sage: return a.parent([i+j for i,j in zip(a,b)])
sage:
sage: eadd=infix_operator('add')(eadd)
sage: u=vector([1,2,3])
sage: v=vector([5,4,3])
sage: print u +eadd+ v
sage: print 2*u +eadd+ v
sage: print v +eadd+ 2*u
sage: print v +eadd+ u*2
sage: print (v +eadd+ u)*2
(6, 6, 6)
(7, 8, 9)
(7, 8, 9)
(7, 8, 9)
(12, 12, 12)
# Last example: function composition not commutative as expected
sage: def thendo(a,b): return b(a)
sage: thendo=infix_operator('or')(thendo)
sage: print x |thendo| cos |thendo| (lambda x: x^2)
sage: print x |thendo| (lambda x: x^2) |thendo| cos
cos(x)^2
cos(x^2)
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6245#comment:13>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.