Changeset 5894:9b0b78864034 for sage/groups/perm_gps/cubegroup.py
- Timestamp:
- 08/23/07 10:57:20 (6 years ago)
- Branch:
- default
- File:
-
- 1 edited
-
sage/groups/perm_gps/cubegroup.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/groups/perm_gps/cubegroup.py
r5644 r5894 38 38 - " (2007-06): added plotting functions 39 39 - " (2007-08): colors corrected, "solve" rewritten, and typos fixed. 40 - Robert Bradshaw (2006-08): RubiksCube object. 40 41 41 42 REFERENCES: … … 58 59 import random 59 60 61 from sage.structure.sage_object import SageObject 60 62 import sage.structure.element as element 61 63 import sage.groups.group as group … … 75 77 sin = Function_sin() 76 78 cos = Function_cos() 77 pi = 3.14159265 79 pi = RDF.pi() 80 81 from sage.plot.graphics3d import * 78 82 79 83 ####################### predefined colors ################## … … 562 566 563 567 568 569 564 570 ####################### end of "internal" utility plot functions ################# 565 571 … … 610 616 611 617 def __str__(self): 612 return "The Rubik's cube group with genrators R,L,F,B,U,D in SymmetricGroup(48)."618 return "The Rubik's cube group with genrators R,L,F,B,U,D in SymmetricGroup(48)." 613 619 614 620 def __repr__(self): 615 return "The PermutationGroup of all legal moves of the Rubik's cube."621 return "The PermutationGroup of all legal moves of the Rubik's cube." 616 622 617 623 def __call__(self,other): … … 632 638 def B(self): 633 639 G = self.group() 634 g = G(self.gens()[0])640 g = G(self.gens()[0]) 635 641 return g 636 642 637 643 def D(self): 638 G = self.group()639 g = G(self.gens()[1])644 G = self.group() 645 g = G(self.gens()[1]) 640 646 return g 641 647 642 648 def F(self): 643 649 G = self.group() 644 g = G(self.gens()[2])650 g = G(self.gens()[2]) 645 651 return g 646 652 647 653 def L(self): 648 654 G = self.group() 649 g = G(self.gens()[3])655 g = G(self.gens()[3]) 650 656 return g 651 657 652 658 def R(self): 653 659 G = self.group() 654 g = G(self.gens()[4])660 g = G(self.gens()[4]) 655 661 return g 656 662 657 663 def U(self): 658 664 G = self.group() 659 g = G(self.gens()[5])665 g = G(self.gens()[5]) 660 666 return g 661 667 … … 703 709 r""" 704 710 Returns the group element and the reordered list of facets, as moved by 705 the list mv (read left-to-right)706 707 INPUT: mv is a string of the form X^a*Y^b*...",708 where X, Y, ... are in {R,L,F,B,U,D}709 and a,b, ... are integers.710 711 EXAMPLES:712 sage: rubik = CubeGroup()713 sage: rubik.move("")[0]714 ()715 sage: rubik.move("R")[0]716 (3,38,43,19)(5,36,45,21)(8,33,48,24)(25,27,32,30)(26,29,31,28)717 sage: rubik.R()718 (25,27,32,30)(26,29,31,28)(3,38,43,19)(5,36,45,21)(8,33,48,24)719 720 """721 m = mv.split("*")722 M = [x.split("^") for x in m]723 #print M724 n = len(M)725 e = 0726 G = self.group()727 R,L,F,B,U,D = G.gens()728 g = G(1)729 fcts = self.facets()730 for i in range(n):731 if len(M[i])==1:732 M[i] = [M[i][0],"1"]733 #print M734 for i in range(n):735 x = M[i][0]736 if x == "R": h = self.R()737 elif x == "L": h = self.L()738 elif x == "U": h = self.U()739 elif x == "D": h = self.D()740 elif x == "F": h = self.F()741 elif x == "B": h = self.B()742 else: h = G(1)743 e = M[i][1]744 if e=="1": g = g*h745 if e=="2": g = g*h*h746 if e=="3": g = g*h*h*h747 if e=="(-1)": g = g*h*h*h748 pos = [g(i) for i in fcts]749 return [g,pos]711 the list mv (read left-to-right) 712 713 INPUT: mv is a string of the form X^a*Y^b*...", 714 where X, Y, ... are in {R,L,F,B,U,D} 715 and a,b, ... are integers. 716 717 EXAMPLES: 718 sage: rubik = CubeGroup() 719 sage: rubik.move("")[0] 720 () 721 sage: rubik.move("R")[0] 722 (3,38,43,19)(5,36,45,21)(8,33,48,24)(25,27,32,30)(26,29,31,28) 723 sage: rubik.R() 724 (25,27,32,30)(26,29,31,28)(3,38,43,19)(5,36,45,21)(8,33,48,24) 725 726 """ 727 m = mv.split("*") 728 M = [x.split("^") for x in m] 729 #print M 730 n = len(M) 731 e = 0 732 G = self.group() 733 R,L,F,B,U,D = G.gens() 734 g = G(1) 735 fcts = self.facets() 736 for i in range(n): 737 if len(M[i])==1: 738 M[i] = [M[i][0],"1"] 739 #print M 740 for i in range(n): 741 x = M[i][0] 742 if x == "R": h = self.R() 743 elif x == "L": h = self.L() 744 elif x == "U": h = self.U() 745 elif x == "D": h = self.D() 746 elif x == "F": h = self.F() 747 elif x == "B": h = self.B() 748 else: h = G(1) 749 e = M[i][1] 750 if e=="1": g = g*h 751 if e=="2": g = g*h*h 752 if e=="3": g = g*h*h*h 753 if e=="(-1)": g = g*h*h*h 754 pos = [g(i) for i in fcts] 755 return [g,pos] 750 756 751 757 def display2d(self,mv): … … 969 975 return P 970 976 return P 977 978 979 980 ########################################################## 981 # 3d object generation 982 ########################################################## 983 984 class RubiksCube(SageObject): 985 986 def __init__(self, facets=None, colors=[green, blue, yellow, white, orange, lpurple]): 987 self.colors = colors 988 self.facets = 989
Note: See TracChangeset
for help on using the changeset viewer.
