Flat QTreeView items - not nested - qt

Does anyone know if it's possible the flatten a QTreeView/QTreeWidget while still being able to expand child items.
What the default is:
- A
-> A1
-> A2
- B
-> B2
+ C
- is expanded and + is collapsed
What I would like:
- A
A1
A2
- B
B2
+ C
all collapsed
+ A
+ B
+ C
A, B, C are the root items.

MyTree -> setIndentation (0) ;

Related

What are the different versions of arithmetic swap and why do they work?

I think we all should be familiar of the arithmetic swap algorithm, that swaps two variables without using a third variable. Now I found out that there are two variations of the arithmetic swap. Please consider the following:
Variation 1.
int a = 2;
int b = 3;
a = a + b;
b = a - b;
a = a - b;
Variation 2.
int a = 2;
int b = 3;
b = b - a;
a = a + b;
b = a - b;
I want to know, why are there two distinct variations of the arithmetic swap and why do they work? Are there also other variations of the arithmetic swap that achieve the same result? How are they related? Is there any elegant mathematical formula that justifies why the arithmetic swap works the way it does, for all variations? Is there anything related between these two variations of the two arithmetic swap, like an underlying truth?
Break each variable out as what it represents:
a = 2
b = 3
a1 = a + b
b1 = a1 - b = (a + b) - b = a
a2 = a1 - b1 = (a + b) - a = b
a = 2
b = 3
b1 = b - a
a1 = a + b1 = a + (b - a) = b
b2 = a1 - b1 = b - (b - a) = a
There's not underlying truth other than the fact that the math works out. Remember that each time you do an assignment, it's effectively a new "variable" from the math side.

Splitting a premise with conjunction conclusion in Coq

