Skip to content

Commit 7ed7609

Browse files
committed
Fix docs and remove class
1 parent 2411db5 commit 7ed7609

File tree

2 files changed

+20
-33
lines changed

2 files changed

+20
-33
lines changed

symplyphysics/core/experimental/vectors/__init__.py

+16-29
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class _VectorZero(VectorExpr):
5555
except for the constant `ZERO` since under the `definition of vector spaces
5656
<https://en.wikipedia.org/wiki/Vector_space#Definition_and_basic_properties>` there can only
5757
be one zero.
58+
59+
Note that the zero vector can be considered having arbitrary (physical) dimension as it can be
60+
added to all vectors.
5861
"""
5962

6063
def _sympystr(self, _p: Printer) -> str:
@@ -101,14 +104,7 @@ def __new__(
101104
if norm == 0:
102105
return ZERO
103106

104-
obj = VectorExpr.__new__(cls)
105-
obj.__init__(
106-
display_symbol=display_symbol,
107-
dimension=dimension,
108-
norm=norm,
109-
display_latex=display_latex,
110-
)
111-
return obj
107+
return VectorExpr.__new__(cls)
112108

113109
def __init__(
114110
self,
@@ -172,7 +168,7 @@ class VectorNorm(Expr): # type: ignore[misc]
172168
def argument(self) -> VectorExpr:
173169
return self.args[0] # type: ignore[no-any-return]
174170

175-
# NOTE: Add __new__ that would dispatch the code execusing depending on the value of `vector`
171+
# NOTE: Add __new__ that would dispatch the code execusion depending on the value of `vector`
176172
# For now, this is handled by the function `norm` below.
177173
def __init__(self, vector: VectorExpr) -> None:
178174
self._args = (vector,)
@@ -229,6 +225,8 @@ class VectorScale(VectorExpr):
229225
230226
3. For all scalars `k` and vectors `a`, `k * a = 0` implies `k = 0` or `a = 0`.
231227
228+
4. For all vectors `a`, `(-1) * a = -a` where `-a` is the additive inverse of `a`.
229+
232230
**Links:**
233231
234232
1. `Wikipedia <https://en.wikipedia.org/wiki/Vector_space#Definition_and_basic_properties>`__.
@@ -290,34 +288,24 @@ def _sympystr(self, p: Printer) -> str:
290288
return f"{p.doprint(vector)}*{p.doprint(value)}"
291289

292290

293-
class Scale(Expr): # type: ignore[misc]
294-
"""
295-
Wrapper class intended to allow the scale to come first in the case of scalar multiplication,
296-
since using an unwrapped `Expr` in the LHS of the multiplication would yield a `TypeError`.
291+
class VectorAdd(VectorExpr):
297292
"""
293+
Class representing the notion of vector *addition* as a property of vectors.
298294
299-
def __init__(self, scale: Any) -> None:
300-
self._args = (scale,)
295+
Note that the addends must have the same (physical) dimension to be added together.
301296
302-
def __mul__(self, other: Any) -> VectorScale:
303-
if isinstance(other, VectorExpr):
304-
return VectorScale(other, self.args[0]).doit()
297+
This operation has the following properties:
305298
306-
raise TypeError(
307-
f"Scale can only be multiplied with a VectorExpr, got {type(other).__name__}.")
299+
1. **Associativity**: for all vectors `a, b, c`, `a + (b + c) = (a + b) + c`.
308300
309-
def _eval_nseries(self, x: Any, n: Any, logx: Any, cdir: Any) -> Any:
310-
pass
301+
2. **Commutativity**: for all vectors `a, b`, `a + b = b + a`.
311302
303+
3. Existence of **identity vector** `0`: for all vectors `a`, `a + 0 = a`.
312304
313-
class VectorAdd(VectorExpr):
314-
"""
315-
Class representing the notion of vector addition as a property of vectors.
305+
4. Existence of **inverse vector**: for all vectors `a`, there exists a vector `-a` s.t. `a + (-a) = 0`.
316306
317-
Note that only
307+
The *subtraction* of two vectors can be defined as such: for all vectors `a, b`, `a - b = a + (-b)`.
318308
319-
This operation has the following properties:
320-
321309
**Links:**
322310
323311
1. `Wikipedia <https://en.wikipedia.org/wiki/Vector_space#Definition_and_basic_properties>`__.
@@ -409,7 +397,6 @@ def _sympystr(self, p: Printer) -> str:
409397

410398
__all__ = [
411399
"ZERO",
412-
"Scale",
413400
"VectorAdd",
414401
"VectorExpr",
415402
"VectorNorm",

test/core/experimental/vectors/test_vector.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from pytest import raises
2-
from sympy import Basic, Symbol as SymSymbol, Atom
2+
from sympy import Basic, Symbol as SymSymbol
33
from symplyphysics import units, dimensionless, symbols, assert_equal
44
from symplyphysics.core.expr_comparisons import expr_equals
55
from symplyphysics.core.errors import UnitsError
6-
from symplyphysics.core.experimental.vectors import VectorSymbol, ZERO, norm, VectorScale, Scale
6+
from symplyphysics.core.experimental.vectors import VectorSymbol, ZERO, norm, VectorScale
77

88

99
def test_init() -> None:
@@ -148,7 +148,7 @@ def test_vector_norm() -> None:
148148
v2 = VectorSymbol("v_2")
149149
assert norm(v1 + v2).args[0] == v1 + v2
150150
assert norm(v1 + v1) == norm(v1) * 2
151-
assert norm(ZERO - v2) == norm(v2)
151+
assert norm(ZERO - v2).doit() == norm(v2) # TODO: check norm.__new__
152152

153153
# .subs
154154

@@ -183,7 +183,7 @@ def test_vector_add() -> None:
183183

184184
mass = symbols.mass
185185
acceleration = VectorSymbol("a", units.acceleration)
186-
assert set((force_1 - Scale(mass) * acceleration).args) == {force_1, acceleration * mass * -1}
186+
assert set((force_1 - acceleration * mass).args) == {force_1, acceleration * mass * -1}
187187

188188
# NOTE: dimensions of sub-expressions are not yet checked
189189
_ = force_1 + acceleration

0 commit comments

Comments
 (0)