aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-03-03 01:11:09 +0100
committerNao Pross <np@0hm.ch>2024-03-03 01:13:35 +0100
commitfbd0fa76bde2346c89a1ca867cf9a6dc2a137a28 (patch)
treea54931ef3263e35faa6caa59840f6d059ba2ae42
parentImplement HasRepr for Param and fix repr of Const (diff)
downloadmdpoly-fbd0fa76bde2346c89a1ca867cf9a6dc2a137a28.tar.gz
mdpoly-fbd0fa76bde2346c89a1ca867cf9a6dc2a137a28.zip
Update README
-rw-r--r--README.md52
1 files changed, 48 insertions, 4 deletions
diff --git a/README.md b/README.md
index bddcf1b..7bd2f0c 100644
--- a/README.md
+++ b/README.md
@@ -2,12 +2,56 @@
Work in progress!
-## Minimal working example
+## Quick Start
+
+There is still a big part of the API missing but the snipped below works enough
+to give an overview.
```python
-import mdpoly as poly
+from mdpoly import State, Variable, Parameter
+from mdpoly.representations import SparseRepr
+
+# Construct an expression
+x, y = Variable.from_names("x, y") # or just Variable("x")
+k = Parameter("k")
+
+p = (x + 2 * y) ** 3 + y ** 2 + k
+print(f"{p = }")
+
+# Make a concrete representation
+state = State(parameters={k: 3.14}) # try to replace with empty dict
+sparse, state = p.to_repr(SparseRepr, state)
+
+# Look inside the representation
+for entry in sparse.entries():
+ print(f"at (row, col) = {entry.row, entry.col} there is a polynomial:")
+ for term in sparse.terms(entry):
+ monomial_str = ""
+ for idx in term:
+ var = state.from_index(idx.var_idx)
+ monomial_str += f"{var.name}^{idx.power} "
+
+ # Get the coefficient
+ coeff = sparse.at(entry, term)
+ print(" - the monomial", monomial_str, "has coefficient", coeff)
+
+# You can also simply iterate over it
+for entry, term, coeff in sparse:
+ print(entry, term, coeff)
+```
+
+There is some advanced stuff that is still broken but the idea is that it will
+work soon (TM)
+
+```
+from mdpoly import Variable, MatrixVariable
+from mdpoly.types import Shape
+
+x = Variable("x")
+V = MatrixVariable("Q", Shape.column(3))
-x, y = poly.Variable.from_names("x, y")
+print(x.shape, V.shape)
-p = x + 2 * y + y ** 2
+z = x + V # error
+scalar = V.T @ V # no error (TODO)
```