# # file: human-readable.gap # # purpose: present elements of a vector space by their names # # created: Pasha Zusmanovich Nov 22 2024 # # transferred from tori-skryabin.gap (former print_elem()) # # v - element of a vector space # B - basis of this vector space # names - names for elements of the basis # returns the string expressing v as a linear combination of B as names elem2name := function (v, B, names) local coef, i, list, toadd; coef := Coefficients (B, v); list := []; for i in [1 .. Length(B)] do if (IsZero (coef[i])) then continue; elif (IsOne (coef[i])) then toadd := names[i]; else toadd := Concatenation (String (coef[i]), names[i]); fi; Add (list, toadd); od; return (JoinStringsWithSeparator (list, " + ")); end; # B - basis of a vector subspace # B_ambient - basis of the ambient vector space # names - names of elements of B_ambient print_vect_subspace := function (B, B_ambient, names) local b, list; list := []; Print ("[ "); for b in B do Add (list, elem2name (b, B_ambient, names)); od; Print (JoinStringsWithSeparator (list, ", "), " ]\n"); end; # eof