how to extract a common factor of vector components
v=vec([ax,ay])
should give
a*vec([x,y])
It's not clear what type of object you want as a result. You could store an 'unevaluated' expression such as a scalar times a vector as a formal sum (FormalSum
) with coefficients in the base ring of the vector:
def extract_gcd(vec):
g = gcd(vec)
return FormalSum([(g, vec/g)], parent=FormalSums(vec.base_ring()))
Now
var('a,x,y')
extract_gcd(vector([a*x,a*y]))
yields
a*(x, y)
As an alternative, you might just want to work with pairs:
def extract_gcd(vec):
g = gcd(vec)
return (g, vec/g)
Asked: 2018-06-30 13:18:38 +0200
Seen: 678 times
Last updated: Jun 30 '18
To display inline code, like
z = x*y
, use backticks.To display blocks of code or error messages, skip a line above and below, and do one of the following (all give the same result):
For instance, typing
produces:
Please edit your question to do that.