You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
print(numeric_test_2) # (1 - 2 * x <= -x) | (-x > x ** 2)
71
+
print(complex_identity) # log2(2 ** x)
69
72
```
70
73
71
-
If you know python you should feel at home here, except for the fact that `or` and `and` should be replaced with their bitwise equivalents `|` and `&`.
74
+
If you know python you should feel at home here, except for two things:
72
75
73
-
Note that the printed version provides the minimal equivalent representation taking into account the operator precedence. Hence `numeric_test_2` got rid of my useless parenthesis. This is **not** a mathematical simplification like in SymPy, i.e. `x - x` will not be simplified to `0`.
76
+
*`or` and `and` should be replaced with their bitwise equivalents `|` and `&`
77
+
* standard unbound (=package-level) methods need to be made lambda-friendly before use. For convenience all of the methods from the `math.py` module are provided in a lambda-friendly way by this package, hence the `from mini_lambda import Log2` above.
74
78
75
-
There are of course a few limitations to `mini_lambda` as compared to full-flavoured python `lambda` functions, the main one being that you can't mix more than one variable in the same expression for now. Check the [Usage](./usage/) page for more details.
79
+
Note that the printed version provides the minimal equivalent representation taking into account the operator precedence. Hence `numeric_test_2` got rid of my useless parenthesis. This is **not** a mathematical simplification like in [SymPy](http://www.sympy.org/fr/), i.e. `x - x` will **not** be simplified to `0`.
80
+
81
+
There are of course a few limitations to `mini_lambda` as compared to full-flavoured python `lambda` functions, the main ones being that
82
+
83
+
* you can't mix more than one variable in the same expression for now.
84
+
*`list`/`tuple`/`set`/`dict` comprehensions are not supported
85
+
*`... if ... else ...` ternary conditional expressions are not supported either
86
+
87
+
Check the [Usage](./usage/) page for more details.
76
88
77
89
78
90
## Main features
79
91
80
92
* More compact lambda expressions for single-variable functions
81
93
* Overriding all operators that can be overriden as of today in python 3.6: the remaining limits come from the language itself, for example chained comparisons are not supported as python casts the partial results to boolean.
82
-
* printability: expressions can be turned to string representation in order to (hopefully) get interpretable messages more easily, for example when the expression is used in a validation context (see[valid8](https://github.com/smarie/python-valid8))
94
+
* printability: expressions can be turned to string representation in order to (hopefully) get interpretable messages more easily, for example when the expression is used in a validation context (that is what I try to do with[valid8](https://github.com/smarie/python-valid8))
83
95
84
96
85
97
## See Also
86
98
87
-
The much-broader debate in the python community about alernate lambda syntaxes is interesting, see [here](https://wiki.python.org/moin/AlternateLambdaSyntax)
99
+
The much-broader debate in the python community about alternate lambda syntaxes is interesting, see [here](https://wiki.python.org/moin/AlternateLambdaSyntax)
88
100
89
101
### Equivalent (python-first)
90
102
@@ -107,6 +119,7 @@ A bit far from the topic but related:
107
119
These libraries create functions from string expressions. Therefore you cannot rely on your favourite IDE to check your expressions, but it might not be a problem for some users/use cases.
0 commit comments