Multiplication of Boolean variables
Hi, I am implementing an arithmetic system for only Boolean variables based on GiNaC. May I know how I can modify the behaviour of symbolic multiplication such that: x*x == x (instead of x*x==x^2), and the multiplication of numeric remains unchanged (eg 3*4 == 12) ? Using subs(x^2 == x) works but I found it is slow if my expressions are huge and there are many symbols. Thank you very much. Best regards, argama
Hi,
On Mon, 26 Aug 2013 00:15:45 +0800, tklam <argama@gmail.com> said: tklam> behaviour of symbolic multiplication such that: x*x == x tklam> (instead of x*x==x^2),
The nearest solution I can propose, is to define a new function bool() of one variable and use, say, bool(x) and bool(y) instead of your Boolean variables x and y. The point is: for a function you have possibility to define its own behaviour under exponentiation, in particular, bool(x)^2=bool(x). Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk www: http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://www.worldscientific.com/worldscibooks/10.1142/p835
I did a quick hack by modifying power's constructor, eval() and expand(). This is very dirty. Your solution is much more elegant. Thanks a lot! Best regards, argama On Sun, Sep 1, 2013 at 5:16 AM, Vladimir V. Kisil <kisilv@maths.leeds.ac.uk>wrote:
Hi,
On Mon, 26 Aug 2013 00:15:45 +0800, tklam <argama@gmail.com> said: tklam> behaviour of symbolic multiplication such that: x*x == x tklam> (instead of x*x==x^2),
The nearest solution I can propose, is to define a new function bool() of one variable and use, say, bool(x) and bool(y) instead of your Boolean variables x and y.
The point is: for a function you have possibility to define its own behaviour under exponentiation, in particular, bool(x)^2=bool(x).
Best wishes, Vladimir -- Vladimir V. Kisil email: kisilv@maths.leeds.ac.uk www: http://www.maths.leeds.ac.uk/~kisilv/ Book: Geometry of Mobius Transformations http://www.worldscientific.com/worldscibooks/10.1142/p835
participants (3)
-
tklam
-
tklam
-
Vladimir V. Kisil