# Xkcd: Garbage Math

**URL:** https://discourse.julialang.org/t/xkcd-garbage-math/38113
**Category:** Offtopic
**Created:** [April 23, 2020, 10:31pm UTC](https://discourse.julialang.org/t/xkcd-garbage-math/38113 "2020-04-23T22:31:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AlfTetzlaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alftetzlaff/32/13124_2.png) [@AlfTetzlaff](https://discourse.julialang.org/u/AlfTetzlaff)
#### Post date: [April 23, 2020, 10:31pm UTC](https://discourse.julialang.org/t/xkcd-garbage-math/38113/1 "2020-04-23T22:31:15Z")

</div>

Is anybody interested in using julia’s advanced type system to implement this? I would definitely enjoy using it!

> **[Garbage Math](https://xkcd.com/2295/)**
>
> 'Garbage In, Garbage Out' should not be taken to imply any sort of conservation law limiting the amount of garbage produced.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [April 24, 2020, 2:01am UTC](https://discourse.julialang.org/t/xkcd-garbage-math/38113/2 "2020-04-24T02:01:15Z")

</div>

I present to you, [GarbageMath.jl](https://github.com/MasonProtter/GarbageMath.jl).

```julia
julia> using GarbageMath

julia> Precise(1.2) + Precise(3.5)
Slightly less precise number 4.7

julia> Precise(3) * Precise(1)
Slightly less precise number 3

julia> Precise(1) + Garbage(2)
Garbage number 3

julia> Precise(1e10) * Garbage(1e-6)
Garbage number 10000.0

julia> √(Garbage(5))
Less bad garbage number 2.23606797749979

julia> Garbage(6)^2
Worse garbage number 36

julia> mean(StatisticallyIndependant([Garbage(3), Garbage(4), Garbage(5)]))
Better garbage number 4.0

julia> Precise(5)^Garbage(6)
Much worse garbage number 15625

julia> Garbage(2) - Garbage(10)
Much worse garbage number -8

julia> Precise(10)/(Garbage(3) - Garbage(4))
Much worse garbage number -10.0

julia> Garbage(3) * 0
Precise number 0

```

If you’re concerned about how poorly implemented this is, I think that’s part of the charm 😉

---

<div class="post-metadata">

### Author: ![AlfTetzlaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alftetzlaff/32/13124_2.png) [@AlfTetzlaff](https://discourse.julialang.org/u/AlfTetzlaff)
#### Post date: [April 24, 2020, 8:27am UTC](https://discourse.julialang.org/t/xkcd-garbage-math/38113/3 "2020-04-24T08:27:39Z")

</div>

I asked the question, went to bed and woke up to this wonderful piece of code! I love this community 😃

I see that the math you are using still produces valid results. Maybe it is worthwhile to add some randomness to make the garbage actual garbage 😃
