Can SymPy's existing set implementation handle parameterized curves?

18 vistas
Ir al primer mensaje no leído

EKW

no leída,
1 oct 2019, 5:58:20 p.m.1/10/2019
para sympy
For example if I wanted to represent the line segment from (0,0) to (1,1) (f(t) = (t, t) for t in (0, 1))- can this be done with an image set? How? Or a curve in 3d space (for example, f(t) = (t^2, t, 1 - t) for t in (0, 1)).

Oscar Benjamin

no leída,
1 oct 2019, 6:24:12 p.m.1/10/2019
para sympy
Yes, you can do that with ImageSet:

In [11]: ImageSet(Lambda(t, (t, t)), Interval(0, 1))
Out[11]: {(t, t) | t ∊ [0, 1]}

In [14]: ImageSet(Lambda(t, (t**2, t, 1-t)), Interval(0, 1))
Out[14]:
⎧⎛ 2 ⎞ ⎫
⎨⎝t , t, 1 - t⎠ | t ∊ [0, 1]⎬
⎩ ⎭

On Tue, 1 Oct 2019 at 22:58, EKW <etk...@gmail.com> wrote:
>
> For example if I wanted to represent the line segment from (0,0) to (1,1) (f(t) = (t, t) for t in (0, 1))- can this be done with an image set? How? Or a curve in 3d space (for example, f(t) = (t^2, t, 1 - t) for t in (0, 1)).
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/8d96f817-802e-412e-948f-a3fc18361419%40googlegroups.com.

EKW

no leída,
1 oct 2019, 6:30:16 p.m.1/10/2019
para sympy
OK, I wasn't sure if that was the intended way, since using tuples quickly leads to errors such as:

>>> a = ImageSet(Lambda(t, (t, t)), Interval(0, 1))
>>> a
ImageSet(Lambda(t, (t, t)), Interval(0, 1))
>>> (0,0) in a
True
>>> b = ImageSet(Lambda(t, (1 - t, t)), Interval(0, 1))
>>> b
ImageSet(Lambda(t, (1 - t, t)), Interval(0, 1))
>>> a.intersect(b)
Intersection(ImageSet(Lambda(t, (t, t)), Interval(0, 1)), ImageSet(Lambda(t, (1 - t, t)), Interval(0, 1)))
>>> simplify(a.intersect(b))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eward/se/sympy/simplify/simplify.py", line 582, in simplify
    return done(expr)
  File "/home/eward/se/sympy/simplify/simplify.py", line 541, in done
    rv = e.doit() if doit else e
  File "/home/eward/se/sympy/core/basic.py", line 1691, in doit
    for term in self.args]
  File "/home/eward/se/sympy/core/basic.py", line 1691, in <listcomp>
    for term in self.args]
  File "/home/eward/se/sympy/sets/fancysets.py", line 460, in doit
    return SetExpr(base_set)._eval_func(f).set
  File "/home/eward/se/sympy/sets/setexpr.py", line 84, in _eval_func
    res = set_function(func, self.set)
  File "/home/eward/se/sympy/sets/sets.py", line 2255, in set_function
    return _set_function(f, x)
  File "/home/eward/se/sympy/multipledispatch/dispatcher.py", line 198, in __call__
    return func(*args, **kwargs)
  File "/home/eward/se/sympy/sets/handlers/functions.py", line 70, in _set_function
    sing = [i for i in singularities(expr, var)
  File "/home/eward/se/sympy/calculus/singularities.py", line 83, in singularities
    if not expression.is_rational_function(symbol):
AttributeError: 'Tuple' object has no attribute 'is_rational_function'

Oscar Benjamin

no leída,
1 oct 2019, 6:41:22 p.m.1/10/2019
para sympy
Yeah, a lot of work is needed in sets.

I see that error on master but not on my PR:
https://github.com/sympy/sympy/pull/17593

There it doesn't raise but just returns unevaluated:
In [3]: simplify(a.intersect(b))
Out[3]: {(t, t) | t ∊ [0, 1]} ∩ {(1 - t, t) | t ∊ [0, 1]}

There is no code to handle intersections of this kind of ImageSet yet.

Oscar
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/9124ca80-5099-4f44-9441-f82af3f9de12%40googlegroups.com.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos