From 6220fb1aabed87982c71194df0bc5d18bf6ba875 Mon Sep 17 00:00:00 2001 From: Michael Schneeberger Date: Thu, 4 Aug 2022 15:41:23 +0200 Subject: add a description of the example given in README.md --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 6ce4eb8..08e5c9a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,18 @@ Some aspects of the library: ## Example +In this example, two polynomial expressions are defined using sympy expressions + +$f_1(x_1, x_2) = x_1 + x_2$ + +$f_2(x_1, x_2) = x_1 + x_1 x_2$ + +Then, the two expression are combined using the `__add__` (or equivalently `+`) function + +$f_3(x_1, x_2) = f_1(x_1, x_2) + f_2(x_1, x_2) = 2 x_1 + x_2 + x_1 x_2$ + +Finally, different representations of the polynomial are printed. + ``` python import sympy import polymatrix @@ -37,19 +49,19 @@ x = polymatrix.from_((x1, x2)) f1 = polymatrix.from_(x1 + x2) f2 = polymatrix.from_(x1 + x1*x2) -expr = f1 + f2 +f3 = f1 + f2 # prints the data structure of the expression # ExpressionImpl(underlying=AdditionExprImpl(left=FromSympyExprImpl(data=((x1 + x2,),)), right=FromSympyExprImpl(data=((x1*x2 + x1,),)))) -print(expr) +print(f3) -state, poly_matrix = expr.apply(state) +state, poly_matrix = f3.apply(state) # prints the data structure of the polynomial matrix # PolyMatrixImpl(terms={(0, 0): {((0, 1), (1, 1)): 1, ((0, 1),): 2, ((1, 1),): 1}}, shape=(1, 1)) print(poly_matrix) -state, matrix_repr = polymatrix.to_matrix_repr((expr,), x).apply(state) +state, matrix_repr = polymatrix.to_matrix_repr((f3,), x).apply(state) # prints the numpy matrix representations of the polynomial matrix # array([[2., 1.]]) -- cgit v1.2.1