This file is indexed.

/usr/share/yacas/complex.rep/code.ys is in yacas 1.3.3-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* Complex numbers */

//
// II is the imaginary number Sqrt(-1), and remains that way.
// The difference is it isn't converted to the form Complex(x,y).
//

10 # II^n_IsNegativeInteger <-- (-II)^(-n);
20 # (II^_n)_(IsEven(n) = True) <-- (-1)^(n>>1);
20 # (II^_n)_(IsOdd(n)  = True) <--  II*(-1)^(n>>1);

LocalSymbols(complexReduce) [

  Set(complexReduce,
    Hold(
    {
      Exp(x_IsComplexII) <- Exp(ReII(x))*(Cos(ImII(x))+II*Sin(ImII(x)))
    }));

  NN(_c) <--
  [
    Local(result);
    c := (c /:: complexReduce);
    result := Coef(Expand(c,II),II,{0,1});
    result;
  ];

]; //LocalSymbols(complexReduce)


ReII(_c) <-- NN(c)[1];
ImII(_c) <-- NN(c)[2];
IsComplexII(_c) <-- (ImII(c) != 0);



0 # Complex(_r,i_IsZero) <-- r;
2 # Complex(Complex(_r1,_i1),_i2) <-- Complex(r1,i1+i2);
2 # Complex(_r1,Complex(_r2,_i2)) <-- Complex(r1-i2,r2);

6 # Complex(Undefined,_x) <-- Undefined;
6 # Complex(_x,Undefined) <-- Undefined;

/*Real parts */
110 # Re(Complex(_r,_i)) <-- r;
120 # Re(Undefined) <-- Undefined;
300 # Re(_x) <-- x;

/* Imaginary parts */
110 # Im(Complex(_r,_i)) <-- i;
120 # Im(Undefined) <-- Undefined;
300 # Im(_x) <-- 0;

/* All things you can request a real and imaginary part for are complex */
1 # IsComplex(x_IsRationalOrNumber)     <-- True;
2 # IsComplex(Complex(_r,_i)) <-- True;
3 # IsComplex(_x)             <-- False;

IsNotComplex(x) := Not(IsComplex(x));
/* Addition */

110 # Complex(_r1,_i1) + Complex(_r2,_i2) <-- Complex(r1+r2,i1+i2);
300 # Complex(_r,_i) + x_IsConstant <-- Complex(r+x,i);
300 # x_IsConstant + Complex(_r,_i) <-- Complex(r+x,i);
 
110 # - Complex(_r,_i) <-- Complex(-r,-i);

300 # Complex(_r,_i) - x_IsConstant <-- Complex(r-x,i);
300 # x_IsConstant - Complex(_r,_i) <-- Complex((-r)+x,-i);
111 # Complex(_r1,_i1) - Complex(_r2,_i2) <-- Complex(r1-r2,i1-i2);

/* Multiplication */
110 # Complex(_r1,_i1) * Complex(_r2,_i2) <-- Complex(r1*r2-i1*i2,r1*i2+r2*i1);
/* right now this is slower than above
110 # Complex(_r1,_i1) * Complex(_r2,_i2) <--
[	// the Karatsuba trick
	Local(A,B);
	A:=r1*r2;
	B:=i1*i2;
	Complex(A-B,(r1+i1)*(r2+i2)-A-B);
];
*/


// Multiplication in combination with complex numbers in the light of infinity
250 # Complex(r_IsZero,_i) * x_IsInfinity <-- Complex(0,i*x);
250 # Complex(_r,i_IsZero) * x_IsInfinity <-- Complex(r*x,0);
251 # Complex(_r,_i) * x_IsInfinity <-- Complex(r*x,i*x);

250 # x_IsInfinity * Complex(r_IsZero,_i) <-- Complex(0,i*x);
250 # x_IsInfinity * Complex(_r,i_IsZero) <-- Complex(r*x,0);
251 # x_IsInfinity * Complex(_r,_i) <-- Complex(r*x,i*x);


300 # Complex(_r,_i) * y_IsConstant <-- Complex(r*y,i*y);
300 # y_IsConstant * Complex(_r,_i) <-- Complex(r*y,i*y);

330 # Complex(_r,_i) * (y_IsConstant / _z) <-- (Complex(r*y,i*y))/z;
330 # (y_IsConstant / _z) * Complex(_r,_i) <-- (Complex(r*y,i*y))/z;


110 # x_IsConstant / Complex(_r,_i) <-- (x*Conjugate(Complex(r,i)))/(r^2+i^2);


300 # Complex(_r,_i) / y_IsConstant <-- Complex(r/y,i/y);

110 # (_x ^ Complex(_r,_i)) <-- Exp(Complex(r,i)*Ln(x));

110 # Sqrt(Complex(_r,_i)) <-- Exp(Ln(Complex(r,i))/2);
110 # (Complex(_r,_i) ^ x_IsRationalOrNumber)_(Not(IsInteger(x))) <-- Exp(x*Ln(Complex(r,i)));

// This is commented out because it used MathPower so (2*I)^(-10) became a floating-point number. Now everything is handled by binary algorithm below
//120 # Complex(r_IsZero,_i) ^ n_IsInteger <-- {1,I,-1,-I}[1+Mod(n,4)] * i^n;

123 # Complex(_r, _i) ^ n_IsNegativeInteger <-- 1/Complex(r, i)^(-n);

124 # Complex(_r, _i) ^ (p_IsZero) <-- 1;	// cannot have Complex(0,0) here

125 # Complex(_r, _i) ^ n_IsPositiveInteger <--
[
	// use binary method
	Local(result, x);
	x:=Complex(r,i);
	result:=1;
	While(n > 0)
	[
		if ((n&1) = 1)
		[
		  result := result*x;
		];
		x := x*x;
		n := n>>1;
	];
	result;
];


/*[	// this method is disabled b/c it suffers from severe roundoff errors
  Local(rr,ii,count,sign);
  rr:=r^n;
  ii:=0;
  For(count:=1,count<=n,count:=count+2) [
    sign:=If(IsZero(Mod(count-1,4)),1,-1);
    ii:=ii+sign*Bin(n,count)*i^count*r^(n-count);
    If(count<n, 
      rr:=rr-sign*Bin(n,count+1)*i^(count+1)*r^(n-count-1));
  ];
  Complex(rr,ii);
];
*/

LocalSymbols(a,x)
[
Function("Conjugate",{a}) 
  Substitute(a,{{x},Type(x)="Complex"},{{x},Complex(x[1],-(x[2]))});
]; // LocalSymbols(a,x)

Function("Magnitude",{x}) [
	Sqrt(Re(x)^2 + Im(x)^2);
];

10 # Arg(Complex(Cos(_x),Sin(_x))) <-- x;
10 # Arg(x_IsZero) <-- Undefined;
15 # Arg(x_IsPositiveReal) <-- 0;
15 # Arg(x_IsNegativeReal) <-- Pi;
20 # Arg(Complex(r_IsZero,i_IsConstant)) <-- Sign(i)*Pi/2;
30 # Arg(Complex(r_IsPositiveReal,i_IsConstant)) <-- ArcTan(i/r);
40 # Arg(Complex(r_IsNegativeReal,i_IsPositiveReal)) <-- Pi+ArcTan(i/r);
50 # Arg(Complex(r_IsNegativeReal,i_IsNegativeReal)) <-- ArcTan(i/r)-Pi;