« first day (3971 days earlier)      last day (968 days later) » 

3:53 AM
cbg
 
4:15 AM
hey all, I am interested in the smallest element of a list in every iteration, is it better to do a reverse sort and then pop the last element at every iteration or should I instead maintain a heap, and heappush before and heappop in each iteration to avoid sort?
 
4:40 AM
I don't understand how a heap would help you there, could you elaborate?
 
ok from what I understand, sorting a list is O(nlogn), but popping from a heap is O(logn), and some times I will stop this loop once a condition is reached, so that way I dont really have to sort all the elements to get what I want
I understand that n heappops = O(nlogn) but sometimes I stop midway so I dont really do n pops
is this making sense?
I am preparing for an interview, so this is mostly theoretical in nature as opposed to actual run time difference
 
Hmm, how does a heap help you avoid sorting all elements though?
 
heappop gives the minimum element right? if I have heappushed the elements
 
4:59 AM
Ah, right, a heap isn't completely sorted, my bad
Then yes, in theory using a heap has better run time complexity. But in practice, sorting will most likely be faster and more readable in the majority of cases
 
thank you @Aran-Fey, you have clarified what I had, but if the time complexity is better, then shouldnt it be faster too? since both will use the same input
using sort is definitely a lot readable, so I agree on that
or is this because of what I see, sorting in python uses C code so its faster?
 
Time complexity tells you how the run time changes as the size of the input approaches infinity. If your input isn't infinitely large, an algorithm with a worse complexity can be faster.
 
so in my case, you have mentioned a sort approach will likely be faster, is there a way I can test this in my code
likely = may not be, yes, true, but I am just surprised by the fact that time complexity is not all that matters when telling which is fast
 
Stupid example:
def linear_min(iterable):
    time.sleep(5)
    return min(iterable)

def nlogn_min(iterable):
    return sorted(iterable)[0]
 
kind of silly, but it gets the point true
 
5:11 AM
@Alice Sure, time it. Check out the timeit module
 
ok will look into that, thanks again
have a nice day / eve all :D
 
5:33 AM
Cbg
 
5:58 AM
Uh so few questions today...
 
6:27 AM
@U12-Forward, yeah generally Friday evening to Sunday there are few questions. But this time, even on Monday, there are few questions.
 
@ThePyGuy Ah
 
7:16 AM
what to do to a question that uses 2.7 but a certain newer syntax is not available? should I close it as typo? question
 
i'd also modify/post a new comment directing them on what to actually do before closing it. something like "you should install and use python 3." or what not
other than that, that close reason sounds just fine, more like formality at that stage.
 
thanks, added a comment and close voted as typo
 
Yeah python 4 is already almost coming out so I guess using Python 2 now is actually a bit a lot behind time
 
there won't be any python 4
not in the forseeable future in any case. after python 3.9 it's python 3.10
 
cbg
 
7:27 AM
heart broken, but we get match so :D
cbg Kwsswart
 
@ParitoshSingh Ah missed that
Anyway a person still using python 2 is kind of ancient lol
 
i'm cautiously optimistic about patma. Stuff like the walrus did not get abused as bad as i thought, so fingers crossed patma won't be misused as bad as i think either
 
well, most tutorials are based on 3.6 release time, so walrus still has not got the attention from beginners
there are a couple medium.com articles that show this though
 
@python_user Yeah I just recently switched to a new computer
before I was using 3.6.1 only
So just barely even could have f-strings
But on my new computer I got 3.8.8, it comes with the conda package
So often playing around with new stuff like walrus
 
3.6 still is supported I guess, so its not all bad
 
7:36 AM
@python_user Yeah
I had another PC of like a few years ago which had python 2.7 shell haha
Sometimes play with that
I remembered this
 
my own PC was (it died) more than 5 years old, but I never had trouble having the latest and greatest python on it
python is not a AAA game laurel
 
hello hello, i see familiar faces lurking in chat
 
Hey @cs95
Cbg
 
cbg! random question, does stack overflow have a discord server?
official or unofficial
or perhaps a python specific one
 
the only huge python server (that I know) on discord is the one that the reddit community uses
 
