axiom-developer
[Top][All Lists]

## [Axiom-developer] Re: symbolic (exact) trig expressions versus numeric r

 From: Bill Page Subject: [Axiom-developer] Re: symbolic (exact) trig expressions versus numeric results Date: Thu, 18 Jun 2009 22:02:35 -0400

```In a recent report Arnold Doray observed that conjugate sometimes
seems to fail when operating on complicated exact complex numbers:

http://lists.gnu.org/archive/html/axiom-mail/2009-06/msg00027.html

To resolve this problem, the following cumulative patch against FriCAS
adds 'conjugate' and 'norm' for symbolic complex expressions to the to
the patch I sent earlier today.

===================================================================
@@ -767,6 +767,7 @@
ker2explogs: (KG, List KG, List SY) -> FG
smp2explogs: (PG, List KG, List SY) -> FG
+    nthroot:     (GF,GF) -> GF
supexp     : (UP, GF, GF, Z) -> GF
GR2GF      : GR -> GF
GR2F       : GR -> F
@@ -847,13 +848,24 @@
map(x +-> explogs2trigs(x::FG), GR2GF, p)\$PolynomialCategoryLifting(
IndexedExponents KG, KG, GR, PG, GF)

-    explogs2trigs f ==
-      (m := mainKernel f) case "failed" =>
+    -- De Moivre's theorem
+    nthroot(a:GF,n:GF):GF ==
+      r := nthRoot(sqrt(norm(a)),retract(n)@Z)
+      e := exp(complex(0, 1)*argument(a)/n)
+      r*e
+
+    explogs2trigs(f:FG):GF ==
+      m := mainKernel f
+      m case "failed" =>
GR2GF(retract(numer f)@GR) / GR2GF(retract(denom f)@GR)
-      op  := operator(operator(k := m::KG))\$F
+      k := m::KG
+      op  := operator(operator(k))\$F
arg := [explogs2trigs x for x in argument k]
num := univariate(numer f, k)
den := univariate(denom f, k)
+      is?(op,'nthRoot) =>
+        h := nthroot(first arg, second arg)
+        supexp(num,h,0,0)/supexp(den,h,0,0)
is?(op, 'exp) =>
e  := exp real first arg
y  := imag first arg
@@ -926,6 +938,10 @@
imag   : F -> F
++ is a complex function.
+    conjugate:F-> F
+      ++ conjugate(x+%i*y) returns x-%i*y
+    norm   : F -> F
+      ++ norm(f) returns f*conjugate(f)
real?  : F -> Boolean
complexForm: F -> Complex F
@@ -952,6 +968,8 @@
real? f          == empty?(complexKernels(f).ker)
real f           == real complexForm f
imag f           == imag complexForm f
+    conjugate f      == real(f) - sqrt(-1) * imag(f)
+    norm f           == f * conjugate(f)

-- returns [[k1,...,kn], [v1,...,vn]] such that ki should be replaced by vi
complexKernels f ==
@@ -1067,6 +1085,10 @@
imag   : F -> FR
++ is a complex function.
+    conjugate:F-> F
+      ++ conjugate(x+%i*y) returns x-%i*y
+    norm   : F -> FR
+      ++ norm(f) returns f*conjugate(f)
real?  : F -> Boolean
trigs  : F -> F
@@ -1087,6 +1109,8 @@

real f        == real complexForm f
imag f        == imag complexForm f
+    conjugate f      == F2FG real(f) - complex(0,1) * F2FG imag(f)
+    norm f           == FG2F(f * conjugate f)
rreal? r      == zero? imag r
kreal? k      == every?(real?, argument k)\$List(F)
complexForm f == explogs2trigs f

---

Note: These functions treat symbols appearing in values of type
'Expression Complex R' as variables of type R.

(1) -> conjugate(x+%i*y)

(1)  - %i y + x
Type: Expression(Complex(Integer))
(2) -> norm(x+%i*y)

2    2
(2)  y  + x
Type: Expression(Integer)
(3) -> conjugate(sqrt(x))

+-+
(3)  \|x
Type: Expression(Integer)
(4) -> conjugate(sqrt(x*%i))

+--+         +--+
| 2         4| 2
(\|x   - %i x)\|x
(4)  -------------------
+--+
+-+ | 2
\|2 \|x
Type: Expression(Complex(Integer))
(5) ->

Further testing is encouraged.

Regards,
Bill Page.
```

ctrigmnp-fricas.patch
Description: Binary data