--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
That said, there are issues with &, ^, and |, namely it is unlikely to
know what they mean unless you read the docstrings of Vector or read
the Sphinx documentation that Gilbert has written. Additionally, as
Matthew brings up using '^' for the cross product may visually
conflict with the wedge operator. Then again, it doesn't seem to hurt
to have overlapping syntax's, as long as they are both well
documented.
I vote for keeping the operators and the functions, and if any are
removed, to remove the methods.
If people have thoughts on any negative implications of implementing
multiple ways to perform the same thing, especially related to long
term maintenance of the code, it would be great to hear them.
~Luke
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to
> sympy+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
--
"Those who would give up essential liberty to purchase a little
temporary safety deserve neither liberty nor safety."
-- Benjamin Franklin, Historical Review of Pennsylvania, 1759
--
You received this message because you are subscribed to the Google Groups "Sports Bio Mechanics" group.
To post to this group, send email to sports-bio...@googlegroups.com.
To unsubscribe from this group, send email to sports-bio-mecha...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sports-bio-mechanics?hl=en.
On Thu, Aug 11, 2011 at 1:15 PM, Jason Moore <moore...@gmail.com> wrote:
> I'm for the functional names as it is how all the programming languages that
> I know of implement dot products and cross products. It is clear what they
> mean and the symbols we use in math for the dot product and cross product (a
> dot and a cross) do not exist explicitly on the key board. Secondly, those
> symbols you use are already resevered for python operations, what happens
> when I have a script that requires both the dot product of a vector and the
> bitwise and comparison?
He is only overloading these operators for his classes, so it would
have no effect on the same operators used with other classes. So, if
you wanted to do bitwise manipulations on ints (or any other classes
which support &/^/|) and vector products using the &/^/| operators in
the same script, you could, and the code would work properly, although
a reader would have to be more aware of the context in which the & is
being used. Doing a &/^/| between incompatible types (i.e., int and
Vector) would raise a TypeError exception.
However, one could argue that it is safer to use operators because
they are tied to the classes, whereas with the functions, if you
import them into the global namespace you could unintentionally
overwrite any other dot/cross/outer functions that may have existed.
Obviously this is avoidable with the import syntax Python offers, but
if you were careless, it could happen.
The binary operators he is overloading are really no different from
any other class method, except for the rules of precedence defined by
the Python language.
Obviously there are pros/cons of both ways, I think the real question
is whether to support both interfaces, or to be more restrictive and
only support one. This question of whether it is better to only
support one way of doing things versus a couple ways of doing things
has also come up in regards to how basis vectors of a Reference Frame
are accessed, and it seems like having two ways to do things might not
be too much of a hassle to support, with the added benefit that with
the extra functionality, the Python code can look very similar to how
it is printed/prettyprinted/latex'd, which I think is a very desirable
quality.
Have you looked at naming functions with unicode characters? I don't
remember how restrictive the rules ended up being, but you might well
be able to use mathematical characters in function names. For most
people, that interface would require cut-and-paste, but if one of the
APIs just forwards to another, that shouldn't be a severe problem.
> The only reason not to support all methods, would be if there is a reason
> for maintainability sake. Otherwise, more options are better, because more
> folks will be comfortable with using the program.
It *may* matter depending on how important speed is. Given:
def add3(x):
return x+3
add3(x)
is still slower than
x+3
because of function call overhead.
-jJ
--
You received this message because you are subscribed to the Google Groups "sympy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/bH5GNLGSM7oJ.
The mnemonic I would use is that the ^ looks like the bottom of an x
(for cross product) and the | is an outer key on the keyboard, also
indicative of the side of a matrix (which is the result of an outer
product). The & for "how much do this AND that have in common" works
for me.
Unicode variable names are only supported in Python 3, and anyway,
this is a very bad idea (unless you can remember how to type • or × on
your keyboard).
>
>> The only reason not to support all methods, would be if there is a reason
>> for maintainability sake. Otherwise, more options are better, because more
>> folks will be comfortable with using the program.
>
> It *may* matter depending on how important speed is. Given:
>
> def add3(x):
> return x+3
>
> add3(x)
>
> is still slower than
>
> x+3
>
> because of function call overhead.
>
> -jJ
>
I seriously doubt that this would be an issue. Also, it depends on
the implementation which one actually has more function calls. x + 3
calls x.__add__(3), which may then pass the logic onto something else.
But this should basically be of zero consideration.
Aaron Meurer
The idea of using ** and // is perhaps a good one. Here's the Python
operator precedence table for reference
http://docs.python.org/reference/expressions.html#summary. There's
also % in there at the same level as *. Indeed, do you even use /
(single slash)?
Another idea that I briefly mentioned on the pull request is to use
__call__, __index__, and/or __getattr__. The following are all valid
syntactic sugars:
v1.v2
v1[v2]
v1(v2)
Unlike &, ^, and |, these have operator precedence that you would
expect. The first one will not work in a nested manner,
unfortunately. It also requires you to have a very consistant
variable naming scheme, or else some kind of namespace hacks. It
does look just like v1 dot v2, though.
Finally, I suggested using shorter method names, for less typing. So
instead of v1.dot(v2) or v1.cross(v2), you could have just v1.d(v2) or
v1.c(v2). This would probably be a bad idea to have functions like
this, as they would easily be clobbered, but for methods, it would
work fine.
And by the way, I don't see any reason why you can't have more than
one interface. We allow, e.g., both f(x).diff(x) and diff(f(x), x)
syntaxes in SymPy, and I don't think it leads to any confusion.
Aaron Meurer
An alternative is to write things like that as a function to take an
arbitrary number of elements, so that you could write:
intersection(a, b)
or
intersection(a,b,c,d,e)
That way people don't have to mentally verify that there isn't a
sneaky place in the middle where another function sneaks in, or
parentheses suggest a different order.
-jJ
I don't really know much about the outer product.
Aaron Meurer