7:52 AM
@python_user Python 3.6 is the new Python 2.7 around here. Keeping my fingers crossed that it finally dies...
 
@cs95 howdy :)
 
I have no idea how users just stick to a version of Python and not let it go
I remember 3.2 was like that to an extent, I guess like you said 3.6 now
 
I see! thanks for the info, also heya JC :)
 
Meh... imho the 3.x series didn't really start properly until 3.3 anyway :p
 
I guess I might be blinded on that, when I first tried python that was the version that was in my college PC's :D
 
7:58 AM
and yeah, i don't actually recommend 3.6 anymore, it's like a "if you must... fineeee" version but there are still some rough edges
though it is fairly stable for normal use cases, and you probably won't encounter it's rough edges unless you go poking around
yeah, there's a python discord, no relation with stackoverflow though
 
part of me still likes to suffer, so I visit the server sometimes
 
@python_user apparently, and i learnt this very recently, python 3.9 can't run on windows 7
 
stackoverflow.com/questions/68971793/… can somebody help me in this issue
 
so, it's probably the first python version in a long time that might not run on older machines (specifically running older OS)
 
that is news to me, but I guess even windows stopped the extended support for 7, so python core devs must be targeting that
 
8:02 AM
@IswarChand please do not post fresh questions from the main site as per our room rules (ps. the lock in period is 48 hours)
 
fwiw, your question has 2 close votes for seeking recommendation, so you might want to edit the question if that is not the case
 
@python_user I have to make do with whatever ships as the default on our and other's servers, which usually means LTS versions. 3.6 is still the standard on RHEL7 machines.
There are also apparently some poor souls that inherited Py3.5 or earlier code and are afraid to touch a running system...
 
Do folders in /media sometimes get deleted? I just created one mounted/unmounted and rebooted and the folder is still there. That's a good thing. I just want to make sure that is always the case
 
what os is this?
 
8:19 AM
@MisterMiyagi seems like a legit usecase to stay on older version, is there a reason you cant upgrade?
 
ubuntu 18.04
 
@python_user It's more important for us to have a stable environment than a recent one. There's no manpower to constantly check whether the most recent ones are also stable, so major environment changes only happen every few years.
 
ahh ok, I thought it must be some IT restrictions, ask permission to install etc
 
Well, there's also that bit that RHEL8 with serial numbers filed off isn't exactly stable... :P
 
8:34 AM
random, but question: is it correct to say that all iterators are lazy in python?
was just thinking of what makes generators different, but thinking through it, don't iterators also show the same lazy behaviour?
 
I don't think lazyness makes sense for iterators, only for iterables. Iteration itself is always one-element-at-a-time.
 
7
Q: How to keep Schrödinger's cat alive?

Syed Emad UddinWe know, Schrödinger's cat inside the box is in the equal superposition state of both alive and dead. We can express its state as $$|cat_\phi\rangle= \frac{|alive\rangle+e^{i\phi}|dead\rangle}{\sqrt{2}} \hspace{10mm} where \hspace{2mm}\phi \hspace{2mm}is \hspace{2mm}relative\hspace{2mm}phase.$$ I...

8

TL;DR: This is probably going to be disappointing. If a cat enters a superposition and we loose track of the relative phase ϕ
then there is only one deterministic operation that returns to the |alive⟩ state: the state preparation channel. In other words, we have to get a new cat.
 
SO HNQ is touching my sore spot...
 
import time
def slowwwwwwww_func(x):
    time.sleep(1)
    return x


it = map(slowwwwwwww_func, [1, 2, 3])

for i in it:
    print(i)
Say, this is lazy right. but then, if we say that we don't want to call the iterator lazy, then what is lazy here?
 
8:45 AM
map is a lazy iterable, so there's that... :P
Some iterables are lazy. Generators are lazy iterables. Not all iterables are lazy, and not all lazy iterables are generators.
@Hakaishin Be careful. The cat might decide to get a new Schrödinger.
 
@MisterMiyagi already happened (:
 
Catch 22: Cat's have nine lives, so you can measure <cat|alive> more than once!
 
:)
 
