# Typesetting Simple Student Worksheet Question & need to defer computation

I have

eq1=2*(x+10)/5==3*(6-5*x)/7


the command print latex(eq1) simplifies the equation to $$\frac{2}{5} x + 4 = -\frac{15}{7} x + \frac{18}{7}$$

is there something like latex(eq1.hold()) that would produce

$$\frac{2(x+3)}{5}=\frac{3(6-5x)}{7}$$

edit: I must apologize in advanced as my code may seem infantile but I am very new to this and trying to learn. That said, I was able to get something going but it seems to me there must be a million better ways to do this. Can you point me in the right direction to generalize this process and improve this code. Keep in mind the point of this is to write a student worksheet with problem sets and solutions. can be seen here link text

ri = lambda x,y:  floor(round(random()*(y-x)+x)); #random integer from x to y
ls = [ri(-5,-1),ri(1,3),ri(2,15),ri(2,15)];
rs = [ri(2,10),ri(-3,-1),ri(-6,-2),ri(2,15)];

def texLinearA(t): return "$\\frac{"+str(latex(t))+"\\left("+str(latex(t))+"+"+str(latex(t))+"x\\right)}{"+str(latex(t))+"}$";

def sageLinearA(t): x=var("x"); return  t*(t+t*x)/t;

eq1 = texLinearA(ls)+"="+texLinearA(rs);
eq2 = sageLinearA(ls)==sageLinearA(rs);
eq3 = eq2*lcm(ls,rs);
eq4=eq3-x*eq3.rhs().coefficient(x);
eq5=eq4-(eq4.lhs()).substitute(x=0);
eq6=eq5*(1/eq5.lhs().coefficient(x));

html(eq1);
show(eq2);
show(eq3);
show(eq4);
show(eq5);

edit retag close merge delete

Sort by » oldest newest most voted

Hello,

The nearest I am able to do is

sage:  sage: x.add(10,hold=True).mul(2,hold=True).mul(1/5,hold=True)
1/5*(2*(x + 10))


The thing is that there is nothing like division with symoblic expression (but you can take inverses and use multiplication). It can be seen on

sage: ((x-1)/(x+1)).operands()
[1/(x + 1), x - 1]
sage: ((x-1)/(x+1)).operator()
<built-in function mul>


And there is a problem with the argument hold since it sometimes reorder the terms (i.e. symbolic expressions always assume that + and * are commutative)

sage: var('y')
y
sage: x.mul(y,hold=True).operands()
[x, y]
sage: y.mul(x,hold=True).operands()
[x, y]


So an expression such as (x+3) / 5 does not exist in Sage as it automatically put 1/5 as the second term

sage: (x+3).mul(1/5, hold=True).operands()
[x + 3, 1/5]
sage: SR(1/5).mul(x+3, hold=True).operands()
[x + 3, 1/5]


Good luck.

Vincent

more