I have been trying to use the Magma Calculator: http://magma.maths.usyd.edu.au/calc/
Given a word u, in a finitely presented group, how do I declare g to be the group element represented by u?
Context:
I can define a group via a finite presentation. For example using the code:
G<a,b,c> := Group< a,b,c | a^2=b^2, b^2=c^2, c=a*b >;
If I then ask for the order of the group:
Order (G);
The correct answer of 8 is returned, so it does understand what G is.
However I want to know how to ask if two elements of the group are equal.
The problem is that a,b,c as well as G.1, G.2, G.3 denote elements of the free group generated by a,b,c. Similarly products of those symbols (and their inverses) represent words in the free group.
Thus
a*a^-1 eq a^-1*a;
returns true, as it is true in the free group, but
a^2 eq c^2;
returns false, even though it is true in the group G.
This is explained in https://magma.maths.usyd.edu.au/magma/handbook/text/851.
In the section "Operations on words" it says that:
"u eq v : Returns true if the words u and v are identical when freely reduced. NB When G is not a free group and false is returned, this does not imply that u and v do not represent the same element of G."
However Magma can do operations with group elements, including answering if two elements g,h, are the same:
g eq h;
The question is then, given a word u, in a finitely presented group, how do I declare g to be the group element represented by u?
Following the anwer by #Userulli I typed
G<a,b,c> := Group< a,b,c | a^2=b^2, b^2=c^2, c=a*b >;
u := a^2;
v := c^2;
g := ElementToSequence(G, u);
h := ElementToSequence(G, v);
g eq h;
and got the reply
>> g := ElementToSequence(G, u);
^
Runtime error in 'ElementToSequence': Bad argument types
Argument types given: GrpFP, GrpFPElt
>> h := ElementToSequence(G, v);
^
Runtime error in 'ElementToSequence': Bad argument types
Argument types given: GrpFP, GrpFPElt
>> g eq h;
^
User error: Identifier 'g' has not been declared or assigned
Have you tryied using the ElementToSequence method?
For example :
u := a^2;
g := ElementToSequence(u, G);
Then you can compare g with other elements in the group to see if they are the same:
v := c^2;
h := ElementToSequence(v, G);
h eq g; // this should return true
EDIT:
Stating the doc magma.maths.usyd.edu.au/magma/handbook/text/208 you need to use fields instead, so you should convert the group into a field, and then use ElementToSequence method to compare the two sequences?
Related
Arbitrary expression be
test := a*b*c+x+a*y+c*z;
output := SomeCommand(test, `+`);
output
[a*b*c,x,a*y,c*z];
Is there any command to do it as a expression.
I did this by converting it into string and using StringSplit command. converting each element from list to expression and in for loop.
test := convert(test, string)
with(StringTools):
output:=StringSplit(test, "+")
["a*b*c", "a*y", "c*z", "x"]
InertForm:-Parse(output[1])
value(output[1])
a*b*c
but, My interest is to get this done as a expression. is there any possibility??
You're question has input but no output. You should observe that the expression that you've assigned to test may have its addends stored in a different order from which they are typed in the input.
It is possible to pick off the addends of a sum, and put them in a list. The very simple code for this is below.
The order in which the addends appear in the list match the order in which they are stored internally.
restart;
f := proc(expr)
if type(expr, `+`) then
[op(expr)];
else
expr;
end if;
end proc:
test := a*b*c+x+a*y+c*z;
test := a b c + a y + c z + x
f( test );
[a b c, a y, c z, x]
Are you the same fellow who's asked all these (somewhat related) questions? Or taking the same course? Q1 Q2 Q3 Q4
If so then could you just tell use what you're really trying to accomplish?
I've been trying to define a function compdiff on the Wolfram Language that takes two mathematical expressions f and g and a variable x as input and outputs the difference of their compositions f[g[x]]-g[f[x]] (a sort of commutator if you are into abstract algebra).
For example: compdiff[x^2,x+1,x] = (x+1)^2-(x^2+1).
I've tried with
compdiff[f_,g_,x_]:= Composition[f,g][x]-Composition[g,f][x]
and
compdiff[f_,g_,x_]:= f #* g # x-g #* f # x
but when I input
compdiff[x^2,x+1,x]
it outputs
(x^2)[(1 + x)[x]] - (1 + x)[(x^2)[x]]
What am I doing wrong?
You need to use functions instead of expressions. For example:
f[x_] := x^2
g[x_] := x+1
Then compdiff[f, g, x] will work:
In[398]:= compdiff[f,g,x]
Out[398]= -1-x^2+(1+x)^2
Alternatively, you could use pure functions, as in:
In[399]:= compdiff[#^2&,#+1&,x]
Out[399]= -1-x^2+(1+x)^2
I am trying to look for specific characters in an array and print the output into an excel sheet in the same order (i.e if there are elements in between without a match it is left blank).
I used the following code within the loop:
EDIT:
[num,txt,~] = xlsread('protein-peptides.xls')
for i=1:size(txt)
str(i)=txt(i)
expression='\w*Pyro-glu from E\w*';
matchStr(i)=regexp(str(i),expression,'match','once');
ArrayOfStrings=vertcat(matchStr{:});
end
After the loop:
xlswrite(filename,ArrayOfStrings,1);
And the output is like below.
1) The elements without a match are not shown as blank
2) Each word of the match is displayed in a different cell.
P y r o - g l u f r o m E
P y r o - g l u f r o m E
P y r o - g l u f r o m E
P y r o - g l u f r o m E
How do I get the blank spaces left out in the matrix and have the entire matching phrase in a single cell in the output?
I tried concatenation of cells but that is printing all the output in a single row but still each character in different cells
I know you'd probably prefer to use xlswrite, but I wasn't able to get this to work (at least on OS X). It appears that xlswrite automatically strips out empty cells, as you observed. It also appears to be spreading each cell over multiple columns, which is bizarre and different from the behavior I remember. I wonder if there was a recent update (I'm using R2015b).
I was able to get this to work using simple fprintf calls to write a CSV file, which can be opened in Excel. Note that the termination character (\r) is critical; empty cells do not seem to be preserved in Excel if this is replaced by a linefeed. I also refactored your code a bit.
% Load data from Excel file
[~, txt, ~] = xlsread('protein-peptides.xls');
% Perform analysis
expression='\w*Pyro-glu from E\w*';
for i = 1:length(txt)
matches(i, 1) = regexp(txt(i), expression, 'match', 'once');
end
% Write data to CSV file
fid = fopen('test.csv', 'w+');
for i = 1:length(matches)
fprintf(fid, '%s\r', matches{i});
end
fclose(fid);
Input file rows
Pyro-Flu from E
test
Pyro-Flu from E
test
Output file rows
Pyro-glu from E
Pyro-glu from E
The following code is from perm.v in the Ssreflect Coq library.
I want to know what this result is.
Lemma perm_invK s : cancel (fun x => iinv (perm_onto s x)) s.
Proof. by move=> x /=; rewrite f_iinv. Qed.
Definitions in Ssreflect can involve lots of concepts, and sometimes it is hard to understand what is actually going on. Let's analyze this by parts.
iinv (defined in fintype.v) has type
iinv : forall (T : finType) (T' : eqType) (f : T -> T')
(A : pred T) (y : T'),
y \in [seq f x | x in A] -> T
What this does is to invert any function f : T -> T' whose restriction to a subdomain A \subset T is surjective on T'. Put in other words, if you give me an y that is in the list of results of applying f to all elements of A, then I can find you an x \in A such that f x = y. Notice that this relies crucially on the fact that T is a finite type and that T' has decidable equality. The correctness of iinv is stated in lemma f_iinv, which is used above.
perm_onto has type codom s =i predT, where s is some permutation defined on a finite type T. This is saying, as its name implies, that s is surjective (which is obvious, since it is injective, by the definition of permutations in perm.v, and by the fact that the domain and codomain are the same). Thus, fun x => iinv (perm_onto s x) is a function that maps an element x to an element y such that s y = x. In other words, its the inverse of s. perm_invK is simply stating that this function is indeed the inverse (to be more precise, it is saying that it is the left inverse of s).
The definition that is actually useful, however, is perm_inv, which appears right below. What it does is that it packages fun x => iinv (perm_onto s x) with its proof of correctness perm_invK to define an element of perm_inv s of type {perm T} such that perm_inv s * s = s * perm_inv s = 1. Thus, you can view it as saying that the type {perm T} is closed under inverses, which allows you to use a lot of the ssr machinery for e.g. finite groups and monoids.
I am learning Coq at school, and I have an assignment to do for home. I have a lemma to proove: If a list contains a zero among its elements, then the product of its elements is 0. I started my code, and I am stuck in a point where I do not know how to go on. I do not know all the commands from Coq, I did a lot of research, but I cannot manage to find my way to the end of the Proof. Here is my code:
Require Import List ZArith.
Open Scope Z_scope.
Fixpoint contains_zero (l : list Z) :=
match l with
nil => false
| a::tl => if Zeq_bool a 0 then true else contains_zero tl
end.
Fixpoint product (l : list Z) :=
match l with
nil => 1
| a::tl => a * product tl
end.
Lemma Zmult_integral_r :
forall n m, m <> 0 -> m * n = 0 -> n = 0.
Proof.
intros n m m0; rewrite Zmult_comm; apply Zmult_integral_l.
assumption.
Qed.
Lemma product_contains_zero :
forall l, contains_zero l = true -> product l = 0.
intros l H.
So, I thought that it would be a good idea to create a function that checks if the list contains a zero, and another one to calculate the product of its elements. I have also found (luckily) a lemma online that prooves that if I have 2 numbers , and I know that one of them is not 0, and their product is 0, then necessarily the other number is 0 (I thought that might help). I thought about doing a proof by induction, but that didn't work out. Any ideas? I know that this is not the place to ask someone to do my work , I AM NOT ASKING THAT, I just need an idea.
1/ You do not need the theorem that you mention, " if I have 2 numbers , and I know that one of them is not 0, and their product is 0, then necessarily the other number is 0". You don't need it because you want to prove that the product is 0, you are not in a situation where you want to use the fact that the product is zero.
So the theorem Zmult_integral_r is not useful for the lemma in this question. It would be useful if you had to prove forall l, product l = 0 -> contains_zero l = true.
Here, for your problem, the two functions that you consider are recursive, so the usual hint is to do a proof by induction, and then to use the tactic simpl to make the functions look simpler.
Represent product of two numbers as one number while you will stand with that lemma.