>
> Unfortunately, though 'modulus' works in some cases of solve/algsys:
>
> modulus:3$
> solve(x^2+2,x) => [x=-1,x=1]
>
> It does not work in all cases:
>
> modulus:11$
> algsys([3*x^4-1],[x]) => [[x = sqrt(2)], [x = - sqrt(2)], [x = 3], [x
> = - 3]]
>
The problem is that Maxima is going to find solutions outside the
space we're currently working in... As long as it can find the good
solutions next to those bad ones, I'm totally happy with that. But
indeed it's a strange behaviour.
__
Actually I'm experimenting with a very simple and geek example, but I can't
find the way how to get it work properly:
modulus:2$
e : [
s2 = a2 + b2,
s1 = c2 + a1 + b1,
c2 = a2*b2 ,
c1 = c2*a1 + a1*b1 + c2*b1,
s0 = c1 + a0 + b0
];
This is en equation system that models the sum of two 3 bit unsigned
integers. s = a + b, where s, a and b are 3 bit numbers. a0, a1, a2 are
the bits of 'a', b0,b1,b2 are the bits of 'b', and s0,s1,s2 are the bits of
the
sum 's'. c2 and c1 are the carry bits. (Yes, I know that it's a silly
thing
to do binary arithmetic with Z2, but it's just my small example to get to
know the way I can solve my real problem - which is very similar in
structure to this one.)
So I fill in the values of the inputs (I mean the bits of 'a' and 'b'):
(a0:0,a1:1,a2:1)$
(b0:0,b1:1,b2:1)$
[a0,a1,a2];
=> [0, 1, 1]
[b0,b1,b2];
=> [0, 1, 1]
...and calculate the sum:
solve(eliminate(''e, [c1,c2]), [s0,s1,s2]);
=> [[s0 = - 1, s1 = - 1, s2 = 0]]
That's correct, the sum is [1,1,0]. But I'm quite sure I do something
strange here, because it does not work without the elimination of the two
carry variables. (Why??)
What's more suspicious, when I try to use the same equations to calculate
a difference (in that case 's' is the input/known variable and 'b' (or 'a'
if
you want) is the output/unknown), I get a strange error message:
kill(b0,b1,b2)$
(s0:1,s1:1,s2:0)$
solve(eliminate(''e, [c1,c2]), [b0,b1,b2]);
=> Polynomial quotient is not exact
This is because of the elimination of the carry variables, but solve just
does not do what I want (with ot without eliminate() either):
solve(''e, [b0,b1,b2]);
=> []
But for me the equations obviously have a solution (I can come up
with it even in head):
''e;
=> [0 = b2 + 1, 1 = c2 + b1 + 1, c2 = b2, c1 = b1 c2 + c2 + b1, 1 = c1 + b0]
b2 must be 1 because of the first equation, c2 is also 1 because of the
third one,
so the second one now looks like 1=1+b1+1, so b1 must be 1, too. The 4th
equation
is then c1 = 1*1 + 1 + 1 = 1 + 1 + 1 = 1, so c1 = 1, and that means that
because of
the last equation (which is now 1 = 1 + b0) b0 must be 0. => 'b' is
bitwise [0,1,1].
Why can't Maxima tell this simply to me? Or if I'm wrong with the usage of
Maxima
somewhere, how can I do it right? Maybe the input variables shouldn't be
defined as
expressions? Or it's not solve() what I have to use?