To find the real conjugate (Maple Procedure)

43 Views Asked by At

I'm trying to write a procedure which returns the real conjugate of a real number.

Ex: $2 + \sqrt3 \rightarrow 2 - \sqrt3$

I tried:

rconj:= proc(x) local i,y; y:=-x; for i to nops(x) do if type(op(i,x),rational) then op(i,y):= -op(i,x); end if; end do; return y; end proc

It isn't working. Error statement: "Error, (in rconj) invalid left hand side in assignment".

Any suggestions? Thank you.

1

There are 1 best solutions below

2
On BEST ANSWER

For simple cases

rconj := proc(x::radnum)
  maptype(`+`, (y -> `if`(type(y,anything^fraction), -y, y)), x)
end proc;

this will do what you want. It is not properly general (it really doesn't do the right thing for cube roots), but gives you a starting point.