# Introduction

How to prove that 1 = 2:

1 = 2
2 = 4 (*2)
-1 = 1 (-3)
1 = 1 (^2)


You can just multiply both sides by 0, but that's cheating. This is just bending the rules a little bit.

Write a program/function that, when given two integers, outputs a "proof" that the two are equal.

# Rules

• Your program's output must start with a = b, where a and b are the integers, and end with c = c, where c can be any number. Don't output the operations.
• Your output can only use integers.
• The only operations you can use are addition, multiplication, division, subtraction, and exponentiation, and you cannot multiply, divide or exponentiate by 0.
• Each line must be one of the above operations done to both sides of the equation in the previous line.

For example, you could go:

4 = 9
5 = 10 (+1)
1 = 2 (/5)
8 = 16 (*8)
-4 = 4 (-12)
16 = 16 (^2)


# Scoring

This is , shortest wins!

• Sandboxed. Going to sleep now, will try to clarify stuff later. Jun 1, 2021 at 11:46
• Alternatively phrased, this is equivalent to finding the steps from an input $(a, b)$ to $(-n, n)$ for some integer $n$, where the "steps" are the 5 provided operators Jun 1, 2021 at 11:55
• May we assume that a≠b? Jun 1, 2021 at 11:57
• From the sandbox: It's worth mentioning that for any a=b as input you can always do the steps a=b;2a=2b (*2); a-b=b-a (-(a+b));a^2-2ab+b2=a^2-2ab+b2 (^2). Sometimes you can do faster but there is not much reason to do anything more complex than (*2)->(-(a+b))->(^2). Jun 1, 2021 at 15:49
• Must I separate integers and an equal sign with a space?
– user100411
Jun 2, 2021 at 12:20

# JavaScript (Node.js), 57 54 bytes

a=>b=>a+=${b}${a+a}=${b+b}${a-=b}=${-a}${a*=a}=+a


Try it online!

## How?

There always exists a multiple of $$\0.5\$$ which, when subtracted from each number, creates a pair of the form $$\-a = a\$$. If $$\a-x=c\$$, then $$\b-(a-x+b)=-c\$$, so then if $$\a-x+b=x\$$, then $$\x=\frac{(a+b)}2\$$. This might not be an integer, so multiply by 2 beforehand.

-3 bytes thanks to Arnauld.

• 54 bytes Jun 1, 2021 at 12:18

# 05AB1E, 13 12 bytes

xIÂ-Dn)'=δý»


Try it online!

A port of my Jelly answer. I thought that 05AB1E's stack-based functionality would be shorter, but it isn't great at joining.

-1 byte thanks to ovs!

xIÂ-Dn)'=δý» - Full program. Takes [a, b] on the stack
x            - Push [2a, 2b];   Stack = [[a, b], [2a, 2b]]
I           - Push [a, b];     Stack = [[a, b], [2a, 2b], [a, b]]
Â          - Bifurcate;       Stack = [[a, b], [2a, 2b], [a, b], [b, a]]
-         - Subtract;        Stack = [[a, b], [2a, 2b], [a-b, b-a]]
D        - Duplicate;       Stack = [[a, b], [2a, 2b], [a-b, b-a], [a-b, b-a]]
n       - Square;          Stack = [[a, b], [2a, 2b], [a-b, b-a], [(a-b)², (b-a)²]]
)      - Wrap into array; Stack = [[[a, b], [2a, 2b], [a-b, b-a], [(a-b)², (b-a)²]]]
'=    - Push '='
δý  - Join each with '='
» - Join array by newlines

• A few 12-byters. '=δý uses double-vectorize (δ), the other ones use that » joins inner lists by spaces.
– ovs
Jun 1, 2021 at 14:52
• @ovs Nice! I think I'll go with the first one, δ seems a lot easier to understand than either # or :, especially in the context of » Jun 1, 2021 at 15:00

# R, 64 51 bytes

-7 bytes thanks to Dominic van Essen.

