g | x | w | all
Bytes Lang Time Link
024Juby250505T132729ZJordan
003Thunno 2230827T164616ZThe Thon
012Desmos220507T043128ZAiden Ch
007J220305T100653Zsinvec
035Halfwit220305T094216Zemanresu
004Japt m210709T072714ZShaggy
003Vyxal210709T054848Zemanresu
016ARM Thumb210708T091554ZBubbler
026Factor210519T230349Zchunes
018Zsh210212T174848Zpxeger
003Jelly161125T031746ZDennis
017Wonder161129T212108ZMama Fun
011ised161129T185932Zorion
019Haskell161125T100839ZRenzeee
005Dyalog APL161128T185612Zngn
024Labyrinth161128T170203ZMartin E
034Labyrinth161128T154058ZRobert H
nanPerl161126T180402ZDenis Ib
030Python 2161125T033038ZDennis
008Mathematica161125T032535ZGreg Mar
009Pushy161125T211907ZFlipTack
008APL161125T203826Zmarinus
048PHP161125T181456Zuser5917
016CJam161125T174337ZLinnea G
036C++14161125T171724ZKarl Nap
076BrainFlak161125T154902ZRiley
016Perl 6161125T151138ZBrad Gil
023Ruby161125T135335ZG B
00405AB1E161125T091127ZEmigna
021JavaScript ES6161125T075821Zedc65
017R161125T033945ZJonathan
004Pyke161125T073737ZBlue
005Pyth161125T033305ZSteven H
044Python161125T032104ZDJMcMayh

J-uby, 24 bytes

~:*%(:first|:*&2|:& &:-)

Attempt This Online!

Thunno 2, 3 bytes

Ḍh_

Try it online!

Port of Dennis's Jelly answer.

Explanation

Ḍh_  # Implicit input
Ḍ    # Double each number
 h   # Take the first item
  _  # Subtract input from this
     # Implicit output

Desmos, 12 bytes

f(l)=2l[1]-l

Try It On Desmos!

J, 7 bytes

