Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy_list from various input data #16137

Closed
MatthieuDien opened this issue Apr 11, 2014 · 156 comments
Closed

lazy_list from various input data #16137

MatthieuDien opened this issue Apr 11, 2014 · 156 comments

Comments

@MatthieuDien
Copy link

The lazy_list in sage.misc.lazy_list only deals with infinite list built from iterator.
In many situations we want to create infinite list from more various data:

  • an iterator (current implementation),
  • an explicit form a function n -> n-th term
  • an update function: a function that given a buffer of already computed values compute some extra terms (e.g. in the context of words: fixed point of substitutions and in the context of power series: Newton iteration and relaxed multiplication).

Those new lazy lists aim to be very basic Python objects. Their purpose is to be used as fast and reliable data structures in:

See also: rational o.g.f. #15714, hypergeometric e.g.f. part of #2516

In the original proposal there was also ultimately periodic lazy lists (that would simply store two attributes for the pre-period and period). In this ticket we focus on the ones that need a cache mechanism.

CC: @MatthieuDien @videlec @nthiery @mantepse @rwst

Component: misc

Keywords: LazyPowerSeries, lazy_list, days57

Author: Matthieu Dien, Vincent Delecroix, Daniel Krenn

Branch/Commit: f7960c1

Reviewer: Daniel Krenn

Issue created by migration from https://trac.sagemath.org/ticket/16137

@rwst

This comment has been minimized.

@videlec
Copy link
Contributor

videlec commented Apr 13, 2014

comment:3

Hi Ralf,

I think that our third item also includes CFinite sequences. The difference is about how the function update is written. It might be either

def update1(cache):
    cache.append(cache[-1] + cache[-2])

or

def update2(cache):
    return cache[-1]+cache[-2]

Actually, even a closed form is a special case of update1 as one can call len on the cache. Do you agree or did I miss something?

The main task of this ticket is to write precise specifications of what we need... adapting the current implementation of lazy_list is straightforward.

@videlec

This comment has been minimized.

@rwst
Copy link

rwst commented Apr 13, 2014

comment:4

OK then please clarify the scope of the ticket. Also a periodic list is a special case of update.

@mantepse
Copy link
Collaborator

comment:5

I don't think it is a good design decision to have lazy_list include functionality that really belong to formal power series or recursive sequences. I think that this is one of the things Axiom/FriCAS really got right: there is one class (in Axiom-parlance: Stream) which does not require any functionality from the elements. Formal power series and sequences then use this class, and allow access to it via a method coefficients.

In any case, there is quite a large interesting hierarchy of formal power series and sequences, and it is in my opinion a very bad idea to single out rational or hypergeometric functions.

Note that I am not at all against functionality that allows to define lazy lists recursively (on the contrary!), just please do not limit it to sequences built of numbers then.

@videlec
Copy link
Contributor

videlec commented Apr 14, 2014

comment:6

Replying to @mantepse:

I don't think it is a good design decision to have lazy_list include functionality that really belong to formal power series or recursive sequences. I think that this is one of the things Axiom/FriCAS really got right: there is one class (in Axiom-parlance: Stream) which does not require any functionality from the elements. Formal power series and sequences then use this class, and allow access to it via a method coefficients.

In any case, there is quite a large interesting hierarchy of formal power series and sequences, and it is in my opinion a very bad idea to single out rational or hypergeometric functions.

Note that I am not at all against functionality that allows to define lazy lists recursively (on the contrary!), just please do not limit it to sequences built of numbers then.

Hey Martin,

There is no way lazy_list would be made only of numbers! My first goal was to have better data structure for words (sage.combinat.words). I also had in mind its usage in lazy power series. Do you prefer the new description? Please edit it if there is something wrong. The concrete implementation did not start yet. We are waiting for the best possible specifications...

@videlec

This comment has been minimized.

@videlec

This comment has been minimized.

@rwst
Copy link

rwst commented Apr 14, 2014

comment:8

I am aware that it looks like we would only look at numbers. But I was only listing what is already available in code. I would like to have an overview of the hierarchy you mention, not the least because it would help with the design of the code planned here. Where could such an overview (of the hierarchy of formal power series and sequences) be found?

@rwst

This comment has been minimized.

@videlec
Copy link
Contributor

videlec commented Apr 14, 2014

comment:9

Replying to @rwst:

I am aware that it looks like we would only look at numbers. But I was only listing what is already available in code. I would like to have an overview of the hierarchy you mention, not the least because it would help with the design of the code planned here. Where could such an overview (of the hierarchy of formal power series and sequences) be found?

Ralf,

I do not understand what happened and if you did it on purpose. I modified the description twice and you reverted my changes twice !! It is very annoying.

@rwst
Copy link

rwst commented Apr 14, 2014

comment:10

What. No way.

@videlec
Copy link
Contributor

videlec commented Apr 14, 2014

comment:11

Replying to @rwst:

What. No way.

Yes you did. But, my mistake, only once. Have a look: #16137. It might really be that we were editing the ticket at the same time and something bad happened. I will roll back the previous version.

@rwst
Copy link

rwst commented Apr 14, 2014

comment:12

Replying to @videlec:

I will roll back the previous version.

Yes, please. Apparently, I opened the 'Modify ticket' form without editing, you saved your change, then (after display of the yellow warning) I saved my comment, and with it the content of the Modify ticket form. Sorry.

