Ukvayat

52 Reputation

2 Badges

11 years, 336 days

MaplePrimes Activity


These are answers submitted by Ukvayat

Here is the completed program, but you can see that I'm missing a proc that takes each alpha and beta from the Step procs. We don't know how many times it will go through each proc before it completes. But the next program in the algorithm requires the alphas to be multiplied together and the betas multiplied together in order.

PROGRAM CODE

 

01

LocSubAlg:=module()

 

 

 

 

 

 

 

 

02

    description "the local case sub-algorithm";

 

 

 

 

03

    local DegCk, Step1, Step2,

 

 

 

 

 

 

 

04

         UnitCk, Step3, Step4, g,

 

 

 

 

 

 

05

         k, m, n, p, z, z0, z1, z2,

 

 

 

 

 

 

06

         z3, a1, B, a, b, c, d, h, l;

 

 

 

 

 

07

    global A, q, alpha, alpha1,

 

 

 

 

 

 

 

08

         beta, beta1, beta2, beta0;

 

 

 

 

 

 

09

    export Start, Print;

 

 

 

 

 

 

 

 

10

    Start:= proc()

 

 

 

 

 

 

 

 

11

        a:=readstat("Please enter the polynomial a: ");

 

 

 

12

        b:=readstat("Please enter the polynomial b: ");

 

 

 

13

        c:=readstat("Please enter the polynomial c: ");

 

 

 

14

        d:=readstat("Please enter the polynomial d: ");

 

 

 

15

          A:= Matrix(3,3);

 

 

 

 

 

 

 

16

             A[1,1]:= a;

 

 

 

 

 

 

 

 

17

             A[1,2]:= b;

 

 

 

 

 

 

 

 

18

             A[2,1]:= c;

 

 

 

 

 

 

 

 

19

             A[2,2]:= d;

 

 

 

 

 

 

 

 

20

             A[3,3]:= 1;

 

 

 

 

 

 

 

 

21

          alpha:= Matrix(3, 3, shape = identity);

 

 

 

 

22

          beta:= Matrix(3, 3, shape = identity);

 

 

 

 

23

        DegCk();

 

 

 

 

 

 

 

 

 

24

    end proc;

 

 

 

 

 

 

 

 

 

25

    DegCk:= proc()

 

 

 

 

 

 

 

 

26

        m:= degree(A[1,1], t);

 

 

 

 

 

 

 

27

        n:= degree(A[1,2], t);

 

 

 

 

 

 

 

28

        if m = 0 then

 

 

 

 

 

 

 

 

29

          Step4()

 

 

 

 

 

 

 

 

 

30

        elif m < n then

 

 

 

 

 

 

 

 

31

          Step1()

 

 

 

 

 

 

 

 

 

32

        elif m = n then

 

 

 

 

 

 

 

 

33

          Step1()

 

 

 

 

 

 

 

 

 

34

        else

 

 

 

 

 

 

 

 

 

35

          UnitCk()

 

 

 

 

 

 

 

 

36

        end if;

 

 

 

 

 

 

 

 

 

37

    end proc;

 

 

 

 

 

 

 

 

 

38

    Step1:= proc()

 

 

 

 

 

 

 

 

39

        alpha:= Matrix(3, 3, shape = identity);

 

 

 

 

40

        beta:= Matrix(3, 3, shape = identity);

 

 

 

 

41

        q:=quo(A[1,2], A[1,1], t);

 

 

 

 

 

 

42

        beta:=beta.(Matrix([[1, (-1)*q, 0],

 

 

 

 

 

43

                            [0, 1, 0],

 

 

 

 

 

44

                            [0, 0, 1]]));

 

 

 

 

 

45

        A:=A.beta;

 

 

 

 

 

 

 

 

 

46

        A:=simplify(A);

 

 

 

 

 

 

 

 

47

        print(A);

 

 

 

 

 

 

 

 

 

48

        UnitCk();

 

 

 

 

 

 

 

 

 

49

    end proc;

 

 

 

 

 

 

 

 

 

50

    UnitCk:= proc()

 

 

 

 

 

 

 

 

51

        z0:=eval(A[1,1], t=0);

 

 

 

 

 

 

 

52

        z1:=eval(A[1,2], t=0);

 

 

 

 

 

 

 

53

        z2:=eval(A[2,1], t=0);

 

 

 

 

 

 

 

54

        z3:=eval(A[2,2], t=0);

 

 

 

 

 

 

 