-~+:@{.

Try it online!

Halfwit, 3.5 bytes

+><iN+

Try It Online!

Dennis port.

+      # Double the input, adding it to itself
 ><i   # Get the first one
    N+ # Subtract from the input

Once again, I'm reminded of how annoying Halfwit's minimalism is to program with.

Japt -m, 4 bytes

nWÎÑ

Try it here

Vyxal, 3 bytes

dh-

Try it Online!

Dennis port

   
d   # Double the array
 h  # Take the first
  - # Subtract

Or, by implementing the original spec,

Vyxal 2.5, 5 bytes

¯?hp¦

Try it Online!

¯     # Deltas (negated, this is a bug, and will be fixed, that is why it's 2.5)
 ?hp  # Prepend the first item of input
    ¦ # Take the cumulative sum

ARM (Thumb), 16 bytes

.section .text
.global func
.thumb
// void func(int* arr, int len)
// arr[i] = 2*arr[0] - arr[i] for each i
// r0 = arr, r1 = len, r2 = arr[0], r3 = arr[i]
func:
    ldr r2, [r0, #0]         // 6802        int head = *arr;
.loop:                       //             do {
    ldr r3, [r0, #0]         // 6803        int cur = *arr;
    rsb r3, r3, r2, lsl #1   // ebc3 0342   cur = (head << 1) - cur;
    stmia r0!, {r3}          // c008        *arr++ = cur;
    sub r1, #1               // 3901        len -= 1;
    bne .loop                // d1f9        } while (len != 0);
    bx lr                    // 4770        return;

Uses the formula, which nicely fits into exactly four registers in use. The stm tip was used to overwrite the value and advance the pointer in a single narrow instruction, and a wide rsb instruction was used to evaluate exactly what we want. (I know it's possible to do with a 3-operand sub and then an add for the same byte count, but I figured a single instruction would add some coolness.)

Factor, 26 bytes

[ dup first 2 * v-n vneg ]

Try it online!

Zsh, 18 bytes

for a;<<<$[$1*2-a]

Try it online!

Jelly, 7 3 bytes

ḤḢ_

Try it online!

Background

The deltas of (a, b, c, d) are b - a, c - b, and d - c. Cumulatively reducing (a, b - a, c - b, d - c) by subtraction yields a - (b - a) = 2a - b, 2a - b - (c - b) = 2a - c, and 2a - c - (d - c) = 2a - d, so the correct result is (2a - a, 2a - b, 2a - c, 2a - d).

How it works

ḤḢ_  Main link. Argument: A (array)

Ḥ    Unhalve; multiply all integers in A by 2.
 Ḣ   Head; extract first element of 2A.
  _  Subtract the elements of A from the result.

Wonder, 17 bytes

@->#@- *2:0#1#0#0

Not sure why I didn't post this earlier. Usage:

(@->#@- *2:0#1#0#0)[5 6 7 8]

More readable:

@(map @
  - (
    * 2 get 0 #1
  ) #0
) #0

ised, 11 bytes

2*$1_0-$1

Invocation: ised --l 'file with input.txt' '2*$1_0-$1

(edit: corrected by stealing the algebra from Dennis)

Haskell, 20 19 bytes

f(x:r)=x:map(2*x-)r

Same solution as Dennis, thank you for your idea of 2a - x.

Saved one byte thanks to Christian Severs.

Dyalog APL, 5 bytes

-+2×⊃

this is a 5-train, it parses like two nested 3-trains ("forks"): -+(2×⊃)

reads like: the negation (-) of the whole array plus (+) twice () the first element ()

Labyrinth, 24 bytes

+:}:?
}
<}}?;%):,\!-{:{>

Input and output format are linefeed-separate lists (although the input format is actually a lot more flexible). The program terminates with an error.

Try it online!

I've got two other solutions at this byte count, which work basically the same but use somewhat different control flow.

:+:}:?
{
,}-!
?  {
:";\@
{:+:}:?
_
<>__-?:;%):,\!

Explanation

The instruction pointer (IP) starts moving east along the first line, but all the commands before the ? are basically no-ops on the global state, since we're not using stack depth commands anywhere. So the code really starts at the ? going west, since the IP turns around when it hits the dead end.

The code therefore starts with the following linear bit of code:

?:}:+}

This simply sets us up with a copy of 2a to use the [2a - a, 2a - b, 2a - c, ...] formula.

?   Read first integer a.
:}  Move a copy off to the auxiliary stack.
:+  Multiply a by 2 (by adding it to itself).
}   Move that off to the auxiliary stack as well.

We now enter the main loop of the program, using a fairly standard trick to loop through a single line of code:

<...>

Note that the stack will be empty whenever we hit the < so we know we'll get zeros there. The < then rotates the entire line left, taking the IP with it, so we get this:

...><

The IP then has to move left, where the > shifts the line back into its original place (to prepare it for the next iteration). Then the line is simply executed from right to left, so a single loop iteration is this:

{:{-!\,:)%;?}}

The catch when working with a loop of this type is that you can't work with any form of conditional execution, since Labyrinth doesn't have a way to skip code. Therefore, we will terminate the program with a division by zero when we hit EOF. Here is a breakdown of each loop iteration.

{:   Pull 2a back to the main stack and make a copy.
{    Pull the latest value i of the input list back to main as well.
-    Compute 2a-i/
!\   Print it with a trailing linefeed.
,    Read a character. If there are input elements left, this will be some
     form of separator character, and therefore a positive value x. However,
     at the end of the program, this will give -1.
:)   Make an incremented copy.
%    Try to to compute x%(x+1). This will error out at EOF.
;    Discard the result of the division.
?    Read the next input value.
}}   Move that and the remaining copy of 2a back to the auxiliary stack.

Labyrinth, 34 bytes

