Where do I find the line number in the Xcode editor?

Question: In Xcode 3, the line number of the current cursor location was displayed.  I don't see this in Xcode 4. Is there a setting that will turn it on? Or a keypress that will give it to me?
Comment: Please file bugs at http://bugreport.apple.com and reference radar://9245044 (for showing cursor line & column) or radar://13255659 (to show line numbers by default).
Answer: For Xcode 4 and higher, open the preferences (command+,) and check "Show: Line numbers" in the "Text Editing" section.
Xcode 9

Xcode 8 and below
Comment: A image is worth a 1000 words! (it´s still the same for xcode 6.. )
Answer: In Preferences->Text Editing-> Show: Line numbers you can enable the line numbers on the left hand side of the file.
Comment: Thanks, I will use that at least some of the time.  But what I really want is to just display the number of the line I am on.
Comment: @William Jockusch I don't think they kept it in XCode4, I've been looking nor for quite a while but to no avail.
Answer: Sure, Xcode->Preferences and turn on Show line numbers.
Comment: `Preferences->Text Editing-> Show: Line numbers`
Answer:
Go to Xcode preferences by clicking on "Xcode" in the left hand side upper corner.

Select "Text Editing".

Select "Show: Line numbers" and click on check box for enable it.

Close it.

Then you will see the line number in Xcode.
Answer: If you don't want line numbers shown all the time another way to find the line number of a piece of code is to just click in the left-most margin and create a breakpoint (a small blue arrow appears) then go to the breakpoint navigator (⌘7) where it will list the breakpoint with its line number. You can delete the breakpoint by right clicking on it.
Answer: To save $4.99 for a one time use and no dealing with HomeBrew and no counting empty lines.

Open Terminal
cd to your Xcode project
Execute the following when inside your target project:

find . -name "*.swift" -print0 | xargs -0 wc -l
If you want to exclude pods:
find . -path ./Pods -prune -o -name "*.swift" -print0 ! -name "/Pods" | xargs -0 wc -l

If your project has objective c and swift:
find . -type d \( -path ./Pods -o -path ./Vendor \) -prune -o \( -iname \*.m -o -iname \*.mm -o -iname \*.h -o -iname \*.swift \) -print0 | xargs -0 wc -l


will I be forgiven if I know Masturbation is haram and I do it?

Question: I know that Masturbation is haram.
I am 15 years old and I Masturbate alone although I know it is haram. I want to repent to Allah but will I be forgiven? I am scared that I won't be forgive I have done it a lot of times
Answer: we know this is a major sin Islam. But we should not forget that Allah is Al Ghaffar
(The Forgiving). It doesn't matter how many times you did this sin Allah is the the most merciful. I am not telling you that you should continue this sin. You must try to give up this sin as fast as possible.
"O ye who believe! Turn to Allah with sincere repentance, in the hope that your Lord will remove from you your ills and admit you to Gardens beneath which Rivers flow "
— Quran, Sura 66 (Al-Tahrim), ayah 08
It clearly states that repentance will remove all your sins.
God accept the repentance of those who do evil in ignorance and repent soon afterwards; to them will God turn in mercy: For God is full of knowledge and wisdom. Of no effect is the repentance of those who continue to do evil, until death faces one of them, and he says, "Now have I repented indeed;" nor of those who die rejecting Faith: for them have We prepared a punishment most grievous.
— Quran, Sura 04 (An-Nisa), ayah 17–18
So whenever you do sin repent as soon as possible because when the death comes none of his repentance will be accepted.
Doing sin is the nature of humans it doesn't mean we will not be forgiven.
** Allah's apostle said, "Every son of Adam sins, the best of the sinners are those who repent."
— Sunan al-Tirmidhi, Hadith no. 2499
**
It is clear to us that Allah forgives all sins but actually the Satan is giving you Waswasa that you won't be forgiven. If someone repents and promise to never do sin again Allah will surely forgive him.
Zazakallah Khair


How do I save my high-quality answer to a duplicate question?

