Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

""" 

Partition backtrack functions for lists -- a simple example of using partn_ref. 

  

EXAMPLES:: 

  

sage: import sage.groups.perm_gps.partn_ref.refinement_lists 

  

""" 

  

#***************************************************************************** 

# Copyright (C) 2006 - 2011 Robert L. Miller <rlmillster@gmail.com> 

# Copyright (C) 2009 Nicolas Borie <nicolas.borie@math.u-psud.fr> 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 2 of the License, or 

# (at your option) any later version. 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

  

from cysignals.memory cimport sig_malloc, sig_free 

  

from .data_structures cimport * 

from .double_coset cimport double_coset, int_cmp 

  

  

def is_isomorphic(self, other): 

r""" 

Return the bijection as a permutation if two lists are isomorphic, return 

False otherwise. 

  

EXAMPLES:: 

  

sage: from sage.groups.perm_gps.partn_ref.refinement_lists import is_isomorphic 

sage: is_isomorphic([0,0,1],[1,0,0]) 

[1, 2, 0] 

  

""" 

cdef int i, n = len(self) 

cdef PartitionStack *part 

cdef int *output 

cdef int *ordering 

part = PS_new(n, 1) 

ordering = <int *> sig_malloc((len(self)) * sizeof(int)) 

output = <int *> sig_malloc((len(self)) * sizeof(int)) 

if part is NULL or ordering is NULL or output is NULL: 

PS_dealloc(part) 

sig_free(ordering) 

sig_free(output) 

raise MemoryError 

for i from 0 <= i < (len(self)): 

ordering[i] = i 

  

cdef bint isomorphic = double_coset(<void *> self, <void *> other, part, ordering, (len(self)), &all_list_children_are_equivalent, &refine_list, &compare_lists, NULL, NULL, output) 

  

PS_dealloc(part) 

sig_free(ordering) 

if isomorphic: 

output_py = [output[i] for i from 0 <= i < (len(self))] 

else: 

output_py = False 

sig_free(output) 

return output_py 

  

cdef bint all_list_children_are_equivalent(PartitionStack *PS, void *S): 

return 0 

  

cdef int refine_list(PartitionStack *PS, void *S, int *cells_to_refine_by, int ctrb_len): 

return 0 

  

cdef int compare_lists(int *gamma_1, int *gamma_2, void *S1, void *S2, int degree): 

r""" 

Compare two lists according to the lexicographic order. 

""" 

cdef list MS1 = <list> S1 

cdef list MS2 = <list> S2 

cdef int i, j 

for i from 0 <= i < degree: 

j = int_cmp(MS1[gamma_1[i]], MS2[gamma_2[i]]) 

if j != 0: return j 

return 0