55

        if ((z0*z3)-(z1*z2))=1 then

 

 

 

 

 

 

56

           Step2()

 

 

 

 

 

 

 

 

 

57

        else Step3()

 

 

 

 

 

 

 

 

58

        end if;

 

 

 

 

 

 

 

 

 

59

    end proc;

 

 

 

 

 

 

 

 

 

60

    Step2:= proc()

 

 

 

 

 

 

 

 

61

        alpha:= Matrix(3, 3, shape = identity);

 

 

 

 

62

        beta:= Matrix(3, 3, shape = identity);

 

 

 

 

63

        g:=eval(A[1,1], t=0);

 

 

 

 

 

 

 

64

        h:=eval(A[1,2], t=0);

 

 

 

 

 

 

 

65

        k:=(-g/h);

 

 

 

 

 

 

 

 

 

66

        beta0:=beta.(Matrix([[1, 0, 0],

 

 

 

 

 

67

                             [k, 1, 0],

 

 

 

 

 

68

                             [0, 0, 1]]));

 

 

 

 

 

69

        B:=A.beta0;       

 

 

 

 

 

 

 

70

        l:=((h-B[1,2])/t);

 

 

 

 

 

 

 

71

        m:=(t*h);

 

 

 

 

 

 

 

 

 

72

        a1:=(B[1,1]/t);

 

 

 

 

 

 

 

 

73

        n:=(((-B[2,1]*(h-B[1,2]))

 

 

 

 

 

 

74

           -(a1*B[2,2]*t))/m);

 

 

 

 

 

 

 

75

        alpha1:=(Matrix([[1, 0, 0],

 

 

 

 

 

 

76

                         [0, 0, 1],

 

 

 

 

 

 

77

                         [0, -1, 0]]))

 

 

 

 

 

78

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

79

                         [0, 1, ((-1)*a1*(B[2,2]))],

 

 

 

80

                         [0, 0, 1]]))

 

 

 

 

 

 

81

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

82

                         [(B[2,1])*(B[2,2]), 1, 0],

 

 

 

83

                         [0, 0, 1]]));

 

 

 

 

 

84

         beta1:=(Matrix([[1, 0, 0],

 

 

 

 

 

 

85

                         [0, 1, 0],

 

 

 

 

 

 

86

                         [(t*B[2,1]), 0, 1]]))

 

 

 

 

87

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

88

                         [0, 1, 0],

 

 

 

 

 

 

89

                         [0, (t*(B[2,2])), 1]]))

 

 

 

 

90

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

91

                         [0, 1, ((-1)*a1)],

 

 

 

 

 

92

                         [0, 0, 1]]))

 

 

 

 

 

 

93

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

94

                         [0, 0, 1],

 

 

 

 

 

 

95

                         [0, -1, 0]]));

 

 

 

 

 

96

         beta2:=(Matrix([[1, l, 0],

 

 

 

 

 

 

97

                         [0, 1, 0],

 

 

 

 

 

 

98

                         [0, 0, 1]]))

 

 

 

 

 

 

99

               .(Matrix([[h, 0, 0],

 

 

 

 

 

 

100

                         [0, h^(-1), 0],

 

 

 

 

 

101

                         [0, 0, 1]]))

 

 

 

 

 

 

102

               .(Matrix([[0, -1, 0],

 

 

 

 

 

 

103

                         [1, 0, 0],

 

 

 

 

 

 

104

                         [0, 0, 1]]))

 

 

 

 

 

 

105

               .(Matrix([[1, m, 0],

 

 

 

 

 

 

106

                         [0, 1, 0],

 

 

 

 

 

 

107

                         [0, 0, 1]]))

 

 

 

 

 

 

108

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

109

                         [n, 1, 0],

 

 

 

 

 

 

110

                         [0, 0, 1]]))

 

 

 

 

 

 

111

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

112

                         [0, 0, -1],

 

 

 

 

 

 

113

                         [0, 1, 0]]));

 

 

 

 

 

114

        alpha:=alpha1.alpha; beta:=beta1.beta2.beta;

 

 

 

 

 

 

 

115

        A:=alpha1.A.beta1.beta2;

 

 

 

 

 

 

116

        A:=simplify(A);

 

 

 

 

 

 

 

 

117

        print(A);

 

 

 

 

 

 

 

 

 

118

        DegCk();

 

 

 

 

 

 

 

 

 

119

    end proc;

 

 

 

 

 

 

 

 

 

120

    Step3:= proc()

 

 

 

 

 

 

 

 