Question: I wrote a self-answered question that was labeled as duplicate. I don't agree with that, but my question is, how can I save my high-quality answer now? Duplicates are automatically deleted, aren't they? Which means my answer is going to be deleted too. It's unfortunate since I believe it's valuable for SO community members, especially beginners
Comment: Duplicates are not, in general, automatically deleted. However, if your answer can be made to apply to the other "main" question, then you should just repost it there (with some editing as necessary), and delete the one you posted on the "duplicate".
Comment: Well, okay. I lack sufficient subject-matter expertise when it comes to Java to have an opinion about whether or not the question is a duplicate. If you think the question is not a duplicate, then [your focus should probably be on that, with the goal of getting it re-opened](https://meta.stackoverflow.com/q/252252). Otherwise, if all you care about is your answer sticking around, then it will continue to do so. A question with an answer will not be deleted automatically (full rules for that [here](https://stackoverflow.com/help/auto-deleted-questions)).
Comment: It is not up to you to judge whether your answer is a "high-quality" answer, but up to the community, which expresses this with votes.
Comment: Just because you are unable to understand that it is a duplicate does not make it any less of a duplicate.
Comment: Questions closed (as duplicates) can still turn up in search (engine) results too. These questions can, and do, still receive views and votes . Reopening because it "[adds something of value](https://stackoverflow.com/questions/76464748/how-do-i-make-a-deep-copy-of-an-array-of-reference-types-in-java/#comment134826527_76464748)" isn't a reason to reopen because the post(s) still do provide that, even in a closed state; closing does not stop a question adding value to the site's content.
Comment: https://stackoverflow.com/help/auto-deleted-questions
Comment: @CodyGray-onstrike since I don't believe it's a duplicate, I don't believe I can just move the answer
Comment: "Duplicates are automatically deleted, aren't they?" - They are not deleted, which is the reason, asking a question that is later closed as a duplicate isn't a necessary a negative event. It only negative, if the question receives downvotes, because the duplicate was presented to the user asking the question before submitting the question. Furthermore, you could always delete the answer, and resubmit it to the original question. However, I would take the feedback you received to heart, and consider the existing answer to the duplicate already expressed your solution.
Comment: I read your argument in the question about why it shouldn't be a duplicate, and have been convinced that I am not missing anything and it is, indeed, a duplicate. Either leave your question as-is, or post your answer to the original question.
Comment: Why do you have to be so toxic? Every time I post on meta, you go and downvote my publications left and right, including the mentioned answer that is obviously a positive contribution to SO (if I came across it a few weeks ago, I would definitely find it useful). It's shameful
Comment: How is the jDoodle question bad? You even have a tag for that, and I did show my efforts to find the answer myself. Whatever the reason you're do full of spite, that reason has nothing to do with me or my questions
Answer: Deletion policy

Duplicates are automatically deleted, aren't they? Which means my answer is going to be deleted too.

No, the site does not work like that. I genuinely have no idea how you came to this conclusion. The only things that get automatically deleted are per roomba policy. The normal way questions get deleted (other than by the OP) is that they are closed, downvoted to -3 or below, and then voted to delete by the community.
The site software is in fact extremely conservative about keeping around possibly useful information. Duplicates, in particular, are kept because a duplicate question can act as a "signpost" for a canonical question (meaning, a question that is used as the target for many other duplicate links). This has two main benefits:

The number of questions in the system that are marked as a duplicate of a canonical, is useful information that helps us know how important that canonical is. It's the basis for sorting by "frequent".

If the title is a good description for the problem, while differing significantly from the canonical, it can help people find the canonical. For logged-out users, the site software will automatically follow the link when a question has been closed as a duplicate of exactly one other question, so this helps people using external search engines as well as people looking around within the site.

The question is very clearly a duplicate
Before we can consider what to do with the answer, it's necessary to understand how duplicates are judged on Stack Overflow. (Ironically, everyone who protests "my question is not a duplicate!" seems to require a custom explanation.)
In your problem setup, there is a class called Person. In some disembodied code (but because this is Java, for it to be runnable it would have to be inside a method of some class somewhere), an array of Persons is created (Person[] arr), and then there is a blank where the code should be to deep-copy the array, and then a request that modifying a Person in the copied array should not result in an observable change to the original array. The reason why such a change would be observed, of course, is because a naive copy would be shallow - the arrays would contain the same actual Person instances. This cannot be fixed "automatically"; the code needs to use some explicit mechanism that "clones" Person instances (creates new instances that are equal to an original instance, but which have a separate identity).
In the problem setup of the current duplicate, there is a class called Position. Then, inside another class PositionList, there is a field which is an array of Positions (private Position[] data), and then there is a failed attempt at code to deep-copy the array, and then an implied complaint that modifying a Person in the copied array should not result in an observable change to the original array. The reason why such a change would be observed, of course, is because the naive copy actually shown is shallow - the copied array contains the same actual Position instances. This cannot be fixed "automatically"; the code needs to use some explicit mechanism that "clones" Position instances (creates new instances that are equal to an original instance, but which have a separate identity).
What's different between these cases?

The class stored in the array is named differently, and presumably has different contents; and you explicitly show the contents of the class in your version. However, this is not relevant; any user-defined class with mutable instances would suffice to demonstrate the same problem. The problem is not related to the implementation of that class, but to the deep-copying algorithm.

Your attempt at the question simply asks how to do it, whereas the reference duplicate shows an attempt. This is not really relevant; it is not useful to distinguish "how do I do X?" from "why doesn't the most obvious/naive attempt at X actually accomplish X?". Nobody who wrote such code and experienced a failure would be satisfied by simply knowing what is wrong with the attempt, and consequently any sensible explanation of how to do the task properly would naturally explain the issue with the non-working naive attempt (because there's no reason to put that information anywhere else).

You don't show the array being a field in some other class, and indeed don't show class or method context for the copying code at all. But none of this is relevant; the problem and solution are still unchanged - as you should reasonably know, given that you understand the problem well enough to answer the question yourself.

In other words: nothing that matters to us. This is a duplicate, clear as day.
Ideally, the existing question should be edited to improve it by making a proper MRE with a concrete description of failure (rather than "my tests don't work"). However, it's already clear and focused, and it explicitly asks (and always has asked) about "making a deep copy" (implying that OP had a basic understanding of the issue).
What do I do now?
The same thing that you would do if you had never written the Q&A, but instead are looking at the canonical Q and have your current A sitting in a text file on your computer. That is:

Check if existing answers describe these approaches to the problem. Is there an answer showing the use of SerializationUtils.clone? Does your answer explain anything about how to use it, that isn't covered by such an existing answer? How about the approach using a for loop and constructor calls? What are the limits on these approaches? (You already know this: SerializationUtils.clone requires a class that implements Serializable; and the constructor approach requires a constructor that can clone an arbitrary valid object state, along with a way to infer arguments for that constructor from an arbitrary instance.)

Check if the proposed answer adds useful information. Do other answers mention that the clone method of the array, Arrays.copyOf, System.arraycopy and manual copying with a for loop and assignment are all shallow copies? (I didn't check in detail, but we can already write off the last one, because the question addresses that.)

Check if it would be better to improve existing answers by editing to fix an obvious oversight. If you are convinced that you have, in your proposed answer, covered something new, then edit what you have down to the part necessary to focus on the actually new information; edit again to make it work within OP's framing; and post that answer to the canonical.

In this particular case: the accepted/top answer for the canonical already clearly describes the entire problem, mentions the copy-constructor approach along with its limitations, and mentions cloning by serialization (using ObjectOutputStream/ObjectInputStream to re-create the instance from an actual serialized form). It also mentions using .clone on the instance type, and cases where it would be necessary to override the Object.clone implementation. (As an aside: since Strings are immutable, in your case you should also have been able to deep-copy this way, without needing a Person.clone implementation.)
To my understanding, SerializationUtils.clone is essentially a wrapper for the ObjectOutputStream/ObjectInputStream approach. It might be worth editing the top answer to describe how to do this. Otherwise, I honestly don't see how your answer possibly adds any information that isn't already well covered.
Comment: This comment is really superfluous, but wow. Thanks for generously taking the time to write such a detailed and informative answer.
Comment: _"some disembodied code (but because this is Java, for it to be runnable it would have to be inside a method of some class somewhere)"_ - stop trying to make this a thing. A question or answer doesn't have to contain code that is copy-pasteable and runnable without modification or boilerplate.
Comment: @CodeCaster true for the site rules, but less true for the quality rating. The more attractive and self-explanatory the code looks, the more it'll help towards attracting upvotes. I would not dismiss advice tailored to prevent bad experiences on the site so easily. Unfortunately it is not really framed as advice but rather just a random bit of trivia.
Comment: @Gimby I have "clashed" with Karl on this subject more than once. They want a question or an answer to contain _everything_ from (obvious) imports to a Program class with a Main method. In my opinion, that is noise. Someone who's searching for an answer to a specific problem already has the containing program, they're just looking for the fixed code (and some explanation of what was fixed, hopefully).
Answer: Your entire Q&A is a setup to promote an approach you found, namely SerializationUtils.clone(arrayOfSerializableObjects).
The rest is noise about methods that don't work. Showing an approach that doesn't work is definitely useful, but not a reason it's not a duplicate. Besides, you casually mention that the class needs to implement Serializable, but you don't mention that needs to be transitive as well, i.e. for properties within your class that are of other class types
The question remains the same, however: how do deep-clone a collection of objects. Just move your answer to the duplicate.


related to UIScrollview with UIImageView

Question: I am developing a shopping apps. Similar to something like Fab app in the iStore. I have placed a UIscrollview to which i have added 4 UIimageview and adding them as subviews to the UIScrollview. Now as user scroll need to load different images(i.e different products for sale). How do i achieve this. Then how to add buttons to this images and title.
Comment: Where are you loading your images from?
Comment: Images are there within the project itself
Answer: See the following links to get the  How to use UIScrollView to show different images on scroll?
Images in UIScrollview
Images Change in UIScrollView
To add button and tittle to image, just add uibutton as addsubView to ImageView.
Answer: You could try this projects :
Project 1
Project 2
Then when you need to add the title, add it as subview for the images. In the project I sent you, the images are added as UIButton frame. Try it.


See scp progress from another machine

Question: Assume I'm scping a large file (300GB) from the corporate server to my workplace machine which I don't have ANY access to during the weekend (firewall blocks ssh to machines inside the office network); hence I can't just connect to it and see the progress. Now is there anyway for me to see the progress of that scp job when I ssh into the server with the same account from my home machine?
This is of course not really useful but I'm curios anyway.
Answer: You can use lsof to list information on the current files opened by the scp process on the server. Find its process id with pidof scp, for example, then use lsof -p on that pid. You will also need option -o to show the current offset within the file being read by scp.  Eg
$ pidof scp
29273

$ lsof -op 29273
COMMAND   PID USER   FD   TYPE DEVICE    OFFSET    NODE NAME
scp     29273  meuh  cwd    DIR  179,2            273367 /home/meuh
scp     29273  meuh  rtd    DIR  179,2                 2 /
scp     29273  meuh  txt    REG  179,2            260817 /usr/bin/scp
...
scp     29273  meuh    0r  FIFO   0,10       0t0 3005108 pipe
scp     29273  meuh    1w  FIFO   0,10       0t0 3005109 pipe
scp     29273  meuh    2w  FIFO   0,10       0t0 3005110 pipe
scp     29273  meuh    3r   REG  179,2 0t2834432     530 /home/meuh/x

The last line shows file descriptor 3 is ready to read from offset 2834432 of file /home/meuh/x. You could use watch to repeat the command and see the changes.
Comment: Not as user friendly as I would have wanted it to be, mainly because it outputs a hex value and not a human-friendly one but I guess that's it anyway. Thanks!

See scp progress from another machine


can I use ATF IV instead of Dexron for 2005 toyota camry

Question: The manual states Dexron or Dexron II to use for power steering fluid. ATF IV is listed on the manual for transmission oil. Can I use that instead of Dexron/Dexron II? Can I mix it with the Dexron already in the car?
The only other options I have are Dexron III or Lucas oil, which states it is universal for all cars but I am skeptical about that.
Comment: Any later generation of Dexron is safe to use in older equipment designed for DX, DXII, or III
Answer: ATF IV and Dexron II are different enough I'd suggest against using it, however all Dexron fluids are backwards compatible, so you could use Dexron III or Dexron VI. If you can get Dexron III you can mix it with the exiting Dexron II in your power steering reservoir without issue.
If you're refilling it then there's a leak somewhere, you may want to have that looked at.
Answer: A "universal" fluid that is commonly available is labeled "Dex/Merc" and are usually compatible with Mercon (not Mercon V), Dexron II, and Dexron III, and possibly others. I would not use ATF+4 since it is a different formulation meant for Chrysler transmissions. Dex/Merc fluid is easy to find and also cheap.
Dexron VI is a superior fluid that is backwards compatible. It could also be used, but it is more expensive.
That being said, would ATF+4 work? In a power steering pump, it would "probably" be OK, since a power steering system is much less demanding on the fluid than an automatic transmission. In an automatic transmission, ATF serves as coolant and lubricant, has to resist high shear forces and temperatures, and must keep debris and contaminants suspended for long periods of time. A power steering pump basically just needs a light hydraulic oil. But the risk in this case is not worth it, IMO.


Master - Detail relationship New record from related list

Question: I have an object which has a master detail relationship with Account object. I want when creating a new record for this new object from the Account related list, to suggest the current account and not giving the ability to the user to change the record. How can this be applied ?
As in the screenshot below, i want the user not to be able to erase this account and select another one. I want it to be the same as in "Edit" action, read only. How can this be achieved?
Comment: I dont thinkwe can achieve this when we are creating a new record. We might need a custom solution.
Answer: Solution1 - Change Master detail to Lookup
Just make it readonly for the desired profile from Field level security of the field (You will need to change your master-detail to Lookup)

Goto the child object,
Select the Lookup field (e.g. Account) .
Select the Field level security and then make it read-only for the desired user profile.

Note: The above will work for non System Administrator profiles only, as they have power to unlock readonly fields.
Deleting children
In order to delete the related children, implement a trigger on Account before delete handler.
Solution2 - Create Custom Component
You can create a VF page or Lightning component that will only have Label/display field that will display the account name and then you can drop on the page layout.
Comment: Hi Mahmood and thanks for your answer. However, Salesforce does not let me make the field read only from the Field Level Security.
Comment: Make sure that the field is not set as `Required`
Comment: Despite the fact that i made it read only, it still gives me the ability to change the parent record. Also, i need it to be a master-detail cause whenever an account is deleted, i want to also make the child records get deleted.
Comment: Remember that system admins can edit fields that are marked read-only via the page layout.
Comment: Ok, forgot to remove the "Edit read only fields" permission. So with lookup, my problem is solved. What about master-detail relationships? Can this be achieved with master-detail ?
Comment: @Mahmood thank you so much for your answer!


Third degree Diophantine equation

Question: I saw an exercise which was meant to find integers all integers $m,n$ satisfying $2m^2 + 5n^2 = 11(mn-11)$. I found them using the factorization $(m-5n)(2m-n)=-11\cdot 11$. However, what kind of methods there are to solve the original problem, find all $(m,n)\in\mathbb{Z}\times\mathbb{Z}$ satisfying $2m^2+5n^3=11(mn-11)$? I haven't solved many cubic Diophantine equations so I was just wondering if there is some birational transformation to convert the equation to a Weierstrass form of an elliptic curve.
Answer: The equation $2y^2+5x^3=11(xy−11)$ describes an elliptic curve. Given any elliptic curve, you can perform a change of variables to put it into Weierstrass form, and if the field of definition has characteristic different from 2 or 3, you can even put it into the form $y^2 = x^3 + ax + b$. In this particular case, to find the transformation is easy: first scale $x$ and $y$ to get rid of make the coefficients of $x^3$ and of $y^2$ equal to 1. Then write $y' = y +  \alpha x$ to get rid of the $xy$-term. This will introduce an $x^2$ term. So now, translate $x$ to get rid of the $x^2$ term (I haven't actually done the computation).
An important thing to note is that while the notion of rational points does not depend on the model over $\mathbb{Q}$ that you are working with (as long as you only change variables over $\mathbb{Q}$), the notion of integral points does depend on the integral model. A theorem of Siegel says that on any Weierstrass model of an elliptic curve, there are only finitely many integral points, and there are bounds on their height in terms of the coefficients of the model. But as far as I know, to actually find the points comes down to brute force methods: e.g. if you manage to compute generators of the Mordell-Weil group, i.e. of the group of the rational points, and the torsion subgroup, then you just check all possible linear combinations up to the given bound. There are better methods using elliptic logarithms, but they are theoretically more involved.
Edit: some more info on your concrete curve:
To get a Weierstrass model you can replace $y$ by $y'/20$ and $x$ by $-x'/10$ in the original equation, resulting in $y'^2+11x'y' = x'^3 - 2^35^211^2$, confirming your hint. The elliptic curve has rank 1, as you say, and no torsion. The point $P=(22,-88)$ generates all the rational points on the curve under the group law. Integral solutions of the original equation correspond to points on the Weierstrass model with integral $x$-coordinate divisible by 10 and integral $y$-coordinate divisible by 20 (see our transformation). So the naive way of ruling out integral solutions to the original equation is to check all multiples of the generator $P=(22,-88)$ under the group law up to the given bound and convince yourself that no point satisfies the divisibility criteria. However, the bound of Baker, referred to in the wikipedia article, is huge and the computation might not actually be feasible. A possibly more promising approach is to write down the polynomial that computes $Q\mapsto Q\oplus P$ and see whether this operation always introduces higher and higher denominators that never cancel the numerators.
Comment: Okay. I thought that transforming the curve to its Weierstrass form allows me to use Sage to compute the points. But I'm not sure that in general, how do the integer points of given curve and integer points of its Weierstrass form corresponds to each other.
Comment: @Jaska You are pointing out another important distinction: while to talk about rational pts of an elliptic curve is legitimate, because it is indep. of the model, the notion of "integral pts" depends on the precise model you choose. When you do these transformations, you will have to watch closely what denominators you can allow in the new coords to get integral solns to the original eqn. Then you use the same bounds that I mentioned, but not for the integral points on the Weierstrass model, but for points with concretely bounded denominators. Siegel's finiteness thm applies to those as well.
Comment: I got some hint that the Weierstrass form of the curve is $y^2 + 11xy = x^3 - 24200$ and its rank is one with generator $(x, y) = (22, -88)$. But at least Silverman's book has no index word generator of an elliptic curve so how to define a generator? And how this proves that there is no integer points of the original equation?

Third degree Diophantine equation


What are some of the basic FPGA synthesis algorithms mapping to LUT?

Question: I am trying to look up easy to understand papers that help explain how logic functions are mapped onto LUT. For e.g. if I have c = (a+b)*c -d how is this mapped on to LUT or if a counter is designed how is the same mapped etc.
Answer: A LUT is a memory (Look. Up. Table).  It implements logic truth tables by using the memory address as the input bits, and the memory data output as the output bits.
By way of example, for a 4-bit up counter: at address 4'b0000 is stored 4'b0001; at address 4'b0001 is stored 4'b0010; ... ; at address 4'b1011 is stored 4'b1100; and so forth.  The outputs are registered and fed back to the inputs, so on every clock the cycle repeats and the counter output increments.
Answer: Markt's answer is correct.  If you're curious how the synthesis algorithms actually work I'd point you to the work of De Micheli at EPFL.  He was very instrumental in VLSI synthesis http://icwww.epfl.ch/~demichel/.  He wrote a great book on the subject: http://icwww.epfl.ch/~demichel/publications/mcgraw/index.html  It might be a bit more dense than what you're looking for, but it's an excellent text.
Answer: The precise mapping depends on the type of LUT implemented. A very common configuration is a LE with a 16 entry LUT (4 inputs), split into two halves to get two outputs. Each of the half LUTs looks similar to this:

simulate this circuit – Schematic created using CircuitLab
The LE configuration contains the values coming in from the left (table data), as well as some values that get applied to other gates around the LUT, for example a selection flag that can pull the third input from a neighbouring LE's upper half of the table. That way, you can easily implement an adder:
left    right   cin     out     cout
0       0       0       0       0
0       0       1       1       0
0       1       0       1       0
0       1       1       0       1
1       0       0       1       0
1       0       1       0       1
1       1       0       0       1
1       1       1       1       1

The cout signal of the table for bit 0 is connected to the cin signal of bit 1, so you get a full adder with carry.
Subtraction adds the two's compliment of the right hand side value, and multiplication adds the left hand side value shifted by N bits to the left if bit N is set in the right hand side value (so a 9x9 multiplier needs a 9 bit adder, an 8-bit adder, a 7 bit adder, ...).
These operations may be combined if there is a more optimal packing of tables -- for example I can represent the two's complement needed for subtraction in the lookup table for the adder. That optimization is a hard problem, and often no optimal solution exists -- but finding one that matches timing requirements is usually enough.
Mapping c=(a+b)*c-d requires combinatorial logic for (a+b)*c-d, and a register stage that saves the value of c. The register needs an additional signal to trigger the update, otherwise you'd end up with (a+b)*((a+b)*c-d)-d rather quickly.


How to transfer a minecraft world from my ipad to my iphone and back to my ipad

Question: I know how to do this with something like ifunbox, but since my ipad is a school ipad it doesn't work to plug my ipad into my computer and it says that this ipad is owned by another computer. Is there a way I can save worlds with icloud backup?
Answer: Okay, so this is a multi-point answer, well, one thing at a time.
First of all, you want to know if you can copy worlds via a computer. This is doable, even if the iDevice is registered to another PC. Being registered to another PC means you cannot perform an iTunes Sync of the data, but basic iTunes file transfer capability is available (unless, since you say it's a school iPad, they locked it, but that's another affair, and it doesn't have anything to do with the PC you are using). Since you did not specify which OS you are using, I'm gonna provide an answer for the three most used:
Windows/macOS:

Download and install iFunBox from here
Launch it and plug your device in. Make sure you authorise the PC from the popup on the device. If your device does not appear in the program, install iTunes from here, run it once then close it. Replug your device if necessary.
In iFunBox double click on "User Applications" below your device name.
Find the Minecraft icon, double click it, then browse to documents/games/com.mojang/minecraftWorlds.
Folders in here are your worlds, each with its original creation name. You can copy, paste, delete and do whatever else you please with them. This guide is repeatable from step 2 with any Apple device you wish.

Ubuntu:

Plug in your device and authorise the PC from the popup on the device. An iDevice icon should pop up on the Launcher (left dock bar).
Double click the Documents on [DEVICE NAME] icon that appeared.
Find the Minecraft icon, double click it, then browse to documents/games/com.mojang/minecraftWorlds.
Folders in here are your worlds, each with its original creation name. You can copy, paste, delete and do whatever else you please with them. This guide is repeatable with any Apple device you wish.

And now about copying worlds via iCloud; the answer is: no, you cannot. Simple as that. Even if you run an iCloud backup, it still won't sync your worlds. It's actually not a very good idea to use iCloud as a backup solution anyway.
Comment: @sam make sure you accept my answer if it worked
Comment: Using the method you described, I was able to export a Minecraft world from my iPad and run it from Minecraft Windows 10.
The trick for that was to put all the files into a zip and replace the zip extension with ".mcworld"
Comment: @MerkleGroot Now you don't even have to go through this hassle, you can use the Files app on the device to access game files
Answer: An iCloud backup will save your minecraft worlds, I got a new iPad last year and when setting it up I selected the iOS 12 backup from my old iPad mini, and after the backup was done I went into minecraft on the new device, and all my old worlds from my old iPad were there.
Comment: This conflicts with the other answer. Can you expand on this?


How can I make 2 separate meshes blend seamlessly while keeping them as separate meshes?

Question: I'm trying to make a player model for a video game that can have changeable clothing. So I would have a mesh for the head, torso, legs, feet, and hands. The problem I'm having tho, is that the meshes do not blend seamlessly. There is a very apparent cut where the meshes connect:  How can I make this cut seamless for all the different meshes? Any help is appreciated.
Answer: Position all mesh joins under the clothing.
In fact you shouldn't need to "join" the meshes, you position a head and shirt so that the shirt is over the top of the neck vertices.
Another option is to have all clothing and head details in textures, so you always use one solid mesh. Maybe a collection of different complete character meshes with different texture options.
Answer: I think this can be done nicely with a shrinkwrap modifier on a vertex group (the neckline of the head mesh) and then using a data transfer modifier to blend the normals so it looks like a smooth connection.
This video explains that in detail:
https://www.youtube.com/watch?v=luFz5gzvM9s&t=289s


Could robots evolve?

Question: Would artificially created robots that can reproduce and heal themselves be able to evolve?
I imagine a planet where an advanced civilization made robot "creatures" and then died out, so would they be able to evolve?
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/130328/discussion-on-question-by-mewthecatsaur-could-robots-evolve).
Answer: Yes, in fact you can't stop it from evolving given they can reproduce.
If something can reproduce and pass on the instructions to reproduce ,evolution will occur, literally all that is needed is for evolution is reproduction and heredity of the instructions for reproduction.  All you can change is how fast it happens and what form it takes. The less the robots programming can change the slower it will evolve. If it has to wait for errors to occur it will change slowly, if it can change its programing on the fly it will evolve quickly although in the latter case the evolution will be different than normal natural selection.  So if you want slow evolution give them high fidelity copying of instruction.
Comment: Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/130281/discussion-on-answer-by-john-could-robots-evolve).
Answer: Depends.
In terms of hardware there are features when making copies that better allow for evolution then others:

Absolute perfectly similar copies will suppress evolution.(AKA no mutation)

High error copies are unlikely to successfully create next generation.(AKA high mutation)

Next generation with having a few errors randomly distributed biased away from critical sections are most likely to evolve.( AKA low partial controlled mutation)

I am skipping mental evolution here. Mental evolution is much more complicated. It depends heavily on what definitions are used and there are many more options of what definitions to use. Mental evolution depends on at least: hardware, environment, and the transmit received from the society.
Comment: @Pelinore With good enough error correction, digital data could be designed that the probability of error is so low that the average time for the first error to occur could be longer than the heat death of the universe.
Comment: Error correction does not need to be on an individual robot's level. Unlike living creatures, they share the exact same "DNA" and have the means to actually read it. They could compare their entire source code with their peers. Something like each newly created robot must be accepted by X of their (non-sibling) peers or gets destroyed.
Comment: *"Depends"* // I don't think so, copy errors happen in digital data & any data that tells them how to build their 'offspring' is inevitably part of the data that they must copy & transfer to their 'child' so if we're assuming self-replicating machines as a given then over an adequate length of time it's inevitable regardless of if there's any special programming to facilitate or hasten their 'evolution' or not // organic evolution is essentially the same, data copying errors in DNA, so not a lot of difference
Comment: @vsz Very unlikely any error correction countermeasures can be that good you need to worry about the heat death of the universe but the simple answer is *'so don't do that then'* leave out error correction & prevention methods, you can even deliberately add a few extra ways for it to happen with less reliable data copying hardware or bits of code to randomise a few very small segments of program with new copies occasionally (wouldn't recommend more than one time in ten for that last & I've a feeling less frequent than that is probably better) if you want but that really isn't needed.
Comment: @Pepper Exactly my thought - a robot can have an unlimited number of "parents" and opportunities for error correcting. When each robot is "born", every other robot evaluates it, and destroys it if it is not identical to itself in every way. As the population grows, it becomes vanishingly likely that a "defective" or "evolved" robot could survive. If it somehow does, it halts *all future evolution*, since no new robots can be created that are identical to every member of a population of non-identical robots.
Answer: Yes, and quite fast actually
In the field of AI there is a set of algorithms called genetic algorithms:

In computer science and operations research, a genetic algorithm (GA) is a metaheuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on biologically inspired operators such as mutation, crossover and selection. (...)

Problems which appear to be particularly appropriate for solution by genetic algorithms include timetabling and scheduling problems, and many scheduling software packages are based on GAs. GAs have also been applied to engineering. Genetic algorithms are often applied as an approach to solve global optimization problems.

(Emphasis mine)
These algorithms can find solutions for a lot of problems in ways that amaze us humans. They can also ensure continuous adaptation to a dynamic environment.
If the problem the robots are trying to sove is survival, they will be constantly checking what it is in them that helps them thrive - each trait gets treated as a gene in the blueprints for the next batch of robots. I.e.: they find out statistically that tall robots thrive better in environment A, but worse in environment B. Environment A gets taller robots sent there, whereas environment B gets shorter ones.
They can fine tune their own ratio of mutation and recombination to achieve ever greater success in whatever enviroment they happen to conquer. Since robots are built rather than born, this is like industrial eugenics for them.
Comment: @pelinore a random error in a machine system causes a crash or halt of a function, which is then handled or finalized. There is no room for mutation, hence no evolution. All modern systems are built error handling so ingrained in their design that flipping bits will not lead to anything meaningful **unless the system is engineered to allow for that**. Have you ever sent an email that arrived different from what you sent?
Comment: @pelinore self-replicating machines would be able to QA out replication errors. We have to code mutation into them or they can simply overcome it.
Comment: *"In the field of AI there is a set of algorithms called genetic algorithms:"* irrelevant & unnecessary // copy errors happen in digital data & any data that tells them how to build their 'offspring' is inevitably part of the data that they must copy & transfer to their 'child' so if we're assuming self-replicating machines as a given then over an adequate length of time it's inevitable regardless of if there's any special algorithms or not.
Comment: You do understand what evolution is don't you? it's random data copy errors in DNA, most of it isn't useful & is in fact detrimental to an organism, that's where survival of the fittest comes in that's what evolution ***is*** // want to reconsider your response to my original comment now? :)
Answer: They could evolve, but it would be artificial.
Evolution happens because you only have a single copy of each DNA molecule in the sperm and the egg. Faults can creep in, and there's no simple way of error checking.
Computers have RAID arrays. where they store key information in redundant drives. As such, they don't change over future generations. They could store the personality modules and plans for each robot in an extremely low error arrangement.
They could artificially make themselves evolve. Perhaps they've found that the original designs for their bodies are extremely restrictive outside the intended environment, and so they've done evolutionary changes to their design to try to adapt to new environments and niches.
Comment: There is **no such thing a perfect data integrity**. No matter how fancy your RAID array, how intricate your error detection and correction algorithms, all you can do is *reduce* error, not eliminate it.
Comment: Sure, but with good redundancy and error checking the error rate isn't gonna be useful for evolution. Just because there will be errors once every few billion years doesn't mean the planet will last that long.
Comment: Robots can have multiple copies of the data set up in raid arrays, minimizing the chance of copy errors as they can just compare data sets against each other. Likewise, various safeties as Tort mentioned.
Comment: *"They could artificially make themselves evolve"* // They won't need to, copy errors happen in digital data & any data that tells them how to build their 'offspring' is inevitably part of the data that they must copy & transfer to their 'child' so if we're assuming self-replicating machines as a given then over an adequate length of time it's inevitable regardless of if there's any special programming to facilitate or hasten their 'evolution' or not // organic evolution is essentially the same, data copying errors in DNA, so not a lot of difference
Comment: @Pelinore The problem is that AI programming is not that organic. You get an error, the program tends to shut down and malfunction very quickly preventing further reproduction, while it's not as much the case for living beings. It is not accounting that copies are usually made with safeties in place (for instance, sum up some of the "0101" and check with a given value and if they're different then the copy is failed). In order to evolve, you'd need to have a lot of code shifts happening simultaneously on the good parts, which is extremely unlikely, even more than random mutations
Comment: @NepeneNep You do understand what evolution is don't you? it's random data copy errors in DNA, most of it isn't useful & is in fact detrimental to an organism, that's where survival of the fittest comes in & what evolution ***is*** *all about*, yes it takes a long time & no it doesn't insure useful results, ***just like real evolution doesn't*** // want to reconsider your response to PcMan's comment now? :)
Comment: Evolution happens because there's an error rate of around one per billion for DNA, and there's around 3 billion base pairs, so you get a few mutations every round. That means each generation you get a few more mutations which can add up. We often get a Bit Error rate for hard drives of around one in a quadrillion, which is a million times better than DNA, and sci fi technology and solid RAID arrays probably make it safer than that.
Comment: These argument make no sense unless you mention how many generations and how long time you expect to pass before seeing some changes
Answer: Yes, with qualifications.
In order to evolve, your robots must exhibit the following characteristics:

