{"id":16965027,"url":"https://github.com/propensive/mosquito","last_synced_at":"2025-04-11T23:02:35.577Z","repository":{"id":179962000,"uuid":"663922884","full_name":"propensive/mosquito","owner":"propensive","description":"Typesafe vector algebra for Scala","archived":false,"fork":false,"pushed_at":"2025-01-26T12:14:53.000Z","size":840,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-06T07:46:36.069Z","etag":null,"topics":["euclidean-vector","generic-programming","linear-algebra","matrix","matrix-multiplication","scala","vector-spaces","vectors"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/propensive.png","metadata":{"files":{"readme":".github/readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-08T12:55:28.000Z","updated_at":"2025-02-17T13:26:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"3f560684-bd0b-4051-9d73-4184300f95f7","html_url":"https://github.com/propensive/mosquito","commit_stats":null,"previous_names":["propensive/mosquito"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fmosquito","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fmosquito/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fmosquito/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/propensive%2Fmosquito/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/propensive","download_url":"https://codeload.github.com/propensive/mosquito/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492876,"owners_count":21113163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["euclidean-vector","generic-programming","linear-algebra","matrix","matrix-multiplication","scala","vector-spaces","vectors"],"created_at":"2024-10-13T23:44:51.238Z","updated_at":"2025-04-11T23:02:35.536Z","avatar_url":"https://github.com/propensive.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\u003cimg alt=\"GitHub Workflow\" src=\"https://img.shields.io/github/actions/workflow/status/propensive/mosquito/main.yml?style=for-the-badge\" height=\"24\"\u003e](https://github.com/propensive/mosquito/actions)\n[\u003cimg src=\"https://img.shields.io/discord/633198088311537684?color=8899f7\u0026label=DISCORD\u0026style=for-the-badge\" height=\"24\"\u003e](https://discord.com/invite/MBUrkTgMnA)\n\u003cimg src=\"/doc/images/github.png\" valign=\"middle\"\u003e\n\n# Mosquito\n\n__Typesafe vector algebra__\n\nEuclidean vectors, in contrast to scalars and arbitrary collections, represent\nvalues in _a fixed multiple_ number of dimensions. _Mosquito_ provides a\nrepresentation of vectors, `Euclidean`, whose generic type encapsulates both\nits element type and size. In some sense, a `Euclidean` can be considered a\nhybrid of a `Tuple` (whose size in known) and a collection (whose elements are\nhomogeneous). Mosquito supports the use case of _generic programming_ with\n`Euclidean` vectors, but facilitates linear algebra operations, including\nworking with matrices and scalar and vector products.\n\n## Features\n\n- representation of Euclidean vectors and matrices\n- provides many common linear algebraic operations\n- vectors and matrices are generically-typed\n- linear algebraic operations abstract over arithmetic operations\n- results are dependently-typed on inputs\n\n\n## Availability\n\n\n\n\n\n\n\n## Getting Started\n\nAll terms and types are defined in the `mosquito` package, so it's sufficient\nto import,\n\n```scala\nimport mosquito.*\n```\n\n### Constructing vectors\n\nA Euclidean vector, primarily to distinguish it from Scala's `Vector`\ncollection type, is called `Euclidean`. It represents an ordered, generic\ncollection of elements whose length is known, and furthermore encoded in its\ntype. So a three-dimensional vector of `Double` values would have the type,\n`Euclidean[Double, 3]`.\n\nBut since both the element type and the size of a Euclidean vector can be\ninferred from its values, we can create such a vector with just,\n```scala\nval vector = Euclidean(2.7, -0.3, 0.8)\n```\nand it's type will be known to be `Euclidean[Double, 3]`.\n\n### Constructing matrices\n\nA matrix has the type `Matrix`, and like a `Euclidean`, contains homogeneous\nelements, and encodes its size in its type. However, a `Matrix`'s size is\ndetermined by a number of rows and a number of columns. So a 3×4 matrix of\n`Int`s would have the type, `Matrix[Int, 3, 4]`. Conventionally for matrices,\nthe number of rows is given before the number of columns. This is in contrast\nto the more general convention that a width precedes height. So we avoid the\nterminology of _width_ and _height_ when describing a matrix, and talk instead\nof _rows_ and _columns_.\n\nWhen constructing a new `Matrix`, its rows and columns should be specified as\ntype parameters (since they cannot be inferred at present), and organised into\nequal-length tuples for each row of the matrix. The number and length of the\ntuples must, of course, match the rows and columns specified during\nconstruction, and a mismatch will result in a compile error. Here is an example\nof constructing a 2×3 `Int` matrix:\n```scala\nval matrix = Matrix[2, 3](\n  (1, -2, 4),\n  (3, 8, -1)\n)\n```\n\n### Multiplication operations\n\nVectors may be multiplied in several different ways:\n- multiplication of a vector by a scalar, yielding a new vector\n- a _dot product_ between two equal-dimension vectors\n- a _cross product_ between two 3- or 7-dimensional vectors\n- matrix multiplication\n- left- and right-multiplication of a vector by a matrix\n\n#### Scalar multiplication\n\nA vector may be multiplied by a scalar intuitively with the `*`. The result\nwill be a new vector, of the same dimension, and elements of the type resulting\nfrom multiplying the original element types by the scalar value.\n\nOften, as for `Double`s, this would be the same type: the product of a\n`Euclidean[Double, 3]` and a `Double` will be another `Euclidean[Double, 3]`.\nBut this will not always be the case.\n\nIf using [Quantitative](https://github.com/propensive/quantitative/) with\nMosquito, a vector of values in metres per second, multiplied by a time value,\nwould yield a vector distance. Specifically, a `Euclidean[Quantity[Metres[1] \u0026\nSeconds[-1]]]` multiplied by a `Quantity[Seconds[1]]` would produce a\n`Euclidean[Quantity[Metres[1]]]`.\n\n#### Dot Products\n\nThe extension method `dot` is available for combining two `Euclidean` instances\nof equal dimension, and whose scalar elements have a `*` operation defined,\nwhose result type has a `+` operation that returns the same type. Although\nslightly complex, these criteria correspond closely to the low-level operations\nneeded to carry out a dot product.\n\nThe result type of a dot product will therefore be determined by the element\ntypes of each vector. Using another _Quantitative_ example, the dot product of\ntwo vectors of distance `Quantity` values in metres would be a single scalar\nvalue in square metres.\n\n#### Cross Products\n\nThe cross product is only defined for vectors of dimension 3 or 7. Currently,\n_Mosquito_ only provides an implementation for 3-dimensional `Euclidean`\nvalues, but cross products between 7-dimensional vectors will be provided at a\nlater date.\n\n#### Matrix multiplication\n\nA pair of matrices may be multiplied with the `*` operator, if they share the\nsame inner dimension, that is, the number of columns of the left matrix is the\nsame as the number of rows of the right matrix. The result will be a new square\nmatrix, whose elements' type will be determined by the result of `*` and `+`\noperations on their elements.\n\n#### Multiplication of a vector by a matrix\n\nLeft- and right-multiplication by a matrix is not yet implemented, but is a\nlogical and simple inclusion, since the operation is equivalent to matrix\nmultiplication if the vector is interpreted as a single-row or single-column\nmatrix.\n\n[Github issue #3](https://github.com/propensive/mosquito/issues/3) is tracking\nthe implementation of multiplication of a vector by a matrix.\n\n### Other operations\n\nVectors and matrices of equal dimension may also be added and subtracted.\nUsually, that will result in a vector or matrix of the same element type, but\nin some cases, result types may be different. Quantitative would, for example,\nproduce a value in metres per second when adding units in feet per second and\nmetres per minute.\n\n\n\n## Status\n\nMosquito is classified as __fledgling__. For reference, Soundness projects are\ncategorized into one of the following five stability levels:\n\n- _embryonic_: for experimental or demonstrative purposes only, without any guarantees of longevity\n- _fledgling_: of proven utility, seeking contributions, but liable to significant redesigns\n- _maturescent_: major design decisions broady settled, seeking probatory adoption and refinement\n- _dependable_: production-ready, subject to controlled ongoing maintenance and enhancement; tagged as version `1.0.0` or later\n- _adamantine_: proven, reliable and production-ready, with no further breaking changes ever anticipated\n\nProjects at any stability level, even _embryonic_ projects, can still be used,\nas long as caution is taken to avoid a mismatch between the project's stability\nlevel and the required stability and maintainability of your own project.\n\nMosquito is designed to be _small_. Its entire source code currently consists\nof 286 lines of code.\n\n## Building\n\nMosquito will ultimately be built by Fury, when it is published. In the\nmeantime, two possibilities are offered, however they are acknowledged to be\nfragile, inadequately tested, and unsuitable for anything more than\nexperimentation. They are provided only for the necessity of providing _some_\nanswer to the question, \"how can I try Mosquito?\".\n\n1. *Copy the sources into your own project*\n   \n   Read the `fury` file in the repository root to understand Mosquito's build\n   structure, dependencies and source location; the file format should be short\n   and quite intuitive. Copy the sources into a source directory in your own\n   project, then repeat (recursively) for each of the dependencies.\n\n   The sources are compiled against the latest nightly release of Scala 3.\n   There should be no problem to compile the project together with all of its\n   dependencies in a single compilation.\n\n2. *Build with [Wrath](https://github.com/propensive/wrath/)*\n\n   Wrath is a bootstrapping script for building Mosquito and other projects in\n   the absence of a fully-featured build tool. It is designed to read the `fury`\n   file in the project directory, and produce a collection of JAR files which can\n   be added to a classpath, by compiling the project and all of its dependencies,\n   including the Scala compiler itself.\n   \n   Download the latest version of\n   [`wrath`](https://github.com/propensive/wrath/releases/latest), make it\n   executable, and add it to your path, for example by copying it to\n   `/usr/local/bin/`.\n\n   Clone this repository inside an empty directory, so that the build can\n   safely make clones of repositories it depends on as _peers_ of `mosquito`.\n   Run `wrath -F` in the repository root. This will download and compile the\n   latest version of Scala, as well as all of Mosquito's dependencies.\n\n   If the build was successful, the compiled JAR files can be found in the\n   `.wrath/dist` directory.\n\n## Contributing\n\nContributors to Mosquito are welcome and encouraged. New contributors may like\nto look for issues marked\n[beginner](https://github.com/propensive/mosquito/labels/beginner).\n\nWe suggest that all contributors read the [Contributing\nGuide](/contributing.md) to make the process of contributing to Mosquito\neasier.\n\nPlease __do not__ contact project maintainers privately with questions unless\nthere is a good reason to keep them private. While it can be tempting to\nrepsond to such questions, private answers cannot be shared with a wider\naudience, and it can result in duplication of effort.\n\n## Author\n\nMosquito was designed and developed by Jon Pretty, and commercial support and\ntraining on all aspects of Scala 3 is available from [Propensive\nO\u0026Uuml;](https://propensive.com/).\n\n\n\n## Name\n\nA mosquito is a typical example of a vector: an animal that transmits a pathogen or disease.\n\nIn general, Soundness project names are always chosen with some rationale,\nhowever it is usually frivolous. Each name is chosen for more for its\n_uniqueness_ and _intrigue_ than its concision or catchiness, and there is no\nbias towards names with positive or \"nice\" meanings—since many of the libraries\nperform some quite unpleasant tasks.\n\nNames should be English words, though many are obscure or archaic, and it\nshould be noted how willingly English adopts foreign words. Names are generally\nof Greek or Latin origin, and have often arrived in English via a romance\nlanguage.\n\n## Logo\n\nThe logo represents the _x_, _y_ and _z_ axes of a vector space.\n\n## License\n\nMosquito is copyright \u0026copy; 2025 Jon Pretty \u0026 Propensive O\u0026Uuml;, and\nis made available under the [Apache 2.0 License](/license.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fmosquito","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpropensive%2Fmosquito","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpropensive%2Fmosquito/lists"}