?:_2*}
@    _
)\?_1"
,    ;
!`-}:{

Try it online!

Uses @Dennis's (2a - a, 2a - b, 2a - c, 2a - d) approach.

enter image description here

The yellow tiles are for control flow. In this 2D programming language, the program starts at the top-left-most tile moving east to start. At junctions, the direction is determined by the sign of the top of the main stack. Blank tiles are walls.

Green

This section saves 2a to the auxilary stack.

Orange

This section subtracts 2a from the current number, negates the result, outputs the result, gets the next character (the delimeter), exits if EOF, outputs a newline, gets the next number.

Perl, 26 + 3 (-pla flag) = 29 bytes

$_="@{[map$F[0]*2-$_,@F]}"

or

$_=join$",map$F[0]*2-$_,@F

Using:

perl -plae '$_="@{[map$F[0]*2-$_,@F]}"' <<< "32 18 25 192 199"

Python 2, 30 bytes

lambda x:[x[0]*2-n for n in x]

Test it on Ideone.

How it works

The deltas of (a, b, c, d) are b - a, c - b, and d - c. Cumulatively reducing (a, b - a, c - b, d - c) by subtractiong yields a - (b - a) = 2a - b, 2a - b - (c - b) = 2a - c, and 2a - c - (d - c) = 2a - d, so the correct result is (2a - a, 2a - b, 2a - c, 2a - d).

Mathematica, 8 bytes

2#-{##}&

Unnamed function taking an indeterminate number of arguments. This uses an "easy" way: negates the entire list and adds twice the (original) first element.

Called for example like 2#-{##}&[1,3,4,2,8]; returns a list like {1,-1,-2,0,-6}.

Pushy, 9 bytes

{&}2*K~-_

Give arguments as comma-seperated values on cmd line: $ pushy invdeltas.pshy 1,3,4,2,8. Here's the breakdown, with example stack:

           % Implicit: Input on stack              [1, 3, 4, 2, 8]
{&}        % Copy first item, put at end of stack  [1, 3, 4, 2, 8, 1]
   2*      % Multiply by 2                         [1, 3, 4, 2, 8, 2]
     K~    % Negate everything on stack            [-1, -3, -4, -2, -8, -2]
       -   % Subtract last item from all           [1, -1, -2, 0, -6]
        _  % Print whole stack

Note: this can be 8 bytes if backwards output is allowed: @&2*K~-_

APL, 8 bytes

+\⊃,2-/+

Explanation:

+\           ⍝ running sum of
  ⊃          ⍝ first item of list
   ,         ⍝ followed by
    2-/      ⍝ differences between every pair in
       +     ⍝ input list

Test cases:

      ( +\⊃,2-/+ ) ¨ (5 6 7 8) (1 3 4 2 8) (32 18 25 192 199)
┌───────┬────────────┬──────────────────┐
│5 4 3 2│1 ¯1 ¯2 0 ¯6│32 46 39 ¯128 ¯135│
└───────┴────────────┴──────────────────┘

PHP, 48 bytes

for(;''<$c=$argv[++$i];)echo-$c+2*$a=$a??$c,' ';

Using the technique from Dennis. Use like:

php -r "for(;''<$c=$argv[++$i];)echo-$c+2*$a=$a??$c,' ';" 1 3 4 2 8

Non-Dennis 55 byte version:

for(;''<$c=$argv[++$i];$l=$c)echo$a+=($l??$c*2)-$c,' ';

CJam, 16 bytes

Input format: [1 2 3 4]. Uses the easy formula.

l~_(2*/;a/,@@*.-

Explanation:

l~_(2*/;a/,@@*.-
l~_                     e#Read input twice into an array. Stack: [1 2 3 4] [1 2 3 4]
   (                    e#Get first element of the array. Stack: [1 2 3 4] [2 3 4] 1
    2*                  e#Multiply by two. Stack: [1 2 3 4] [2 3 4] 2
      /;                e#Discard second element. Stack: [1 2 3 4] 2
        a               e#Wrap into an array. Stack: [1 2 3 4] [2]
         /,             e#Rotate and get length. Stack: [2] [1 2 3 4] 4
           @@           e#Rotate twice. Stack: [1 2 3 4] 4 [2]
            *           e#Repeat len times. Stack: [1 2 3 4] [2 2 2 2]
             .-         e#Vectorized substraction. Stack: [-1 0 1 2]
                        e#Implictly print

Sorry for no test link. I guess SE don't like it's links with brackets inside.

C++14, 36 bytes

As unnamed lambda modifying its input:

[](auto&c){for(auto&x:c)x=2*c[0]-x;}

Using the technique from Dennis. Works for any container like int[] or vector<int>.

Usage:

#include<iostream>

auto f=
[](auto&c){for(auto&x:c)x=2*c[0]-x;}
;

int main(){
  int a[] = {1,  3,  4,  2,  8};
  f(a);
  for(auto&x:a)
    std::cout << x << ", ";
  std::cout<<"\n";
}

Brain-Flak, 76 Bytes

([][()]){{}(({})<(({}){}[{}]<>)<>>)([][()])}{}({}<<>([]){{}({}<>)<>([])}<>>)

Try it Online!

Explanation:

Part 1:
(      )                                        # Push:
 []                                             # the height of the stack
   [()]                                         # minus 1
        {                                  }    # While the height - 1 != 0:
         {}                                     # Pop the height
           (({})<                               # Hold onto the top value, but put it back.
                                                # This ensures that the top value is always
                                                # what was the first element of input
                 (            )                 # Push:
                  ({}){}                        # Top * 2
                        [{}]                    # minus the next element
                            <> <>               # onto the other stack

                                 >)             # Put back the element we held onto.
                                   (      )     # Push:
                                    []          # The height of the stack
                                      [()]      # Minus 1  
                                            {}  # Pop the counter used for the height
Part 2:
({}<                                            # Hold onto the top element.
                                                # This was the first number for input
                                                # so it needs to end up on top
    <>                                          # Switch stacks
      ([])                                      # Push the height of the stack
          {              }                      # While the height != 0:
           {}                                   # Pop the height
             (    )                             # Push:
              {}                                # The top element of this stack
                <>                              # onto the other stack
                   <>                           # and switch back
                     ([])                       # Push the new height of the stack
                          <>                    # After every element has switched stacks
                                                # (which reverses their order),
                                                # switch stacks
                            >)                  # Push the first element back on

Perl 6,  40  16 bytes

{[\+] .[0],|.rotor(2=>-1).map({[-] @_})}
{.map(.[0]*2-*)}

Expanded:

{ # bare block lambda with single implicit parameter 「$_」 ( input is a List )

  [\[+]]  # triangle reduce the following using 「&infix:<+>」

    .[0], # the first value

    |(    # Slip this list into outer one ( Perl 6 doesn't auto flatten )

      .rotor( 2 => -1 ) # take the input 2 at a time, backing up 1
      .map({ [-] @_ })  # reduce the pairs using 「&infix:<->」

    )
}
{ # bare block lambda with single implicit parameter 「$_」 ( input is a List )

  .map(          # map over the inputs
    .[0] * 2 - * # take the first value multiply by 2 and subtract the current value
    #          ^- this makes the statement a WhateverCode, and is the input
  )
}

Ruby, 23 bytes

->l{l.map{|x|l[0]*2-x}}

Not particularly original.

05AB1E, 4 bytes

¬·s-

Try it online! or as a Test suite

Explanation

¬     # head of input list
 ·    # multiplied by 2
  s   # swap with input list
   -  # subtract

JavaScript (ES6), 21

Thx @Dennis

l=>l.map(v=>l[0]*2-v)

R, 23 18 17 bytes

x=scan();2*x[1]-x

auto-vectorisation and default print to the rescue!

Pyke, 5 4 bytes

h}m-

Try it here!

Pyth, 5 bytes

-LyhQ

Online Interpreter!

Python, 44 bytes

lambda l:[l[0]]+[x-(x-l[0])*2for x in l[1:]]

This uses the "Easier method".