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

List.rev has quadratic complexity #19839

Closed
MathisBD opened this issue Nov 17, 2024 · 1 comment
Closed

List.rev has quadratic complexity #19839

MathisBD opened this issue Nov 17, 2024 · 1 comment
Labels
kind: wish Feature or enhancement requests. needs: triage The validity of this issue needs to be checked, or the issue itself updated.

Comments

@MathisBD
Copy link
Contributor

Is your feature request related to a problem?

The definition of List.rev in the standard library is quadratic :

Fixpoint rev (l:list A) : list A :=
    match l with
      | [] => []
      | x :: l' => rev l' ++ [x]
    end.

This is very bad for such a common function.

Proposed solution

It should instead use an accumulator to obtain linear complexity :

Fixpoint rev (l : list A) :=
  let fix aux l acc :=
    match l with
    | [] => acc
    | x :: l => aux l (x :: acc)
    end
  in aux l []

Alternative solutions

No response

Additional context

No response

@MathisBD MathisBD added kind: wish Feature or enhancement requests. needs: triage The validity of this issue needs to be checked, or the issue itself updated. labels Nov 17, 2024
@ppedrot
Copy link
Member

ppedrot commented Nov 17, 2024

Duplicate of coq/stdlib#10

@ppedrot ppedrot closed this as completed Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: wish Feature or enhancement requests. needs: triage The validity of this issue needs to be checked, or the issue itself updated.
Projects
None yet
Development

No branches or pull requests

2 participants