List.rev is unexpectedly quadratic
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 35/100
- Tipo di issue
- Documentazione
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Ambito
- performance
Direzione di ricerca
Inizia con le definizioni di rev e rev' in Coq.Lists.List e rivedi il benchmark nell'issue. Chiarisci la differenza di complessità e documentala vicino a rev o all'inizio del modulo; il lavoro è completato quando gli utenti possono scoprire che rev ha complessità quadratica e rev' è ricorsiva in coda.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
This is probably known to a number of Coq developers, but I discovered only yesterday, after 15 years of using Coq, that List.rev is implemented with quadratic complexity. That could explain numerous of the performance bottleneck that I, and others, have encountered.
I then saw that Coq.Lists.List also defines a rev' function, with the proper tail-rec definition. But I don't recall seeing it used in any Coq script that I have looked at.
I suggest to better advertise the issue with the definition of rev. At the very least, I guess there should be a comment above the definition of rev, and possibly also at the top of the file.
Another possibility for tracking down problematic usages would be to develop a profiler version for coqc , that could, among other things, measure the length of arguments of rev and report a warning whenever the length exceeds a couple dozen elements. Such a profiler could be exploited by users who want their scripts to run faster, suggesting hints for improvements.
To see how bad the quadratic behavior gets in practice, I ran the following benchmark. Even for short lists, the computation time is significant.
Set Implicit Arguments.
From Coq Require Import List.
Fixpoint make A (n:nat) (v:A) : list A :=
match n with
| 0 => nil
| S n' => v :: make n' v
end.
Set Implicit Arguments.
From Coq Require Import List.
Fixpoint make A (n:nat) (v:A) : list A :=
match n with
| 0 => nil
| S n' => v :: make n' v
end.
Lemma test : forall (v w:nat),
last (rev (make 300 v)) w = v
/\ last (rev (make 500 v)) w = v
/\ last (rev (make 500 v)) w = v
/\ last (rev (make 1500 v)) w = v
/\ last (rev (make 5000 v)) w = v
/\ last (rev' (make 5000 v)) w = v.
Proof.
intros. split;[|split;[|split;[|split;[|split]]]].
time simpl. auto. (* >1 second for 300 elements *)
time simpl. auto. (* 5 seconds for 500 elements *)
time reflexivity. (* 0.1 seconds for 500 elements *)
time reflexivity. (* >1 seconds for 1500 elements *)
time reflexivity. (* 17 seconds for 5000 elements *)
time reflexivity. (* 0.01 seconds for 5000 elements with the tail rec version *)
Abort.
- Lingua principale
- Rocq Prover
- Stelle
- 42
- Fork
- 40
- Merge medio
- 20h 23m
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rocq-prover/stdlib
-
incl_dec and NoDup_dec should be Defined and not QedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 65/100
rocq-prover/stdlib#25 ·
-
Reals: escape-window separation engine for the constructive Cauchy reals (abstract irrationality criterion)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
rocq-prover/stdlib#312 ·
-
Maintaining NaryFunctionsAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
rocq-prover/stdlib#293 ·
-
`QArith`: Add more rounding modes to complement `Qfloor` and `Qceiling`Forse già presa @RyanGlScott l’ha presa 87 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
rocq-prover/stdlib#283 · 2 commenti ·
-
Inconsistent OPAM packaging of rocq-stdlibForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
rocq-prover/stdlib#256 · 4 commenti · 3 reazioni ·
Tutte le issue di rocq-prover/stdlib
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
[Docs] Add React 19 Suspense streaming benchmark recipe to docs/architecture/01_REACT_19_SSR.mdApertadocumentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Unnecessery/slow ORDER BY clause in PK_FK_using_numeric_or_integer_data_type SQL statement CTEAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
awslabs/pg-collector#13 ·