[GiNaC-list] How to express and simplify symbolic expressions in Ginac?
Vladimir V. Kisil
V.Kisil at leeds.ac.uk
Thu Apr 20 11:49:11 CEST 2023
Hello,
Indeed, GiNaC does not provide a special class for boolean
symbols. Probably, there is another C++ library, which can do
this.
Of course, you can partially model boolean values false/true by
zero/non-zero and logical and/or with ×/+. Furthermore, you may
simplify expressions by substitution (pow(wild(0),wild(1)) == wild(0)).
For boolean negation you may need a new function to be defined, say
neg(x), with a further substitution
({wild(0)*neg(wild(0)) == 0, wild(0)+neg(wild(0)) == 1}), etc.
Best wishes,
Vladimir
--
Vladimir V. Kisil http://www1.maths.leeds.ac.uk/~kisilv/
Book: Geometry of Mobius Maps https://doi.org/10.1142/p835
Soft: Geometry of cycles http://moebinv.sourceforge.net/
Jupyter notebooks: https://github.com/vvkisil?tab=repositories
>>>>> On Wed, 19 Apr 2023 17:51:46 -0700, "Anubhavnidhi Abhashkumar . via GiNaC-list" <ginac-list at ginac.de> said:
AA> Hi,
AA> I am pretty new to GiNac library in c++ and am struggling with
AA> one particular topic. I have been using ginac-1.8.6
AA> I want to represent and simplify symbolic expressions
AA> (expressions with union, intersection, and not operator) with
AA> GiNac. I have been trying the following example
AA> #include <iostream>#include <ginac/ginac.h>using namespace
AA> std;using namespace GiNaC; int main(){ symbol x("x"), y("y"),
AA> z("z"); ex boolean_expr = (!x || y) && (x || z); cout <<
AA> "Boolean expression: " << boolean_expr << endl;
AA> ex simplified_expr = normal(boolean_expr); cout <<
AA> "Simplified expression: " << simplified_expr << endl;
AA> return 0; }
AA> But I keep on getting errors related to ||, !, and &&
AA> operators. For example,
>> note: candidate: ‘operator!(bool)’ <built-in> note: no known
>> conversion for argument 1 from ‘GiNaC::symbol’ to `bool’ error:
>> no match for ‘operator!’ (operand type is `GiNaC::symbol’)
AA> I also tried replacing ||, !, and && to or, not, and,
AA> respectively but get similar errors
>> error: no match for ‘operator!’ (operand type is ‘GiNaC::symbol’)
AA> ex boolean_expr = not(x) or y and (x or not(z));
AA> So my question is how can I represent and, or, not. I am using
AA> Ginac 1.8.6 from here <https://www.ginac.de/Download.html>. I
AA> also checked the manual here <https://www.ginac.de/tutorial.pdf>
AA> but did not find an answer.
AA> Thanks, Archie http://anubhavnidhi.github.io/
More information about the GiNaC-list
mailing list