Skip to content

Commit 36b4862

Browse files
committed
Init and prepare package
0 parents  commit 36b4862

File tree

5 files changed

+133
-0
lines changed

5 files changed

+133
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Robust PHP math integral solver
2+
===============================
3+
4+
Get instance of `IntegralSolver` and compute:
5+
6+
```php
7+
$solver = new IntegralSolver(/* some dependencies */);
8+
9+
// Process simple input:
10+
$solver->process('1 + x');
11+
```
12+
13+
All results can be renderer as LaTeX or returned as array of tokens for future computation.
14+
15+
All dependencies you can get by [Package manager](https://github.com/baraja-core/package-manager).
16+
17+
Fully compatible with `Nette 3.0` and `PHP 7.1`.

common.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
services:
2+
integralSolver: Mathematicator\Integral\IntegralSolver

composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "mathematicator-core/integral-solver",
3+
"description": "Simple package for solving integrals.",
4+
"homepage": "https://github.com/mathematicator-core/integral-solver",
5+
"authors": [
6+
{
7+
"name": "Jan Barášek",
8+
"homepage": "https://baraja.cz"
9+
}
10+
],
11+
"require": {
12+
"php": ">=7.1",
13+
"mathematicator-core/tokenizer": "~1.0",
14+
"mathematicator-core/engine": "~1.0",
15+
"mathematicator-core/numbers": "~1.0"
16+
},
17+
"autoload": {
18+
"classmap": [
19+
"src/"
20+
]
21+
}
22+
}

src/IntegralSolver.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Mathematicator\Integral;
6+
7+
8+
use Mathematicator\Engine\MathematicatorException;
9+
use Mathematicator\Engine\QueryNormalizer;
10+
use Mathematicator\Integral\Rule\Rule;
11+
use Mathematicator\Tokenizer\Token\IToken;
12+
use Mathematicator\Tokenizer\Tokenizer;
13+
use Nette\Tokenizer\Exception;
14+
15+
class IntegralSolver
16+
{
17+
18+
/**
19+
* @var Rule[]
20+
*/
21+
public $rules = [];
22+
23+
/**
24+
* @var Tokenizer
25+
*/
26+
private $tokenizer;
27+
28+
/**
29+
* @var QueryNormalizer
30+
*/
31+
private $queryNormalizer;
32+
33+
/**
34+
* @param Tokenizer $tokenizer
35+
* @param QueryNormalizer $queryNormalizer
36+
*/
37+
public function __construct(Tokenizer $tokenizer, QueryNormalizer $queryNormalizer)
38+
{
39+
$this->tokenizer = $tokenizer;
40+
$this->queryNormalizer = $queryNormalizer;
41+
}
42+
43+
/**
44+
* @param string $query
45+
* @return string
46+
* @throws MathematicatorException|Exception
47+
*/
48+
public function process(string $query): string
49+
{
50+
$tokens = $this->tokenizer->tokensToObject(
51+
$this->tokenizer->tokenize(
52+
$this->queryNormalizer->normalize($query)
53+
)
54+
);
55+
56+
return $this->processByTokens($tokens);
57+
}
58+
59+
/**
60+
* @param IToken[] $tokens
61+
* @return string
62+
*/
63+
public function processByTokens(array $tokens): string
64+
{
65+
bdump($tokens);
66+
67+
return '';
68+
}
69+
70+
/**
71+
* @param Rule $rule
72+
* @return IntegralSolver
73+
*/
74+
public function addRule(Rule $rule): self
75+
{
76+
$this->rules[] = $rule;
77+
78+
return $this;
79+
}
80+
81+
}

src/Rules/Rule.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Mathematicator\Integral\Rule;
6+
7+
8+
interface Rule
9+
{
10+
11+
}

0 commit comments

Comments
 (0)