Anonymous
Maybe you could help me design that?
The initial state is a null state and it is not a final state. On encountering an alphabet a or a b you transfer to corresponding state. Design your fsm such that when the character encountered last is an a or b and the character before that is also the same character then you reach the final state. Otherwise you reach an error state.
Ludovic 'Archivist'
https://godbolt.org/z/cqcsGbqvc
@laopigo This is basically half of the job done here
Anonymous
What is an error state like? I have not been able to understand this topic well
Ask your professor. This btw is a C/C++ community. Questions outside of that are not encouraged here.
Ludovic 'Archivist'
OOpsie, fixed a few optimization mistakes https://godbolt.org/z/8jfja5M8n @ollirz if you have an opinion on this (it is based on your code to some extend)
Ludovic 'Archivist'
How to generate a random double between DBL_MIN and DBL_MAX in C?
https://archivist.nekoit.xyz/ieee754-doubles-and-uniform-random-distribution-in-c/ Here you go, this should be complete and explain all the ins and outs
Anonymous
OOpsie, fixed a few optimization mistakes https://godbolt.org/z/8jfja5M8n @ollirz if you have an opinion on this (it is based on your code to some extend)
How is this a uniform distribution? Maybe I missed something but you are setting only 32 bits out of the 52 bits reserved for the mantissa You are missing out on denormalized numbers because the chance of generating an exponent value exactly equal to -1023 is less. Your program doesn't generate denormalized numbers with the same probability as that of normalised numbers.
Ludovic 'Archivist'
How is this a uniform distribution? Maybe I missed something but you are setting only 32 bits out of the 52 bits reserved for the mantissa You are missing out on denormalized numbers because the chance of generating an exponent value exactly equal to -1023 is less. Your program doesn't generate denormalized numbers with the same probability as that of normalised numbers.
Woops, you are right on the first part Also I fixed some stuff in the blog post (I had to come back to the doc of ieee754 for the bias) if you omit that part, I generate any number with an exponent that makes it less than 1 in absolute value, 50% being above 0.5, 25% above 0.25 etc etc
Ludovic 'Archivist'
but the first part is correct, I need to fix that
Ludovic 'Archivist'
Fixed in the blogpost
Anonymous
Fixed in the blogpost
I will go through the blogpost later.
Ludovic 'Archivist'
Lxjxjxhks
It is Undefined Behavior. Reading a local variable which is not explicitly assigned an initial value is wrong.
That's what I was thinking..that it's wrong to compare a variable which hasn't been assigned anything yet, but this code was given in a head first c
Ludovic 'Archivist'
https://archivist.nekoit.xyz/ieee754-doubles-and-uniform-random-distribution-in-c/ Here you go, this should be complete and explain all the ins and outs
Hey @Tazmikar would you want to take a look at this? you are far better at C than I am (I am more a C++ person) but I think this is decent at making a uniform distribution of doubles
Ludovic 'Archivist'
It seems I can produce results outside of [-1,1] and can create results such as nan
ah yes, sorry I updated this in the blog post I made afterwards
Ludovic 'Archivist'
It seems I can produce results outside of [-1,1] and can create results such as nan
I did potato bullshit and screwed both the optimization and the constants for double like the complete moron I am xD
Anonymous
Appreciated
"An exponent e starts at 1022 (which is actually -1) and has 50% chance of being 1022, 25% chance to be 1021, 12.5% chance to be 1020..." This statement seems wrong because X.e will be 1022 only if bit_divider is all 0 bits. The probability of this happening is 1/2^32. How then can you say that e being 1022 is 50% likely? It will be 1021 only if there is only 1 one bit in bit_divider. This is not 25% likely either. This is not a uniform distribution still. First of all denormalized numbers still are not equally likely. Second, the fact that you are adding a 32 bit number and a 64 bit number and ignoring the top 12 bits makes this a non uniform distribution.
Tuana
hello, Homework Write a program that describes integers -9999 to +9999 with their pronunciation. use switch and case. How can I find a shortcut instead of typing one by one?
Ludovic 'Archivist'
and the probability of the bottom (2**0) bit being 0 is 50%
Ludovic 'Archivist'
and if it is, I return directly
Tuana
help me please!!
Ludovic 'Archivist'
hello, Homework Write a program that describes integers -9999 to +9999 with their pronunciation. use switch and case. How can I find a shortcut instead of typing one by one?
"Asking to solve an assignment/test/whatever without trying it first yourself will get you a warn or will get you BANNED. We won’t write a code for you, but we can push you forward and suggest something." Read the rules
Tuana
but I can’t. I’m new at C
Ludovic 'Archivist'
but I can’t. I’m new at C
Before thinking about C, think about the process in terms of algorithms: in terms of actions and steps
Tuana
is there a shortcut for this?
Ludovic 'Archivist'
is there a shortcut for this?
How do a 5 years old learn how to speak numbers? do they memorize 9999 numbers by heart?
Ludovic 'Archivist'
Or do they memorize a process?
Tuana
waow true
Tuana
so Do I have to write them all one by one?
Tuana
All integers from -9999 to +9999?
Ludovic 'Archivist'
so Do I have to write them all one by one?
Do children under 6 memorize all numbers? If no there is a logic behind saying numbers (the numbers are not written in the 5yo's head) else if they do memorize them by heart that is the only solution (the numbers are engraved in their head)
Tuana
so what is the logic of this
Tuana
define numbers first and then find shortcuts?
Ludovic 'Archivist'
so what is the logic of this
well, pick a number and try to write the english spelling, how do you deduce the spelling when reading a number?
Tuana
https://github.com/ziyaArslan1/Games/blob/main/tarihiYaziyla.c can you look this
Tuana
I found this.
Tuana
someone said i can do it like this
Ludovic 'Archivist'
If looking online is your solution before using what I suppose you have between your ears, then leave any computer science course and never come back
Ludovic 'Archivist'
You need to think, not look for the first thing that pops in google to answer you, particularly when in school
Tuana
I know but I need a answet
Tuana
because I have homework for tomorrow
Ludovic 'Archivist'
I know but I need a answet
No, what you need is to find an answer by yourself, that is the point of learning, else doing the exercise is 100% useless, it is better to not do anything than to lul yourself to sleep by faking learning
Tuana
okay thanks
Anonymous
do you mean that the exponent will be 1022 if the bottom bit of bit_divider is 0? I take bits from bit_divider 1 by one
Was the return statement in the else case there before? I seem to have missed it. Let me tell you why this does not generate numbers with equally likely behavior. The first problem is adding a 64 bit number and a 32 bit number and ignoring the top 12 bits. This makes some numbers for the mantissa more likely than the others. The second problem is denormalized numbers. You won't generate them at all. The third problem will be evident if you consider the probability of a number being generated that is in an uneven range -0.75 and +0.25 (I.e where the left end and right end are not equui distant from 0). You concern yourself with only the exponent and not the mantissa. The problem is that for a uniform distribution,the probability of numbers being generated in the range 0.5 to 1 should be the same as the probability of numbers being in the range -0.3 to 0.2. This won't happen in your case.
Ludovic 'Archivist'
The probability of having a number between 0.5 and 1.0 is the same as between 0 and 0.5, and the same as between -0.2 and 0.3 because I mitigate the non-linearity of ieee754 by not generating a uniformly random exponent, because the exponent should not be uniformly random but having a p = (1/2)**e
Ludovic 'Archivist'
well -e
Ali
Qaraçuxurda hustle
Anonymous
1/ How so, given that the 12 random bits are ignored, we still have the 52 random bits what here could make some numbers more likely than other? 2/ Do I need to generate denormalized numbers to cover the range uniformly? I argue not just like Clang and GCC developers 3/ I actually do, it changes nothing because I don't place numbers in the range according to a random exponent, but to an exponent with a ponderated random that follows not the amount of numbers in those ranges of ieee754 but the amount of real numbers in those ranges
1) Here is an example. Assuming X.m is 3 bits long and and decent_rand() generates a 2 bit number. So your code is equivalent to X.m = decent_rand() + decent_rand() << 2. Assuming decent_rand generates a 2 bit number with equal likelihood, your program should generate all buts from 000 to 111 with equal likelihood. 000 will be generated if decent_rand 1 produced 00 and decent_rand 2 produced 00 as well. 111 will be generated if decwnt_rand 1 produced 11 and decent_rand 2 produced 01 or 11. So the chance of 111 being generated is higher than the chance of 000 being generated 2) Denormalized numbers must be generated and if you take uniform_real_distribution in the standard C++ library, you will see that they are indeed generates. 3) The problem is the same as in situation 1
Ludovic 'Archivist'
likewise for the other
Dr
Design a finite-state automaton for the alphabet Σ = {a, b} that accepts any sequence ending with at least two a or two b. Draw the state diagram, remember to show the start state and the state (s) acceptable.
Create 5 states with 1 as start state, draw 2 paths from start state and 2 more states for wach of them for string ending with a and other ending with b. So this creates 2 final states
Anonymous
2/ Nope, I looked at the code and can tell you that no they are not generated for a std::uniform_real_distribution(0.0,1.0)
http://coliru.stacked-crooked.com/a/585be0cdece94068 Denormalized numbers are indeed generated
Ludovic 'Archivist'
Which both compiler generate then extend with v*(b-a) + a
Ludovic 'Archivist'
I have the code right in front of me
Anonymous
Re read what I said
Ok let me check the standard library code. I am not sure how denormalized numbers can be left out when it is a uniform distribution
Ludovic 'Archivist'
Ok let me check the standard library code. I am not sure how denormalized numbers can be left out when it is a uniform distribution
because they are not needed for a uniform distribution? Uniform doesn't mean any number can be generated, it means that the generated numbers are equaly spread out in the domain
Anonymous
Yeah I get your point. I really got convoluted in my thinking and ignored that for the range 0 and 1 denormals can't be generated in a uniform distribution as all of them would cluster around 0 which obviously should be ignored.
Rania
Is it possible for GNU make to enforce compilation using C++20 without makefile ? I could achieve the same result with g++ by using g++ -std=c++2a, it worked but wasn't practical, so I made an alias in my bashrc alias g++='g++ -std=c++2a', it didn't work. My code was still compiled against C++17, and due to the nature of my project, using make is better approach than g++ anyway. Is there any system-wide solution to enforce C++20 ? Machine : Linux (Ubuntu) GNU make version : 4.2.1 g++ version : 11.1.0
Rania
ごんく
Can gcc compile and run a source code on one command, just like go run xxx
𝓺𝓹𝔁𝓮
ごんく
thanks for reply
Anonymous
You can learn with me
Anonymous
Yaa
Ludovic 'Archivist'
Not loading.
oh that is sad
Ludovic 'Archivist'
I will investigate the issue with that, maybe a dns not propagated properly
Ludovic 'Archivist'
I will investigate the issue with that, maybe a dns not propagated properly
oh, it is solved, ovh burning once more, nothing to worry about
Hisam
int main() { constexpr double cm_per_inch = 2.54; // number of centimeters in // an inch double length = 1; // length in inches or // centimeters char unit = 0; cout<< "Please enter a length followed by a unit (c or i):\n"; cin >> length >> unit; if (unit == 'i') cout << length << "in == " << cm_per_inch*length << "cm\n"; else cout << length << "cm == " << length/cm_per_inch << "in\n"; }