cat(sep=c("=","
"),x<-scan(),2*x,y<-2*x-sum(x),y^2)


Try it online!

The steps followed are:

a = b
2a = 2b (*2)
a-b = b-a (-(a+b))
(a-b)^2 = (b-a)^2 (^2)

• 55 bytes by changing step 3 to 'subtract both sides from a+b' instead of 'subtract a+b from both sides' and rearranging a bit... Jun 1, 2021 at 21:45
• @DominicvanEssen Thanks, but the way I read the rules, I think that would require 2 steps (first multiply by -1, then add a+b). Putting sep up front is a great idea! Jun 1, 2021 at 22:00
• This should be Ok though...? Jun 2, 2021 at 0:06
• @DominicvanEssen Very nice! Jun 2, 2021 at 13:11

# Jelly, 14 bytes

,Ḥ;_U,²$Ɗj€”=Y  Try it online! Uses ophact's observation, that for any $$\a, b\$$, it is sufficient to yield the 4 equations $$a = b \\ 2a = 2b \\ a-b = b-a \\ (a-b)^2 = (b-a)^2$$ ## How it works ,Ḥ;_U,²$Ɗj€”=Y - Main link. Takes [a, b] on the left
Ḥ             - Double, yielding [2a, 2b]
,              - Pair; [[a, b], [2a, 2b]]
U          -   Reverse; [b, a]
_           -   Subtract; [a-b, b-a]
$- Previous two links as a monad f([a-b, b-a]]): ² - Square; [(a-b)², (b-a)²] , - Pair; [[a-b, b-a], [(a-b)², (b-a)²]] ; - Concatenate; [[a, b], [2a, 2b], [[a-b, b-a], [(a-b)², (b-a)²]] j€”= - Join each with "=" Y - Join with newlines  # Python 2, 79 78 bytes for x in'input()','2*a,2*b','a-b>>1,b-a>>1','a*a,'*2:a,b=eval(x);print a,'=',b  Try it online! # Python 3, 70 bytes def f(a,b):x=a-b;return f'{a}={b}\n{2*a}={2*b}\n{x}={-x}\n{x*x}={x*x}'  Try it online! • I actually pointed out this method in the sandbox before ophact. But early bird gets the worm. Jun 1, 2021 at 15:54 • @WheatWizard I did not look at the sandbox before posting. – user100690 Jun 1, 2021 at 18:15 • With Python 3.8 you can get 64 bytes. Jun 1, 2021 at 22:09 # Python 2, 84 $$\\cdots\$$ 73 71 bytes Saved 5 bytes thanks to ovs!!! Saved 2 bytes thanks to dingledooper!!! k=a,b=input() d=a-b for a,b in k,[2*a,2*b],[d,-d],[d*d]*2:print a,'=',b  Try it online! • 73 bytes as a full program (or 75 if you keep it as function). – ovs Jun 1, 2021 at 20:23 • @ovs Nice one - thanks! :D Jun 1, 2021 at 20:56 • 71 bytes Jun 1, 2021 at 22:05 • 61 bytes Jun 2, 2021 at 0:16 • 54 bytes with Python 3.8's walrus operator. Jun 2, 2021 at 3:17 # C (clang), 65 bytes #define r;printf("%d=%d\n",a f(a,b){r,b)r+a,b+b)r-=b,-a)r*=a,a);}  Using clang instead of gcc saves a byte, as clang handles the undefined behavior in the second printf differently than gcc: printf("%d=%d\n",a-=b,-a);  The order of the arguments' evaluation is unspecified. In gcc, the -a is evaluated before a-=b; thus, the second argument is not affected by the subtraction and must be b-a to get the proper value. However, in clang, the a-=b is evaluated first so the second argument is affected by the subtraction so -a is the correct value. # C (gcc), 76 74 66 bytes -8 bytes thanks to tsh #define r;printf("%d=%d\n",a f(a,b){r,b)r+a,b+b)r-=b,b-a)r*=a,a);}  Try it online! • 66: #define r;printf("%d=%d\n",a f(a,b){r,b)r+a,b+b)r-=b,b-a)r*=a,a);} – tsh Jun 4, 2021 at 8:21 # Charcoal, 20 bytes ≔⁻⊗θΣθηＥ⟦θ⊗θηＸη²⟧⪫ι=  Try it online! Link is to verbose version of code. Takes input as a list [a, b]. Explanation: Based on @ophact's approach. ≔⁻⊗θΣθη  Vectorised subtract the sum of the list from its double, thus giving [a-b, b-a]. Ｅ⟦θ⊗θηＸη²⟧⪫ι=  Loop over the lists [a, b], 2[a, b], [a-b, b-a] and [a-b, b-a]², joining each list with = and implicitly printing them on separate lines. # C# (Visual C# Interactive Compiler), 50 bytes Same as the javascript but using C#'s "superior code golfing" interpolation a=>b=>a+@$"={b}
{a+a}={b+b}
{a-=b}={-a}
{a*=a}="+a


Try it online!

# Vyxalj, 12 bytes

:d?Ḃ-:²Wƛ\=j


Try it Online!

Why write your own original answer when you can just port 05ab1e amiright? :p

## Explained

:d?Ḃ-:²Wƛ\=j
:d           # [a, b], [2a, 2b]
?Ḃ-        # [a - b], [b - a]
:²      # that, but squared
Wƛ\=j # join each on "=" and then join that on newlines with the j flag


# Julia 1.0, 48 bytes

a\b="$a=$b
$(2a)=$(2b)
$(a-=b)=$(-a)
$(a*=a)=$a"


Try it online!

## alternative answer, 48 bytes too

output is a list of strings

a\b=join.([a=>b,2a=>2b,(a-=b)=>-a,a*a=>a*a],'=')


Try it online!

# Python 3, 72 bytes

f=lambda a,b:f"{a}={b}\n{2*a}={2*b}\n{a-b}={b-a}\n{(a-b)**2}={(a-b)**2}"


Uses ophact's observation to answer in 4 steps.

Try it online!

• Nice! You can save two bytes by going a+f"= at the start and ="+(a-b)**2 at the end. Jun 8, 2021 at 4:24
• @Ausername That would be attempting to concatenate an integer and a string, which Python doesn't allow. Thanks anyway! Jun 8, 2021 at 10:50
• Sorry, I'm used to Javascript. Jun 8, 2021 at 11:02
• @Ausername Oh, ok. Javascript has a lot of strange type conversions (e.g. []+[] gives ""), so that makes sense. Jun 8, 2021 at 11:23

# GolfScript, 37 bytes

~:%;:$' = ':&%n$2*&%2*n$%-&%$-.n\2?.&\


Try it online!

# Desmos, 207 characters

Try it online!

Code:

<input 1>
<input 2>
<input 3>
a=ans_0
b=ans_1
c=ans_2
m=-(a+b)/2                           #Parenthesises placed here to show that addition occurs before addition; they don't appear in actual graph
d=-((a-m)^2-c)
l=[a,a+m,(a+m)^2,(a+m)^2+d]
l_1=[b,b+m,(b+m)^2,(b+m)^2+d]
(-1,[0,-1,-2,-3])
(0,[0,-1,-2,-3])
(1,[0,-1,-2,-3])
(4,0)
(4,-1)
(4,-2)
(4,-3)
#LABELS (From higher to lower)
${l} =${l_1}
(given)
(${m}) (^2) (${d})


Explanation:

a and b are the starting numbers, and c is the target number. Like my other programs, ans_n correspond to the line number, acting as inputs.

m is the midpoint of a and b. The reason that it is subtracted from a and b is so that they become equidistant from 0. NOTE: m is negative simply for formatting the proof; simply treat it as a positive and that all operations involving it are subtractions.

d is simply the distance between c and (a-m)^2. The squaring ensures that the term is positive, making both sides of the equation equal to each other. From there, the distance is added on to the result, making both sides of the equation equal to c.

l and l_1 are lists. This is used to provide the labels. From left to right, the terms in the lists are as follows: the input, the input minus m, the square of (the input minus m), and the square of (the input minus m) plus d.

The first point, (-1,[0,-1,-2,-3]), uses ${l} as a label. The list within the point creates multiple copies of the point at those y values, and the label uses the corresponding value from l to make it have the corresponding value on the graph. For example, (-1,0) would have a as its label. Likewise, the third point, (1,[0,-1,-2,-3]), would use l_1 to produce its labels in a similar manner. The second point, however, would simply have the label be =. Point (4,0) has the label (given), which is self explanatory. Point (4,-1) has the label (${m}), which uses m to produce the label of (m).

Point (4,-2) has the label (^2). The backticks are used to format the ^2 as a square and not as ^2.

Point (4,-3) has the label (\${d}), which uses d to produce the label of (d).

• a=ans_0 (and the other ans's) doesn't paste correctly; you will need to add a backslash in front of every single one of them. For example, a=\ans_0` Jul 7, 2022 at 1:26
• Also could you provide the code without any comments in them? I'm not seeing how you are getting 207 bytes. Jul 7, 2022 at 1:29