Class as unionOf but without this other classes being disjoint - owl

I have a class A with two subclasses B and C, and I want to say that A is the union of B and C. But B and C are not disjoint, so I can't use Disjoint Union Of in Protege.
What is the correct way of doing this? And Equivalent To with and and?

Related

Is union a user-defined or derived data type in C language

https://byjus.com/gate/derived-data-types-in-c/ indicates that a union is a Derived Data Type in C
Types of Derived Data Types in C
The C language supports a few derived data types. These are:
Arrays – The array basically refers to a sequence (ordered sequence) of a finite number of data items from the same data type
sharing one common name.
Function – A Function in C refers to a self-contained block of single or multiple statements. It has its own specified name.
Pointers – The Pointers in C language refer to some special form of variables that one can use for holding other variables’ addresses.
Unions – The unions are very similar to the structures. But here, the memory that we allocate to the largest data type gets reused for
all the other types present in the group.
Structures – A collection of various different types of data type items that get stored in a contagious type of memory allocation is
known as structure in C.
https://www.cs.auckland.ac.nz/references/unix/digital/AQTLTBTE/DOCU_034.HTM indicate that a union is a Derived Data Type in C
3.4 Derived Types
There are five derived types in C:
Function types
Pointer types
Array types
Structure types
Union types
but http://www.jnkvv.org/PDF/25042020093559244201357.pdf indicates that union is a User-defined Data Type in C
C Union
Union is a user-defined datatype in C programming language.
It is a collection of variables of different datatypes in the same memory location.
We can define a union with many members, but at a given point of time, only one member can contain a value.
Unions can be very handy when you need to talk to peripherals through some memory-mapped registers.
https://www.cplusplus.in/union-in-c/ indicate that a union is a User-defined Data Type in C
User defined data type : Union
Like structures in C, union is a user defined data type.
I search the web but could not get an answer.
I would be grateful if somebody could let me know if a union is a User-defined or Derived data type in C language.
A union is both a 'derived type' — because that is what the C standard calls it — and a 'user-defined type' — because union types don't exist unless a user defines them. The standard doesn't include the word/phrase 'user-defined' (with or without a hyphen).
Both terms are reasonable — and both apply to union types. They are not mutually exclusive.
For comparison, read the whole section of the standard on 'types' that I linked to. See how many different ways types are classified. Every built-in type is classified in a number of non-exclusive ways.

Any name for a data structure like an array/list but with additional elements between the usual elements?

I sometimes find myself needing a one-dimensional collection of items of alternating "outer" and "inner" types. For example, for types A and B, the structure could hold a sequence of types:
A, B, A, B, A
where A and B are respectively the "outer" and "inner" types. (The sequence always starts and ends with the "outer" type.)
It's like an array/vector/list, but with additional members (of a different type) inserted "between" the array/vector/list's elements.
Such a structure is of course easy to implement using, for example, two arrays (of sizes n and n-1), or a special linked list using two types of nodes. But I feel a clean interface is warranted.
I have no idea what to call it. Is there any existing or sensible name for such a thing?

Why are unboxed arrays not an instance of foldable?

Figuring out the correct data container to use can be a bit tricky in Haskell, for my 2D grid application I thought using UArray would be appropriate. However, as far as I can tell UArray is not an instance of foldable (not in Data.Array.IArray nor Data.Array.Unboxed).
Is there a reason for this? I can make my own helper functions but the absence of a foldable instance suggests that maybe I shouldn't.
I believe such an instance is impossible, because it requires an extra constraint in the data type contained by the array, which cannot be expressed in Foldable. In mono-traversable, I do define MonoFoldable instances for unboxed and storable vectors.
EDIT: To be clear, the constraint I'm referring to is that all functions in Data.Vector.Unbox only work if the value contained by the Vector is an instance of Unbox, whereas Foldable requires that foldMap, foldr, etc, are defined for all possible types (as is the case for types like lists, boxed vectors, etc). There is no way with the Foldable typeclass to state "the contained value must meet these constraints." With MonoFoldable, there is.

functional dependencies involving the empty set

I am trying to grasp the concept of the empty set with FDs. Say i have
R(A,B,C,D)
A-> E
B-> C
B-> D
where E is the empty set, from what I understand, this is a trivial FD, since you are learn nothing new from having A. But when you have
E-> A
B-> C
B-> D
what does this mean exactly? Is it simply "Nothing implies A", so A can have any value it wants within the defined domain or is it A must be a NULL value?
The empty set is usually written as ∅ or {}.
A->{} is trivial. (because {} is a subset of A).
{}->A is not trivial. (except if A is {}, since {} is the subset of every set, and so a subset of {} as well).
{}->A means the value of A can be determined without using any other value, in other words the value of A must be the same for every tuple in R. This is not the same as saying that A has no determinants or that A is null. If there were no determinants for A then A would be unconstrained and could have different values in different tuples.
An example of a dependency on the empty set might be the Sex attribute in a Members relation that defines the membership of a men-only club: {}->Sex.

When to use a union and when to use a structure

I know the differences between union and structure.
But from a design and coding perspective what are the various use cases of using a union instead of a structure? One is a space optimization. Are there any more advantages of using them?
There's really only two major uses. The first is to create a discriminated union. That's probably what you were thinking of by "space optimization," but there's a bit more to it. You need an extra bit of data to know which member of the union is "alive" (has valid data in it) since the compiler does not do this for you. You'd usually see code like that having a union inside of a struct, something like:
struct mixed {
enum { TYPE_INT, TYPE_FLOAT } type;
union {
int int_value;
float float_value;
} data;
};
When assigning to either data.int_value or data.float_value, you'd be expected to set the type member to the appropriate enumeration value as well. Then your code using the mixed value can figure out whether to read the int_value or float_value.
The second significant use of unions is to offer an API that allows the user to access the same data multiple ways. This is pretty limited, as it requires all types in the union to be laid in memory in identical ways. For example, an int and a float are entirely different, and accessing a float as an integer does not give you any particularly meaningful data.
For a useful example of this use case, see how many networking APIs will define a union for IPv4 addresses, something like:
union ipv4addr {
unsigned address;
char octets[4];
};
Most code just wants to pass around the 32-bit integer value, but some code wants to read the individual octets (bytes). This is all doable with pointer casts, but it's a bit easier, more self-documenting, and hence slightly safer to use a union in such a fashion.
In general though, if you're not sure if you need a union, you almost certainly do not need one.
You use a union when your "thing" can be one of many different things but only one at a time.
You use a structure when your "thing" should be a group of other things.
For example, a union can be used for representing widgets or gizmos (with a field allowing us to know what it is), something like:
struct {
int isAGizmo;
union {
widget w;
gizmo g;
}
}
In this example, w and g will overlap in memory.
I've seen this used in compilers where a token can be a numeric constant, keyword, variable name, string, and many other lexical elements (but, of course, each token is one of those things, you cannot have a single token that is both a variable name and a numeric constant).
Alternately, it may be illegal for you to process gizmos without widgets, in which case you could use:
struct {
widget w;
gizmo g;
}
In this case, g would be at a distinct memory location, somewhere after w (no overlap).
Use cases for this abound, such as structures containing record layouts for your phone book application which will no doubt earn you gazillions of dollars from your preferred app store :-)
Ins some cases we may have to use only one variable at a time but the different results will have to be stored with different names. In such cases union will help by allocating same space for each variable at one location with the maximum variable size.
i.e if we use int and char then union will allocate space for char which has the bigger size and the int too 'll be stored in the same space overriding the last one.
You cannot compare unions to structures, it's like comparing apples to oranges, they are used for different things. Unions are typically used in situations where space is premium but more importantly for exclusively alternate data. Unions help eliminate typos and ensure that mutually exclusive states remain mutually exclusive because error in programming logic will surface more quickly when we use unions for mutually exclusive data.
Also unions can lead to much easier pointer mathematics when working with complex data passing between components. case-in-point when developing compilers with LEX and YACC the values are passed from the lexer to the parser in a union. The parser implementation and subsequent typecasting is made significantly easier because of the use of union.

Resources