Context("Numeric"); Context()->variables->are(m=>"Real",s=>"Real"); $a = random(2,9,1); do { $b = random(2,9,1); } until ($a != $b); $f = Formula("$a s + $b (s-m)"); $A = $f->eval(s=>1,m=>0); $B = $f->eval(s=>0,m=>1); $F = Formula("$A s + $B m")->reduce; TEXT($F == $f ? "F and f agree" : "F and f are different");The key is that (for a linear function) the coefficients of s and m are the values of the function when (s,m)=(1,0), and (s,m)=(0,1), respectively. Then you can create the formula with the proper coefficients directly. The
TEXT
call should print "F and f agree", but you can use a test like this to check that the original function actually was linear (if it is coming from student input, for example).
Davide