Compare commits
48 Commits
1a20e6927d
...
V2.3.1
Author | SHA1 | Date | |
---|---|---|---|
f767aa390c | |||
55985bfe20 | |||
41d0de79cc | |||
3b5c01e5cc | |||
73b19e9644 | |||
27e7dcba20 | |||
5f398b4c8d | |||
ec823c85eb | |||
d72a2be175 | |||
e596c1af60 | |||
b84cf047bd | |||
d446139af3 | |||
975728f8dc | |||
2317296534 | |||
c211ed1591 | |||
0c84c63ad3 | |||
25bfb7699b | |||
0abd80655a | |||
a3f7efca12 | |||
1a74c54548 | |||
1dccaabd86 | |||
510f6a1fa2 | |||
6b353d2dd0 | |||
fbfaeb5a58 | |||
1a4e8ffb19 | |||
d6bb61dc48 | |||
02214b0f82 | |||
e52fec4057 | |||
219d923ff5 | |||
419e5955eb | |||
f471a1efb3 | |||
7600962fe4 | |||
3e258b2d41 | |||
9f492378c8 | |||
0c3c20262e | |||
b3ec098b0b | |||
9d9224fcba | |||
b53de690d5 | |||
beb319f21d | |||
50f77c4d60 | |||
a83b5ada8d | |||
0aba5eaef6 | |||
0faaf481ca | |||
b51ac7880d | |||
fdf3b088f2 | |||
c7bd77e341 | |||
37601be549 | |||
19cdddf27e |
@@ -136,11 +136,9 @@ class Expression(object):
|
|||||||
:returns: TODO
|
:returns: TODO
|
||||||
|
|
||||||
:example:
|
:example:
|
||||||
>>> e = Expression.random("{a}/{a*k}")
|
>>> Expression.random("{a}/{a*k}") # doctest: +SKIP
|
||||||
>>> e # doctest: +SKIP
|
|
||||||
<Exp: -3 / -15>
|
<Exp: -3 / -15>
|
||||||
>>> e = Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}})
|
>>> Expression.random("{a}/{a*k} - 3*{b}", variables_scope={'a':{'min_max':(10, 30)}}) # doctest: +SKIP
|
||||||
>>> e # doctest: +SKIP
|
|
||||||
<Exp: 18 / 108 - 3 * 9>
|
<Exp: 18 / 108 - 3 * 9>
|
||||||
>>> e = Expression.random("{a}*x + {b}*x + 3", ["a>b"], rejected=[0, 1])
|
>>> e = Expression.random("{a}*x + {b}*x + 3", ["a>b"], rejected=[0, 1])
|
||||||
>>> ee = e.simplify()
|
>>> ee = e.simplify()
|
||||||
|
@@ -64,10 +64,25 @@ class Token(object):
|
|||||||
yield self
|
yield self
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"<{self.__class__.__name__} {renders['txt'](self._mo)}>"
|
return f"<{self.__class__.__name__} {self.__txt__}>"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return renders[self.RENDER](self._mo)
|
if self.RENDER == "tex":
|
||||||
|
return self.__tex__
|
||||||
|
elif self.RENDER == "txt":
|
||||||
|
return self.__txt__
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unknow render {self.RENDER}")
|
||||||
|
|
||||||
|
# return renders[self.RENDER](self._mo)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def __txt__(self):
|
||||||
|
return self._mo.__txt__
|
||||||
|
|
||||||
|
@property
|
||||||
|
def __tex__(self):
|
||||||
|
return self._mo.__tex__
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def raw(self):
|
def raw(self):
|
||||||
@@ -250,6 +265,7 @@ class Token(object):
|
|||||||
"""
|
"""
|
||||||
return self._operate(other, "^")
|
return self._operate(other, "^")
|
||||||
|
|
||||||
|
|
||||||
def _roperate(self, other, operation):
|
def _roperate(self, other, operation):
|
||||||
""" Make a operation between 2 Tokens """
|
""" Make a operation between 2 Tokens """
|
||||||
from ..expression import Expression
|
from ..expression import Expression
|
||||||
@@ -299,7 +315,6 @@ class Token(object):
|
|||||||
<Linear x - 3>
|
<Linear x - 3>
|
||||||
"""
|
"""
|
||||||
return self._roperate(other, "-")
|
return self._roperate(other, "-")
|
||||||
|
|
||||||
def __rmul__(self, other):
|
def __rmul__(self, other):
|
||||||
""" Multiply 2 Tokens or a Token and a Expression
|
""" Multiply 2 Tokens or a Token and a Expression
|
||||||
|
|
||||||
@@ -327,6 +342,7 @@ class Token(object):
|
|||||||
"""
|
"""
|
||||||
return self._roperate(other, "/")
|
return self._roperate(other, "/")
|
||||||
|
|
||||||
|
|
||||||
def _get_soul(self, other=None):
|
def _get_soul(self, other=None):
|
||||||
""" Get the builtin soul of self or other """
|
""" Get the builtin soul of self or other """
|
||||||
if isinstance(other, Token):
|
if isinstance(other, Token):
|
||||||
|
@@ -71,7 +71,7 @@ This function ignores tree structure and works with lists
|
|||||||
{'a': -8, 'a*b': -40, 'b': 5, 'c': 4}
|
{'a': -8, 'a*b': -40, 'b': 5, 'c': 4}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__all__ = ["list_generator"]
|
__all__ = ["generator"]
|
||||||
|
|
||||||
from random import choice
|
from random import choice
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
@@ -256,7 +256,7 @@ def build_variable_scope(rd_variables, rejected, min_max, variables_scope):
|
|||||||
return complete_scope
|
return complete_scope
|
||||||
|
|
||||||
|
|
||||||
def list_generator(var_list, conditions=[], rejected=[0], min_max=(-10, 10), variables_scope={}, dictionnary=False):
|
def list_generator(var_list, conditions=[], rejected=[0], min_max=(-10, 10), variables_scope={}):
|
||||||
""" Generate random computed values from the list
|
""" Generate random computed values from the list
|
||||||
|
|
||||||
:param rd_variables: list of random variables to generate (can be computed value - "a*b")
|
:param rd_variables: list of random variables to generate (can be computed value - "a*b")
|
||||||
@@ -264,25 +264,17 @@ def list_generator(var_list, conditions=[], rejected=[0], min_max=(-10, 10), var
|
|||||||
:param rejected: Rejected values for the generator (default [0])
|
:param rejected: Rejected values for the generator (default [0])
|
||||||
:param min_max: (min, max) limits in between variables will be generated
|
:param min_max: (min, max) limits in between variables will be generated
|
||||||
:param variables_scope: rejected and min_max define for individual variables
|
:param variables_scope: rejected and min_max define for individual variables
|
||||||
:param dictionnary: the return value will be a dictionnary with var_list as keys (default False)
|
|
||||||
:return: dictionnary of generated variables
|
:return: dictionnary of generated variables
|
||||||
|
|
||||||
:example:
|
:example:
|
||||||
>>> a, ab, b, c = list_generator(["a", "a*b", "b", "c"])
|
>>> values = list_generator(["a", "a*b", "b", "c"])
|
||||||
>>> a, ab, b, c # doctest: +SKIP
|
>>> values # doctest: +SKIP
|
||||||
(5, -20, -4, -3)
|
>>> values["a"] * values["b"] == values["a*b"]
|
||||||
>>> a * b == ab
|
|
||||||
True
|
True
|
||||||
>>> ab # doctest: +SKIP
|
>>> values["a*b"] # doctest: +SKIP
|
||||||
-20
|
>>> values["a"] * values["b"] # doctest: +SKIP
|
||||||
>>> a, b # doctest: +SKIP
|
|
||||||
5, -4
|
|
||||||
>>> list_generator(["a", "a*b", "b", "c"], dictionnary=True) # doctest: +SKIP
|
|
||||||
{'a': -3, 'a*b': 18, 'b': -6, 'c': -4}
|
|
||||||
"""
|
"""
|
||||||
rv = extract_rv(var_list)
|
rv = extract_rv(var_list)
|
||||||
rv_gen = random_generator(rv, conditions, rejected, min_max, variables_scope)
|
rv_gen = random_generator(rv, conditions, rejected, min_max, variables_scope)
|
||||||
generated = compute_leafs(var_list, rv_gen)
|
generated = compute_leafs(var_list, rv_gen)
|
||||||
if dictionnary:
|
return generated
|
||||||
return generated
|
|
||||||
return [generated[v] for v in var_list]
|
|
||||||
|
2
setup.py
2
setup.py
@@ -7,7 +7,7 @@ except ImportError:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="mapytex",
|
name="mapytex",
|
||||||
version="2.3.2",
|
version="2.3.1",
|
||||||
description="Computing like a student",
|
description="Computing like a student",
|
||||||
author="Benjamin Bertrand",
|
author="Benjamin Bertrand",
|
||||||
author_email="programming@opytex.org",
|
author_email="programming@opytex.org",
|
||||||
|
Reference in New Issue
Block a user