@MisterMiyagi yep. this all makes perfect sense. but generators are iterators (afaik, yeah?). So we had no issues assigning the label "lazy" to generators. so, specifically for iterators, would the label "lazy" work as well?
 
slightly related clarification, is a file object an iterator that is a lazy iterable?
 
8:54 AM
@ParitoshSingh I don't think so. For good measure, keep in mind though that every iterator is an iterable. :P
Not the other way around, though.
So the "lazy" part about generators is iterableness, not iteratorness. 🧐
 
yeah. but it's i suppose leaving me unsatisfied. we managed to put a sticker on the more general term, iterable. we managed to put a sticker on the more specific term, generator. what's our sticker for iterator specifically
 
@python_user In the sense that it doesn't load the entire file into memory at once, sure
 
melon, I will try to remember that distinction in the long run
 
(ps. it's mostly just a thought experiment, the answer " i dont care go away" would also be perfectly acceptable)
 
Hush. Don't give up while you are on the edge of entering the marvellous headache of types!
@ParitoshSingh I think you might be going wrong by trying to put a sticker on iterable and iterator. There's no one sticker for the entire bunch. Iterables are the superset of Lazy Iterables and Non-Lazy Iterables. Iterators are just Iterators.
 
8:59 AM
IMO "lazy" is too vague of a term. How would you define that? What's the difference between, say, a generator and a list iterator that you'd call one of them lazy but not the other?
 
I'd call the list iterator lazy, TBH. :P
 
laurel. but yeah, if we say that all iterators have to be lazy (even if their iterables are not) then i'd be amused but satisfied. and if we say that no, all iterators are lazy isn't correct, then you know what's coming... what's a "not-lazy" iterator.
 
Not the list, though.
 
yeah, i'm also leaning that way currently
 
Might be worth pointing out that the generator iterable and generator iterator are the exact same thing. A list iterable and list iterator are two separate things.
20 Quatloo Cents saying that an iterable is lazy if it may be realised as being identical to its iterator.
Eh, no, that's yamlocks...
 
9:01 AM
laurel
 
*but 20 quatloo cents in the kitty*
 
yeah, the kitty might have the answer. answer - "yes|no". right, ofcourse.
 
They know. They just don't feel like telling.
 
but yeah, list iterable is definitely "eager", zero questions about it. a list iterator i suppose, to me i want to say it's lazy
as for generators, they're lazy, no questions there either
 
What's a list eager about? It literally doesn't do anything at all, that's as lazy as it gets
 
9:06 AM
a list has to be stored in it's entirety upfront
 
I see eagerness to mean the items are computed on definition, not on usage.
In that regard a (non-FP) container is always eager.
# Lazy?
def kitty(*items):
    for item in items:
        yield item
 
A generator also has to be stored in its entirety up front :D
 
Not its items, though.
 
A generator has items? Does that mean a function also has items, because I can call it and it returns something?
 
Overthinking intensifies
 
9:08 AM
i like how this conversation is shaping up :D
 
Are functions lazy?
 
@Aran-Fey Yes. :D
 
you can't iterate over a function, but to be honest, functions are definitely lazy, are they not
but yeah, we like to assign lazy or eager to things we iterate over, but if we wanted to use it outside that context, i would easily classify functions as lazy in a heartbeat
 
sounds right
 
So lists are eager because memory. But functions are lazy because they do nothing until called. I sense some inconsistency here, but I can't put my finger on it...
@MisterMiyagi What's "FP"?
 
9:16 AM
hmm, lists are also eager because they had to do "everything" to be created, whereas functions just held it's "meat of the instructions" but didn't carry them out
 
@MisterMiyagi umm... have you got something against yield from? :p
 
@Aran-Fey Functional programming.
 
that's how i'd try to reconcile the two in any case
 
@JonClements I blame async. :P
(Just wanted to have something to ponder for Paritosh, TBH)
 
@MisterMiyagi I suppose I can live with that definition, although there's a boatload of edge cases that prevent me from coming up with a real formal definition
 
9:23 AM
Shouldn't exist_ok swallow this error?
    os.makedirs("/media/stick", exist_ok=True)
  File "/usr/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/media/stick'
 
Maybe it's a file and not a directory?
 
ah yes
to avoid getting an exception if the directory already exists. This will still raise an exception if path exists and is not a directory.
 
yep, makes sense why it shouldn't swallow in this case
 
@Aran-Fey TBH I'm not a fan of most programming terms because there isn't (and in many cases, can't be) a sound formal definition. At least the sound formal systems are still lightyears away from any practical stuff.
 
And now for something completely different... I'm trying to create a Gtk ComboBox that lets you pick a Person object out of a list. The ComboBox should display the person's name. I can successfully do this if I store both the Person object and its name in the combobox's underlying data store (a Gtk.ListStore, essentially a list-of-tuples), as seen here.
If I remove the name from the liststore, I can successfully convince the combobox to render persons as names, but if you select one from the dropdown, this warning message appears:
> Gtk-CRITICAL **: 11:03:37.476: gtk_entry_set_text: assertion 'text != NULL' failed
And the name of the selected Person also doesn't show up in the text box. Code here.
Bonus points for figuring out how to left-align the names in the dropdown
I could manually set the text in the texbox, but... I want to get rid of that warning error
 
10:10 AM
Hi, I'm Aran-Fey's smurf account. I exist to experience SO with minimal privileges. laurel. I was thinking, something's off :D
 
Haha, I've been using this account for years at this point :P
 
I like this comment "i give upvote i'm a new contributor like you", user had no clue :D
 
My disguise was flawless
 
11:11 AM
I have a dumb problem. I'm writing a function decorator that passes a positional argument to the decorated function. This is usually the first argument, but if the decorated function is a method, it should be the 2nd argument (so that self remains the 1st argument). What's a sane way to achieve this? Is there a reliable way to detect if a function was defined in a class? Should I have a separate decorator specifically for methods?
Some sample code:
@progresslib.callable_task
def some_long_running_task(progress):
    progress.total = 5

    for _ in range(5):
        progress.completed += 1

task = some_long_running_task()  # this creates a Task object
task()  # this executes the task
 
the stdlib does use separate decorators for functions and methods.
I think the correct approach is to support __get__. AFAIK function-decorators should do that out of the box, but I'd rather check.
Yeah, function decorators applied on methods worked fine in my test.
 
I do implement __get__, but it does the exact same thing in both cases. It just adds the implicit self as the first positional argument, like any other function would. The difference between the two is in their __call__ - one does decorated_func(progress, *args, **kwargs), the other does decorated_func(instance, progress, *args, **kwargs)
 
That looks about right to me. Gonna be a bit of boilerplate with the class and all but should be doable.
 
Alright, separate decorators it is
The problem is that using the wrong one will lead to bugs that are tricky to track down :|
 
11:26 AM
Just add a ConsentingAdultsError.
 
One more question, should a signature-altering decorator like this use functools.wraps or not? I don't think I can set __wrapped__ and a custom __signature__
Hmm, inspect.signature actually does return the custom __signature__.
 
__signature__ serves as a cache that is filled in whenever something actually creates the full signature representation. So you can write there whatever you wish in advance.
 
Still feels weird to have a __wrapped__ function with a different signature though. I can't think of any specific case where this would cause a problem, but... it doesn't feel right
 
11:42 AM
Setting __wrapped__ would be fine. You might want to skip __signature__ though.
 
Well that sounds backwards. I want to hide the progress argument from the signature, since that's passed in automatically
 
If you know which argument isn't exposed, you can modify the Signature of the __wrapped__ function and assign it to the wrapper.
It's the little things that show you care.
 
Ok, I'll set both __signature__ and __wrapped__ then. If it ends up causing a problem, I'm sure I'll hear about it from my upset users (as if I had any)
 
Since you got me thinking of a "decorator __get__", here's a working draft.
 
I swear I have the weirdest problems today
  File "D:\Users\Aran-Fey\Desktop\folder\coding\python\medialib\medialib\media.py", line 25, in <module>
    class Media:
  File "D:\Users\Aran-Fey\Desktop\folder\coding\python\medialib\medialib\media.py", line 636, in Media
    async def download_async(self, progress, *args, **kwargs):
TypeError: 'module' object is not callable
excuse me, what
 
12:04 PM
@MisterMiyagi Hmm, is there a practical use case for this? I don't see the benefit of handling __get__ this way, as opposed to a regular decorator
I mean, sure, it lets you separate the self from the other positional arguments, but only if the method was called correctly (i.e. like Foo().method() and not Foo.method(Foo()))
 
I've long since stopped caring about users that do it wrong if it means inconveniencing those that do it right. There are just too many ways to do it wrong.
 
Huh. I never realized, but you're right, that is wrong.
Good thing I never do metaprogramming, otherwise I'd be sitting on like 200 incorrectly written decorators by now. Haha. Lucky me. *wipes sweat*
 
12:48 PM
Python
I had a weirdly difficult time this weekend finding documentation on running Selenium in headless mode. Am I overestimating how much of a killer feature that is? I'd expect it to be in every "getting started" tutorial, not buried three results deep on Google.
Maybe I have a warped sense of the average Selenium user's needs. The only time I personally see it get mentioned is when someone asks "how do I make my web scraper fetch JS-generated content?". From my point of view, 100% of help seekers that need Selenium, need headless Selenium. But maybe those help seekers make up only 1% of the Selenium user base.
"Yeah, we like headful mode actually," says Alice TypicalDev. "when it pops up a hundred windows during the execution of our test suite, it really impresses management. Makes it very computery."
 
I'm having a hard time adding flashy bits to documentation of technical packages, so I can kind of understand not wanting to remove the flashy bits from a package that has them.
 
@Kevin Is that the new Cabbage?
 
Nah, I just wanted to increase the on-topic-ness of my paragraph
It can't be the new Cabbage because it doesn't replicate the behavior of the current Cabbage. In particular, it doesn't make readers think "what the heck does this mean?"
 
1:07 PM
pyt
 
Mental note: if we ever rename The Rotating Knives, consider "The Pyt"
 
1:31 PM
Could also go for "ytho"
 
@Aran-Fey People could think that you're confused
 
^^ Strong contender
My current theory is that Selenium only really wants to document things that are consistent across the major web browsers. Headlessness is not a standardized quality, so they shrug and say "not our department"
 
curious, do you pick up new projects every other week and complete them?
 
"complete" -- hahahaha
 
I wouldnt have expected you to do a scraping project, the last project I remember you working on some handwriting classifier
 
1:40 PM
That might have been someone else. Or possibly you're thinking of my project to extract text from a screenshot.
 
I am confident its you, maybe I was wrong with the project, but I remember you talking about image recognition, and something with tesseract to Paritosh, so it must be the text from screenshot thing then
 
That one I actually sort of did finish, although the requirements changed substantially by the end, to the point where I was getting 99% of the data I needed from non-screenshot sources
I don't mind leaving a trail of half-finished projects behind me on my journeys. A lot of them are just pretexts for interesting technical puzzles
 
good to know I am not the alone in incomplete projects, though your half complete is what my full complete would be like :D
 
Well, let's all keep growing together, and achieve half-greatness
 
perfection is anyway impossible because to become perfect you have to first be half perfect and then 3/4 perfect and so on. So why even bother :D
 
1:53 PM
Don't try to become perfect. Just be perfect. :P
 
Sounds like you're auditioning for a makeup advert, MM :P
 
Lol, the new way to document stuff. "look the console. you should search in the history of command, it's full of information" Who needs doc if you have a command log xD
 
Does anyone use snakeviz (or similar) in a useful way for finding potential refactor points? I have some code that I don't think I've done my best work in generalising functions so I'm just wondering whether there's a tool that can help diagnose bad code paths vs. just making pretty graphs
 
2:12 PM
@roganjosh yes
"bad code paths", maybe not, not sure what that means. But time sinks: absolutely.
 
Specifically snakeviz or is there a contender?
 
that's what I use but it was the first I tried and I stuck with it
runsnakerun also came up a while back, but I never tried it
 
Cool, thanks for the feedback, I'll have a play :)
 
3:02 PM
How do I ignore the duplication in list. When I input some thing

x = [1.0, 2, 1]

I want the list to count it individually because currently, when I do x.count(1) it returns 2 instead of 1
 
I don't know of a built-in approach, but it's not too hard to write a custom counter:
>>> x = [1.0, 2, 1]
>>> def type_sensitive_count(seq, value):
...     return sum(1 for item in seq if item == value and type(item) == type(value))
...
>>> type_sensitive_count(x, 1)
1
 
morning cabbage
 
May I know what is the "1" for right after sum()? It returns 0 when I changed the value to 3.0 and 3
 
The generator expression 1 for A in B if C creates a collection that contains only ones, and the number of ones it contains is equal to the number of elements of B that satisfy the C condition
For example, in type_sensitive_count(x, 1) the collection will be a single one. And type_sensitive_count(x, 3)'s collection will be no ones at all.
return len([A for A in B if C]) has the same ultimate outcome, if that's easier to visualize
 
3:21 PM
Oh I see, I broke it down and not sure if it's correct, it returns the length of 1 though when my list contains only 1 type of that value.
    lst = []

    for item in seq:
        if item == value and type(item) == type(value):
            lst.append(item)
    return len(lst)
 
Yeah, that's equivalent 👍
 
@RoyalFrog Do you want to count the numerical value 1 only once, i.e. test whether it is present at all, or do you want to count it with respect to its type?
 
I use the sum(1... recipe because I vaguely recall reading that it's slightly more efficient
Probably space-wise since generator expressions don't have to allocate enough memory to build the whole list
 
type actually, so I'm calculating mode, and I want it to return it's data type and not count that into one type. So when user inputs 3.0, 5, 3, 2, the program should not return 3.0 or 3, it should've return a message, but the program currently counts that into one type
I know where the error occurs, just wanting to know how to check that specifically
 
If you need to do that a lot, it's probably easier to store pairs of (value, type(value)) instead.
 
3:25 PM
it's because I use the count function without checking the type, that's why 1.0 == 1 returns true
for number in set(numbers_list):
counter[number] = numbers_list.count(number)

When it reaches the second line, it just stores the result into the dictionary as two values instead of one
for number in numbers_list:
    counter[number] = numbers_list.count(number)
 
If the ultimate goal is to show the mode of all the floats in a list, and then show the mode of all the ints in a list, then perhaps it would be easier to separate the list into two lists first, and then do mode-calculation on each of them. Then your mode algorithm doesn't have to care about type, because it's guaranteed that the lists contain one type each
This is an especially attractive approach because then you can use collections.Counter instead of writing your own
 
I'm storing it into a dictionary because I'll be using that to count the frequency of the numbers. Do you mean that it's better to create like int_counter and then float_counter, something like that?
 
Yeah.
Quick prototype pastebin.com/BxBGv9U9
I created a dict of homogeneous lists rather than making int_counter and float_counter, just in case requirements for the project changes and it needs to handle a bunch of other types
 
3:53 PM
Ooo this is a little bit difficult to digest. Is it alright if I go over this with you to show if I've misunderstood anything?
 
sure
 
So,

`x` is a list that contains a mixture of ints and floats with duplication of course.

And then, it seems to me that `separate_by_type` is like an empty dictionary except it's taking what the data type of `seq` is and return that according to its type. Because it is appending the values based on the data type of `item`. 1.0 and 2.0 went into float and 3 and 4 went into integer.
And I guess mode() function basically finds the most common values in the sequence?
 
Yeah
 
 
1 hour later…
5:10 PM
@Kevin The sum(1 ...) construction is faster than making a list and calling len on it, if the number of items is large enough. But list comps are pretty efficient. IIRC, you need around 100 to 200 items or more (depending on what you're doing) for gen exps to be faster than list comps.
 
Yeah I figured it would be marginal at best for small lists
 
I like to promote the use of generators. I tend to assume that the real code is running on a lot of items, and the list of 3 or 4 items is just a MCVE. ;)
 
My priority is not having to write ([...]) because I don't like the way it looks
 
5:25 PM
@Kevin That's reasonable. Cluttered code is a little slower to read. OTOH, I always do "".join([...]).
If the number of items really is small, and the code's in a time-critical loop, it's definitely a good idea to do timeit tests with realistic data to see if a list comp or gen exp is faster.
 
Gathering data is good and we should do it more often
(not sarcasm)
 
Indeed.
Everyone knows Knuth's adage against premature optimization. But they don't always remember the fine details...
May 24 '18 at 10:09, by PM 2Ring
BTW, Knuth actually said: "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
 
My 3% occurs exclusively in December while doing Christmas themed coding challenges
 
:)
A little while ago, I learned about a great way to make a bunch of cubic Bézier curves that do a closed loop through a collection of points. At each point, both the 1st & 2nd derivatives of the 2 curves match, so both the tangents & the curvatures are identical.
Unfortunately, for n points, you have to solve a set of n simultaneous equations in n vector variables. And that gets expensive for large n. Fortunately, there's a way to solve it using Fast Fourier Transforms, which makes it usable for large n.
And Numpy is quite fast at doing FFTs. :)
 
5:45 PM
How expensive are we talking here, O(N) with a big constant multiplier?
 
Without FFT, it's basically inverting a n×n matrix.
Typically, that's O(n^3), using Gaussian elimination. en.wikipedia.org/wiki/…
But FFT is only O(n log n)
I posted an example in the Math chat that does a 3D curve on the vertices of a dodecahedron. But it was during an off-peak time and I didn't get any feedback. It's Sage / Numpy code. Sage has a lot of nice stuff for handling matrices. It also has some FFT stuff, but it's pretty pathetic and annoying to use, compared to the Numpy FFT functions.
 
Got a link? I'd like to see it
 
The Sage stuff shouldn't be too hard to read: the matrix object & functions behave logically. My code has a few comments, but they don't fully explain the algorithm.
@Kevin Sure. Give me a minute.
You can change the path if you want. it's case insensitive. The path can re-visit points, if you like. It's currently limited to 30 points, but that's easy to change.
You just need to change the 30 in line 40.
 
6:17 PM
Looks quite neat. I was initially confused by the problem because I misread "both the tangents & the curvatures are identical" as "both the tangents & the endpoints are identical". I don't think you need FFT for that.
0th and 1st derivative, easier to solve for than 1st and 2nd derivative. In other news, water is wet
 
I almost said the 0th, 1st, and 2nd derivatives are identical. ;)
 
