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 sum shouldn't take quadratic time #1430

Open
Negabinary opened this issue Dec 5, 2024 · 3 comments
Open

List sum shouldn't take quadratic time #1430

Negabinary opened this issue Dec 5, 2024 · 3 comments
Assignees

Comments

@Negabinary
Copy link
Contributor

image

let list_of_ones : Int -> [Int] = fun n ->
  if n == 0 then [] else 1 :: list_of_ones(n-1)   
in

let sum : [Int] -> Int = fun l ->
  case l
    | [] => 0
    | x::xs => x + sum(xs)  
  end   
in

let n = 2000 in

sum(list_of_ones(n))
@Negabinary
Copy link
Contributor Author

Negabinary commented Dec 5, 2024

I checked and list_of_ones is linear, but sum is quadratic.

I suspect it's because of this transition rule (possibly my fault). Specifically is_value:false makes variable lookup take O(n) time.

image

In order to switch to is_value:true, we are going to have to comb through evaluation rules and convince ourselves that everything that goes into a closure (function arguments, fixpoints, builtins, etc.) is always final; which I suspect isn't true now.

@cyrus- cyrus- moved this to Team Dynamics in Hazel Big Board Dec 5, 2024
@cyrus-
Copy link
Member

cyrus- commented Dec 5, 2024

Only thing that may not be final is a fixpoint...

@Negabinary
Copy link
Contributor Author

builtin functions are also not currently final, because they have always been stored in the initial environment without a closure (though that should be an easy fix)

@Negabinary Negabinary self-assigned this Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Team Dynamics
Development

No branches or pull requests

2 participants