{"id":13669159,"url":"https://github.com/hoaproject/Math","last_synced_at":"2025-04-27T01:32:36.942Z","repository":{"id":4401618,"uuid":"5538835","full_name":"hoaproject/Math","owner":"hoaproject","description":"The Hoa\\Math library.","archived":true,"fork":false,"pushed_at":"2021-04-29T19:09:54.000Z","size":194,"stargazers_count":366,"open_issues_count":15,"forks_count":37,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-10-30T00:00:43.017Z","etag":null,"topics":["arithmetic-expression","hoa","library","mathematics","php"],"latest_commit_sha":null,"homepage":"https://hoa-project.net/","language":"PHP","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/hoaproject.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-24T10:31:13.000Z","updated_at":"2024-01-30T14:33:26.000Z","dependencies_parsed_at":"2022-09-05T02:12:06.050Z","dependency_job_id":null,"html_url":"https://github.com/hoaproject/Math","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FMath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FMath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FMath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoaproject%2FMath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoaproject","download_url":"https://codeload.github.com/hoaproject/Math/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237926611,"owners_count":19388577,"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":["arithmetic-expression","hoa","library","mathematics","php"],"created_at":"2024-08-02T08:01:04.459Z","updated_at":"2025-04-27T01:32:36.891Z","avatar_url":"https://github.com/hoaproject.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://static.hoa-project.net/Image/Hoa.svg\" alt=\"Hoa\" width=\"250px\" /\u003e\n\u003c/p\u003e\n\n---\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/hoaproject/math\"\u003e\u003cimg src=\"https://img.shields.io/travis/hoaproject/math/master.svg\" alt=\"Build status\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/hoaproject/math?branch=master\"\u003e\u003cimg src=\"https://img.shields.io/coveralls/hoaproject/math/master.svg\" alt=\"Code coverage\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://packagist.org/packages/hoa/math\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/hoa/math.svg\" alt=\"Packagist\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://hoa-project.net/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/hoa/math.svg\" alt=\"License\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  Hoa is a \u003cstrong\u003emodular\u003c/strong\u003e, \u003cstrong\u003eextensible\u003c/strong\u003e and\n  \u003cstrong\u003estructured\u003c/strong\u003e set of PHP libraries.\u003cbr /\u003e\n  Moreover, Hoa aims at being a bridge between industrial and research worlds.\n\u003c/p\u003e\n\n# Hoa\\Math\n\n[![Help on IRC](https://img.shields.io/badge/help-%23hoaproject-ff0066.svg)](https://webchat.freenode.net/?channels=#hoaproject)\n[![Help on Gitter](https://img.shields.io/badge/help-gitter-ff0066.svg)](https://gitter.im/hoaproject/central)\n[![Documentation](https://img.shields.io/badge/documentation-hack_book-ff0066.svg)](https://central.hoa-project.net/Documentation/Library/Math)\n[![Board](https://img.shields.io/badge/organisation-board-ff0066.svg)](https://waffle.io/hoaproject/math)\n\nThis library provides tools around mathematical operations.\n\n[Learn more](https://central.hoa-project.net/Documentation/Library/Math).\n\n## Installation\n\nWith [Composer](https://getcomposer.org/), to include this library into\nyour dependencies, you need to\nrequire [`hoa/math`](https://packagist.org/packages/hoa/math):\n\n```sh\n$ composer require hoa/math '~1.0'\n```\n\nFor more installation procedures, please read [the Source\npage](https://hoa-project.net/Source.html).\n\n## Testing\n\nBefore running the test suites, the development dependencies must be installed:\n\n```sh\n$ composer install\n```\n\nThen, to run all the test suites:\n\n```sh\n$ vendor/bin/hoa test:run\n```\n\nFor more information, please read the [contributor\nguide](https://hoa-project.net/Literature/Contributor/Guide.html).\n\n## Quick usage\n\nWe propose a quick overview of one feature: evaluation of arithmetical\nexpressions.\n\n### Evaluation of arithmetical expressions\n\nThe `hoa://Library/Math/Arithmetic.pp` describes the form of an arithmetical\nexpression. Therefore, we will use the classical workflow when manipulating a\ngrammar, that involves the [`Hoa\\Compiler`\nlibrary](https://central.hoa-project.net/Resource/Library/Compiler) and the\n`Hoa\\Math\\Visitor\\Arithmetic` class.\n\n```php\n// 1. Load the compiler.\n$compiler = Hoa\\Compiler\\Llk::load(\n    new Hoa\\File\\Read('hoa://Library/Math/Arithmetic.pp')\n);\n\n// 2. Load the visitor, aka the “evaluator”.\n$visitor    = new Hoa\\Math\\Visitor\\Arithmetic();\n\n// 3. Declare the expression.\n$expression = '1 / 2 / 3 + 4 * (5 * 2 - 6) * PI / avg(7, 8, 9)';\n\n// 4. Parse the expression.\n$ast        = $compiler-\u003eparse($expression);\n\n// 5. Evaluate.\nvar_dump(\n    $visitor-\u003evisit($ast)\n);\n\n/**\n * Will output:\n *     float(6.4498519738463)\n */\n\n// Bonus. Print the AST of the expression.\n$dump = new Hoa\\Compiler\\Visitor\\Dump();\necho $dump-\u003evisit($ast);\n\n/**\n * Will output:\n *     \u003e  #addition\n *     \u003e  \u003e  #division\n *     \u003e  \u003e  \u003e  token(number, 1)\n *     \u003e  \u003e  \u003e  #division\n *     \u003e  \u003e  \u003e  \u003e  token(number, 2)\n *     \u003e  \u003e  \u003e  \u003e  token(number, 3)\n *     \u003e  \u003e  #multiplication\n *     \u003e  \u003e  \u003e  token(number, 4)\n *     \u003e  \u003e  \u003e  #multiplication\n *     \u003e  \u003e  \u003e  \u003e  #group\n *     \u003e  \u003e  \u003e  \u003e  \u003e  #substraction\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  #multiplication\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  token(number, 5)\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  token(number, 2)\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  token(number, 6)\n *     \u003e  \u003e  \u003e  \u003e  #division\n *     \u003e  \u003e  \u003e  \u003e  \u003e  token(constant, PI)\n *     \u003e  \u003e  \u003e  \u003e  \u003e  #function\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  token(id, avg)\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  token(number, 7)\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  token(number, 8)\n *     \u003e  \u003e  \u003e  \u003e  \u003e  \u003e  token(number, 9)\n */\n```\n\nWe can add functions and constants on the visitor, thanks to the `addFunction`\nand `addConstant` methods. Thus, we will add the `rand` function (with 2\nparameters) and the `ANSWER` constant, set to 42:\n\n```php\n$visitor-\u003eaddFunction('rand', function ($min, $max) {\n    return mt_rand($min, $max);\n});\n$visitor-\u003eaddConstant('ANSWER', 42);\n\n$expression = 'rand(ANSWER / 2, ANSWER * 2)'\nvar_dump(\n    $visitor-\u003evisit($compiler-\u003eparse($expression))\n);\n\n/**\n * Could output:\n *     int(53)\n */\n```\n\n## Documentation\n\nThe\n[hack book of `Hoa\\Math`](https://central.hoa-project.net/Documentation/Library/Math) contains\ndetailed information about how to use this library and how it works.\n\nTo generate the documentation locally, execute the following commands:\n\n```sh\n$ composer require --dev hoa/devtools\n$ vendor/bin/hoa devtools:documentation --open\n```\n\nMore documentation can be found on the project's website:\n[hoa-project.net](https://hoa-project.net/).\n\n## Getting help\n\nThere are mainly two ways to get help:\n\n  * On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)\n    IRC channel,\n  * On the forum at [users.hoa-project.net](https://users.hoa-project.net).\n\n## Contribution\n\nDo you want to contribute? Thanks! A detailed [contributor\nguide](https://hoa-project.net/Literature/Contributor/Guide.html) explains\neverything you need to know.\n\n## License\n\nHoa is under the New BSD License (BSD-3-Clause). Please, see\n[`LICENSE`](https://hoa-project.net/LICENSE) for details.\n\n## Related projects\n\nThe following projects are using this library:\n\n  * [PSIH \u0026 PMSIpilot](http://www.psih.fr/en/),\n    PSIH is the leading French integrator of business intelligence solutions for\n    the healthcare sector,\n  * [PHP Telegram Bot](https://github.com/akalongman/php-telegram-bot/),\n    Telegram bot based on the official Telegram Bot API.\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FMath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoaproject%2FMath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoaproject%2FMath/lists"}