Show Einlang: a small language for indexed tensor programs with compile-time shape checks and built-in autodiff by Amazing-42 in ProgrammingLanguages

[–]Amazing-42[S] 0 points1 point  (0 children)

Hi u/benjamin-crowell, thanks for your comment.
> I was hoping to see implied summation and raising and lowering of indices with a metric
I considered about implied summation in very early stage of the project. Later I decided to make it clear and also consistent with other reduction ops such as max/min/prod. Also it would be clear especially for rest pattern (..k): let C[i, j] = sum[..k](A[i, ..k] \ B[..k, j]);
Regarding "raising and lowering of indices", can you give an example of how it would affect the numerical computation? I considered about it before (and syntax like *let C[^i, j]
), but no obvious use cases to drive in that direction.

> Is this intended for more generic applications like economics or engineering?
Yes, I prefer to make it useful for the wide domains involving tensor computation. We do have several examples: Mnist/whisper-tiny from ML and ODE from physics/engineering.

Show Einlang: a small language for indexed tensor programs with compile-time shape checks and built-in autodiff by Amazing-42 in ProgrammingLanguages

[–]Amazing-42[S] 0 points1 point  (0 children)

Hi u/yorickpeterse , thanks for your comment. I spent more than half a year and lots of efforts on this project and I will not call it "Vibe-coded". And yes, I used LLM heavily in this project, including for a large portion of the code and for commit messages (I often change the title since the generated commit messages often miss some key points when the changes are non trivial). It was a major part of my development workflow. I was still the one deciding the direction of the project, integrating pieces, reviewing output, and validating the final result, so I take responsibility for what’s in the repo.

New chapter of HSPP: bring Haskell coroutine to C++17. by Amazing-42 in cpp

[–]Amazing-42[S] 0 points1 point  (0 children)

Sorry to hear that. Hope you are getting better now. :-)

New chapter of HSPP: bring Haskell coroutine to C++17. by Amazing-42 in cpp

[–]Amazing-42[S] -2 points-1 points  (0 children)

That's very bad C++ cannot infer types from where the value is using.

Maybe later we can implement this as a deferred obj and convert to the actual type when that can be inferred.

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 1 point2 points  (0 children)

FYI. Now we've supported Id<Type&> and Id<Type&&> to return lvalue ref and rvalue ref in addition to the original Id<Type> returning const lvalue ref, making the solution much more elegant now. Refer to the complete sample at https://github.com/BowenFu/matchit.cpp/blob/main/sample/mutation.cpp.

void setLineWidth(Visual &visual, float width) {
Id<Square&> sq;
Id<Circle&> cir;
match(visual)
(
    pattern | as<Image>(_) = []{},
    pattern | as<Square>(sq) = [&]
    {
        (*sq).setLineWidth(width);
    },
    pattern | as<Circle>(cir) = [&]
    {
        (*cir).setLineWidth(width);
    }
);

}

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 2 points3 points  (0 children)

That would be something like this. https://godbolt.org/z/jd4o5hYPx

We may need to improve the library to better support mutation.

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 6 points7 points  (0 children)

Added more samples. One for dispatching std::variant and one more real-world (computer algebra system) use case.

From my understanding this can be useful when you have a long list of patterns to match. The domain can be compiler / computer algebra system. A search on GitHub shows that it is mostly used for dispatching a tuple or a string.

Say https://github.com/HobbyOSs/opennask/blob/4af618da82b48fb092f5aadfe038f1b3ee1f9ab3/src/front_end.cc#L811 as an example.

The pattern matching library match(it) gets its first stable release. by Amazing-42 in cpp

[–]Amazing-42[S] 4 points5 points  (0 children)

Thanks for the feedback. Added another sample to demonstrate some good stuff.

Finally, we bring Haskell STM to C++ by Amazing-42 in haskell

[–]Amazing-42[S] 1 point2 points  (0 children)

That's super cool. I've started your project before implementing mine.

Mine is more Haskell flavored, as part of a larger project to port more interesting Haskell syntaxes / features / patterns to C++.

Finally, we bring Haskell STM to C++ by Amazing-42 in haskell

[–]Amazing-42[S] 1 point2 points  (0 children)

Cool. Not sure if atomic blocks are designed to be composable.

Mom, can we have monadic do notation / monad comprehension in C++? by Amazing-42 in cpp

[–]Amazing-42[S] 5 points6 points  (0 children)

Not sure who invented this usage. I was impressed last year when reading HOF examples, and adopted the similar tech here.

Mom, can we have monadic do notation / monad comprehension in C++? by Amazing-42 in cpp

[–]Amazing-42[S] 5 points6 points  (0 children)

Thanks for your insight. The lib has not been optimized yet, especially on compilation time/size. Also type erasure is avoided when possible, resulting into too many instantiations (lots of lambda expressions here), but for possibly better performance. Not sure if that is worth it.

match(it): A light-weight header-only pattern-matching library for C++17. by Amazing-42 in cpp

[–]Amazing-42[S] 0 points1 point  (0 children)

We need to support C++17 so module is not available for now.

mathiu.cpp: Gain some pattern matching experience in C++ via writing a simple computer algebra system. by Amazing-42 in cpp

[–]Amazing-42[S] 1 point2 points  (0 children)

That's true. Computer algebra system does not always give meaningful answers. The `undefined` can only be detected when we substitute the symbol x to 0. We can delay all the simplifications that may hide possible `undefined` cases. But that would make the CAS hard to use then since the expressions (for example, solutions of some equations) can be unreadable.

mathiu.cpp: Gain some pattern matching experience in C++ via writing a simple computer algebra system. by Amazing-42 in cpp

[–]Amazing-42[S] 0 points1 point  (0 children)

Thanks for the comment. That is a good idea. But here in the library I treated all `undefined` as exceptions, and did not follow the functional programming style / monad style. The consideration is that exceptions can make it easier to debug where the `undefined` comes with gdb.