[Question]
  [
The derivative of a function is a cornerstone of mathematics, engineering, physics, biology, chemistry, and a large number of other sciences as well. Today we're going to be calculating something only tangentially related: the arithmetic derivative.
# Definition
The arithmetic derivative `a(n)` or `n'` is defined here ([A003415](http://oeis.org/A003415)) by a number of properties that are similar to the derivative of a function.
* `a(0) = a(1) = 0`,
* `a(p) = 1`, where `p` is any prime, and
* `a(mn) = m*a(n) + n*a(m)`.
The third rule is based on the product rule for differentiation of functions: for functions `f(x)` and `g(x)`, `(fg)' = f'g + fg'`. So with numbers, `(ab)' = a'b + ab'`.
Also of note, since the arithmetic derivative can be extended to the negative numbers via this simple relation, `a(-n) = -a(n)`, the input may be negative.
# Rules
* Write a program or function that, given any integer `n`, returns the arithmetic derivative of `n`.
* Inputs will be `-230 < n < 230`, to avoid problems with integer sizes and numbers too large to factor in a reasonable amount of time. Your algorithm should still be able to theoretically calculate the arithmetic derivative of numbers outside this range.
* Built-ins for symbolic math, prime factorization and differentiation are allowed.
# Examples
```
> a(1)
0
> a(7)
1
> a(14)   # a(7)*2 + a(2)*7 = 1*2 + 1*7 = 9
9
> a(-5)   # a(-5) = -a(5) = -1
-1
> a(8)    # a(8) = a(2**3) = 3*2**2 = 12
12
> a(225)  # a(225) = a(9)*25 + a(25)*9 = 6*25 + 10*9 = 150 + 90 = 240
240
> a(299792458)  # a(299792458) = a(2)*149896229 + a(7)*42827494 + a(73)*4106746 + a(293339)*1022 = 1*149896229 + 1*42827494 + 1*4106746 + 1*1022 = 149896229 + 42827494 + 4106746 + 1022 = 196831491
196831491
```
As always, if the problem is unclear, please let me know. Good luck and good golfing!
  
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), 12 bytes
```
|1>?GtYf/s}0
```
[**Try it online!**](http://matl.tryitonline.net/#code=fDE-P0d0WWYvc30w&input=Mjk5NzkyNDU4)
### Explanation
Consider an integer *a* with |*a*|>1, and let the (possibly repeated) prime factors of |*a*| be *f*1, ..., *f**n*. Then the desired result is *a*·(1/*f*1 + ... + 1/*f**n*).
```
|1>     % take input's absolute value. Is it greater than 1?
?       % if so:
  Gt    %   push input twice
  Yf    %   prime factors. For negative input uses its absolute value
  /     %   divide element-wise
  s     %   sum of the array
}       % else:
  0     %   push 0
```
[Answer]
## Python, 59 bytes
```
f=lambda n,p=2:+(n*n>1)and(n%p and f(n,p+1)or p*f(n/p)+n/p)
```
A recursive function. On large inputs, it runs out of stack depth on typical systems unless you run it with something like [Stackless Python](https://en.wikipedia.org/wiki/Stackless_Python).
The recursive definition is implemented directly, counting up to search for candidate prime factors. Since `f(prime)=1`, if `n` has a prime `p` as a factor, we have `f(n) == p*f(n/p)+n/p`.
[Answer]
# Jelly, ~~8~~ 7 bytes
*-1 byte by @Dennis*
```
ÆfḟṠ³:S
```
Uses the same formula everyone else does. However, there's a little trick to deal with `0`.
```
o¬AÆfİS×     Main link. Inputs: n
o¬             Logical OR of n with its logical NOT
               That is, 0 goes to 1 and everything else goes to itself.
  A            Then take the absolute value
   Æf          get its list of prime factors
     İ         divide 1 by those
      S        sum
       ×       and multiply by the input.
```
Try it [here](http://jelly.tryitonline.net/#code=w4Zm4bif4bmgwrM6Uw&input=&args=LTI5OTc5MjQ1OA).
[Answer]
## Python 2, ~~87~~ ~~78~~ ~~76~~ 74 bytes
```
a=b=input()
d=2
s=0
while d<=abs(b):
    if a%d==0:
        a=a/d
        s+=b/d
    else:
        d+=1
print s
```
Improvements thanks to @Maltysen: 
```
a=b=input()
d=2
s=0
while d<=abs(b):
    if a%d==0:a/=d;s+=b/d
    else:d+=1
print s
```
Further improvement by two bytes:
```
a=b=input()
d=2
s=0
while abs(a)>1:
    if a%d<1:a/=d;s+=b/d
    else:d+=1
print s
```
Further improvement thanks to @xnor:
```
a=b=input()
d=2
s=0
while a*a>1:
    if a%d<1:a/=d;s+=b/d
    else:d+=1
print s
```
### Explanation
The arithmetic derivative of `a` is equal to `a` times the sum of the reciprocals of the prime factors of `a`. No exception for 1 is needed since the sum of the reciprocals of the prime factors of 1 is zero. 
[Answer]
# Haskell, ~~203~~ 90 bytes
Thanks @nimi!
I still have no idea when what indentations cause what interpretation, this is the shortest I managed so far, and as always, I'm sure it can be golfed a lot more. I'm going to try again in the evening.
```
n#(x:_)|y<-div n x=x*a y+y*a x;_#_=1
a n|n<0= -a(-n)|n<2=0|1<2=n#[i|i<-[2..n-1],mod n i<1]
```
[Answer]
# J, ~~30~~ ~~27~~ 19 chars
Thanks to [@Dennis](https://codegolf.stackexchange.com/users/12012/dennis) for chopping off 3 characters.
Thanks to [@Zgarb](https://codegolf.stackexchange.com/users/32014/zgarb) for chopping off 8 characters.
```
0:`(*[:+/%@q:@|)@.*
```
[Try it online!](http://tryj.tk/)
Sample input:
```
0:`(*[:+/%@q:@|)@.* _8
_12
0:`(*[:+/%@q:@|)@.* 0
0
0:`(*[:+/%@q:@|)@.* 8
12
```
How it works:
```
0:`(*[:+/%@q:@|)@.* N
XX`[[email protected]](/cdn-cgi/l/email-protection)   if Z then Y else X end
0:                        X:  return 0
                  Z       Z:  signum(N)
   (*[:+/%@q:@|)          Y:  N*add_all(reciprocal_all(all_prime_factors(abs(N))))
                              N
    *                          *
      [:+/                      add_all(                                         )
          %@                            reciprocal_all(                         )
            q:@                                       all_prime_factors(      )
               |                                                        abs( )
                                                                            N
```
[Answer]
# Pyth - ~~10~~ 8 bytes
Lovin' the implicit input! Should bring it on par with Jelly for most things (Except Dennis' golfing skills).
```
*scL1P.a
```
[Test Suite](http://pyth.herokuapp.com/?code=%2ascL1P.a&test_suite=1&test_suite_input=1%0A7%0A14%0A-5%0A8%0A225%0A299792458&debug=0).
```
*             Times the input, implicitly (This also adds the sign back in)
 s            Sum
  cL1         Reciprocal mapped over lit
   P          Prime factorization
    .a        Absolute value of input, implicitly
```
[Answer]
## Haskell, 59 bytes
```
n%p|n*n<2=0|mod n p>0=n%(p+1)|r<-div n p=r+p*r%2
(%2)
```
Implements the recursive definition directly, with an auxiliary variable `p` that counts up to search for potential prime factors, starting from `2`. The last line is the main function, which plugs `p=2` to the binary function defined in the first line.
The function checks each case in turn:
* If `n*n<2`, then `n` is one of `-1,0,1`, and the result is `0`.
* If `n` is not a multiple of `p`, then increment `p` and continue.
* Otherwise, express `n=p*r`, and by the "derivative" property, the result is `r*a(p)+p*a(r)`, which simplifies to `r+p*a(r)` because `p` is prime.
The last case saves bytes by [binding `r` in a guard](https://codegolf.stackexchange.com/a/76749/20260), which also avoids the `1>0` for the boilerplate `otherwise`. If `r` could be bound earlier, the second condition `mod n p>0` could be checked as `r*p==n`, which is 3 bytes shorter, but I don't see how to do that.
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [-x](https://codegolf.meta.stackexchange.com/questions/14337/command-line-flags-on-front-ends/14339#14339), ~~16~~ ~~13~~ 10 bytes
```
ÒU©a k £/X
```
*- 6 bytes thanks to @Shaggy*
[Try it online!](https://tio.run/##y0osKPn///Ck0EMrExWyFQ4t1o/4/9/QREG3AgA "Japt – Try It Online")
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~13~~ 9 bytes
A simple solution. The Dyalog Unicode version was simply a longer version of this so it has been omitted.
**Edit:** Saved 4 bytes by adopting the method in [lirtosiast's Jelly solution](https://codegolf.stackexchange.com/a/76976/47581).
```
{+/⍵÷⍭|⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/v1pb/1Hv1sPbD29/1DHjUeeiRz07HvWurQGK1f5Pe9Q24VFv36O@qZ7@j7qaD603ftQ2EcgLDnIGkiEensH/0w6tMFQwVzA0UTi03lTBQsHIyBQA "APL (Dyalog Extended) – Try It Online")
**Ungolfing**
```
{+/⍵÷⍭|⍵}
{        }  A dfn, a function in {} brackets.
     ⍭|⍵   The prime factors of the absolute value of our input.
   ⍵÷      Then divide our input by the above array,
            giving us a list of products for the product rule.
 +/         We sum the above numbers, giving us our arithmetic derivative.
```
[Answer]
# Ruby, ~~87~~ ~~66~~ ~~80~~ ~~75~~ ~~70~~ 68 bytes
This answer is based on [Luis Mendo's MATL answer](https://codegolf.stackexchange.com/a/76949/47581), [wythagoras's Python answer](https://codegolf.stackexchange.com/a/76957/47581), and the idea that the arithmetic derivative of a number `m` is equal to `m·(1/p1 + 1/p2 + ... + 1/pn)` where `p1...pn` is every prime factor of `n` to multiplicity.
```
->n{s=0;(2...m=n.abs).map{|d|(m/=d;s+=n/d)while m%d<1};m<2?0:s+0**s}
```
This function is called in the following way:
```
> a=->n{s=0;(2...m=n.abs).map{|d|(m/=d;s+=n/d)while m%d<1};m<2?0:s+0**s}
> a[299792458]
196831491
```
**Ungolfing:**
```
def a(n)
  s = 0
  m = n.abs
  (2...m).each do |z|
    while m%d == 0
      m /= d
      s += n / d
    end
  end
  if s == 0
    if n > 1
      s += 1 # if s is 0, either n is prime and the while loop added nothing, so add 1
             # or n.abs < 2, so return 0 anyway
             # 0**s is used in the code because it returns 1 if s == 0 and 0 for all other s
    end
  end
  return s
end
```
[Answer]
# Julia, ~~72~~ 43 bytes
```
n->n^2>1?sum(p->n÷/(p...),factor(n^2))/2:0
```
This is an anonymous function that accepts an integer and returns a float. To call it, assign it to a variable.
For an input integer *n*, if *n*2 ≤ 1 return 0. Otherwise obtain the prime factorization of *n*2 as a `Dict`, then for each prime/exponent pair, divide the prime by its exponent, then divide *n* by the result. This is just computing *n* *x* / *p*, where *p* is the prime factor and *x* is its exponent, which is the same as summing *n* / *p*, *x* times. We sum the resulting array and divide that by 2, since we've summed twice as much as we need. That's due to the fact that we're factoring *n*2 rather than *n*. (Doing that is a byte shorter than factoring |*n*|.)
Saved 29 bytes thanks to Dennis!
[Answer]
# [Seriously](http://github.com/Mego/Seriously), ~~17~~ ~~14~~ ~~11~~ 12 bytes
My first ever Seriously answer. This answer is based on [Luis Mendo's MATL answer](https://codegolf.stackexchange.com/a/76949/47581) and the idea that the arithmetic derivative of a number `m` is equal to `m·(1/p1 + 1/p2 + ... + 1/pn)` where `p1...pn` is every prime factor of `n` to multiplicity. My addition is to note that, if `m = p1e1·p2e2·...·pnen`, then `a(m) = m·(e1/p1 + e2/p2 + ... + en/pn)`. Thanks to [Mego](https://codegolf.stackexchange.com/users/45941/mego) for golfing and bug fixing help. [Try it online!](http://seriously.tryitonline.net/#code=LDt3YGlAL2BNzqMqbA&input=LTEy)
```
,;w`i@/`MΣ*l
```
**Ungolfing:**
```
,             get a single input
 ;w           duplicate input and get prime factorization, p_f
               for input [-1..1], this returns [] and is dealt with at the end
   `   `M     map the function inside `` to p_f
    i         pop all elements of p_f[i], the prime and the exponent, to the stack
     @        rotate so that the exponent is at the top of the stack
      /       divide the exponent by the prime
         Σ    sum it all together
          *   multiply this sum with the input
           l  map and multiply do not affect an empty list, so we just take the length, 0
               l is a no-op for a number, so the result is unchanged for all other inputs
```
[Answer]
# Jolf, 13 bytes
```
*jmauΜm)jd/1H
```
Kudos to the MATL answer for the algorithm! [Try it here](http://conorobrien-foxx.github.io/Jolf/#code=KmptYXXOnG0pamQvMUg), [or test them all at once](http://conorobrien-foxx.github.io/Jolf/#code=b25bMSwgNywgMTQsIC01LCA4LCAyMjUsIDI5OTc5MjQ1OF0KzpxuZM26SCpIbWF1zpxtKUhkLzFI). (Outputs [key,out] in an array.)
## Explanation
```
*jmauΜm)jd/1H
*j             input times
      m)j         p.f. of input
     Μ   d/1H      mapped to inverse
    u            sum of
  ma            abs of
```
[Answer]
# Mathematica 10.0, 39 bytes
```
Tr[If[#>1,#2/#,0]&@@@FactorInteger@#]#&
```
[Answer]
# APL(NARS), 35 char, 70 bytes
```
{1≥a←∣⍵:0⋄1=≢k←πa:×⍵⋄c+m×∇c←⍵÷m←↑k}
```
test and how to use:
```
  f←{1≥a←∣⍵:0⋄1=≢k←πa:×⍵⋄c+m×∇c←⍵÷m←↑k}
  f 14
9
  f 8
12
  f 225
240
  f ¯5
¯1
  f 299792458
196831491
```
I thought that it would not be ok because I don't know if c variable is composed (and not a prime)... But seems ok for the test...
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~7~~ 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ÄÒ÷O
```
Port of [*@lirtosiast*'s Jelly answer](https://codegolf.stackexchange.com/a/76976/52210).
[Try it online](https://tio.run/##yy9OTMpM/f//cMvhSYe3@///r2tkaWluaWRiagEA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfeXhCf8PtxyedHi7/3@d/9EGOoY65jqGJjq6pjoWOkZGpjpGlpbmlkYmphY6unBmLAA).
**Explanation:**
```
Ä     # Take the absolute value of the (implicit) input
 Ò    # Get all its prime factors (with duplicates)
  ÷   # Integer divide the (implicit) input by each of these prime factors
   O  # And take the sum (which is output implicitly)
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `s`, 3 bytes
```
ȧǐ/
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=s&code=%C8%A7%C7%90%2F&inputs=225&header=&footer=)
```
ȧ   # Abs. val
 ǐ  # All prime factors
    # (Implicit input)
  / # Divided by each factor.  
    # (s flag) sum of stack
```
-1 thx to Underslash
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 44 bytes
```
n->n*vecsum([i[2]/p|i<-factor(n)~,0<p=i[1]])
```
[Try it online!](https://tio.run/##FYzRCsIgGEZf5WNXGr@UsrEJ215EvJCRIZT92AqC6NXNrr5z4PBxKElduEYsqFmt@fA6b4/nTbjkjD/yJ80qhm2/F5Hll04zL8lp72UNzNe3yFAruKS8N@z@0iG2VBKcJowE3RPUQJgIxrQ11o7W9MPUPn4 "Pari/GP – Try It Online")
[Answer]
# Perl 5, 62 bytes
```
perl -MMath::Prime::Util=:all -E"map$i+=1/$_,factor abs($j=<>);say$i*$j"
```
Uses the formula (from OEIS): `If n = Product p_i^e_i, a(n) = n * Sum (e_i/p_i).`
[Answer]
## Perl 6, 90
```
sub A(\n) {0>n??-A(-n)!!(n>1)*{$_??n/$_*A($_)+$_*A n/$_!!1}(first n%%*,2..^n)};say A slurp
```
This might be a bit slow for large numbers. Replace `2..^n` with `2..n.sqrt` for longer code but faster computation.
[Answer]
# [Ink](https://github.com/inkle/ink), 183 bytes
```
==function a(n)
{n<0:
~return-a(-n)
}
{n<2:
~return 0
}
~temp f=t(n,2)
{f:
~return a(n/f)*f+n/f
}
~return 1
==function t(n,i)
{n>1&&n-i:
{n%i:
~return t(n,i+1)
}
~return i
}
~return 0
```
[Try it online!](https://tio.run/##TY1BDoMgEEX3nIJNDdSSAtFYTOldTCMJaTo2BldGr06HYqqrN7zh//HwinPHFF8IoslQVaaoM28ZWm9vbUxjdFWjj9a6CZ7BD0A7BpzMcJctWcc@TCMI7EC3JKv/lko0a@jfH@psYHDRGHP7Gnuujp9diUg/N63I4VaK@XTtoYoChG9xPPm947cvFT/k/WGWMX4B "ink – Try It Online")
I refuse to believe this is a good solution, but I can't see a way to improve it either.
]