numberscope / frontscope

Numberscope's front end and user interface: responsible for specifying sequences and defining and displaying visualizers
MIT License
7 stars 14 forks source link

Formula sequence throws error when formula is empty, among others #372

Open katestange opened 4 days ago

katestange commented 4 days ago

This doesn't seem correct: I put formula n^2+1, and use 10000 terms in Histogram, and I get a large bar of "0" factors. This does not occur with 1000 terms, for example. Something to do with bigint, I suppose?

katestange commented 4 days ago

Also, while then changing the formula, I was able to produce the attached error... this should have gotten caught by parameter checking somehow? It seemed to happen when I hit "delete" enough times to clear the sequence entry field. Screenshot from 2024-07-01 08-55-44

katestange commented 4 days ago

Oh no this large bar at "0" bug is even weirder. With 1000 terms, it occurs for n^3-n^2-1 but not for n^3-n^2.

gwhitney commented 4 days ago

OK, here's what's going on with the big bar at 0: The items put in the 0 bar include (a) sequence values that are -1, 0, or 1; and (b) sequence values that the scope can't factorize. The Formula sequence has a built-in factorizer (it doesn't go to the backend) that works just by trial division, using divisors as the primes up to just over 1000. So it is only guaranteed to factor numbers up to 1,000,000. That explains all of the "big 0 bar" phenomena you are seeing: many more numbers of the form 'n^3-n^2-1' have no factor under 1000 than of 'n^3-n^2', etc.

That problem should go away when we change the backend to provide factors on a per-number basis, rather than per-sequence, so I don't think we need to worry about it in this issue. So I am changing the title of the issue to focus on the other problem you found, which I think we can address after all the Delft PRs.

katestange commented 4 days ago

Actually I think that bug is just with the formula sequence handling, and has nothing to do with factor histogram, i just happened to find it there. For example, it was happening with turtle also: whenever I'm trying to mess with the formula entry field, lots of those errors are popping up while I'm momentarily typing incomplete/invalid formulas on the way from changing one valid formula to another. I'm changing the name to reflect this.