#6245: make a custom infix operator decorator
-------------------------+--------------------------------------------------
Reporter: jason | Owner: cwitty
Type: enhancement | Status: new
Priority: major | Milestone: sage-4.1.2
Component: misc | Keywords:
Reviewer: | Author:
Merged: |
-------------------------+--------------------------------------------------
Comment(by jason):
The patch is an initial go at this. The documentation for the function
needs to change (it still is just the same docs as the code I followed in
plot/misc.py).
Here are some examples:
{{{
sage: from sage.misc.misc import infix_operator
sage: # A post-fix operator
sage: @infix_operator('or')
sage: def pipe(a,b):
... return b(a)
...
sage: print (x |pipe| cos)
sage: print pi |pipe| n
sage: print pi |pipe| n |pipe| cos
cos(x)
3.14159265358979
-1.00000000000000
sage: # an infix dot product
sage: @infix_operator('multiply')
sage: def dot(a,b):
... return a.dot_product(b)
...
...
sage: vector([1,2]) *dot* vector([2,4])
10
sage: # an infix sum
sage: @infix_operator('add')
sage: def esum(a,b):
... return [i+j for i,j in zip(a,b)]
...
sage: [1,2,4] +esum+ [3,-1,2]
[4, 1, 6]
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6245#comment:2>
Sage <http://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
-~----------~----~----~----~------~----~------~--~---