Live data from Hacker News

Wave Function Collapse library in pure C

github.com

71–80 of 87 posts

Re: Wave Function Collapse library in pure C

#71
post #58
post #47

Earlier quoted context omitted.

is it though? I've heard the argument, but to me it still makes sense as it is used colloquially. It is a discrete jump forward, thus if you are not talking about electrons and just the latin definition can be an arbitrary sized quanta if defined to an an appropriate set. a quantum leap between scientific epochs is quite large for example also just reread your comment. I don't agree with the definition "small and ran…

Here's my interpretation: a classical leap is when you are somewhere, you expend a bit of energy you have, and you end up somewhere else as a result. Basically, you do something and something happens. A quantum leap, on the other hand, happens when you are somewhere just sitting, and boom, now you're somewhere else. It just happened randomly, without any energy input from you. So to bring this back to the idiom, an e…

The main example of a quantum leap that comes to mind is between energy levels of an electron of an atom, and that does involve emitting or absorbing a photon, carrying the energy that needs to be accounted for.

I don’t think what you’ve said is correct.

Re: Wave Function Collapse library in pure C

#72
post #69

Earlier quoted context omitted.

How is it more flexible exactly? I hate this idiom every time I come across it. I like to look at the header file to see the interface and important documentation, and this just obscures it. Depending on your compiler it can make debugging a huge pain as well.

Its a slow to compile idiom. The only reason to use it is if you expect people to download the header and plop it in. Basically its an end-run around build systems.

In my tests with STB-style headers written in C between a few thousand to a few tens of thousands of line of code, the compilation speed difference between including the header with disabled implementation, versus including with the implementation section removed from the file is absolutely negligible. This is because the implementation block is already skipped in the preprocessor, and never parsed by the compiler frontend.

Again, this is different from typical C++ single-header-libraries (e.g. pretty much all C++ stdlib headers) where the implementation code is inlined or in template code.

Re: Wave Function Collapse library in pure C

#73
post #67
post #50

Earlier quoted context omitted.

That work will be done by the preprocessor and should be fairly quick given it doesn't compile the duplicated code and only removes it.

It may still generate code for function definitions, which are deduped by the linker, so a lot of the code can still go through the whole compiler.

An STB-style header with the implementation disabled (which is the default) looks exactly the same to the compiler as a regular C header which only contains public API declarations (e.g. just struct declarations and function prototypes, and most importantly, no inline code).

All code that would otherwise live in .c files is between an #ifdef/#endif block which is only activated in a single compilation unit in the whole project.

Not sure how this approach would lead to redundant "function definitions" which would need to be deduped by the linker. The only overhead is in the preprocessor for skipping the implementation block, but that happens pretty much at IO speed - it's not comparable with the parsing overhead in typical C++ headers with template and inline code.

Re: Wave Function Collapse library in pure C

#74
post #62

Earlier quoted context omitted.

Sure, but should it? Do you really want nasal demons from your build tool?

Due to the success of build tools like Gradle, build.rs or any other one that packages a Turing complete language to steer a build, apparently many want such daemons on their homedir.

Just because you can do something, doesn't mean you should. A `build.rs` is supposed to be for compiling non-Rust code and stuff like that, not mucking about with the package manager – and by and large, people don't use it for mucking about with the package manager.

Re: Wave Function Collapse library in pure C

#75
post #62

Earlier quoted context omitted.

Due to the success of build tools like Gradle, build.rs or any other one that packages a Turing complete language to steer a build, apparently many want such daemons on their homedir.

Just because you can do something, doesn't mean you should . A `build.rs` is supposed to be for compiling non-Rust code and stuff like that, not mucking about with the package manager – and by and large, people don't use it for mucking about with the package manager.

People use it to muck with the host OS in any possible way, unless one bothers to do the necessary code audit.

Besides that was just one example, there are plenty of them with turing complete languages.

Re: Wave Function Collapse library in pure C

#76
post #36

Earlier quoted context omitted.

Another nonsense, no I haven't ever bothered with it. A hack designed by those that cannot be bothered to modularize a build with binary libraries.

Not entirely. If you think about it, a resulting C binary is just data and text - it’s all compiled into a single unit of globals and functions, much like a unity build layout. Regarding optimization it allows for LTO without the need for a link time optimizer. Regarding convenience, it spares one from function prototypes and using Make or CMake. Should one use Make to speed up build times it’s as simple as tossing t…

I rather prefer the software engineering mind to use binary libraries for what they were designed for.

Re: Wave Function Collapse library in pure C

#77
post #12
post #6

Earlier quoted context omitted.

Very naive question but is it even possible to do quantum experiments with code on a regular computer? Anyone knows if it's been tried?

Yes. It's just an equation. The complexity of quantum system that can be simulate is limited. https://marl0ny.github.io/QM-Simulator-2D/index.html From the above link you can look single slit, double slit, triple slit, step, spike, or load an arbitrary image as a potential and do experiments in 2d box. >This WebGL program simulates the quantum mechanics of a single particle confined in a 2D box, where inside this box…

If you like that simulation you might also like my own webGL Gross-Pitaevskii Equation (GPE) solver. It uses RK4 to simulate a 2D box of ultracold atoms undergoing Bose-Einstein Condensation.

The GPE models a condensate as a single-particle quantum wavefunction with a non-linear form of the Schrödinger Equation, so you get some interesting behaviour from the non-linearity while the simulation remains computationally feasible.

You can interact with the potential term by clicking and dragging inside the 2D box.

https://georgestagg.github.io/webgl_gpe/

Re: Wave Function Collapse library in pure C

#78

I feel like the algorithm is maybe poorly named. At first I thought this was a tool to help with computational quantum physics.

It's reasonable to be surprised when a computer science term uses a metaphor, but I don't think it's fair to call it a poor name unless you also object to almost every other name in programming.

Strings have nothing to do with textiles. And, very confusingly, they aren't even related to fibers or threads. Zippers aren't related to textiles either.

Trees and bloom filters are not related to botany. Heaps and garbage collection are not about municipal waste management. Graph coloring, despite the term, has nothing to do with either pictures or pigments. Red-black trees aren't colored or botanical.

Bubble sort does not involve fluid dynamics. Neither does bucket or cocktail shaker sort for that matter.

Circular buffers are not round. You can't eat a spaghetti stack or poke your finger on a cactus stack.

Re: Wave Function Collapse library in pure C

#79
post #51

Earlier quoted context omitted.

Whats the matter? Never used 3+ levels of indirection on a variable before? /s

See also: https://wiki.c2.com/?ThreeStarProgrammer

Hah, this is actually a FiveStarProgrammer with 5 indirections, rather than https://wiki.c2.com/?FiveStarProgrammer

Re: Wave Function Collapse library in pure C

#80
post #67

Earlier quoted context omitted.

It may still generate code for function definitions, which are deduped by the linker, so a lot of the code can still go through the whole compiler.

An STB-style header with the implementation disabled (which is the default) looks exactly the same to the compiler as a regular C header which only contains public API declarations (e.g. just struct declarations and function prototypes, and most importantly, no inline code). All code that would otherwise live in .c files is between an #ifdef/#endif block which is only activated in a single compilation unit in the who…

Sure, after brushing up on this "stb style", then I see what you mean.

Still, it seems like an ugly kludge to cope with a breathtakingly antiquated way of doing things.

Post reply on HN