I'm trying to plot to graphs in one canvas using Cern ROOT. When I use gr -> Draw("ap") and gr2 -> Draw("p1 same"), the lines of the plots are not visible, only the markers are visible. When I use gr1 -> Draw("") and gr2 -> Draw("same"), the first plot is visible with line and marker but the second plot is only visible with line and not markers.
I want to see both of their lines and markers. How can I do it? My code:
graph_one -> GetXaxis() -> SetTitle(" x ");
graph_one -> GetYaxis() -> SetTitle(" y ");
graph_one -> GetXaxis() -> SetRangeUser(0,8);
graph_one -> GetYaxis() -> SetRangeUser (0,3);
graph_one -> SetLineWidth(2);
graph_one -> SetLineColor(kBlack);
graph_one -> SetMarkerStyle(8);
graph_one -> SetMarkerSize(3);
graph_one -> SetMarkerColor(kRed);
graph_two -> SetLineWidth(2);
graph_two -> SetMarkerStyle(8);
graph_two -> SetMarkerSize(3);
graph_two -> SetLineColor(kBlue);
graph_two -> SetMarkerColor(kBlack);
graph_one -> Draw("");
graph_two -> Draw("same");
Use
graph_one -> Draw("acp");
graph_two -> Draw("cp");
a draws the axes around the graph (obviously needed only for one graph)
c draws a continuous line between the markers
p draws the markers themselves
(this is explained in https://root.cern.ch/doc/master/classTGraphPainter.html#GrP1)
Please note there is no same drawing option for TGraph.
Related
Idris 2 doesn't have Control.ST, only Control.Monad.ST which is a completely different beast (it is basically the same as Haskell's Control.Monad.ST, i.e. mutable references behind a safe, pure interface). It seems that Control.App is roughly-vaguely what is supposed to replace it. However, the Control.App documentation isn't written with Control.ST in mind, and I can't figure out what the migration path is supposed to be.
For example, in this Js frontend library, we have the following Idris 1 API:
public export
interface Dom (m : Type -> Type) where
DomRef : (a:Type) -> (f : a -> Type) -> (g : a -> Type) -> a -> Type
initBody : List (DomOption a f g) -> ((x:a) -> f x -> Html (g x)) -> (z:a) -> f z -> ST m Var [add (DomRef a f g z)]
clearDom : (dom : Var) -> ST m () [remove dom (DomRef a f g z)]
domPut : (dom : Var) -> {x:a} -> f x -> ST m () [dom ::: (DomRef a f g x)]
It is not at all clear what the App version of this interface would be. Is it supposed to simply use App {l} e () everywhere, and the relationship between e and DomRef {e} would be tracked somehow differently? Is initBody / clearDom supposed to use the with pattern, i.e. something like withDom : (App {l} e ()) -> App {l} e ()? If domPut : {x:a} -> f x -> App {l} e (), how is f's type connected to DomRef {e}?
I have copy pasted some code from a tutorial but when I arrived here:
azimuth = Math.round(azimuth.toFloat())
compass_image.rotation = (-azimuth).toFloat()
val where = when(azimuth){
in 281...348 -> "NW"
in 281...348 -> "NW"
in 281...348 -> "NW"
in 281...348 -> "NW"
in 281...348 -> "NW"
in 281...348 -> "NW"
in 281...348 -> "NW"
else -> "N"
}
view_degree.text = "$azimuth° $where"
Android Studio failed to recognize the command "in"... How come?
Thanks in advance
It's because you have to use two dots instead of three to express ranges. Furthermore, all those cases are equal so it's useless to repeat them.
val where = when(azimuth){
in 281..348 -> "NW"
else -> "N"
}
Additional info here: kotlinlang.org/docs/reference/ranges.html
I am trying to create module/interface (i dont exactly know how its called, i am new to the language) for basic operations on BST in OCaml. My goal is to have an implementation that lets me doing something like this:
T.create();;
T.push(2);;
T.push(3);;
T.push(5);;
in order to get a bst tree consisting of 2,3,5.
But at the moment to achieve this i have to write something like this:
let teeBst = T.push(2)(T.push(3)(T.push(5)(T.create())));;
So when I am checking/using my code I have to do it like this:
let tee2 = T.push(2)(T.push(3)(T.push(5)(T.create())));;
T.postorder(tee2);;
The output is fine:
# val tee2 : T.bt = <abstr>
# - : int list = [2; 3; 5]
But, as I said before, I would like to achieve this doing as below:
T.push(2);;
T.push(3);;
T.push(5);;
T.postorder();;
(I realise this requires some changes to my postorder function but the one I am currently using is a temporary one so I can check the tree I have atm )
Below is my implementation. If you see the solution, please let me know ;)
module type Tree =
sig
type bt
val create: unit -> bt
val push: int -> bt -> bt
val find: int -> bt -> bool
val preorder: bt -> int list
val postorder: bt -> int list
val inorder: bt -> int list
end;;
module T : Tree =
struct
type bt = E | B of bt * int * bt
let create () = E
let rec push x = function
| E -> B(E, x, E)
| B (l, y, r) when x<y -> B(push x l, y, r)
| B (l, y, r) when x>y -> B(l, y, push x r)
| xs -> xs;;
let rec find x = function
| E -> false
| B(l, y,_) when x< y -> find x l
| B(_,y,r) when x>y -> find x r
| _ -> true;;
let rec preorder = function
| B(l,v,r) -> v::(preorder r) # (preorder l)
| E -> [];;
let rec inorder = function
| B(l,v,r) ->(inorder r) # v::(inorder l)
| E -> []
let rec postorder = function
| B(l,v,r) -> (postorder r) # (postorder l) # [v]
| E -> []
end;;
It seems like you want modules to be classes, but I'd advise you to consider more idiomatic solutions. Have you considered using the pipe operator?
T.create()
|> T.push(2)
|> T.push(3)
|> T.push(5)
|> T.postorder;;
Or with local open (which makes more sense if you have a module with a longer name than just T of course) you can even do
T.(
create()
|> push(2)
|> push(3)
|> push(5)
|> postorder
);
What you're asking for would require introducing global mutable state, which isn't just "some changes" but an entirely different paradigm. And one that is generally frowned upon because it makes your code unpredictable and hard to debug since it relies on state that might change at any moment from anywhere.
Another possibility is to actually use classes, since OCaml has those too. Then you'd still have mutable state, but it would at least be contained.
I want a find function for Streams of size-bounded types which is analogous to the find functions for Lists and Vects.
total
find : MaxBound a => (a -> Bool) -> Stream a -> Maybe a
The challenge is it to make it:
be total
consume no more than constant log_2 N space where N is the number of bits required to encode the largest a.
take no longer than a minute to check at compile time
impose no runtime cost
Generally a total find implementation for Streams sounds absurd. Streams are infinite and a predicate of const False would make the search go on forever. A nice way to handle this general case is the infinite fuel technique.
data Fuel = Dry | More (Lazy Fuel)
partial
forever : Fuel
forever = More forever
total
find : Fuel -> (a -> Bool) -> Stream a -> Maybe a
find Dry _ _ = Nothing
find (More fuel) f (value :: xs) = if f value
then Just value
else find fuel f xs
That works well for my use case, but I wonder if in certain specialized cases the totality checker could be convinced without using forever. Otherwise, somebody may suffer a boring life waiting for find forever ?predicateWhichHappensToAlwaysReturnFalse (iterate S Z) to finish.
Consider the special case where a is Bits32.
find32 : (Bits32 -> Bool) -> Stream Bits32 -> Maybe Bits32
find32 f (value :: xs) = if f value then Just value else find32 f xs
Two problems: it's not total and it can't possibly return Nothing even though there's a finite number of Bits32 inhabitants to try. Maybe I could use take (pow 2 32) to build a List and then use List's find...uh, wait...the list alone would take up GBs of space.
In principle it doesn't seem like this should be difficult. There's finitely many inhabitants to try, and a modern computer can iterate through all 32-bit permutations in seconds. Is there a way to have the totality checker verify the (Stream Bits32) $ iterate (+1) 0 eventually cycles back to 0 and once it does assert that all the elements have been tried since (+1) is pure?
Here's a start, although I'm unsure how to fill the holes and specialize find enough to make it total. Maybe an interface would help?
total
IsCyclic : (init : a) -> (succ : a -> a) -> Type
data FinStream : Type -> Type where
MkFinStream : (init : a) ->
(succ : a -> a) ->
{prf : IsCyclic init succ} ->
FinStream a
partial
find : Eq a => (a -> Bool) -> FinStream a -> Maybe a
find pred (MkFinStream {prf} init succ) = if pred init
then Just init
else find' (succ init)
where
partial
find' : a -> Maybe a
find' x = if x == init
then Nothing
else
if pred x
then Just x
else find' (succ x)
total
all32bits : FinStream Bits32
all32bits = MkFinStream 0 (+1) {prf=?prf}
Is there a way to tell the totality checker to use infinite fuel verifying a search over a particular stream is total?
Let's define what it means for a sequence to be cyclic:
%default total
iter : (n : Nat) -> (a -> a) -> (a -> a)
iter Z f = id
iter (S k) f = f . iter k f
isCyclic : (init : a) -> (next : a -> a) -> Type
isCyclic init next = DPair (Nat, Nat) $ \(m, n) => (m `LT` n, iter m next init = iter n next init)
The above means that we have a situation which can be depicted as follows:
-- x0 -> x1 -> ... -> xm -> ... -> x(n-1) --
-- ^ |
-- |---------------------
where m is strictly less than n (but m can be equal to zero). n is some number of steps after which we get an element of the sequence we previously encountered.
data FinStream : Type -> Type where
MkFinStream : (init : a) ->
(next : a -> a) ->
{prf : isCyclic init next} ->
FinStream a
Next, let's define a helper function, which uses an upper bound called fuel to break out from the loop:
findLimited : (p : a -> Bool) -> (next : a -> a) -> (init : a) -> (fuel : Nat) -> Maybe a
findLimited p next x Z = Nothing
findLimited p next x (S k) = if p x then Just x
else findLimited pred next (next x) k
Now find can be defined like so:
find : (a -> Bool) -> FinStream a -> Maybe a
find p (MkFinStream init next {prf = ((_,n) ** _)}) =
findLimited p next init n
Here are some tests:
-- I don't have patience to wait until all32bits typechecks
all8bits : FinStream Bits8
all8bits = MkFinStream 0 (+1) {prf=((0, 256) ** (LTESucc LTEZero, Refl))}
exampleNothing : Maybe Bits8
exampleNothing = find (const False) all8bits -- Nothing
exampleChosenByFairDiceRoll : Maybe Bits8
exampleChosenByFairDiceRoll = find ((==) 4) all8bits -- Just 4
exampleLast : Maybe Bits8
exampleLast = find ((==) 255) all8bits -- Just 255
Is it possible to see the interface of a loaded module in interactive OCaml? I have (unsuccessfully) tried searching for such a possibility, and online docs/sources are not what I am looking for.
The standard trick for this is to define a synonym for the module, which induces the toplevel to list the interface.
$ ocaml
OCaml version 4.00.1
# #load "str.cma";;
# module S = Str;;
module S :
sig
type regexp = Str.regexp
val regexp : string -> regexp
val regexp_case_fold : string -> regexp
val quote : string -> string
val regexp_string : string -> regexp
val regexp_string_case_fold : string -> regexp
val string_match : regexp -> string -> int -> bool
. . .
val first_chars : string -> int -> string
val last_chars : string -> int -> string
end
Update
(Note that this answer is from 2013. Recent revisions of OCaml provide a toplevel directive to show a module interface:
# #show_module Str;;
module Str :
sig
type regexp
val regexp : string -> regexp
. . .
val first_chars : string -> int -> string
val last_chars : string -> int -> string
end
So the semi-clever workaround is no longer required.
(There are many new directives. Type #help;; at toplevel to get a list.)
Both utop and ocaml interpreters added the #show directive since a moment. It does exactly what you want, as in the following example :
│ Welcome to utop version 1.19.3 (using OCaml version 4.04.0) │
└──────────────────────────────────────────────────────────────┘
Type #utop_help for help about using utop.
─( 15:12:33 )─< command 0 >──────────────────────────────────────{ counter: 0 }─
utop # #show List;;
module List :
sig
val length : 'a list -> int
val cons : 'a -> 'a list -> 'a list
val hd : 'a list -> 'a
...
val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list
val sort_uniq : ('a -> 'a -> int) -> 'a list -> 'a list
val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
end
PS:i'm using 4.04 version but i know that it also works for 4.03.> and maybe before that too.
In OCaml toplevel version 4.04.0, the trick of defining a module's synonym works no more:
# module L = List;;
module L = List
#
but you can use the include directive:
# module L = struct include List end;;
module L :
sig
val length : 'a list -> int
val cons : 'a -> 'a list -> 'a list
val hd : 'a list -> 'a
val tl : 'a list -> 'a list
val nth : 'a list -> int -> 'a
val rev : 'a list -> 'a list
...
val sort_uniq : ('a -> 'a -> int) -> 'a list -> 'a list
val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
end
#