odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.55k stars 570 forks source link

Proposal: tensors #364

Closed gingerBill closed 5 years ago

gingerBill commented 5 years ago

This proposal extends the Odin programming language to include tensors, a geometric object that maps in a multi-linear manner vectors, scalar, and other tensors to a resulting tensors. They would be very useful in many areas that require linear algebra, such as physics, engineering, and mathematics.

A common form of tensors are rank-2 tensors, also known as matrices.

Concretely, this proposal changes the language as follows:

Also, it implies corresponding support and extension to support library packages.

Example syntax:

Tensor22 :: tensor[rank=2, 2, 2]f32;

a := Tensor22{{2, -3}, { 1, 4}};
b := Tensor22{{4,  3}, {-2, 1}};
c := a * b - a;
fmt.println(c); // {{9.0, 3.0}, {-4.0, 6.0}}

x0 := c[0, 0]; // 9
x1 := c[0, 1]; // 3
x2 := c[1, 0]; // -4
x3 := c[1, 1]; // 6

This is a partial proposal, conforming to The Proposal Process step 2.

dotbmp commented 5 years ago

Hell yes. A couple questions though:

  1. It seems these would be compile-time types, analogous to multi-dimensional arrays. How would this relate to slices, then? Would there be a runtime equivalent?

  2. Why is it necessary to specify the rank explicitly, when it could be inferred from the number of dimension arguments provided?

  3. Is there a specific reason to use the tensor keyword rather than just extending arrays to multiple dimensions when there is more than one comma-delineated dimension argument?

This is an excellent proposal, and I'm pretty excited given that I'm too shit at math to implement a tensor library myself.

ThisDevDane commented 5 years ago

Do we need to have kronecker_delta, levi_civita, christoffel, weyl as built-in procedures, or couldn't we have them in a core:tensor library? The less built-ins the better afterall.

dotbmp commented 5 years ago

@ThisDrunkDane I think the idea is that the tensors would be implemented as array equivalents - i.e. compile-time sized - therefore you would want these procedures to work at compile-time. If there is a runtime equivalent as per my first question, something like a "tensor slice", then I would expect those functions to also be implemented in the core:tensor library.

gingerBill commented 5 years ago

April Fool's Day has now ended. This proposal was a joke.

dotbmp commented 5 years ago

Noooooo