I often have to do "induction loading" to prove goals in Coq, where I prove multiple things simultaneously by induction.
The problem is, I often end up with Inductive Hypotheses of the following form:
forall a1 ... an,
Premise1 -> Premise2 -> ... Premisek ->
Conclusion1 /\ Conclusion2 /\ ... Conclusion_m
This is fine, but tactics like eauto really don't know how to handle things like this, so it kills automation most of the time.
What I'm wondering is, is there a way to automatically break such a premise into m different premises, i.e.
forall a1 ... an,
Premise1 -> Premise2 -> ... Premisek ->
Conclusion1
...
forall a1 ... an,
Premise1 -> Premise2 -> ... Premise_k ->
Conclusion_m
The main problem I'm running into is that I don't know how to match with an arbitrary length chain of arrows in LTac. I could hard-code up to a certain length, but I'm hoping there's a better way.
Additionally, if it were possible to do the dual (i.e. split on all combinations of disjunctions in Premise1 .. Premise_k) that would also be useful.
I am not an expert of Ltac, but I gave it a try and came up with the following tactic.
Ltac decomp H :=
try match type of H with
context c [?A /\ ?B] =>
let H' := fresh H in
let Pa := context c[A] in
assert (H' : Pa) by (apply H);
let H'' := fresh H in
let Pb := context c[B] in
assert (H'' : Pb) by (apply H);
clear H;
rename H' into H;
rename H'' into H';
decomp H'
end.
Tactic Notation "decomp_hyp" hyp(H) := decomp H.
decomp H searches occurrences of conjunctions in H, then decomposes it into H' and H'', clean the state and calls itself recursively.
On a trivial example, this seems to work.
Perhaps something like this (minus the debug printouts)?
Ltac foo :=
match goal with
| |- forall q, ?X =>
let x := fresh in intros x; idtac x q ; (try foo); generalize x as q; clear x
| |- ?X -> _ =>
let x := fresh in intros x; idtac x ; (try foo); generalize x; clear x
| |- _ /\ _ => repeat split
end; idtac "done".
Goal forall {T} (a1 a2 a3:T) P1 P2 P3 Q1 Q2 Q3, P1 a1 -> P2 a2 -> P3 a3 -> Q1 /\ Q2 /\ Q3.
foo.
This leaves you with the goals
3 subgoals (ID 253)
============================
forall (T : Type) (a1 a2 a3 : T) (P1 P2 P3 : T -> Type) (Q1 : Prop),
Prop -> Prop -> P1 a1 -> P2 a2 -> P3 a3 -> Q1
subgoal 2 (ID 254) is:
forall (T : Type) (a1 a2 a3 : T) (P1 P2 P3 : T -> Type),
Prop -> forall Q2 : Prop, Prop -> P1 a1 -> P2 a2 -> P3 a3 -> Q2
subgoal 3 (ID 255) is:
forall (T : Type) (a1 a2 a3 : T) (P1 P2 P3 : T -> Type),
Prop -> Prop -> forall Q3 : Prop, P1 a1 -> P2 a2 -> P3 a3 -> Q3

Maths Two Percentage Increases - Any Takers

Maths Puzzle
A = 10 (COST)
B = 20 (Sell Price)
C = 15% (Fee)
D = Tax at 20% or 1/6th if you are taking it away
E = Margin
B x C = 3.60
B / 6 in Reverse = 3.33
E = B - A - (B x C) - (B / 6) = 3.07
Ok The above works correct when i i provide B Sell Price
I want a formula that will Give me E, If i say E = 3.07 It says B = 20
How would i do that, the math
Any boffins can help
Thanks
First:
You did not use D: I suppose instead of B / 6, it should read B x D, where D can be either 20% or 16,666...%
There is a mistake: B x C is not 3.60 for the given values (B=20, C=15%), it is 3.
This is a matter of mathematical deduction:
Given the equation:
E = B - A - (B x C) - (B x D)
Add A to both sides:
E + A = B - (B x C) - (B x D)
Isolate B:
E + A = B x (1 - C - D)
Divide both sides by (1 - C - D). Condition: C + D cannot equal 100%
(E + A) / (1 - C - D) = B
So there is your formula for calculating B. Take note of the condition: this only holds true when C + D is not equal to 100%.

Graphviz Draw graph nodes using BFS order

I've a graph file (.dot) with nodes that has depth and size "properties". I want to use graphviz to draw this graph considering "depth" as the depth of a Breadth First Search and the size property as a relative size of the node.
I've tried using twopi and setting all nodes that have the same depth on the same rank, but with no success. Any suggestion on how I can accomplish this?
Sample graph:
strict digraph {
root = 0;
ranksep = 5;
{rank=same;
0
14754221888142813049
}
{rank=same;
17110173155996056797
8860119836345733269
12488214955576990298
5164430016200693425
6534280015544966791
16035081712171710670
7728255721346380016
3065692608114503807
15537038826989012875
15464545769657918305
7964210557574239786
17237485240931079100
9667703542183627069
9063621412962345275
4956992700610885217
703599774521196210
}
0 [label="A"];
14754221888142813049 [label="B"];
17110173155996056797 [label="C"];
8860119836345733269 [label="D"];
12488214955576990298 [label="E"];
5164430016200693425 [label="F"];
6534280015544966791 [label="G"];
16035081712171710670 [label="H"];
7728255721346380016 [label="I"];
3065692608114503807 [label="J"];
15537038826989012875 [label="K"];
15464545769657918305 [label="L"];
7964210557574239786 [label="M"];
17237485240931079100 [label="N"];
9667703542183627069 [label="O"];
9063621412962345275 [label="P"];
4956992700610885217 [label="Q"];
703599774521196210 [label="R"];
0 -> 14754221888142813049
0 -> 12488214955576990298
0 -> 5164430016200693425 [weight=0, constraint=false];
0 -> 15537038826989012875
0 -> 7964210557574239786
0 -> 9667703542183627069
0 -> 17237485240931079100
5164430016200693425 -> 8860119836345733269 [weight=0, constraint=false];
8860119836345733269 -> 4956992700610885217
8860119836345733269 -> 9063621412962345275
8860119836345733269 -> 703599774521196210
8860119836345733269 -> 17110173155996056797
8860119836345733269 -> 6534280015544966791
8860119836345733269 -> 16035081712171710670
8860119836345733269 -> 7728255721346380016
8860119836345733269 -> 3065692608114503807
8860119836345733269 -> 15464545769657918305
}
You are trying to capture hierarchical structure so you want to use the dot layout. By default, if you have an edge a->b, node b will be 1 level below node a. If you have a tree, and make sure the node of depth 0 appears first, you'll get the layout you want by default. If your graph is more complex, the edge criteria mentioned, or cycle breaking, may interfere with what you want. In that case, you need to make the depth constraints more explicit and turn off other edge constraints. There are several ways to do this.
Suppose you have the following graph where the numbers in the node names indicate the depth.
digraph {
0 -> a1
0 -> b1
a1 -> a2
a1 -> b2
b1 -> c2
b1 -> d2
a2 -> d2
a2 -> b1
}
A simple way to get what you want is to do a BFS, and set any edge not part of the BFS tree to have constraint=false.
digraph {
0 -> a1
0 -> b1
a1 -> a2
a1 -> b2
b1 -> c2
b1 -> d2
a2 -> d2 [constraint=false]
a2 -> b1 [constraint=false]
}
Or you can use rank=same to make sure nodes are placed on ranks corresponding to their depths, again turning off edges that conflict. (This assumes you have at least one chain of edges going from depth 0 to the bottom. If not, you can introduce an invisible chain of dummy nodes and edges satisfying this, and adding each dummy node to its rank=same subgraph.}
digraph {
0 -> a1
0 -> b1
a1 -> a2
a1 -> b2
b1 -> c2
b1 -> d2
a2 -> d2 [constraint=false]
a2 -> b1 [constraint=false]
{rank=same a1 b1}
{rank=same a2 b2 c2 d2}
}
This allows the depth function to not be actually tied to a BFS tree.
By the way, twopi should have worked, but with the layout center out instead of top down, as its levels are based on a BFS from a root node. This assumes you set the root attribute and, as you have an explicit BFS in mind, turning off non-tree edges by setting weight=0.
digraph {
root=0
0 -> a1
0 -> b1
a1 -> a2
a1 -> b2
b1 -> c2
b1 -> d2
a2 -> d2 [weight=0]
a2 -> b1 [weight=0]
}

Lambda calculus problem

I gotta solve a lambda calculus problem. I reached certain point and I don´t know how to continue:
h f x = \g -> g (f x g)
(h::a1 f::a2 x::a3)::a4 = (\g -> g::a5 (f::a2 x::a3 g::a5)::a6)::a4
a1 = a2 -> a3 -> a4
a2 = a3 -> a5 -> a6
a5 = a6 -> a4
a1 = (a3 -> a5 -> a4) -> a3 -> a4
a1 = (a3 -> (a6->a4) -> a4) -> a3 -> a4
is there any way of finishing?. I use "a1,a2,a3..." to represent a type for the element or function. For example, 1::Int, 2.4::Float, f::a1, x::a3 and so on. I don´t know if it is clear enought...
Thank you so much!!
You've made a mistake. g=a5: a6 -/-> a4. Your brackets are wrong on line 2.
h f x = \g -> g (f x g)
(h::a1 f::a2 x::a3)::a4 = (\g -> (g::a5 (f::a2 x::a3 g::a5)::a6)::a7)::a4
a1 = a2 -> a3 -> a4
a2 = a3 -> a5 -> a6
a5 = a6 -> a7
a4 = a5 -> a7
a1 = (a3 -> a5 -> a6) -> a3 -> a4
a1 = (a3 -> (a6->a7) -> a6) -> a3 -> a5 -> a7
a1 = (a3 -> (a6->a7) -> a6) -> a3 -> (a6 -> a7) -> a7
That is therefore the correct type for h (you can check if you're paranoid just by typing fun h f x = (fn g => g (f x g) ) into an SML prompt and getting the exact same result; same goes for Haskell with appropriate syntax). h is a polymorphic function, so all the a's are arbitrary, but express the relationship between the types of h's argument and the argument of the result of applying h and so on.

Resources