Representing Logical Combinations in Analysis Programs

  • Thread starter DEvens
  • Start date
  • Tags
    String
In summary, the conversation discusses a method for representing combinations of "and" and "or" operations in string form, and suggests using a tree structure to represent these combinations internally. There is also a suggestion for using specific symbols to represent these operations. The conversation ends with a clarification of the number of nodes in the tree structure.
  • #1
DEvens
Education Advisor
Gold Member
1,207
464
TL;DR Summary
How to internally represent string of and's and or's
I have an analysis program. (It's MCNP if it makes any difference.) Part of the input is to specify the surfaces of a cell in a string of "this side of surface x" and "that side of surface y" entries. It looks a little something like this.

((a b):(c -d)):(f -g))

So the : means "or" and otherwise it's "and". So this example is

{(outside a and outside b ) or (outside c and inside d) } or (outside f and inside g)

So my question is, is there a standard way of internally representing such strings of combinations of and's and or's? I'm thinking possibly some kind of tree structure? This seems like it should be one of those "standard questions" that gets asked all the time.
 
Last edited:
Technology news on Phys.org
  • #2
For string representation I'd use somethijg like + for or, * for and and ~ for not.

But internally as you suggest some kind of node structure that suits the language you are using would be best - four kinds of node (value, and, or and not) with pointers to child nodes.
 
  • #4
DEvens said:
So this example is
{(outside a and outside b ) or (outside c and inside d) }
I would read (outside c or inside d)
 
  • #5
DEvens said:
Well that's a slightly different arrangement to the one I outlined (and you hinted at); the nodes on the wiki page have an arbitrary number of children whereas 'my' nodes have at most two children. Depending on the particular circumstances (language, data, algorithm), one of these may be more efficient and/or easier to implement than the other. In particular dealing with an arbitrary number of things in a low-level language is more complicated than dealing with at most two.

BvU said:
I would read (outside c or inside d)
Yes, IME it is always better to stick to + * and ~ or some similar characters in the base 7 bit ASCII set where you are dealing with operations that are similar to addition, multiplication and negation.
 
  • #6
BvU said:
I would read (outside c or inside d)

Fixed.
 
  • #7
pbuk said:
Well that's a slightly different arrangement to the one I outlined (and you hinted at); the nodes on the wiki page have an arbitrary number of children whereas 'my' nodes have at most two children.
[snips]

Considering that my example already had three...
 
  • #8
DEvens said:
Considering that my example already had three...

This has three:
Code:
(a b):(c -d):(f -g)

but you wrote

DEvens said:
Code:
((a b):(c -d)):(f -g)
 
  • #9
DEvens said:
Fixed.
Great. Now my post looks like nonsense :wink:
 
  • #10
Guys, maybe you noticed the post where I said "Got it!" and posted a link? Mods, please close this thread.
 
  • #11
Thread closed.
 

Related to Representing Logical Combinations in Analysis Programs

What is a logical string?

A logical string is a sequence of characters or symbols that represents a logical statement or mathematical expression. It is used in computer programming and logic systems to evaluate and manipulate logical values and operations.

How is a logical string represented?

A logical string can be represented using various methods such as Boolean algebra, mathematical notation, or programming languages. It can be written in a series of letters, numbers, and symbols that follow a specific syntax and grammar.

What are the benefits of representing logical strings?

Representing logical strings allows for the manipulation and evaluation of complex logical statements and expressions. It also enables the use of logical operators and functions to simplify and analyze data, making it easier to understand and process.

Can a logical string be converted to a different representation?

Yes, a logical string can be converted to a different representation depending on the purpose and context. For example, it can be translated into a different programming language or converted into a mathematical equation.

Are there any limitations to representing logical strings?

The syntax and grammar used to represent a logical string may vary depending on the context or system. This can sometimes lead to confusion or errors if not used correctly. Additionally, there may be limitations to the complexity of logical statements that can be represented using certain methods or systems.

Similar threads

  • Programming and Computer Science
Replies
6
Views
2K
  • Calculus and Beyond Homework Help
Replies
14
Views
1K
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Introductory Physics Homework Help
Replies
10
Views
212
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Programming and Computer Science
Replies
2
Views
2K
  • Differential Geometry
Replies
1
Views
2K
  • Sci-Fi Writing and World Building
Replies
30
Views
2K
  • Introductory Physics Homework Help
Replies
7
Views
1K
Back
Top