@videlec

This comment has been minimized.

@videlec
Copy link
Contributor

videlec commented Apr 14, 2014

comment:13

Replying to @rwst:

Replying to @videlec:

I will roll back the previous version.

Yes, please. Apparently, I opened the 'Modify ticket' form without editing, you saved your change, then (after display of the yellow warning) I saved my comment, and with it the content of the Modify ticket form. Sorry.

It is a bit strange that there is no warning that forbid you to add changes from version 6 when 7 is the current one... No problem, the previous version is back.

@mantepse
Copy link
Collaborator

comment:14

Replying to @rwst:

Where could such an overview (of the hierarchy of formal power series and sequences) be found?

You can find some references in http://arxiv.org/abs/math/0702086. But this is certainly by no means complete.

@mantepse
Copy link
Collaborator

comment:15

I very much like the new description, nothing to add...

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@mantepse
Copy link
Collaborator

comment:18

Hi there! Is there any news on this front? I'm especially interested because of the connection with #15673...

@MatthieuDien
Copy link
Author

comment:19

Replying to @mantepse:

Hi there! Is there any news on this front? I'm especially interested because of the connection with #15673...

I should work on it but I did not have much time since the Sage Days :s

I will work on it during September (I hope).

@mantepse
Copy link
Collaborator

comment:20

Great! No hurry, though...

@MatthieuDien
Copy link
Author

@MatthieuDien
Copy link
Author

comment:22

Hi there !

I propose a draft of code for 'lazy_list_from_iterator' and 'lazy_list_from_fun'.
Currently, the file is composed of three class : one abstract class (but I don't know how to precise this more formally in Python / Cython / Sage) to facorize the code between lazy_list_from_iterator and lazy_list_from_fun.

I have to do choices :

  • to define lazy list with function I propose to use a fonction which takes 2 arguments : the rank of the element to compute and all the already computed elements
  • Currently, the _add_ method force the computation of all the elements : that's very annoying for not finite iterator. I suppressed it, for the moment.

Give me feedback !

Thanks


New commits:

b7a58c2work in progress
37e6768work in progress

@dkrenn
Copy link
Contributor

dkrenn commented Jan 14, 2016

Changed branch from u/vdelecroix/16137 to u/dkrenn/16137

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2016

Branch pushed to git repo; I updated commit sha1. New commits:

daa9990forgotten change import

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 14, 2016

Changed commit from 295a870 to daa9990

@vbraun
Copy link
Member

vbraun commented Jan 19, 2016

comment:115
sage -t --long src/sage/misc/lazy_list.pyx
**********************************************************************
File "src/sage/misc/lazy_list.pyx", line 543, in sage.misc.lazy_list.lazy_list_generic._fit
Failed example:
    l._info()
Expected:
    cache length 0
    start        2
    stop         9223372036854775807
    step         3
Got:
    cache length 0
    start        2
    stop         2147483647
    step         3
**********************************************************************
1 item had failures:
   1 of  10 in sage.misc.lazy_list.lazy_list_generic._fit
    [204 tests, 1 failure, 0.05 s]

@videlec
Copy link
Contributor

videlec commented Jan 20, 2016

comment:116

right. 32 bits vs 64 bits. I am fixing the corresponding doctests.

@videlec
Copy link
Contributor

videlec commented Jan 20, 2016

Changed commit from daa9990 to 55a1918

@videlec
Copy link
Contributor

videlec commented Jan 20, 2016

New commits:

f1c6036Trac 16137: merge Sage-7.0
55a1918Trac 16137: fixing a doctest and a constructor

@videlec
Copy link
Contributor

videlec commented Jan 20, 2016

Changed branch from u/dkrenn/16137 to u/vdelecroix/16137

@dkrenn
Copy link
Contributor

dkrenn commented Jan 21, 2016

comment:118

Replying to @videlec:

right. 32 bits vs 64 bits. I am fixing the corresponding doctests.

As the first number in

stop         9223372036854775807    # 64-bit
stop         2147483648             # 32-bit

2^63-1, I believe that the second should be 2^31-1 = 2147483647. Unfortunately, I don't have a 32-bit system to test.

@dkrenn
Copy link
Contributor

dkrenn commented Jan 21, 2016

comment:119

Replying to @videlec:

f1c6036 Trac 16137: merge Sage-7.0

What was the reason for merging? Was there any conflict?
BTW: You did not merge 7.0 into the branch but the other way round, i.e., you merged this ticket into 7.0 (like the release manager). This makes seeing the changes much more difficult, since the git specifications like HEAD^ or HEAD~3 all take the first parent, which now is not the original branch of this ticket anymore.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2016

Changed commit from 55a1918 to f7960c1

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2016

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

f7960c1Trac 16137: fixing a doctest and a constructor

@dkrenn
Copy link
Contributor

dkrenn commented Feb 2, 2016

comment:121

Replying to @sagetrac-git:

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

f7960c1Trac 16137: fixing a doctest and a constructor

Sorry for the delay (for some unknown reason I didn't got a notification about the commit; double-checked). Everything is fine now; thanks.

@vbraun
Copy link
Member

vbraun commented Feb 2, 2016

Changed branch from u/vdelecroix/16137 to f7960c1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants