How does the Logical Equivalence Distributive Law make sense? - boolean-logic

I understand that a truth table can prove the Distributive Law as a Logical Equivalence:
p V (q ^ r) <=> (p V q) ^ (p V r)
However, this makes no intuitive sense to me. Here is the contradiction I see: if p and q are both true, then wouldn't that result in p ^ q? that can work with the expression on the right, but that doesn't seem to work with the expression on the left. As I see it (and there must be something wrong with how I see it), either only p is true, or only q and r are true, according to the left expression.
Is anyone able to explain to me how this makes sense?
Let me know if I need to clarify anything.

The left hand equation is saying that either p is true or q and r are true. It does not say either p and only p is true, or q and r are only true.
For your example, p^q=> p (it also implies q, and pvq), which makes both sides true.
For example, in English the first equation says that at least one of the following is true
Pablo can swim OR
Quincy and Reginald can swim
If all three of them are true the statement is also true.
The one on the right says both of the following are true
Pablo or Quincy can swim AND
Pablo or Reginald can swim
If we have Pablo and Quincy can swim (your example), then we see that both statements hold. Pablo can swim so the first expression works because of its first clause. For the second expression since Pablo can swim both of its parts are true so it also holds.

I suspect you are using a colloquial meaning of "or", in the sense of "one or the other, but not both." E.g., "Choose the red pen or the blue pen." The meaning of "or" in formal logic is "at least one is true." In your hypothetical, certainly p^q, but the the values of q & r are irrelevant when p.

Related

Lilypond: how do I add a slur/tie mark in lyrics to indicate that the singer should not breathe at this point?

In Lilypond I am trying to add a mark into the lyrics that looks like a tie or a slur, to indicate that the singer should not take a breath at that point in the music. I believe the technical term is a "lyric liaison" but I could be mistaken. Here's an example that I photographed:
In this example, the singer should not breathe in bar 2, indicated by a "slur" mark spanning from the end of the word "high" to the start of the word "in".
I found that you can use the "~" character to insert an elision into the lyrics, but this is primarily used to assign two words to the same note. I then tried to trick Lilypond into doing what I wanted by eliding the word "high" to a space, which is almost correct, but the alignment is off. The slur starts before the end of the word "high" and stops in the space between "high" and "in".
\relative {
\key bes \major
\time 2/2
bes'4 bes c8 bes a g | f2. f4 | g bes bes a | bes2 bes
}
\addlyrics {Ding dong! mer -- ri -- ly on high~ in heav'n the bells are ring -- ing:}
Putting the space and the tilde the other way around produces a similar effect: just as wrong but in the opposite direction.
What am I doing wrong?

How can I make this function more elegant

I have the function:
wrap :: Text -> [Text] -> Text
wrap x = intercalate "" . map ((<> x) . (x <>))
The purpose of which is to wrap each element of a list with a given string and join them all together.
The brackets around the first argument to map annoy me, and so does the use of "". So I wonder is there a more elegant (or generic, I guess) way to express this function?
(Copied from my comment so the question can be marked as answered.)
You could use foldMap f instead of intercalate "" . map f. Note that intercalate "" is equivalent to Data.Text.concat.
Just to put my hat in the ring... Since the pattern is
xexxexxex
(where the es are placeholders for elements of the original list), another way you can build this output is by putting two xs between each element, and wrapping the bookends manually. So:
wrap x es = x <> intercalate (x <> x) es <> x
One small but nice feature of this rewrite is that for input lists of length n, this will incur only n+2 calls to (<>) rather than 3n-1 as in theindigamer's answer.

How to prevent maxima to rewrite the output of 2*sqrt(2) to 2^(3/2)?

Maxima input of
2*sqrt(2)
by default returns the output
2^(3/2)
How can I get Maxima to just return 2*sqrt(2) ?
(I use this in the tex() function.)
To the best of my knowledge, there is no way to prevent Maxima from simplifying 2*sqrt(2) to 2^(3/2), with two probably-hard-to-use exceptions:
(1) Turn off simplification entirely. But that disables all simplifications, e.g. 1 + 1 simplifying to 2. But if you want to try it: just enter simp : false;.
(2) Disable the simplification sqrt(2) to 2^(1/2) via :lisp (setf (get '%sqrt 'operators) nil) But then Maxima for the most part doesn't know what to do with sqrt.
I don't recommend either one of these.
You can try something like
simp: false;
tex(2*sqrt(2));
block code...;
simp: true;
That way you don't have to disable the simplification permanently.
You can do this:
(%i1) matchdeclare(n_, integerp,m_, integerp)$
tellsimp(n_*sqrt(m_), n_*sqrt(box(m_)))$
and afterwards:
(%i3) 2*sqrt(2);
(%o3) 2 √2
(%i4) sqrt(3)*9;
(%o4) 9 √3
You'll notice that the number under the square root sign in the output is colored red, because of box(). But if you select the expression in wxMaxima, and then popup "Copy LaTeX", you'll get exactly what you want, e. g.
\[2\,\sqrt{2}\]
Unfortunately if you try tex(2*sqrt(2)) to get the TeX code, you'll get $$2\,\sqrt{\boxed{2}}$$instead.

Switching a logic gate on or off

if I have an "AND gate" with three inputs "A,B and control line C"
can I control switching AND gate on or off .. just like this if C == 1 then AND gates works with input A,B if C==0 then nothing happens
can this be done by any method ??
This is how you would do it in pseudo-code(if I understood correctly):
if((c == 1) && (A || B))
Forgive me if I've got the wrong end of the stick- logic gates are just a way of making a simple concept confusing to me.
Achieve the same output from simpler (2-input) AND gates:
Yeah, hook a switch to the chip to toggle whether it is powered on or not. You don't need any fancy equipment or doubled gates, just turn the thing on to have it function as normal, turn it off and no matter what inputs you apply you'll get 0v on the output pin.

Given an R,G,B triplet and a factor F, how do I calculate a “watermark” version of the color?

I have an (R, G, B) triplet, where each color is between 0.0 and 1.0 . Given a factor F (0.0 means the original color and 1.0 means white), I want to calculate a new triplet that is the “watermarked” version of the color.
I use the following expression (pseudo-code):
for each c in R, G, B:
new_c ← c + F × (1 - c)
This produces something that looks okayish, but I understand this introduces deviations to the hue of the color (checking the HSV equivalent before and after the transformation), and I don't know if this is to be expected.
Is there a “standard” (with or without quotes) algorithm to calculate the “watermarked” version of the color? If yes, which is it? If not, what other algorithms to the same effect can you tell me?
Actually this looks like it should give the correct hue, minus small variations for arithmetic rounding errors.
This is certainly a reasonable, simple was to achieve a watermark effect. I don't know of any other "standard" ones, there are a few ways you could do it.
Alternatives are:
Blend with white but do it non-linearly on F, e.g. new_c = c + sqrt(F)*(1-c), or you could use other non-linear functions - it might help the watermark look more or less "flat".
You could do it more efficiently by doing the following (where F takes the range 0..INF):
new_c = 1 - (1-c)/pow(2, F)
for real pixel values (0..255) this would convert into:
new_c = 255 - (255-c)>>F
Not only is that reasonably fast in integer arithmetic, but you may be able to do it in a 32b integer in parallel.
Why not just?
new_c = F*c
I think you should go first over watermarking pixels and figure out if it should be darker or lighter.
For lighter the formula might be
new_c=1-F*(c-1)