121

        alpha:= Matrix(3, 3, shape = identity);

 

 

 

 

122

        beta:= Matrix(3, 3, shape = identity);

 

 

 

 

123

        gcdex(A[1,1], A[1,2], resultant(A[1,1],A[1,2],t), t, 'v', 'w');

124

        p:=(w*A[2,2]-v*A[2,1]);

 

 

 

 

 

 

 

125

        alpha1:=(Matrix([[1, 1, 0],

 

 

 

 

 

 

126

                         [0, 1, 0],

 

 

 

 

 

 

127

                         [0, 0, 1]]))

 

 

 

 

 

 

128

               .(Matrix([[1, 0, 0],

 

 

 

 

 

 

129

                         [p, 1, 0],

 

 

 

 

 

 

130

                         [0, 0, 1]]));

 

 

 

 

 

131

        alpha:=alpha1.alpha;

 

 

 

 

 

 

 

132

        A:=alpha1.A;

 

 

 

 

 

 

 

 

133

        A:=simplify(A);

 

 

 

 

 

 

 

 

134

        print(A);

 

 

 

 

 

 

 

 

 

135

        UnitCk();

 

 

 

 

 

 

 

 

 

136

    end proc;

 

 

 

 

 

 

 

 

 

137

    Step4:= proc()

 

 

 

 

 

 

 

 

138

        alpha:= Matrix(3, 3, shape = identity);

 

 

 

 

139

        beta:= Matrix(3, 3, shape = identity);

 

 

 

 

140

        beta1:=(Matrix([[1, (-1)*A[1,2], 0],

 

 

 

 

141

                        [0, 1, 0],

 

 

 

 

 

 

142

                        [0, 0, 1]]));

 

 

 

 

 

 

143

        alpha1:=(Matrix([[1, 0, 0],

 

 

 

 

 

 

144

                         [(-1)*A[2,1], 1, 0],

 

 

 

 

145

                         [0, 0, 1]]));

 

 

 

 

 

146

        alpha:=alpha1.alpha;

 

 

 

 

 

 

 

147

        beta:=beta.beta1;

 

 

 

 

 

 

 

148

        A:=alpha1.A.beta1;

 

 

 

 

 

 

 

149

        A:=simplify(A);

 

 

 

 

 

 

 

 

150

        print(A);

 

 

 

 

 

 

 

 

 

151

    end proc;

 

 

 

 

 

 

 

 

 

152

end module;

 

 

 

 

 

 

 

 

 

 

Sorry for the long reply - July has been busy (lazy).

I understood the second one better but now see the first one, sometimes one just needs to step back for a moment. And now I believe it would work, I haven't had the chance to implement it yet.

The one question I have is: Can I specify it up to n times and it only pull the ones needed? Since 10 definately won't be enough in some cases but I don't want reduncancy at say 1000.

Which brings up the reason I have it as a module - I had no clue how to set this up as one continuous procedure like I could in good ole QBasic and "goto line 21" statements. The only option I could think of and see was to encapsulate them all into a module. Surely there has to be a better way.

The purpose of Print is just to print the A, the main matrix and I might add some of the other matrices that appear in the program. The use really is to be a part of a larger whole and the matrix A will be used in other algorithms.

Thank you so much for your help, if I'm still having problems after I get done tinkering with this (hopefully tomorrow or Wednesday) I'll be sure to reply again. But the recommendations have seemed to remove some of the things I was having difficulties with.

Thanks!

'If' is a statement that tells you what you are beginning with and the 'then' part tells you what you end up with. 'If' is the cause and 'then' is the effect. Tells us that the statement is a logical consequence of what we start out with.

I really thought Maple 13 was more student friendly :D Guess it still has some of those little quirks.

...to do this but for some reason even the resultant wasn't working right for me.

I set f:=xy+1 and g:=x^2+1 and then typed resultant(f, g, x) just to make sure I was going to get what I wanted since I had worked this little problem by hand. But oddly enough it doesn't pump out the expected y^2+1 but rather (xy+1)^2. I then went with(Algebraic) and then Resultant(f,g,x) and got the exact same thing.

Either it is early Saturday morning and my brain hasn't kicked in yet or there is something wrong with my Maple.

So are you saying GCDex should work for what I need it to since the GCD should be 1 and then just multiply through by the resultant?

...I spend hours searching on Maple and related websites and nothing like that pops up....Mom always told me I was blind.

Thank you very very much!

Page 1 of 1