grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
124 stars 24 forks source link

Remove variable names #277

Closed mikldk closed 5 years ago

mikldk commented 5 years ago

It is probably easy for you, but is there an easy way to remove variable names in a solution to Solve()? E.g. when I get

{x==10,y==10,a==50/3}

I would like an easy way to remove the variable names, e.g. called StripNames() such that

StripNames({x==10,y==10,a==50/3})

would return

{10, 10, 50/3}

Does such a function exists?

grzegorzmazur commented 5 years ago

Not a function, but there's a quite general mechanism (local rules) which works great in this case:

In> solutions := Solve({(x*y)/2-3*a == 0, x^2/4-(3*a)/2 == 0, 45-(3*x+(3*y)/2) == 0}, {x, y, a})
Out> {{x==0,y==30,a==0},{x==10,y==10,a==50/3}}
In> solutions := solutions /:: { _lhs == _rhs <- rhs }
Out> {{0,30,0},{10,10,50/3}}

The /:: operator applies a local rule, which matches _lhs==_rhs and rewrites it as rhs. Note that, contrary to global rules, local ones are defined by <- and not by <--.

mikldk commented 5 years ago

Fantastic. Thanks.