Intelligence. They don't have to be brilliant, mind you; they just need to be capable of adapting to changing situations. As such, dumb assembly-line robots will not evolve.

The ability to modify themselves. Being able to think of useful adaptations is useless if they can't affect changes upon themselves.

A reason to evolve. Evolution doesn't happen for literally no reason, after all. This will present a bit a problem; the robots can repair themselves, so the only reason for them to change would be a catastrophe which irretrievably breaks them out of their routine.
Comment: *"The information you have provided is wholly insufficient for a detailed answer"* No it  isn't, copy errors happen in digital data & any data that tells them how to build their 'offspring' is inevitably part of the data that they must copy & transfer to their 'child' **so the answer is simply *'Yes'*** if we're assuming self-replicating machines as a given then over an adequate length of time it's inevitable // all organic evolution is essentially the same as this, data copying errors in DNA, so not a lot of difference
Comment: Would the downvoter care to clarify why he did it?
Answer: yes.
This answer assumes the robots are capable of modifying their bodies in a way or another, even if it takes several generations.
Basically, to achieve something close to "evolution" at least in a natural sense, your robot needs to be in many ways like a very instinct-based animal (aka it can basically survive on its own from birth, relying very little on actual learning and much more on basic instincts or "programming") in several ways at first:
Essentially, programming is to your robot what DNA is to the animal I've described: it dictates everything from how it repairs damage it sustains to how it behaves to how it fabricates the next generations.
If your robots' programming is fail-proof and never changes (which apparently, as some seem to think, is necessarily impossible and a thing that should never be Done in any setting under any circumstances), there can be no evolution, every new robot will be exactly like the older ones and every robot will do the same thing in the same way under the same circumstances.
However, if there can be bugs in the coding, particularly when writing the coding on the newer generations, we start to have a glimpse at a potential "natural selection". Maybe the error does nothing, maybe it makes them better at not sustaining critical damage and thus being unable to create more copies, maybe it only makes it a bit jittery in certain circumstances, changing nothing otherwise (this is natural evolution, where changes undergone by a generation aren't necessarily good or bad, but they stack into changes that helps the thing perform better, be it by being better at surviving or at finding a mate,although in your case sexual selection doesn't seem to be at play).
If however your robots can willingly change their own coding to adapt to a certain problem, then machine-like evolution (as in newer generations are by default better than the older ones) can certainly be achieved, because they're constantly attempting to improve themselves (this is fairly similar to the RNA editing we see in cephalopods, except that, depending on Howe exactly this code rewriting works, the changes might be more long lasting).
So summing up, if your robot can have its programming changed, be it willingly or through bugs, without needing someone to actively tampering with them, evolution to some degree (be it in the natural or in the mechanical sense) is possible.
The final outcome most certainly will change drastically depending on how this evolution occurs though. Mechanically evolved robots probably will be better in every way compared to older generations within the natural constraints of their technology. You can and should expect them to be improved versions of their predecessors, since that's the goal of mechanical evolution.
However, if the evolution happens through bugs and errors in programming piling up, you should expect them to be simply more adapted to the environment they find themselves in than previous generations. Natural evolution doesn't work in the sense of improvement, but simply on the concept of what changes make the creature better at making more copies of itself and surviving long enough to achieve that goal (evolution doesn't necessarily make a moth capable of karate chopping its predators to survive, but it might simply result in it looking like a piece of bird poop to deceive said predators, because that's what allowed it to survive better).
Comment: *"It will depend mainly on the robots' programming."* // No not really, copy errors happen in digital data & any data that tells them how to build their 'offspring' is inevitably part of the data that they must copy & transfer to their 'child' so if we're assuming self-replicating machines as a given then over an adequate length of time it's inevitable regardless of if there's any special programming to facilitate or hasten their 'evolution' or not // organic evolution is essentially the same, data copying errors in DNA, so not a lot of difference.
Comment: @Pelinore we're talking about futuristic, self replicating and self repairing robots. Assuming they will naturally have flaws when copying their programming when they're perfectly capable of things that would require a few decent leaps in robotics isn't exactly something we can absolutely do here. Furthermore I did state that even if they weren't capable of actively modifying their programming they'd still evolve, but in a natural sense (simply become more adapted through environmental pressures) if we assumed imperfect copying of their programming to their offspring.
Comment: @Pelinore can you objectively affirm that the programming the offspring is necessarily subjective to changes? Or that the robots don't have advanced built-in debugs specifically designed to ensure such errors do not happen? The problem here is that the OP didn't give us every detail about their robots, how they work and the technology level, so I gave an answer that reflects what is necessary for that robot to have (aka it can't have the ability to always copy its programming perfectly and never have any bugs occur no matter the tech level or it can't evolve in any sense).
Comment: Data copy errors are inevitable in any self replicating system, ergo the answer is a simple ***'Yes, it's inevitable'*** special programming or any of the other fluff you've padded your answer with are at best irrelevant trivia & at worst disguise the fact you've missed the most basic & relevant fact involved in any good answer to this question, that being ***"data copy errors"*** // they simply don't need to *"willingly change their own coding"*.
Comment: @Pelinore let me say this again: we're talking about **self replicating, self repairing, clearly futuristic robots which are not possible with our current tech level**. We're talking about sci-fi setting, and clearly refers to technology far more advanced than ours, that assuming it isn't borderline magic disguised as techno babble so **no**, you can't objectively affirm it's impossible for there not to be bugs, because the one who will define that is the OP depending on what they assume does and doesn't happen to the machines in their setting.
Comment: Yes, & the most basic relevant fact & answer is ***'data copy errors makes it inevitable'*** regardless of how advanced they are or aren't, no good answer can exist that doesn't give that top billing far less one that ignores it.
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/130276/discussion-between-projectapex-and-pelinore).
Answer: What does "reproduce" even mean?
Robots constructing robots (internally or externally)
External construction basically means the robots are made in a factory.
Of course you can also build parts to upgrade the factory, or to make another factory, from within a factory. The factory itself may or may not be intelligent.
In this case they'd be able to make as many or as few improvements from one "generation" to the next as you wish. Any new discoveries could be incorporated into any new robots built, but you could also limit their ability to come up with new discoveries/improvements based on their programming. Such a limit would suggest that they're not truly intelligent; although, on the other hand, even humans can be very much stuck in their ways across many generations, and they have the benefit of actual evolution, whereas robots may just be stuck making exact copies of the same robot indefinitely.
This would follow the colloquial definition of "evolve", rather than the biological one.
Internal construction means one robot making a copy of themselves (or something similar) from within their own body.
How would a robot actually "grow" to reach the size of their "parent" (since the "child" would necessarily have to be smaller to fit within the "parent")? Perhaps they could gather the resources required and have the mechanisms to build any missing parts after birth. Or perhaps they're simply physically compressed from their natural state or the "parent" significantly expands during pregnancy (much like humans).
Although, overall, this seems quite inefficient. It would generally be much better to just have a factory somewhere rather than having a whole lot of robots carry around the parts to construct a copy of themselves at all times. On the other hand, you could have these parts be removable (in which case it probably needn't be part of them at all, and we're largely back to a factory), or you could have only a small subset of "female" robots capable of giving birth, who will then essentially serve as the factories mentioned above (although having an actual factory is probably still much more efficient).
For internal construction "evolution" may be slightly slower than for external construction (you probably wouldn't be able to double the size of a robot within 1 generation, nor create a part or structure that your mechanisms can't physically build). But they'd still be able to change almost everything about themselves within 1 or 2 generations, as long as their parts allows for some programming in terms of how to construct their "offspring" (otherwise you could, again, be left with them making exact copies of themselves indefinitely).
Biological reproduction, i.e. cyborgs
If the "robots" are actually cyborgs, i.e. they have some robotic parts and some biological parts, they may be able to biologically reproduce.
Their biological parts would probably roughly evolve like any animal, i.e. fairly slowly due to mutations. Their robotic parts would need to be constructed at some point during the pregnancy, and this can be improved as much or as little as you want (following from the above). I expect the most reasonable option would be to probably have this mostly take place in a lab or factory (much like external construction, except that it would use the actual DNA and whatnot).
Of course with gene editing, you could make a whole lot of changes to their biological parts from one generation to the next.
Why reproduce? Just upgrade!
While there are some common themes in fiction of robots becoming outdated and being replaced by better robots, this isn't the only way to end up with better robots.
You could also have robots with removable parts, who simply construct some new part (in a factory, probably) and replace whichever of their existing parts they want to replace.
You could go one step further and create an entirely new body and just move the "brain" onto the new body.
As for upgrading the "brain": they may have memory or processing power modules, and it can be realistic to have them be able to increase, upgrade or replace these without affecting their personality (as long as you don't remove any memories, that is). They may also have some sort of personality module, which may be more limited in terms of what you can actually improve there, while maintaining their personality. You could also back up the whole thing to mitigate any potential damage, so they can simply restore themselves. Depending on how all of this works, e.g. if it's a neural network, these parts may all be one and the same, or they may be entirely distinct (like a conventional computer with RAM, a CPU, etc.), which could make it easier or more difficult to make adjustments within the same robot.
If you want to go this route, you can also, if you want, have robots refrain from making improvements in new robots built that they can't apply to themselves. They may realise doing so could eventually lead to their own downfall, as there would be less and less of a need to cater to their old parts, and they would be less and less capable of keeping up with the new robots.
If they can upgrade themselves, this would likely mean that they would largely stop reproducing at some point (as long as they aren't expanding across their planet or the universe).
Answer: It's Life Jim But Not As You Know It.
Forget robots. Robots are just machines. They can be pulled apart and put back together. It's the programming that evolves.
The whole point of AI is that it can learn and adapt. It can then apply changes that work to every robot. Need to run faster? Every bot gets faster legs.
Look at Skynet in the Terminator movies. One learning AI building better and better terminators. In the books Skynet starts with running people over with self drive cars. It then builds the early terminators and then infiltrators with rubber skin then ones with real skin and finally shape shifting ones made of liquid metal.

It's evolving but not as you know it.
Comment: *"Forget robots // It's the programming that evolves"* Yes that's right the programming, the programming that tells the machine what to do (including how to build a new one) .. & a machine with a program that tells it what to do is ***a robot***, a program without a body of some sort is pretty useless // no special code is needed for a program to 'evolve' // copy errors happen in digital data (including that for how to make a new one) that has to be transferred to any 'child' it makes, this is what we call evolution in organic animals & would work just the same in self-replicating machines.
Comment: Yes but a program can hop from body to body. It can reside on a server and control multiple bodies remotely. It can replicate itself. It can merge itself. It can rewrite itself. An AI can do things organic evolution only dreams of.
Comment: "Yes but a program can hop from body to body" which is what it is doing when it's copied to a new body, so why bother erasing it from the old body, what does it achieve? nothing, it just insures that if the random copy error this time was bad the old body can't make any more without that new error & it's hardwired into the line of descent potentially killing that line off completely there & then, without multiple copies you get no competition without competition evolutions main method of destruction testing new against old is gone.
Comment: It doesn't have to wipe itself but it can certainly overwrite a old copy. Evolution in living creatures is random (semi) but an AI is directed. An AI can make two copies with different modifications to see which works better and then overwrite the loser with the winner. To an AI, a robotic body is nothing more than a tool.
Comment: Why overwrite an old copy? again, evolution needs competition to weed the better from the worse by survival of the fittest, you wipe a copy to make the new you've just removed a competitor without needing to compete, you need multiple copies, multiple copies need multiple bodies & it's better they're new bodies that then have to compete against the old ones, that way only those better than the old tend to survive & the old can try again with new offspring if they don't // you appear to think the question is about sky net? it's not.
Comment: "evolution needs competition to weed the better from the worse" Why? Maybe for random evolution but directed evolution, no it doesn't. AI chooses it's evolution.
Answer: Adaptive Repair/Construction behaviour
If your robots are capable of adapting the design of new robots to make use of local materials (this spark plug will do the same job as this other component with minor modifications) then they will tend to become quite diverse as they repair themselves or find themselves lacking raw materials when reproducing themselves.
This is a natural extension of a Field-Repair ability that would be highly useful for robots intended to operate away from ideal repair-facilities for extended periods.
Some of these ad-hoc modifications to the design may actually be more efficient than the base design, or be more robust in the given scenarios the robots find themselves in, and if the robots are capable of recognising this, they may formally adopt the change and accept whatever trade-off that brings them.
After all, if having half a microwave oven hanging out of your power core is more power-efficient than using your base-design, then you'll probably benefit more from having the oven on day one than clunking along for a few hundred days before maintenance requirements cause you to implement the change anyway.
Answer: Short answer yes, and very, very quickly, depending on how advanced they are.
If you have an artificial creature that can reproduce itself, especially if it has human level intelligence, it can create new selves to whatever liking it desires.
The concept of self reproducing machines is known as Von Neumann machines, and such machines could easily "evolve" - yet it would bear little resemblance to natural selection. It would not be a random process at all, unless the intelligence of such creatures was very unadvanced.
If you desire something resembling more traditional ideas of evolution, the machines could be extremely advanced to the point that modifying themselves is difficult, or they are lower intelligence - or lacking in the specific knowledge needed to intervene in how new selves are made.
Comment: *"the machines could be extremely advanced to the point that modifying themselves is difficult, or they are lower intelligence"* None of that is needed // copy errors happen in digital data & any data that tells them how to build their 'offspring' is inevitably part of the data that they must copy & transfer to their 'child' so if we're assuming self-replicating machines as a given then over an adequate length of time it's inevitable regardless of if there's any special programming to facilitate or hasten their 'evolution' or not.
Answer: Your question is only about whether it is possible or not, but it will not make sense without planning out how.
Can they evolve or not, would have an easy answer. Yes they can and will evolve.
But what you might find harder to explain would be, how exactly would they do it?
And for that, all you have to assume is that their whole genetic "code" is stored inside some drives. Which you can describe as however you want to as it would make sense to show them as some advanced technology.
Next, you would need to dive deeper into how they reproduce. Maybe in order to reproduce, they take a new drive and then they both connect their own drives together and the third drive in order to copy the data from those two drives to the third. But in doing so they have to expose off the drives to the outside.
And then again maybe, their planet has a lot of radiations on it and also cosmic rays. To induce random error all around the code. This does not affect the adult robots that much, because they have protection on themselves. But the adult robots don't have to be perfect against the radiation. They can still be somewhat affected by it, Just like mutations in adult humans. Radiations would also explain how the species that made them died off.
And for the hardware, it would make sense if the instructions to construct their hardware were present inside their drives.
Then, all you would need in order to complete the process of evolution would be some local reproduction factories? That would make the new offspring using the instructions from the drive.
This brings the robot evolution as close to human evolution as possible. Easier to implement and easier to digest.
Answer: Yes, absolutely.
But the timescale depends on the robot architecture.
It doesn't matter how error-checking & redundant your programming & hardware is, there's always (some ridiculously implausible) simultaneous set of random errors (quantum tunneling/cosmic rays/etc) that can bypass all the error checking & redundancy & automatic shutdowns & manage to create a viable mutant.
So yes, anything (and I mean anything) that reproduces can evolve, but I wouldn't be surprised if even with today's technology it wouldn't be possible to make such a digital architecture that it'd take longer than the lifetime of the universe before you could expect such a "miracle fault" to occur & produce a viable mutated offspring.
However, this is disadvantageous in a competitive environment. Excessive error checking is time- & energy-demanding & does not lend itself to an efficient organism, artificial or otherwise. Of course, the benefits of being able to evolve on relatively fast timescales are apparent; otherwise you will not be able to adapt as a population to a changing environment. In organic organisms, the amount of error checking it itself an evolved trait--too little, and the organism cannot compete as efficiently; too much, and deleterious mutations wrack the organism.
So again, yes, but the timescale is up to the designer (until enough mutating generations pass & the evolution rate itself becomes an evolved trait).
Answer: Sure. Especially if they're self-replicating. Others have covered macroscopic versions, so I'll cover the microscopic.
If you have self-replicating nanobots, then so long as they don't have an existing biosphere to compete with, they'll happily spread over the entire planet providing a starting point for a whole new biosphere to evolve from.
They'll make errors when replicating, and while the designers will have included error-correction codes, you can only design in so much error correction into your microscopic robot. Eventually you'll get a few where the software gets garbled enough that something gets past the code (or disables it), and if those have differences in how likely they are to replicate, then you've got evolution in action.
Now, note I said before "so long as they don't have an existing biosphere to compete with". If your nanobots get out on a planet that already has a biosphere, they're unlikely to go very far. They're basically artificial microorganisms and the biosphere consists in large part of microorganisms that have been competing with each other for billions of years. The nanobots won't have any optimisations for that, and even if they did have some designed in, the existing biosphere will have far more variety in its own methods of competition. The nanobots will either get eaten, get out-competed for resources, or at best become just another species in the ecosystem.
If you want a nanobot-descended ecosystem, it has to get its start on a lifeless planet. Even then, the old grey-goo trope of turning the whole planet into nanobots won't happen, and definitely not quickly. Thermodynamics limits how fast they can operate. They can only withstand so much heat and still work, and that'll limit how far down they can go, assuming they can even find what materials they need.
So, overall, self-replicating nanobots undergoing subsequent evolution could be how life on a given planet got started. Could leave explorers from a more Earth-like origin scratching their heads after putting some samples under a microscope.

Could robots evolve?


Color Picker Button

Question: I am wondering how i would go about creating a button which changes colors based on the current selection of a color picker wheel. I already have the color wheel working but i am stuck on the button. An example of this is in the QuickOffice app. (An image can be seen by going to http://www.quickoffice.com/ and clicking the android tab in the photo gallery)
Answer: I'll assume you're using the color picker dialog from API demos.
You could implement the OnColorChangedListener inside the activity so that it changes the color of a ShapeDrawable, that you'll use as drawable in an ImageButton.

Color Picker Button


Speed up/slow down audio file

Question: I am importing an audiofile to Mathematica and want to play it back at double speed. The only functions I see are the advanced options of AudioPitchShift (which doesn't alter the duration but increases the pitch) and AudioTimeStretch (which doesn't alter the pitch but does alter the duration). However, I want it both at the same time, half the duration, double the pitch. Which function should I use?
Comment: Can't you compose those two together, with a judicious setting of options, to achieve the result you want ?  ie, something like `AudioTimeStretch[AudioPitchShift[myaudiofile, dp], 0.5]`
Comment: Yes I can, but I suspect there is a faster & simpler option which I am overlooking
Answer: I was looking for the same. The best I came up with is this (replace a with your audio):
AudioPlay[Audio[AudioData[a],SampleRate->AudioSampleRate[a]*2]]

Speed up/slow down audio file


SQL Developer: Joining tables from connected SQL Server DB and connected Oracle DB

Question: We are migrating from SQL Server 2005 to Oracle 11G. I have been trying to do an update to a table in Oracle using data stored in a table in SQL Server.
Using SQL Developer, I have completed the following:

Created a connection to the Oracle Database
Created Connection name --> e9_crp
Supplied User name and Pass
Defined Host Name and SID

I also created a connection to the SQL Server that contains the reference data
Connection Name --> sql_data
User Name and Pass
Host and Port

The connection name used for SQL Server is sql_data
The connection name used for Oracle is e9_crp
The table in SQL Server is in a database my_tmp with owner of dbo and is called tiers (my_tmp.dbo.tiers).
In SQL Developer, I can see, select, and view the tiers table. This SQL statement also works using the worksheet when in the sql_data connection:
 select * from [my_tmp].[dbo].[tiers]

Trying to connect to this table when in the e9_crp connection schema, I have been trying to do something like this:
 select * from [sql_data].[my_tmp].[dbo].[tiers]

But this returns an error stating that the tiers table does not exist:
 ORA-00903: invalid table name
 00903. 00000 -  "invalid table name"

Both tables have a unique ID of 'item', so in a perfect world this should work:
 select a.itm, b.tier
 from [e9_crp].[crpdta].[itemmaster] a inner join [sql_data].[my_tmp].[dbo].[tiers] b
     on(a.itm = b.itm)

This is assuming that I use the connection name in the table identifier. BUT, this obviously does not work. What I need to do is be able to join these 2 databases together in a similar fashion as necessary.
How can I use SQL Developer to join these 2 tables? I have tried multiple iterations of table strings for the join but no luck. Any help is appreciated.
Answer: Oracle has the concept of a DBLink, and SQL Server has the concept of a Linked Server.  Both these features let you query data from two separate databases.
Here's a link with instructions for setting up an Oracle DBLink to a SQL Server DB...
http://www.dba-oracle.com/t_database_link_sql_server_oracle.htm
And here's a link with instructions for setting up a SQL Server Linked Server to an Oracle DB...
http://support.microsoft.com/kb/280106
See also this SO post...
SQL statement joining Oracle and MS SQL Server


Brushed motor VS BLDC

Question: Our brushed DC motor is rated for 3-4 amps and can be overloaded for 8+ amps. We are currently changing the brushed motor for a brushless (BLDC) motor, rated at 3.5 amps. How much can I overload the BLDC motor? I think much less, than the brushed motor. Am I correct?
Comment: You can't go beyond the rated *voltage*, the "current" is determined by the speed and the load. I think a better thing to do would be to study how BLDC motors work
Answer: tl;dr A BLDC motor may have a lower overload current than a brushed motor
When you overload something like a motor, there are several different mechanisms by which Something Bad could happen.
In a brushed motor, the brushes themselves will have a limit, which does not of course apply to a BLDC motor.
You are unlikely to be able to push enough current through the motor to break it mechanically, through too much torque. However, watch out for excess torque on things you add externally.
You could overheat the windings. With a steady current, this depends on the cooling of the motor. With a single pulse of current, it depends on the \$I^2t\$ of the pulse. If you keep the pulse duration short enough, then the amount of heat it dumps in the windings will be small.
The last, and often under-appreciated, limit on the motor current is demagnetisation of any permanent magnets in the motor. In a conventional brushed DC motor (small ones at least, less than a few kW), they are usually engineered so that the current surge taken at switch-on does not damage the motor. As that tends to be an order of magnitude more than the running current, almost everybody ignores it as being too big to be relevant, too big ever to be reached when powering it from the rated voltage.
BLDC motors on the other hand cannot be started or run by simply connecting them to a large battery. The controller always applies some form of current limiting. This may mean that BLDC motors do not have the same wide margin between running current and demagnetisation damage current. If the motor has a maximum current specified, then I would advise sticking to it. If you want to go above it, then get more data from the manufacturer, or buy a motor and test it to destruction.

Brushed motor VS BLDC


Non-significant Kruskal-Wallis and significant post hoc tests

Question: I have done this analysis where in Figure A-D. the Kruskal-Wallis global p-value is non-significant, but the p-value for pair CS and SCS in Figure A however is significant (at P<0.05). I read somewhere that if the global p-value is non-significant we don't report post-hoc pairwise tests. So In figure A, B, C, D and H, should I just delete the p-values for paired tests as the global p-values in these plots are not significant? Could someone please clarify this?
Comment: You also do not say if you perform any adjustments for multiple comparisons? (My packages [dunn.test](https://cran.r-project.org/package=dunn.test) and [conover.test](https://cran.r-project.org/web/packages/conover.test/) implement this functionality in truly *post hoc* tests for K-W.)
Comment: Okay.  At least to me that webpage is unclear as to what test it's performing in this case.  It might be performing pairwise Wilcoxon-Mann-Whitney tests.  This is probably less advantageous than the Dunn test (1964) or some other tests, and that may play into the test finding significant difference between groups.
Comment: Yeah, simple pairwise `wilcox.test`s don't reflect a post-hoc environment for the Kruskal-Wallis test as well as e.g. the Dunn test (1964). It could be part of the disconnect in the results.
Comment: Specifically, pairwise rank sum tests do not (1) use the same rankings of the data used by the Kruskal-Wallis test, and (2) do not use the pooled variance implied by the null hypothesis of the Kruskal-Wallis test.
Comment: I like Dunn test (1964). It makes sense to me, but I'm not an expert.
Comment: Dunn's test is better known, but the Conover-Iman test (conover.test) has more power to reject the null.
Comment: I'm curious about what post hoc test you used...
Comment: I take my words back. I actually used `wilcox.test` for post hoc comparison which is in line with @BruceET 's answer.
Comment: @SalMangiafico So what would you suggest for post-hoc after Kruskal-Wallis?
Comment: I think we are getting wrapped up in solving the "paradox" that is not a paradox-- the problem is trying to interpret pairwise comparisons that were not specifically planned a priori before getting a nonsignificant omnibus test.
Comment: @LSC , I'm adding an answer to this post to address your final comment. There is an (apparent) paradox here that shouldn't be summarily dismissed.
Comment: @SalMangiafico, you are certainly free to do so. The apparent paradox is just that, apparent and not a real paradox (the logic is unsound). Again, different questions are asked, and the "paradox" arises from failing to recognize the different questions (and calculations used). I agree it is something to discuss (mainly what can happen in illogical testing), but the OP specifically asked about including the p-values in this case, so it won't help the OP in the specific problem. Nowhere did the OP ask for help with a nonexistent paradox.
Answer: In general, if you use an omnibus test, such as an ANOVA F-test or a Kruskal-Wallis H-test, it is illogical and poor practice to conduct pairwise comparisons when you fail to reject the null hypothesis on the omnibus test. Conducting the comparisons flies in the face of the omnibus: insufficient evidence to conclude differences does not warrant further investigation, as a general rule.
Usually, I would say report analyses you run, but in this case (which is different from selective reporting), the post-hoc p-values are inappropriate to interpret and should be omitted. The omnibus p-value is appropriate since this is the "gatekeeper" test.
Comment: With the caveat that many tests we think of as post-hoc could also be used as the primary analysis, without first conducting an omnibus test.  A discussion relating to  traditional anova can be found at the following link.  I've seen this discussed with nonparametric tests as well, but I don't have a reference or link. https://stats.stackexchange.com/questions/9751/do-we-need-a-global-test-before-post-hoc-tests
Comment: Right, I understand this. My point is if someone uses an omnibus, it is presumably to help mitigate multiplicity and act as a gatekeeper. That was done in this case, so getting tied up in an apparent paradox isn't particularly helpful. I say "apparent paradox" because the tests ask different questions and so "conflicting results" aren't really conflicting because different questions are asked. The question posed here was whether pairwise comparisons are appropriate (presumably without preplanning) in light of a nonsignificant omnibus test; the short answer is no. 1/2
Comment: The logical flow of testing helps prevent p-hacking or "just because" "inferences" from occurring. This is also why in my response I said, "in general", because this is a strongly generalized answer but it applies specifically to the OP's scenario. If the OP had given a scenario of pre-planned contrasts irrespective of the omnibus, then a different answer would be helpful. 2/2
Answer: Illustrating @LSC's answer (+1), here is an example to show that doing ad hoc two-sample Wilcoxon tests can lead to 'false discoveries' if a Kruskal-Wallis test is not significant.
Suppose we have five groups of size $n = 20$ with values distributed uniformly on the same
interval. So, ideally we should not find any significant differences at all.

Let the significance level of all tests be 10%.
  Then the K-W test will reject $H_0$ that all five groups come from
  the same population distribution about 10% of the time.
If we were to
  do ad hoc two sample Wilcoxon tests to compare the two groups out of five that have the most different medians, we would reject the null
  hypothesis that those two groups differ another 10% of the time.

A simulation in R of 10,000 such datasets, each with five groups of 20 observations, is shown below:
set.seed(2019)
m = 10^4;  p.kw = p.wx = numeric(m)
for(i in 1:m) {
  x1 = runif(20, 10, 25);  x2 = runif(20, 10, 25)
  x3 = runif(20, 10, 25);  x4 = runif(20, 10, 25)
  x5 = runif(20, 10, 25)
  p.kw[i] = kruskal.test(list(x1,x2,x3,x4,x5))$p.val
  MAT=rbind(x1,x2,x3,x4,x5)
  h = apply(MAT,1,median)
  mx = which(h==max(h));  mn = which(h==min(h))
  p.wx[i] = wilcox.test(MAT[mx,1],MAT[mn,])$p.val
}
mean(p.kw<.1);  mean(p.wx<.1)
[1] 0.0947      # rejection rate for K-W
[1] 0.1017      # rej rate: all Wilcoxon for two extremes
mean(p.wx[p.kw > .1] < .1)
[1] 0.09632166  # rej rate: improper ad hoc Wilcoxon tests

It happens that one of the unwarranted ad hoc Wilcoxon rank sum tests
occurred for the last of the 10,000 iterations. Boxplots for the
five groups are shown, followed by a non-significant (10% level) K-W test
and a significant two-sample Wilcoxon test comparins groups 2 and  3.

kruskal.test(list(x1,x2,x3,x4,x5))$p.value
[1] 0.3357694             # not significant at 10%
wilcox.test(x2,x3)$p.val
[1] 0.09108615            # 'significant' improper ad hoc test

Added per Comment: The P-value for a K-W test comparing the same two groups gives very nearly the same P-value as the Wilcoxon test above; both P-values essentially 0.9.
kruskal.test(list(x2,x3))$p.val
[1] 0.08835202

Comment: Non familiar with that exact procedure.  Usually two-sample Wilcoxon tests _ad hoc_ comparisons among levels after a significant K-W test (often with Bonferroni levels to protect against false discovery). However, K-W tests work for only 2 groups and then are very nearly the same as 2-sample Wilcoxon, so it might not make a difference which is used.
Comment: See K-W test for last example in my Answer, just added.
Comment: Thank you so much for this great answer.
Comment: Thank you. Just wanted to be clear- I followed the tests illustrated here http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/76-add-p-values-and-significance-levels-to-ggplots/. I used `stat_compare_means(comparisons = my_comparisons, method = "kruskal.method")`. I thought I used `kruska.test` for post-hoc comparisons also. Am I missing something here?
Answer: There is a question underlying OP's example that is not a trivial one:  If a test like KW assesses a hypothesis that all groups are (stochastically) equal, and if we find a non-significant result for KW, but then a significant result for pairwise tests, How is it that these tests are valid?  Why would we ever want to use an omnibus test instead of jumping to pairwise tests?
Some of the comments on the original post partially address this situation.
One issue is that KW looks at the data in all groups simultaneously, whereas presumably the software in the OP's example is using pairwise Mann-Whitney tests which look at two groups at a time while ignoring the other groups.  So, simply, they are addressing the analysis in different ways.  Usually it is considered better to look at all groups simultaneously.  This can also avoid potential incommensurate pairwise results (where e.g. A > B, B > C, and C > A).  As mentioned in the comments on the original post, we might use Dunn's test (1964) or Conover-Iman instead of a simple pairwise approach.
Likely another issue here is that the post-hoc approach used may not have adjusted p values for multiple tests.  If this is the case, then the likelihood of finding a significant result in the pairwise tests, just by chance, is elevated.
I also think there's some sense to the idea that if are really interested in comparing groups, that we can skip the omnibus test and look at group comparisons (Link1, Link2).  In the context of KW, this logic may also apply to effect size statistics.  That is, using pairwise or maximum Vargha and Delaney's A rather than epsilon-squared.
Comment: "How is it that these tests are valid? " I think this question skirts totally past the point that the tests may be entirely valid because they're asking different questions, so the "contradiction'' isn't real. You only perceive contradiction because you ran the different tests and fail to understand the questions that are formulated into the tests.


Estimator examples of non-normal probability distributions?

Question: The maximum likelihood estimators for expectation $\mu$ and variance $\sigma^{2}$ of a normal distribution are:
$$\hat{\mu} = \frac{1}{n}\sum_{i=1}^{n} \Big(x_{i}\Big)$$
and
$$\hat{\sigma^{2}} = \frac{1}{n}\sum_{i=1}^{n}\Big((\hat{\mu}-x_{i})^{2}\Big)$$
They are used so frequently in statistics that it is easy to think that they apply to all probability distributions. What would be the mean, variance (or other parameter of the distribution) estimators for some of the non-normal probability distributions?
Comment: The Wikipedia article for each distribution normally quotes the ML estimators for the parameters of the distribution. These can not always be given in closed form, e.g. Gamma distribution.
Answer: Here is a list of Maximum Likelihood Estimators of some distributions:
<code>                           Parameter      ML-Estimator
</code>
Binomial distribution   $\qquad \qquad    p    \qquad \qquad      \qquad         \frac{X}{n}$
Poisson distribution      $\qquad \qquad    \lambda    \qquad \qquad      \qquad         \overline X$
Geometric distribution $\qquad \qquad    p    \qquad \quad     \large{ \qquad         \frac{1}{\overline X+1}}$
Neg. Binomial Distribution $\qquad   k,p      \qquad \quad      \quad         $ ---
Exponential distribution      $\qquad \quad    \lambda    \quad \qquad
 \qquad         \frac1{\overline X}$
Gamma distribution  $\qquad \qquad    k,\lambda    \quad \qquad
 \qquad         $---
Uniform distribution $\qquad \quad    N \ \text{or} \ \theta    \quad \quad
 \qquad     X_{n}=Max \ X_i    $
Source: $\small{\text{Einführung in die Statistik: Analyse und Modellierung von Daten (9th Edition), Author: Rainer Schlittgen}}$,$\small{\text{p. 295}}$
It can be read off that not for all listed distributions a MLE can be determined.
Comment: Interesting list (+1). However, I wonder if a dash means 'no MLE' or 'no MLE in closed form'. For example, computational methods are needed to find MLEs for some [_gamma distributions_](https://en.wikipedia.org/wiki/Gamma_distribution#Parameter_estimation).
Comment: @BruceET Thanks. Good question. The book says that it exists no MLE. In such cases the MLE values can only be evaluated by numerical methods for only specific samples. But it is not mentioned how it would work. The book is a little bit squishy at this point.
Answer: Suppose $X(t)$ is a random variable depending on a parameter $t$ with probability or probability density function $f(t, x)$ (I will only refer to pdfs from now on but the beginning of the argument applies to the discrete case as well). Then the pdf of $n$ independent samples of $X(t)$ is given by $\prod_{i=1}^n f(t, x_i)$, so the maximum likelihood value of $t$ given samples $x_i$ is
$$\text{argmax}_t \prod_{i=1}^n f(t, x_i) = \text{argmax}_t \sum_{i=1}^n \log f(t, x_i).$$
This is as much as we can say with no further assumptions on the form of $f$. However, if we make the useful simplifying assumption that $f$ is an exponential family, so that $f(t, x_i)$ is proportional to $\exp (\eta(t) T(x_i) - A(t))$ for some functions $\eta, T, A$, then the argmax becomes
$$\text{argmax}_t \sum_{i=1}^n \left( \eta(t) T(x_i) - A(t) \right) = \text{argmax}_t \, \eta(t) \left( \frac{1}{n} \sum_{i=1}^n T(x_i) \right) - A(t).$$
Note that now the samples $x_i$ only affect this estimate via the sample average $\frac{1}{n} \sum_{i=1}^n T(x_i)$, which has become a sufficient statistic for $t$. For example, if $t$ is the mean of a normal distribution with known variance we have $T(x_i) = x_i$, and if $t$ is the variance of a normal distribution with known mean $\mu$ we have $T(x_i) = (x_i - \mu)^2$. (This discussion generalizes to the case that $t$ is multivariate but I want to stick to one variable for simplicity.)
Assuming that $\eta$ and $A$ are smooth, differentiating with respect to $t$ now gives
$$\boxed{ \eta'(t_{MLE}) \left( \frac{1}{n} \sum_{i=1}^n T(x_i) \right) = A'(t_{MLE}) }.$$
So the MLE of $t$ is given by applying the inverse of $\frac{A'(t)}{\eta'(t)}$, assuming that exists, to the sample average $\frac{1}{n} \sum_{i=1}^n T(x_i)$.
Example. For a normal distribution with unknown mean $t = \mu$ and known variance $\sigma^2$ the density is proportional to $\exp \left( - \frac{(x - \mu)^2}{2 \sigma^2} \right)$, which gives $A(\mu) = \frac{\mu^2}{2 \sigma^2}$, $\eta(\mu) = \frac{\mu}{\sigma^2}$, and $T(x) = x$. Applying the boxed equation then gives
$$\frac{1}{\sigma^2} \left( \frac{1}{n} \sum_{i=1}^n x_i \right) = \frac{\mu_{MLE}}{\sigma^2}.$$
Happily the $\sigma$s cancel and we get $\mu_{MLE} = \frac{1}{n} \sum_{i=1}^n x_i$ as expected.
Example. Consider a lognormal distribution whose logarithm is normally distributed with unknown mean $t = \mu$ and known variance $\sigma^2$. Then everything is the same as in the normal case except that we have $T(x) = \log x$. Hence we find that
$$\mu_{MLE} = \frac{1}{n} \sum_{i=1}^n \log x_i.$$
Taking exponentials we get that $\exp (\mu_{MLE})$ is given by the geometric mean of the samples $x_i$ (note that $\exp(\mu)$ is not the mean of the lognormal distribution, but the geometric mean). In this case the arithmetic mean of the samples will be strongly biased upward, which the geometric mean corrects for.
You can compute other examples for yourself using the table of exponential family distributions given in the linked Wikipedia article.