[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Axiom-developer] expand sin (nx) and cos (nx)
From: |
Francois Maltey |
Subject: |
[Axiom-developer] expand sin (nx) and cos (nx) |
Date: |
15 Mar 2006 17:56:23 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Hello Martin, hello everybody !
I try to improve the expand function,
I want to use it with my students in the chapter "trigonometric functions"
Today I don't change the package MANIP.spad, but I write *.input files.
I hope I can compile it without problem later inside the MANIP.spad
At the end of this input file you can try :
expand1 (cos (3*x))+%i*expand1 (sin (3*x)) - (cos(x)+%i*sin(x))^3
expand1 (cos (a+b))
expand1 (sin (a-b)) -- doesn't work
expand1 (sin (b-a)) -- is right
So I have several problems :
// A //
My first function is a function which gives the name of the function :
With mupad I done :
op (3*x+5*y, 1) -> _plus
op (3*x, 1) -> _mult
op (x^3, 1) -> _power
op (sin(3*x), 1) -> sin
op (cos(3*x), 1) -> cos
With axiom I try this function :
operator1 x ==
(retractIfCan x)@Union(Kernel Expression Integer,"failed")
but it works only for Expression Integer, not Expression Complex Integer.
Is it possible to translate the mupad function : mainFct := x -> op (x, 1)
// B //
Why must I add some coerces in this input file
// C //
What are the usual Expression ... type.
Can I be sure that coef in Integer, Fraction Integer, Complex Integer ?
Is it possible to have Float or DoubleFloat...
How can I test if variable coef in an Integer or not ?
Thanks a lot if you can give me your advice !
Francois maltey. [I post at 17h UTC, 18h in France]
------------------------------------------------------------------------
You can test it in an *.input file.
error remains.
But I'd like to have information about dirty functions as operator1
or silly coerce.
------------------------------------------------------------------------
operator1 x ==
(retractIfCan x)@Union(Kernel Expression Integer,"failed")
expand1 (a : Expression Integer) : Expression Integer ==
op := operator1 a
op case "failed" => a
arg := first argument (op::Kernel Expression Integer) -- I must coerce
is? (operator op, "cos"::Symbol) => expandcos arg
is? (operator op, "sin"::Symbol) => expandsin arg
a
sinnx (n,x) == eval (imag ((c + %i * s)^n), [c, s], [cos x, sin x])
cosnx (n,x) == eval (real ((c + %i * s)^n), [c, s], [cos x, sin x])
expandsin arg ==
arg = 0 => 0
num := numer arg
den := denom arg
head := leadingMonomial num
coef := leadingCoefficient num
a := head / coef / den
tail := reductum num
b := (tail / den)::Expression Integer -- I must coerce
sinnx (coef, a) * expand1 (cos b) + cosnx (coef, a) * expand1 (sin b)
expandcos arg ==
arg = 0 => 1
num := numer arg
den := denom arg
head := leadingMonomial num
coef := leadingCoefficient num
a := head / coef / den
tail := reductum num
b := (tail / den)::Expression Integer -- I must coerce
cosnx (coef, a) * expand1 (cos b) - sinnx (coef, a) * expand1 (sin b)
-- You can try :
expand1 (cos (3*x))+%i*expand1 (sin (3*x)) - (cos(x)+%i*sin(x))^3
expand1 (sin (a-b))
expand1 (sin (a+b))
expand1 (cos (b-a))
- [Axiom-developer] expand sin (nx) and cos (nx),
Francois Maltey <=