need to clean...

This commit is contained in:
Lafrite
2015-05-14 10:59:56 +02:00
parent 46417c2853
commit 70096cf075
12 changed files with 847 additions and 327 deletions

View File

@@ -1,131 +0,0 @@
#!/usr/bin/env python
# encoding: utf-8
from random import randint, uniform
from math import sqrt
from jinja2 import Template
"""
Generate expression for litteral calculous
3 types of expression (a, b, c != 0, 1)
1 -> ax + b and eval for x != -b / a
2 -> ax(bx + c) and eval for x != 0 and x != -c / b
3 -> ax^2 + b and eval for x != +-sqrt(b/a) (if a and b have same sign)
"""
def gene_type1(min_ = -10, max_ = 10):
"""@todo: Docstring for gene_type1
:param min_: @todo
:param max_: @todo
:returns: @todo
"""
a, b = 0, 0
while (b in [0]) or (a in [0, 1]):
a = randint(min_, max_)
b = randint(min_, max_)
return "{}x + {}".format(a,b), [-b/a]
def gene_type2(min_, max_):
"""@todo: Docstring for gene_type2
:param min_: @todo
:param max_: @todo
:returns: @todo
"""
a, b, c = 0, 0, 0
while (a in [0, 1]) or (b in [0, 1]) or c in [0]:
a = randint(min_, max_)
b = randint(min_, max_)
c = randint(min_, max_)
return "{}x({}x + {})".format(a,b,c), [0, -c/b]
def gene_type3(min_ = -10, max_ = 10):
"""@todo: Docstring for gene_type3
:param min_: @todo
:param max_: @todo
:returns: @todo
"""
a, b = 0, 0
while (b in [0]) or (a in [0, 1]):
a = randint(min_, max_)
b = randint(min_, max_)
if a*(-b) > 0:
VI = [-sqrt(-b/a), sqrt(-b/a)]
else:
VI = []
return "{}x^2 + {}".format(a,b), VI
def get_goodX(VI, approx = 0, min_ = -10, max_ = 10):
"""@todo: Docstring for get_goodX
:param VI: @todo
:returns: @todo
"""
x = uniform(min_, max_)
if approx == 0:
x = int(x)
else:
x = round(x,approx)
while x in VI:
x = uniform(min_, max_)
if approx == 0:
x = int(x)
else:
x = round(x,approx)
return x
def fullExo(min_ = -10 , max_ = 10):
"""Generate the whole exo
:param min_: @todo
:param max_: @todo
:returns: @todo
"""
template = Template("""
\\begin{equation*}
$A = {{type1}}$ \\qquad $B = {{type2}}$ \\qquad $C = {{type3}}
\\end{equation*}
Évaluer $A$, $B$ et $C$ pour $x = {{x1}}$ puis $x = {{x2}}$""")
type1, VI1 = gene_type1(min_, max_)
type2, VI2 = gene_type2(min_, max_)
type3, VI3 = gene_type3(min_, max_)
VI = VI1 + VI2 + VI3
x1, x2 = get_goodX(VI), get_goodX(VI, approx = 1)
info = {"type1": type1, "type2": type2, "type3": type3, "x1":x1, "x2":x2}
exo = template.render(**info)
return exo
if __name__ == '__main__':
print(fullExo())
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del

View File

@@ -1,133 +0,0 @@
#!/usr/bin/env python
# encoding: utf-8
from random import randint, random
from random_expression import RdExpression
from arithmetic import gcd
from renders import tex_render
"""Classe which generate randomly fractions calculus
Types of sums
add1 -> b / a + c / a
add2 -> b / a + c / ka
add3 -> b / a + e / d
add4 -> f + b / a
add5 -> b / a + f
where:
a integer > 2
b integer different from 0 (could be coprime with a)
c integer different from 0 (could be coprime with a or ka)
e integer different from 0 (could be coprime with d)
d integer > 2 ( a not divisible by d and d not divisible by a)
k integer > 2
f integer different from 0
Types of multiplications
mult1 -> a x b / c
mult2 -> a x b / c + d / c
mult3 -> a x b / c + d / e
mult4 -> e / f x g / h >>> TODO
mult5 -> i / j x k / l
where:
a integer different from -1, 0, 1
b integer different from 0
c integer different from 0 and 1 (could be coprime with b)
d integer different from 0
e, g integer different from 0
f, g integer different from 0 and 1 such that e*g is coprime with f*h
i, k integer different from 0
j, l integer different from 0 and 1 such that i*k and j*l have divisor in common
Types of divisions
div1 -> a / b : c / d
where:
a integer different from 0
b integer different from 0, 1
c integer different from 0
d integer different from 0
#Signs can be mod
"""
add1 = RdExpression("{b} / {a} + {c} / {a}", \
conditions = ["{a} > 2", "{b} != 0","{c} != 0"])
add2 = RdExpression("{b} / {a} + {c} / {k*a}", \
conditions = ["{a} > 2","{k} > 2", "{b} != 0","{c} != 0"])
add3 = RdExpression("{b} / {a} + {e} / {d}", \
conditions = ["{a} not in [0,1]", "{e} not in [0,1]", "{b} != 0","{d} not in [0,1]"])
add4 = RdExpression("{b} / {a} + {f}", \
conditions = ["{a} > 2", "{b} != 0", "{f} != 0"])
add5 = RdExpression("{f} + {b} / {a}", \
conditions = ["{a} > 2", "{b} != 0", "{f} != 0"])
mult1 = RdExpression("{a} * {b} / {c}",\
conditions = ["{a} not in [-1, 0, 1]", "{b} != 0", "{c} not in [0,1]"])
mult2 = RdExpression("{a} * {b} / {c} + {d} / {c}",\
conditions = ["{a} not in [-1, 0, 1]", "{b} != 0", "{c} not in [0,1]", \
"{d} != 0"])
mult3 = RdExpression("{a} * {b} / {c} + {d} / {e}",\
conditions = ["{a} not in [-1, 0, 1]", "{b} != 0", "{c} not in [0,1]", \
"{d} != 0", "{e} not in [0,1]", "{c} != {e}"])
#mult4 = RdExpression("{e} / {f} * {g} / {h}", \
# conditions = ["{e} != 0", "{g} != 0", "{f} != 0", "{g} != 0", \
# "gcd({e*g}, {f*h}) == 1"])
mult5 = RdExpression("{e} / {f} * {g} / {h}", \
conditions = ["{e} != 0", "{g} != 0", "{f} not in [0, 1]", "{h} not in [0, 1]"])
#"gcd({e*g}, {f*h}) != 1"])
div1 = RdExpression("{a} / {b} : {c} / {d}", \
conditions = ["{a} not in [0]", "{b} not in [0,1]", "{c} != 0","{d} not in [0]"])
frac = {"add1": add1,\
"add2": add2,\
"add3": add3,\
"add4": add4,\
"add5": add5, \
"mult1": mult1,\
"mult2": mult2,\
"mult3": mult2,\
#"mult4": mult2,\
"mult5": mult5, \
"div1": div1 }
if __name__ == '__main__':
print(add1())
print(add2())
print(add3())
print(add4())
print(add5())
print(mult1())
print(mult2())
print(mult3())
#print(mult4())
print(mult5())
print(div1())
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del