Re: [sage-devel] making faster nf -> RR conversions

2018-12-20 Thread Nils Bruin
On Thursday, December 20, 2018 at 11:17:54 AM UTC-8, vdelecroix wrote:
>
> Le 20/12/2018 à 17:40, Vincent Delecroix a écrit : 
> > My use case is that I have one billion of number field elements that 
> > I want to plot. That goes through __float__ that calls 
> > numerical_approx that goes through conversion to MPFR real field. 
> > 
> > Considering my use case, I know how to make it faster (implement 
> > __float__ on nf elements). Though I thought I would also make the 
> > general real floating point conversion faster and I failed. 
>
> Computing embeddings to specified precision can be remarkably tricky, so I 
think it depends a bit on what you want to use this for. If it's just for 
plotting, you are probably not interested in knowing that basically all 
digits computed are correct. However, for general float semantics, we 
probably SHOULD guarantee that. It looks like some gains should be 
achievable because presently there just seems to be coercion overhead, but 
for a really "fast" conversion I think you might want to abandon the idea 
of using the general purpose coercion. For your special purpose you can 
probably do *much* better (I imagine just taking the appropriate Q-linear 
combination of the embedding of a basis might do -- generically that is 
certainly not the case. Interesting algebraic numbers tend to be 
numerically very poorly conditioned).

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] making faster nf -> RR conversions

2018-12-20 Thread Vincent Delecroix

Le 20/12/2018 à 17:40, Vincent Delecroix a écrit :

My use case is that I have one billion of number field elements that
I want to plot. That goes through __float__ that calls
numerical_approx that goes through conversion to MPFR real field.

Considering my use case, I know how to make it faster (implement
__float__ on nf elements). Though I thought I would also make the
general real floating point conversion faster and I failed.


for Python floats see #26927 (needs review).

But I still have no clue on how to achieve what I want for MPFR
floating points (#26925). Which was the object of my question on
sage-devel.

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] making faster nf -> RR conversions

2018-12-20 Thread Vincent Delecroix

My use case is that I have one billion of number field elements that
I want to plot. That goes through __float__ that calls
numerical_approx that goes through conversion to MPFR real field.

Considering my use case, I know how to make it faster (implement
__float__ on nf elements). Though I thought I would also make the
general real floating point conversion faster and I failed.

Note that it works perfectly well with RIF, CIF, RBF and CBF via
respectively the methods _real_mpfi_, _complex_mpfi_, _arb_ and
_acb_. You can see

sage: cm = get_coercion_model()
sage: K. = NumberField(x^2 - x - 1, embedding=(1+AA(5).sqrt())/2)
sage: cm.explain(K, RIF)

And compare the timings with RR conversion!! (> factor x100)

Vincent

Le 20/12/2018 à 17:33, John Cremona a écrit :

You should say that this coercion is only being proposed when nf is a *real
quadratic field*!  For a general number field F one can get
F.embeddings(RR) (or variants with RR replaced by a RealField of any
precision, for example, or CC, or...).  Why can that not be used for this
coercion?

Personally I would never want this anyway since I would always want to
specify exactly which real embedding I wanted.  What sort of use case do
you have in mind?

John

On Thu, 20 Dec 2018 at 16:15, Vincent Delecroix <20100.delecr...@gmail.com>
wrote:


Dear all,

At #26925 I failed to make a more direct coercion nf -> RR. What
we have now go through nf -> AA -> RLF -> RR and is dramatically slow.
The coercion path can be analyzed via

sage: K. = NumberField(x^2 - x - 1, embedding=(1+AA(5).sqrt())/2)
sage: cm = get_coercion_model()
sage: cm.explain(K, RR)

The real field RR declares "_mpfr_" as being a conversion method
in its constructor. However, the coercion model does prefer a
composite map with 2 intermediates rather than this direct
conversion method...

1) Would it be desirable that a direct named conversion such as _mpfr_
would be preferred than a coercion through intermediate?

2) Is there a way to tell Sage that I want this specific coercion to
go through the _mpfr_ method?

Any input appreciated.

Vincent

--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.





--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-devel] making faster nf -> RR conversions

2018-12-20 Thread John Cremona
You should say that this coercion is only being proposed when nf is a *real
quadratic field*!  For a general number field F one can get
F.embeddings(RR) (or variants with RR replaced by a RealField of any
precision, for example, or CC, or...).  Why can that not be used for this
coercion?

Personally I would never want this anyway since I would always want to
specify exactly which real embedding I wanted.  What sort of use case do
you have in mind?

John

On Thu, 20 Dec 2018 at 16:15, Vincent Delecroix <20100.delecr...@gmail.com>
wrote:

> Dear all,
>
> At #26925 I failed to make a more direct coercion nf -> RR. What
> we have now go through nf -> AA -> RLF -> RR and is dramatically slow.
> The coercion path can be analyzed via
>
> sage: K. = NumberField(x^2 - x - 1, embedding=(1+AA(5).sqrt())/2)
> sage: cm = get_coercion_model()
> sage: cm.explain(K, RR)
>
> The real field RR declares "_mpfr_" as being a conversion method
> in its constructor. However, the coercion model does prefer a
> composite map with 2 intermediates rather than this direct
> conversion method...
>
> 1) Would it be desirable that a direct named conversion such as _mpfr_
> would be preferred than a coercion through intermediate?
>
> 2) Is there a way to tell Sage that I want this specific coercion to
> go through the _mpfr_ method?
>
> Any input appreciated.
>
> Vincent
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


[sage-devel] making faster nf -> RR conversions

2018-12-20 Thread Vincent Delecroix

Dear all,

At #26925 I failed to make a more direct coercion nf -> RR. What
we have now go through nf -> AA -> RLF -> RR and is dramatically slow.
The coercion path can be analyzed via

sage: K. = NumberField(x^2 - x - 1, embedding=(1+AA(5).sqrt())/2)
sage: cm = get_coercion_model()
sage: cm.explain(K, RR)

The real field RR declares "_mpfr_" as being a conversion method
in its constructor. However, the coercion model does prefer a
composite map with 2 intermediates rather than this direct
conversion method...

1) Would it be desirable that a direct named conversion such as _mpfr_
would be preferred than a coercion through intermediate?

2) Is there a way to tell Sage that I want this specific coercion to
go through the _mpfr_ method?

Any input appreciated.

Vincent

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.