rizalmf/deductive-formula
Composer 安装命令:
composer require rizalmf/deductive-formula
包简介
Evaluate given math expressions
README 文档
README
DeductiveFormula is library evaluate expression of variables from given string
Install via "composer require"
composer require rizalmf/deductive-formula
Usage:
use rizalmf\formula\DeductiveFormula; use rizalmf\formula\exception\FormulaException; require_once __DIR__ . '/vendor/autoload.php'; // example path $formula = new DeductiveFormula();
Example 1: (Define Expressions & Set Formula)
try { $expression = '{foo}^({bar}/2+(2+3^(1/2)))'; $requestedVariables = $formula->setFormula($expression); var_dump($formula->getFormula()); var_dump($requestedVariables); } catch (FormulaException $e) { // handle Exceptions } // output : // {foo}^({bar}/2+(2+3^(1/2))) // array ([0] => "foo", [1] => "bar")
Example 2: (Set Variables)
// ... // 1. define value per variable $formula->setVariable("foo", 4); $formula->setVariable("bar", 1); // 2. use array $formula->setVariables([ "foo" => 4, "bar" => 1 ]);
Example 3: (Get Variables)
// ... // 1. get value from specific variable var_dump($formula->getVariable("foo")); // output : 4 // 2. get values all variables var_dump($formula->getVariables()); // output : array ([foo] => 4, [bar] => 1) // 1. get possible variables from Formula var_dump($formula->getRequestedVariables()); // output : array ([0] => "foo", [1] => "bar")
Example 4: (Evaluate)
$result = $formula->execute(); var_dump($result); // output : 353.141268350837
Example 5: (Set Limit Iteration & Debug)
// (optional) set limit iteration calculating machine. default 200 $formula->setLimit(50); // show prepared formula var_dump($formula->getFormulaExposed()); // output : 4^(1/2+(2+3^(1/2))) // debug $result = $formula->execute(true); var_dump($result); // output : // iteration-1 => 4^(1/2+(2+3^(1/2))) // iteration-2 => 4^(1/2+(2+3^0.50)) // iteration-3 => 4^(1/2+(2+1.73205080756888)) // iteration-4 => 4^(1/2+3.73205080756888) // iteration-5 => 4^(0.50+3.73205080756888) // iteration-6 => 4^4.23205080756888 // 353.141268350837
Exception Tree
FormulaException
|- BadFormulaException
Unit Test:
- Composer is a prerequisite for running the tests.
composer install
- The tests can be executed by running this command from the root directory:
./vendor/bin/phpunit test
LICENSE
The MIT License (MIT) Copyright (c) 2021 Rizal Maulana Fahmi
rizalmf/deductive-formula 适用场景与选型建议
rizalmf/deductive-formula 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 04 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「formula」 「calculate」 「evaluate」 「math expression」 「deductive」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rizalmf/deductive-formula 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rizalmf/deductive-formula 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rizalmf/deductive-formula 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LaTeX formula to PNG
Evaluate mathematical and logic equations
Handle simple VAT calculations.
Making life easier while writing complex math formulas, take a breath
The PrestaBehatEvaluator library leverages adapters to evaluate and transform input values into more complex objects.
Parse excel formula to syntax tree
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-04-04