Opened 5 years ago

failed coercion for vectors from spaces versus "just vectors"

Reported by: Owned by: kcrisman major sage-9.5 linear algebra paulmasson, slelievre N/A

Description

In this ask.sagemath question we have the following perplexing behavior:

```sage: M = matrix([[1., 1., -1.], [1., 12., -5.]])
sage: u = vector(SR,[5, 4, 2])
sage: v = M.right_kernel().basis()[0]
sage: u-v
TypeError: unsupported operand parent(s) for '-': 'Vector space of dimension 3 over Symbolic Ring' and 'Vector space of degree 3 and dimension 1 over Real Field with 53 bits of precision Basis matrix:[ 1.00000000000000 0.571428571428571 1.57142857142857]'
```

Something with coercion is failing. Ideas?

comment:2 Changed 5 years ago by nbruin

This might be an interesting example. It shows that coercion for vectors in subspaces goes out of its way to construct as small a parent as possible. However, it does seem that it also does proper discovery on the common overparent of the base ring:

```sage: U=matrix(QQbar,[[0,1,0],[1,0,0]]).right_kernel()
sage: V=matrix([[0.0,1.0,0.0],[0.0,0.0,1.0]]).right_kernel()
sage: cs=get_coercion_model()
sage: cs.explain(U,V)
Coercion on left operand via
Vector space morphism represented by the matrix:
[0.000000000000000  1.00000000000000]
Domain: Vector space of degree 3 and dimension 1 over Algebraic Field
Basis matrix:
[0 0 1]
Codomain: Vector space of degree 3 and dimension 2 over Complex Field with 53 bits of precision
User basis matrix:
[ 1.00000000000000 0.000000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000  1.00000000000000]
Coercion on right operand via
Vector space morphism represented by the matrix:
[ 1.00000000000000 0.000000000000000]
Domain: Vector space of degree 3 and dimension 1 over Real Field with 53 bits of precision
Basis matrix:
[  1.00000000000000 -0.000000000000000 -0.000000000000000]
Codomain: Vector space of degree 3 and dimension 2 over Complex Field with 53 bits of precision
User basis matrix:
[ 1.00000000000000 0.000000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000  1.00000000000000]
Arithmetic performed after coercions.
Result lives in Vector space of degree 3 and dimension 2 over Complex Field with 53 bits of precision
User basis matrix:
[ 1.00000000000000 0.000000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000  1.00000000000000]
Vector space of degree 3 and dimension 2 over Complex Field with 53 bits of precision
User basis matrix:
[ 1.00000000000000 0.000000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000  1.00000000000000]
```

I don't quite have an explanation why SR behaves oddly in this setting, though.

comment:3 Changed 5 years ago by slelievre

I know very little about the coercion and conversion mechanisms, but this works.

```sage: u-u.parent()(v)
(4.00000000000000, 3.42857142857143, 0.428571428571429)
```

comment:4 Changed 13 months ago by mkoeppe

• Milestone changed from sage-7.5 to sage-9.3

comment:5 Changed 7 months ago by mkoeppe

• Milestone changed from sage-9.3 to sage-9.4

Setting new milestone based on a cursory review of ticket status, priority, and last modification date.

comment:6 Changed 2 months ago by mkoeppe

• Milestone changed from sage-9.4 to sage-9.5
Note: See TracTickets for help on using tickets.