Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Views: 1794
Image: ubuntu2004
1
load("__common__.sage")
2
3
def generator():
4
x=var("x")
5
function_letter=choice(["f","g","h"])
6
f=function(function_letter)(x)
7
fp=function(function_letter+"p",latex_name=function_letter+"'")(x)
8
9
# some linear terms
10
linear_terms = [
11
x^randrange(0,4)*f,
12
f(x=x^randrange(1,4)),
13
f(x=choice([-1,1])*randrange(1,6)),
14
fp,
15
fp(x=choice([-1,1])*randrange(1,6)),
16
]
17
shuffle(linear_terms)
18
# some non-linear
19
nonlinear_terms = [
20
f^randrange(2,4),
21
f*fp,
22
x^randrange(0,4),
23
]
24
shuffle(nonlinear_terms)
25
26
linear_trans = choice([-1,1])*randrange(1,6)*linear_terms[0] +\
27
choice([-1,1])*randrange(1,6)*linear_terms[1]
28
29
nonlinear_trans = choice([-1,1])*randrange(1,6)*linear_terms[2] +\
30
choice([-1,1])*randrange(1,6)*nonlinear_terms[0]
31
32
swapped = choice([True,False])
33
34
return {
35
"swapped": swapped,
36
"linear_trans": linear_trans,
37
"nonlinear_trans": nonlinear_trans,
38
"f_letter": function_letter
39
}
40
41