If the endpoints don't need to meet, then the problem becomes easier :-P
 
Much. :)
Most of the time that I use Bézier curves, I have point & tangent data (like in that black hole photon trajectory program), and I don't worry about the curvatures. But it does look more natural when the curvatures do match.
 
I don't think I've ever considered curvature when evaluating the aesthetics of my bezier curves. I may need to do some experiments
 
6:38 PM
Oh yam. A Sage Bézier script that I used in an Astronomy answer is doing very weird things when you ask it to plot in SVG. Maybe there's been a buggy Sage update...
How weird. That SVG bug also affects my black hole program, but the SVG file saver produces a valid file.
Ah! There's an easy fix. I just need to pass the SVG data to the Sage html() function.
 
7:07 PM
FWIW, here's that Astronomy answer: astronomy.stackexchange.com/a/44903/16685 It plots the Sun's distance from the Solar System barycentre, using data fetched from JPL's Horizons system, which covers 9999 BC to 9999 AD.
Here's a simple interactive SVG Bézier toy gist.github.com/PM2Ring/25c503092bca5b4444a1112d2d1ca59b Sorry, it's in HTML / JavaScript. ;)
 
I've finally remembered to look up change ringing. This video mentions permutohedrons related to it. @PM2Ring you either know of this tradition already, or it's right up your alley.
 
7:23 PM
@AndrasDeak Oh yes, I know about it. :) Many years ago, I spent an afternoon with a bunch of change ringers in an old church in Melbourne, watching them do their thing, and chatting with one of them about the mathematics.
 
7:34 PM
@AndrasDeak permutahedra! Grr.
 
 
4 hours later…
11:26 PM
@AndrasDeak permutohedra! Grr^2.
 

« first day (3971 days earlier)      last day (968 days later) »