summary refs log tree commit diff stats
path: root/compiler/ccgcalls.nim
blob: 200ff91e038237cdbeb769fd3207c26ec4b9353b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#
#
#           The Nim Compiler
#        (c) Copyright 2013 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#
#
# included from cgen.nim

proc leftAppearsOnRightSide(le, ri: PNode): bool =
  if le != nil:
    for i in 1 .. <ri.len:
      let r = ri[i]
      if isPartOf(le, r) != arNo: return true

proc hasNoInit(call: PNode): bool {.inline.} =
  result = call.sons[0].kind == nkSym and sfNoInit in call.sons[0].sym.flags

proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc,
               callee, params: PRope) =
  var pl = con(callee, ~"(", params)
  # getUniqueType() is too expensive here:
  var typ = skipTypes(ri.sons[0].typ, abstractInst)
  if typ.sons[0] != nil:
    if isInvalidReturnType(typ.sons[0]):
      if params != nil: pl.app(~", ")
      # beware of 'result = p(result)'. We may need to allocate a temporary:
      if d.k in {locTemp, locNone} or not leftAppearsOnRightSide(le, ri):
        # Great, we can use 'd':
        if d.k == locNone: getTemp(p, typ.sons[0], d, needsInit=true)
        elif d.k notin {locExpr, locTemp} and not hasNoInit(ri):
          # reset before pass as 'result' var:
          resetLoc(p, d)
        app(pl, addrLoc(d))
        app(pl, ~");$n")
        line(p, cpsStmts, pl)
      else:
        var tmp: TLoc
        getTemp(p, typ.sons[0], tmp, needsInit=true)
        app(pl, addrLoc(tmp))
        app(pl, ~");$n")
        line(p, cpsStmts, pl)
        genAssignment(p, d, tmp, {}) # no need for deep copying
    else:
      app(pl, ~")")
      if p.module.compileToCpp and lfSingleUse in d.flags:
        # do not generate spurious temporaries for C++! For C we're better off
        # with them to prevent undefined behaviour and because the codegen
        # is free to emit expressions multiple times!
        d.k = locCall
        d.r = pl
        excl d.flags, lfSingleUse
      else:
        if d.k == locNone: getTemp(p, typ.sons[0], d)
        assert(d.t != nil)        # generate an assignment to d:
        var list: TLoc
        initLoc(list, locCall, d.t, OnUnknown)
        list.r = pl
        genAssignment(p, d, list, {}) # no need for deep copying
  else:
    app(pl, ~");$n")
    line(p, cpsStmts, pl)

proc isInCurrentFrame(p: BProc, n: PNode): bool =
  # checks if `n` is an expression that refers to the current frame;
  # this does not work reliably because of forwarding + inlining can break it
  case n.kind
  of nkSym:
    if n.sym.kind in {skVar, skResult, skTemp, skLet} and p.prc != nil:
      result = p.prc.id == n.sym.owner.id
  of nkDotExpr, nkBracketExpr:
    if skipTypes(n.sons[0].typ, abstractInst).kind notin {tyVar,tyPtr,tyRef}:
      result = isInCurrentFrame(p, n.sons[0])
  of nkHiddenStdConv, nkHiddenSubConv, nkConv:
    result = isInCurrentFrame(p, n.sons[1])
  of nkHiddenDeref, nkDerefExpr:
    # what about: var x = addr(y); callAsOpenArray(x[])?
    # *shrug* ``addr`` is unsafe anyway.
    result = false
  of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
    result = isInCurrentFrame(p, n.sons[0])
  else: discard

proc openArrayLoc(p: BProc, n: PNode): PRope =
  var a: TLoc

  let q = skipConv(n)
  if getMagic(q) == mSlice:
    # magic: pass slice to openArray:
    var b, c: TLoc
    initLocExpr(p, q[1], a)
    initLocExpr(p, q[2], b)
    initLocExpr(p, q[3], c)
    let fmt =
      case skipTypes(a.t, abstractVar+{tyPtr}).kind
      of tyOpenArray, tyVarargs, tyArray, tyArrayConstr:
        "($1)+($2), ($3)-($2)+1"
      of tyString, tySequence:
        if skipTypes(n.typ, abstractInst).kind == tyVar and
            not compileToCpp(p.module):
          "(*$1)->data+($2), ($3)-($2)+1"
        else:
          "$1->data+($2), ($3)-($2)+1"
      else: (internalError("openArrayLoc: " & typeToString(a.t)); "")
    result = ropef(fmt, [rdLoc(a), rdLoc(b), rdLoc(c)])
  else:
    initLocExpr(p, n, a)
    case skipTypes(a.t, abstractVar).kind
    of tyOpenArray, tyVarargs:
      result = ropef("$1, $1Len0", [rdLoc(a)])
    of tyString, tySequence:
      if skipTypes(n.typ, abstractInst).kind == tyVar and
            not compileToCpp(p.module):
        result = ropef("(*$1)->data, (*$1)->$2", [a.rdLoc, lenField(p)])
      else:
        result = ropef("$1->data, $1->$2", [a.rdLoc, lenField(p)])
    of tyArray, tyArrayConstr:
      result = ropef("$1, $2", [rdLoc(a), toRope(lengthOrd(a.t))])
    else: internalError("openArrayLoc: " & typeToString(a.t))

proc genArgStringToCString(p: BProc, n: PNode): PRope {.inline.} =
  var a: TLoc
  initLocExpr(p, n.sons[0], a)
  result = ropef("$1->data", [a.rdLoc])

proc genArg(p: BProc, n: PNode, param: PSym; call: PNode): PRope =
  var a: TLoc
  if n.kind == nkStringToCString:
    result = genArgStringToCString(p, n)
  elif skipTypes(param.typ, abstractVar).kind in {tyOpenArray, tyVarargs}:
    var n = if n.kind != nkHiddenAddr: n else: n.sons[0]
    result = openArrayLoc(p, n)
  elif ccgIntroducedPtr(param):
    initLocExpr(p, n, a)
    result = addrLoc(a)
  elif p.module.compileToCpp and param.typ.kind == tyVar and 
      n.kind == nkHiddenAddr:
    initLocExprSingleUse(p, n.sons[0], a)
    # if the proc is 'importc'ed but not 'importcpp'ed then 'var T' still
    # means '*T'. See posix.nim for lots of examples that do that in the wild.
    let callee = call.sons[0]
    if callee.kind == nkSym and
        {sfImportC, sfInfixCall, sfCompilerProc} * callee.sym.flags == {sfImportC} and 
        {lfHeader, lfNoDecl} * callee.sym.loc.flags != {}:
      result = addrLoc(a)
    else:
      result = rdLoc(a)
  else:
    initLocExprSingleUse(p, n, a)
    result = rdLoc(a)

proc genArgNoParam(p: BProc, n: PNode): PRope =
  var a: TLoc
  if n.kind == nkStringToCString:
    result = genArgStringToCString(p, n)
  else:
    initLocExprSingleUse(p, n, a)
    result = rdLoc(a)

proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
  var op: TLoc
  # this is a hotspot in the compiler
  initLocExpr(p, ri.sons[0], op)
  var params: PRope
  # getUniqueType() is too expensive here:
  var typ = skipTypes(ri.sons[0].typ, abstractInst)
  assert(typ.kind == tyProc)
  assert(sonsLen(typ) == sonsLen(typ.n))
  var length = sonsLen(ri)
  for i in countup(1, length - 1):
    if ri.sons[i].typ.isCompileTimeOnly: continue
    if params != nil: app(params, ~", ")
    if i < sonsLen(typ):
      assert(typ.n.sons[i].kind == nkSym)
      app(params, genArg(p, ri.sons[i], typ.n.sons[i].sym, ri))
    else:
      app(params, genArgNoParam(p, ri.sons[i]))
  fixupCall(p, le, ri, d, op.r, params)

proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =

  proc getRawProcType(p: BProc, t: PType): PRope =
    result = getClosureType(p.module, t, clHalf)

  proc addComma(r: PRope): PRope =
    result = if r == nil: r else: con(r, ~", ")

  const PatProc = "$1.ClEnv? $1.ClPrc($3$1.ClEnv):(($4)($1.ClPrc))($2)"
  const PatIter = "$1.ClPrc($3$1.ClEnv)" # we know the env exists
  var op: TLoc
  initLocExpr(p, ri.sons[0], op)
  var pl: PRope
  
  var typ = skipTypes(ri.sons[0].typ, abstractInst)
  assert(typ.kind == tyProc)
  var length = sonsLen(ri)
  for i in countup(1, length - 1):
    assert(sonsLen(typ) == sonsLen(typ.n))
    if i < sonsLen(typ):
      assert(typ.n.sons[i].kind == nkSym)
      app(pl, genArg(p, ri.sons[i], typ.n.sons[i].sym, ri))
    else:
      app(pl, genArgNoParam(p, ri.sons[i]))
    if i < length - 1: app(pl, ~", ")
  
  template genCallPattern {.dirty.} =
    lineF(p, cpsStmts, callPattern & ";$n", op.r, pl, pl.addComma, rawProc)

  let rawProc = getRawProcType(p, typ)
  let callPattern = if tfIterator in typ.flags: PatIter else: PatProc
  if typ.sons[0] != nil:
    if isInvalidReturnType(typ.sons[0]):
      if sonsLen(ri) > 1: app(pl, ~", ")
      # beware of 'result = p(result)'. We may need to allocate a temporary:
      if d.k in {locTemp, locNone} or not leftAppearsOnRightSide(le, ri):
        # Great, we can use 'd':
        if d.k == locNone:
          getTemp(p, typ.sons[0], d, needsInit=true)
        elif d.k notin {locExpr, locTemp} and not hasNoInit(ri):
          # reset before pass as 'result' var:
          resetLoc(p, d)
        app(pl, addrLoc(d))
        genCallPattern()
      else:
        var tmp: TLoc
        getTemp(p, typ.sons[0], tmp, needsInit=true)
        app(pl, addrLoc(tmp))
        genCallPattern()
        genAssignment(p, d, tmp, {}) # no need for deep copying
    else:
      if d.k == locNone: getTemp(p, typ.sons[0], d)
      assert(d.t != nil)        # generate an assignment to d:
      var list: TLoc
      initLoc(list, locCall, d.t, OnUnknown)
      list.r = ropef(callPattern, op.r, pl, pl.addComma, rawProc)
      genAssignment(p, d, list, {}) # no need for deep copying
  else:
    genCallPattern()

proc genOtherArg(p: BProc; ri: PNode; i: int; typ: PType): PRope =
  if i < sonsLen(typ):
    # 'var T' is 'T&' in C++. This means we ignore the request of
    # any nkHiddenAddr when it's a 'var T'.
    assert(typ.n.sons[i].kind == nkSym)
    if typ.sons[i].kind == tyVar and ri.sons[i].kind == nkHiddenAddr:
      result = genArgNoParam(p, ri.sons[i][0])
    else:
      result = genArgNoParam(p, ri.sons[i]) #, typ.n.sons[i].sym)
  else:
    result = genArgNoParam(p, ri.sons[i])

discard """
Dot call syntax in C++
======================

so c2nim translates 'this' sometimes to 'T' and sometimes to 'var T'
both of which are wrong, but often more convenient to use.
For manual wrappers it can also be 'ptr T'

Fortunately we know which parameter is the 'this' parameter and so can fix this
mess in the codegen.
now ... if the *argument* is a 'ptr' the codegen shall emit -> and otherwise .
but this only depends on the argument and not on how the 'this' was declared
however how the 'this' was declared affects whether we end up with
wrong 'addr' and '[]' ops...

Since I'm tired I'll enumerate all the cases here:

var
  x: ptr T
  y: T

proc t(x: T)
x[].t()  --> (*x).t()  is correct.
y.t()    --> y.t()  is correct

proc u(x: ptr T)
x.u()          --> needs to become  x->u()
(addr y).u()   --> needs to become  y.u()

proc v(x: var T)
--> first skip the implicit 'nkAddr' node
x[].v()        --> (*x).v()  is correct, but might have been eliminated due
                   to the nkAddr node! So for this case we need to generate '->'
y.v()          --> y.v() is correct

"""

proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): PRope =
  # for better or worse c2nim translates the 'this' argument to a 'var T'.
  # However manual wrappers may also use 'ptr T'. In any case we support both
  # for convenience.
  internalAssert i < sonsLen(typ)
  assert(typ.n.sons[i].kind == nkSym)
  # if the parameter is lying (tyVar) and thus we required an additional deref,
  # skip the deref:
  var ri = ri[i]
  while ri.kind == nkObjDownConv: ri = ri[0]
  if typ.sons[i].kind == tyVar:
    let x = if ri.kind == nkHiddenAddr: ri[0] else: ri
    if x.typ.kind == tyPtr:
      result = genArgNoParam(p, x)
      result.app("->")
    elif x.kind in {nkHiddenDeref, nkDerefExpr} and x[0].typ.kind == tyPtr:
      result = genArgNoParam(p, x[0])
      result.app("->")
    else:
      result = genArgNoParam(p, x)
      result.app(".")
  elif typ.sons[i].kind == tyPtr:
    if ri.kind in {nkAddr, nkHiddenAddr}:
      result = genArgNoParam(p, ri[0])
      result.app(".")
    else:
      result = genArgNoParam(p, ri)
      result.app("->")
  else:
    result = genArgNoParam(p, ri) #, typ.n.sons[i].sym)
    result.app(".")

proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): PRope =
  var i = 0
  var j = 1
  while i < pat.len:
    case pat[i]
    of '@':
      if j < ri.len:
        result.app genOtherArg(p, ri, j, typ)
        for k in j+1 .. < ri.len:
          result.app(~", ")
          result.app genOtherArg(p, ri, k, typ)
      inc i
    of '#':
      if pat[i+1] in {'+', '@'}:
        let ri = ri[j]
        if ri.kind in nkCallKinds:
          let typ = skipTypes(ri.sons[0].typ, abstractInst)
          if pat[i+1] == '+': result.app genArgNoParam(p, ri.sons[0])
          result.app(~"(")
          result.app genOtherArg(p, ri, 1, typ)
          for k in j+1 .. < ri.len:
            result.app(~", ")
            result.app genOtherArg(p, ri, k, typ)
          result.app(~")")
        else:
          localError(ri.info, "call expression expected for C++ pattern")
        inc i
      elif pat[i+1] == '.':
        result.app genThisArg(p, ri, j, typ)
        inc i
      else:
        result.app genOtherArg(p, ri, j, typ)
      inc j
      inc i
    of '\'':
      inc i
      let stars = i
      while pat[i] == '*': inc i
      if pat[i] in Digits:
        let j = pat[i].ord - '0'.ord
        var t = typ.sons[j]
        for k in 1..i-stars:
          if t != nil and t.len > 0:
            t = if t.kind == tyGenericInst: t.sons[1] else: t.elemType
        if t == nil: result.app(~"void")
        else: result.app(getTypeDesc(p.module, t))
        inc i
    else:
      let start = i
      while i < pat.len:
        if pat[i] notin {'@', '#', '\''}: inc(i)
        else: break
      if i - 1 >= start:
        app(result, substr(pat, start, i - 1))

proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
  var op, a: TLoc
  initLocExpr(p, ri.sons[0], op)
  # getUniqueType() is too expensive here:
  var typ = skipTypes(ri.sons[0].typ, abstractInst)
  assert(typ.kind == tyProc)
  var length = sonsLen(ri)
  assert(sonsLen(typ) == sonsLen(typ.n))
  # don't call 'ropeToStr' here for efficiency:
  let pat = ri.sons[0].sym.loc.r.data
  internalAssert pat != nil
  if pat.contains({'#', '(', '@', '\''}):
    var pl = genPatternCall(p, ri, pat, typ)
    # simpler version of 'fixupCall' that works with the pl+params combination:
    var typ = skipTypes(ri.sons[0].typ, abstractInst)
    if typ.sons[0] != nil:
      if p.module.compileToCpp and lfSingleUse in d.flags:
        # do not generate spurious temporaries for C++! For C we're better off
        # with them to prevent undefined behaviour and because the codegen
        # is free to emit expressions multiple times!
        d.k = locCall
        d.r = pl
        excl d.flags, lfSingleUse
      else:
        if d.k == locNone: getTemp(p, typ.sons[0], d)
        assert(d.t != nil)        # generate an assignment to d:
        var list: TLoc
        initLoc(list, locCall, d.t, OnUnknown)
        list.r = pl
        genAssignment(p, d, list, {}) # no need for deep copying
    else:
      app(pl, ~";$n")
      line(p, cpsStmts, pl)
  else:
    var pl: PRope = nil
    #var param = typ.n.sons[1].sym
    app(pl, genThisArg(p, ri, 1, typ))
    app(pl, op.r)
    var params: PRope
    for i in countup(2, length - 1):
      if params != nil: params.app(~", ")
      assert(sonsLen(typ) == sonsLen(typ.n))
      app(params, genOtherArg(p, ri, i, typ))
    fixupCall(p, le, ri, d, pl, params)

proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
  # generates a crappy ObjC call
  var op, a: TLoc
  initLocExpr(p, ri.sons[0], op)
  var pl = ~"["
  # getUniqueType() is too expensive here:
  var typ = skipTypes(ri.sons[0].typ, abstractInst)
  assert(typ.kind == tyProc)
  var length = sonsLen(ri)
  assert(sonsLen(typ) == sonsLen(typ.n))

  # don't call 'ropeToStr' here for efficiency:
  let pat = ri.sons[0].sym.loc.r.data
  internalAssert pat != nil
  var start = 3
  if ' ' in pat:
    start = 1
    app(pl, op.r)
    if length > 1:
      app(pl, ~": ")
      app(pl, genArg(p, ri.sons[1], typ.n.sons[1].sym, ri))
      start = 2
  else:
    if length > 1:
      app(pl, genArg(p, ri.sons[1], typ.n.sons[1].sym, ri))
      app(pl, ~" ")
    app(pl, op.r)
    if length > 2:
      app(pl, ~": ")
      app(pl, genArg(p, ri.sons[2], typ.n.sons[2].sym, ri))
  for i in countup(start, length-1):
    assert(sonsLen(typ) == sonsLen(typ.n))
    if i >= sonsLen(typ):
      internalError(ri.info, "varargs for objective C method?")
    assert(typ.n.sons[i].kind == nkSym)
    var param = typ.n.sons[i].sym
    app(pl, ~" ")
    app(pl, param.name.s)
    app(pl, ~": ")
    app(pl, genArg(p, ri.sons[i], param, ri))
  if typ.sons[0] != nil:
    if isInvalidReturnType(typ.sons[0]):
      if sonsLen(ri) > 1: app(pl, ~" ")
      # beware of 'result = p(result)'. We always allocate a temporary:
      if d.k in {locTemp, locNone}:
        # We already got a temp. Great, special case it:
        if d.k == locNone: getTemp(p, typ.sons[0], d, needsInit=true)
        app(pl, ~"Result: ")
        app(pl, addrLoc(d))
        app(pl, ~"];$n")
        line(p, cpsStmts, pl)
      else:
        var tmp: TLoc
        getTemp(p, typ.sons[0], tmp, needsInit=true)
        app(pl, addrLoc(tmp))
        app(pl, ~"];$n")
        line(p, cpsStmts, pl)
        genAssignment(p, d, tmp, {}) # no need for deep copying
    else:
      app(pl, ~"]")
      if d.k == locNone: getTemp(p, typ.sons[0], d)
      assert(d.t != nil)        # generate an assignment to d:
      var list: TLoc
      initLoc(list, locCall, nil, OnUnknown)
      list.r = pl
      genAssignment(p, d, list, {}) # no need for deep copying
  else:
    app(pl, ~"];$n")
    line(p, cpsStmts, pl)

proc genCall(p: BProc, e: PNode, d: var TLoc) =
  if e.sons[0].typ.callConv == ccClosure:
    genClosureCall(p, nil, e, d)
  elif e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags:
    genInfixCall(p, nil, e, d)
  elif e.sons[0].kind == nkSym and sfNamedParamCall in e.sons[0].sym.flags:
    genNamedParamCall(p, e, d)
  else:
    genPrefixCall(p, nil, e, d)
  postStmtActions(p)
  when false:
    if d.s == onStack and containsGarbageCollectedRef(d.t): keepAlive(p, d)

proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
  if ri.sons[0].typ.callConv == ccClosure:
    genClosureCall(p, le, ri, d)
  elif ri.sons[0].kind == nkSym and sfInfixCall in ri.sons[0].sym.flags:
    genInfixCall(p, le, ri, d)
  elif ri.sons[0].kind == nkSym and sfNamedParamCall in ri.sons[0].sym.flags:
    genNamedParamCall(p, ri, d)
  else:
    genPrefixCall(p, le, ri, d)
  postStmtActions(p)
  when false:
    if d.s == onStack and containsGarbageCollectedRef(d.t): keepAlive(p, d)
s="na">class="org-right">P ⇒ Q (P̅ ∨ Q)</th> <th scope="col" class="org-right">P ⇔ Q</th> </tr> </thead> <tbody> <tr> <td class="org-right">1</td> <td class="org-right">1</td> <td class="org-right">0</td> <td class="org-right">0</td> <td class="org-right">1</td> <td class="org-right">1</td> <td class="org-right">1</td> <td class="org-right">1</td> </tr> <tr> <td class="org-right">1</td> <td class="org-right">0</td> <td class="org-right">0</td> <td class="org-right">1</td> <td class="org-right">1</td> <td class="org-right">0</td> <td class="org-right">0</td> <td class="org-right">0</td> </tr> <tr> <td class="org-right">0</td> <td class="org-right">1</td> <td class="org-right">1</td> <td class="org-right">0</td> <td class="org-right">1</td> <td class="org-right">0</td> <td class="org-right">1</td> <td class="org-right">0</td> </tr> <tr> <td class="org-right">0</td> <td class="org-right">0</td> <td class="org-right">1</td> <td class="org-right">1</td> <td class="org-right">0</td> <td class="org-right">0</td> <td class="org-right">1</td> <td class="org-right">1</td> </tr> </tbody> </table> <p> <i>Note: P implying Q is equivalent to P̅ implying Q̅, or: (P ⇒ Q) ⇔ (P̅ ⇒ Q̅)</i><br /> </p> </div> <div id="outline-container-orgb936329" class="outline-3"> <h3 id="orgb936329">Properties:</h3> <div class="outline-text-3" id="text-orgb936329"> </div> <div id="outline-container-orgf5da498" class="outline-4"> <h4 id="orgf5da498"><b>Absorption</b>:</h4> <div class="outline-text-4" id="text-orgf5da498"> <p> (P ∨ P) ⇔ P<br /> </p> <p> (P ∧ P) ⇔ P<br /> </p> </div> </div> <div id="outline-container-org49dbf9d" class="outline-4"> <h4 id="org49dbf9d"><b>Commutativity</b>:</h4> <div class="outline-text-4" id="text-org49dbf9d"> <p> (P ∧ Q) ⇔ (Q ∧ P)<br /> </p> <p> (P ∨ Q) ⇔ (Q ∨ P)<br /> </p> </div> </div> <div id="outline-container-orge255044" class="outline-4"> <h4 id="orge255044"><b>Associativity</b>:</h4> <div class="outline-text-4" id="text-orge255044"> <p> P ∧ (Q ∧ R) ⇔ (P ∧ Q) ∧ R<br /> </p> <p> P ∨ (Q ∨ R) ⇔ (P ∨ Q) ∨ R<br /> </p> </div> </div> <div id="outline-container-org31cc6c8" class="outline-4"> <h4 id="org31cc6c8"><b>Distributivity</b>:</h4> <div class="outline-text-4" id="text-org31cc6c8"> <p> P ∧ (Q ∨ R) ⇔ (P ∧ Q) ∨ (P ∧ R)<br /> </p> <p> P ∨ (Q ∧ R) ⇔ (P ∨ Q) ∧ (P ∨ R)<br /> </p> </div> </div> <div id="outline-container-orgf861930" class="outline-4"> <h4 id="orgf861930"><b>Neutral element</b>:</h4> <div class="outline-text-4" id="text-orgf861930"> <p> <i>We define proposition <b>T</b> to be always <b>true</b> and <b>F</b> to be always <b>false</b></i><br /> </p> <p> P ∧ T ⇔ P<br /> </p> <p> P ∨ F ⇔ P<br /> </p> </div> </div> <div id="outline-container-org8cb6e02" class="outline-4"> <h4 id="org8cb6e02"><b>Negation of a conjunction &amp; a disjunction</b>:</h4> <div class="outline-text-4" id="text-org8cb6e02"> <p> Now we won&rsquo;t use bars here because my lazy ass doesn&rsquo;t know how, so instead I will use not()!!!<br /> </p> <p> not(<b>P ∧ Q</b>) ⇔ P̅ ∨ Q̅<br /> </p> <p> not(<b>P ∨ Q</b>) ⇔ P̅ ∧ Q̅<br /> </p> <p> <b>A rule I really like to use here is: Break and Invert. Basically you break the bar into the three characters of the propositions, so you get not(P) not(∧ or ∨) <i>NOT AN ACTUAL MATH WRITING. DONT USE IT ANYWHERE ELSE OTHER THAN YOUR BRAIN</i> and not(Q)</b><br /> </p> </div> </div> <div id="outline-container-orgfe01ac7" class="outline-4"> <h4 id="orgfe01ac7"><b>Transitivity</b>:</h4> <div class="outline-text-4" id="text-orgfe01ac7"> <p> [(P ⇒ Q) AND (Q ⇒ R)] ⇔ P ⇒ R<br /> </p> </div> </div> <div id="outline-container-org976f527" class="outline-4"> <h4 id="org976f527"><b>Contraposition</b>:</h4> <div class="outline-text-4" id="text-org976f527"> <p> (P ⇒ Q) ⇔ (Q̅ ⇒ P̅)<br /> </p> </div> </div> <div id="outline-container-org0865f2b" class="outline-4"> <h4 id="org0865f2b">God only knows what this property is called:</h4> <div class="outline-text-4" id="text-org0865f2b"> <p> <i>If</i><br /> </p> <p> (P ⇒ Q) is true<br /> </p> <p> and<br /> </p> <p> (P̅ ⇒ Q) is true<br /> </p> <p> then<br /> </p> <p> Q is always true<br /> </p> </div> </div> </div> <div id="outline-container-org316b141" class="outline-3"> <h3 id="org316b141">Some exercices I found online :</h3> <div class="outline-text-3" id="text-org316b141"> </div> <div id="outline-container-orga3825f4" class="outline-4"> <h4 id="orga3825f4">USTHB 2022/2023 Section B :</h4> <div class="outline-text-4" id="text-orga3825f4"> </div> <ul class="org-ul"> <li><a id="orge27aa8d"></a>Exercice 1: Démontrer les équivalences suivantes:<br /> <div class="outline-text-5" id="text-orge27aa8d"> <ol class="org-ol"> <li><p> (P ⇒ Q) ⇔ (Q̅ ⇒ P̅)<br /> </p> <p> Basically we are asked to prove contraposition, so here we have ( P ⇒ Q ) which is equivalent to P̅ ∨ Q <b>By definition : (P ⇒ Q) ⇔ (P̅ ∨ Q)</b><br /> </p></li> </ol> <p> So we end up with : <b>(P̅ ∨ Q) ⇔ (Q̅ ⇒ P̅)</b>, now we just do the same with the second part of the contraposition. <b>(Q̅ ⇒ P̅) ⇔ (Q ∨ P̅)</b> therefor :<br /> </p> <p> <b>(Q ∨ P̅) ⇔ (P̅ ∨ Q)</b>, which is true because of commutativity<br /> </p> <ol class="org-ol"> <li>not(P ⇒ Q) ⇔ P ∧ Q̅<br /></li> </ol> <p> Okaaaay so, let&rsquo;s first get rid of the implication, because I don&rsquo;t like it : <b>not(P̅ ∨ Q)</b><br /> </p> <p> Now that we got rid of it, we can negate the whole disjunction <b>not(P̅ ∨ Q) ⇔ (P ∧ Q̅)</b>. Which is the equivalence we needed to prove<br /> </p> <ol class="org-ol"> <li><p> P ⇒ (Q ∧ R) ⇔ (P ⇒ Q) ∧ (P ⇒ R)<br /> </p> <p> One might be tempted to replace P with P̅ to get rid of the implication&#x2026;sadly this isnt it. All we have to do here is resort to <b>Distributivity</b>, because yeah, we can distribute an implication across a {con/dis}junction<br /> </p></li> <li><p> P ∧ (Q ∨ R) ⇔ (P ∧ Q) ∨ (P ∧ R)<br /> </p> <p> Literally the same as above 🩷<br /> </p></li> </ol> </div> </li> <li><a id="orgd9c7023"></a>Exercice 2: Dire si les propositions suivantes sont vraies ou fausses, et les nier:<br /> <div class="outline-text-5" id="text-orgd9c7023"> <ol class="org-ol"> <li><p> ∀x ∈ ℝ ,∃y ∈ ℝ*+, tels que e^x = y<br /> </p> <p> For each x from the set of Real numbers, there exists a number y from the set of non-zero positive Real numbers that satisfies the equation : e^x = y<br /> </p></li> </ol> <p> &ldquo;The function f(x)=e^x is always positive and non-null&rdquo;, the very definition of an exponential function !!!!<br /> </p> <p> <b>So the proposition is true</b><br /> </p> <ol class="org-ol"> <li>∃x ∈ ℝ, tels que x^2 &lt; x &lt; x^3<br /></li> </ol> <p> We just need to find a value that satisifies this condition&#x2026;thankfully its easy&#x2026;.<br /> </p> <p>&lt; x &lt; x³ , we divide the three terms by x so we get :<br /> </p> <p> x &lt; 1 &lt; x² , or :<br /> </p> <p> <b>x &lt; 1</b> ; <b>1 &lt;</b><b>x &lt; 1</b> ; <b>1 &lt; x</b> <i>We square root both sides</i><br /> </p> <p> We end up with a contradiction, therefor its wrong<br /> </p> <ol class="org-ol"> <li>∀x ∈ ℝ, ∃y ∈ ℝ tels que y = 3x - 8<br /></li> </ol> <p> I dont really understand this one, so let me translate it &ldquo;For any value of x from the set of Real numbers, 3x - 8 is a Real number&rdquo;&#x2026;. i mean&#x2026;.yeah, we are substracting a Real number from an other real number&#x2026;<br /> </p> <p> <b>Since substraction is an Internal composition law in ℝ, therefor all results of a substraction between two Real numbers is&#x2026;Real</b><br /> </p> <ol class="org-ol"> <li><p> ∃x ∈ ℕ, ∀y ∈ ℕ, x &gt; y ⇒ x + y &lt; 8<br /> </p> <p> &ldquo;There exists a number x from the set of Natural numbers such as for all values of y from the set of Natural numbers, x &gt; y implies x + y &lt; 8&rdquo;<br /> </p></li> </ol> <p> Let&rsquo;s get rid of the implication :<br /> </p> <p> ∃x ∈ ℕ, ∀y ∈ ℕ, (y &gt; x) ∨ (x + y &lt; 8) <i>There exists a number x from the set of Natural numbers such as for all values of y from the set of Natural numbers y &gt; x OR x + y &lt; 8</i><br /> </p> <p> This proposition is true, because there exists a value of x that satisfies this condition, it&rsquo;s <b>all numbers under 8</b> let&rsquo;s take 3 as an example:<br /> </p> <p> <b>x = 3 , if y &gt; 3 then the first condition is true ; if y &lt; 3 then the second one is true</b><br /> </p> <p> Meaning that the two propositions CAN NOT BE WRONG TOGETHER, either one is wrong, or the other<br /> </p> <p> y &gt; x<br /> </p> <p> <b>y - x &gt; 0</b><br /> </p> <p> y + x &lt; 8<br /> </p> <p> <b>y &lt; 8 - x</b> <i>This one is always true for all values of x below 8, since we are working in the set ℕ</i><br /> </p> <ol class="org-ol"> <li><p> ∀x ∈ ℝ, x² ≥ 1 ⇔ x ≥ 1<br /> </p> <p> &#x2026;.This is getting stupid. of course it&rsquo;s true it&rsquo;s part of the definition of the power of 2<br /> </p></li> </ol> </div> </li> </ul> </div> </div> </div> <div id="outline-container-org21d6c03" class="outline-2"> <h2 id="org21d6c03">2éme cours <i>Oct 2</i></h2> <div class="outline-text-2" id="text-org21d6c03"> </div> <div id="outline-container-orgd6c9f49" class="outline-3"> <h3 id="orgd6c9f49">Quantifiers</h3> <div class="outline-text-3" id="text-orgd6c9f49"> <p> A propriety P can depend on a parameter x<br /> </p> <p> ∀ is the universal quantifier which stands for &ldquo;For any value of&#x2026;&rdquo;<br /> </p> <p> ∃ is the existential quantifier which stands for &ldquo;There exists at least one&#x2026;&rdquo;<br /> </p> </div> <ul class="org-ul"> <li><a id="orge92d880"></a>Example<br /> <div class="outline-text-6" id="text-orge92d880"> <p> P(x) : x+1≥0<br /> </p> <p> P(X) is True or False depending on the values of x<br /> </p> </div> </li> </ul> <div id="outline-container-orgb332b43" class="outline-4"> <h4 id="orgb332b43">Proprieties</h4> <div class="outline-text-4" id="text-orgb332b43"> </div> <ul class="org-ul"> <li><a id="org8587885"></a>Propriety Number 1:<br /> <div class="outline-text-5" id="text-org8587885"> <p> The negation of the universal quantifier is the existential quantifier, and vice-versa :<br /> </p> <ul class="org-ul"> <li>not(∀x ∈ E , P(x)) ⇔ ∃ x ∈ E, not(P(x))<br /></li> <li>not(∃x ∈ E , P(x)) ⇔ ∀ x ∈ E, not(P(x))<br /></li> </ul> </div> <ul class="org-ul"> <li><a id="org3a19f5f"></a>Example:<br /> <div class="outline-text-6" id="text-org3a19f5f"> <p> ∀ x ≥ 1 x² &gt; 5 ⇔ ∃ x ≥ 1 x² &lt; 5<br /> </p> </div> </li> </ul> </li> <li><a id="orgab7b647"></a>Propriety Number 2:<br /> <div class="outline-text-5" id="text-orgab7b647"> <p> <b>∀x ∈ E, [P(x) ∧ Q(x)] ⇔ [∀ x ∈ E, P(x)] ∧ [∀ x ∈ E, Q(x)]</b><br /> </p> <p> The propriety &ldquo;For any value of x from a set E , P(x) and Q(x)&rdquo; is equivalent to &ldquo;For any value of x from a set E, P(x) AND for any value of x from a set E, Q(x)&rdquo;<br /> </p> </div> <ul class="org-ul"> <li><a id="org8ba49ff"></a>Example :<br /> <div class="outline-text-6" id="text-org8ba49ff"> <p> P(x) : sqrt(x) &gt; 0 ; Q(x) : x ≥ 1<br /> </p> <p> ∀x ∈ ℝ*+, [sqrt(x) &gt; 0 , x ≥ 1] ⇔ [∀x ∈ R*+, sqrt(x) &gt; 0] ∧ [∀x ∈ R*+, x ≥ 1]<br /> </p> <p> <b>Which is true</b><br /> </p> </div> </li> </ul> </li> <li><a id="org91796f9"></a>Propriety Number 3:<br /> <div class="outline-text-5" id="text-org91796f9"> <p> <b>∃ x ∈ E, [P(x) ∧ Q(x)] <i></i> [∃ x ∈ E, P(x)] ∧ [∃ x ∈ E, Q(x)]</b><br /> </p> <p> <i>Here its an implication and not an equivalence</i><br /> </p> </div> <ul class="org-ul"> <li><a id="org1f20a27"></a>Example of why it&rsquo;s NOT an equivalence :<br /> <div class="outline-text-6" id="text-org1f20a27"> <p> P(x) : x &gt; 5 ; Q(x) : x &lt; 5<br /> </p> <p> Of course there is no value of x such as its inferior and superior to 5 at the same time, so obviously the proposition is false. However, the two propositions separated are correct on their own, because there is a value of x such as its superior to 5, and there is also a value of x such as its inferior to 5. This is why it&rsquo;s an implication and NOT AN EQUIVALENCE!!!<br /> </p> </div> </li> </ul> </li> <li><a id="org2b9f54b"></a>Propriety Number 4:<br /> <div class="outline-text-5" id="text-org2b9f54b"> <p> <b>[∀ x ∈ E, P(x)] ∨ [∀ x ∈ E, Q(x)] <i></i> ∀x ∈ E, [P(x) ∨ Q(x)]</b><br /> </p> <p> <i>Same here, implication and NOT en equivalence</i><br /> </p> </div> </li> </ul> </div> </div> <div id="outline-container-orged685c1" class="outline-3"> <h3 id="orged685c1">Multi-parameter proprieties :</h3> <div class="outline-text-3" id="text-orged685c1"> <p> A propriety P can depend on two or more parameters, for convenience we call them x,y,z&#x2026;etc<br /> </p> </div> <ul class="org-ul"> <li><a id="org747b217"></a>Example :<br /> <div class="outline-text-6" id="text-org747b217"> <p> P(x,y): x+y &gt; 0<br /> </p> <p> P(0,1) is a True proposition<br /> </p> <p> P(-2,-1) is a False one<br /> </p> </div> </li> <li><a id="org5d93eaf"></a>WARNING :<br /> <div class="outline-text-6" id="text-org5d93eaf"> <p> ∀x ∈ E, ∃y ∈ F , P(x,y)<br /> </p> <p> ∃y ∈ F, ∀x ∈ E , P(x,y)<br /> </p> <p> Are different because in the first one y depends on x, while in the second one, it doesn&rsquo;t<br /> </p> </div> <ul class="org-ul"> <li><a id="orgc60c61d"></a>Example :<br /> <div class="outline-text-7" id="text-orgc60c61d"> <p> ∀ x ∈ ℕ , ∃ y ∈ ℕ y &gt; x -&#x2013;&#x2014; True<br /> </p> <p> ∃ y ∈ ℕ , ∀ x ∈ ℕ y &gt; x -&#x2013;&#x2014; False<br /> </p> </div> </li> </ul> </li> </ul> <li><a id="orgda9f614"></a>Proprieties :<br /> <div class="outline-text-5" id="text-orgda9f614"> <ol class="org-ol"> <li>not(∀x ∈ E ,∃y ∈ F P(x,y)) ⇔ ∃x ∈ E, ∀y ∈ F not(P(x,y))<br /></li> <li>not(∃x ∈ E ,∀y ∈ F P(x,y)) ⇔ ∀x ∈ E, ∃y ∈ F not(P(x,y))<br /></li> </ol> </div> </li> </ul> </div> <div id="outline-container-org78d7ed0" class="outline-3"> <h3 id="org78d7ed0">Methods of mathematical reasoning :</h3> <div class="outline-text-3" id="text-org78d7ed0"> </div> <div id="outline-container-org7d21c38" class="outline-4"> <h4 id="org7d21c38">Direct reasoning :</h4> <div class="outline-text-4" id="text-org7d21c38"> <p> To show that an implication P ⇒ Q is true, we suppose that P is true and we show that Q is true<br /> </p> </div> <ul class="org-ul"> <li><a id="org59d34b3"></a>Example:<br /> <div class="outline-text-5" id="text-org59d34b3"> <p> Let a,b be two Real numbers, we have to prove that <b>a² + b² = 1 ⇒ |a + b| ≤ 2</b><br /> </p> <p> We suppose that a²+b² = 1 and we prove that |a + b| ≤ 2<br /> </p> <p> a²+b²=1 ⇒ b² = 1 - a² ; a² = 1 - b²<br /> </p> <p> a²+b²=1 ⇒ 1 - a² ≥ 0 ; 1 - b² ≥ 0<br /> </p> <p> a²+b²=1 ⇒ a² ≤ 1 ; b² ≤ 1<br /> </p> <p> a²+b²=1 ⇒ -1 ≤ a ≤ 1 ; -1 ≤ b ≤ 1<br /> </p> <p> a²+b²=1 ⇒ -2 ≤ a + b ≤ 2<br /> </p> <p> a²+b²=1 ⇒ |a + b| ≤ 2 <b>Which is what we wanted to prove, therefor the implication is correct</b><br /> </p> </div> </li> </ul> </div> <div id="outline-container-orgcfd8723" class="outline-4"> <h4 id="orgcfd8723">Reasoning by the Absurd:</h4> <div class="outline-text-4" id="text-orgcfd8723"> <p> To prove that a proposition is True, we suppose that it&rsquo;s False and we must come to a contradiction<br /> </p> <p> And to prove that an implication P ⇒ Q is true using the reasoning by the absurd, we suppose that P ∧ not(Q) is true, and then we come to a contradiction as well<br /> </p> </div> <ul class="org-ul"> <li><a id="orga4a0e2d"></a>Example:<br /> <div class="outline-text-5" id="text-orga4a0e2d"> <p> Prove that this proposition is correct using the reasoning by the absurd : ∀x ∈ ℝ* , sqrt(1+x²) ≠ 1 + x²/2<br /> </p> <p> We assume that ∃ x ℝ* , sqrt(1+x²) = 1 + x²/2<br /> </p> <p> sqrt(1+x²) = 1 + x²/2 ; 1 + x² = (1+x²/2)² ; 1 + x² = 1 + x^4/4 + x² ; x^(4)/4 = 0 &#x2026; Which contradicts with our proposition, since x = 4 and we are working on the ℝ* set<br /> </p> </div> </li> </ul> </div> <div id="outline-container-org102d3fa" class="outline-4"> <h4 id="org102d3fa">Reasoning by contraposition:</h4> <div class="outline-text-4" id="text-org102d3fa"> <p> If an implication P ⇒ Q is too hard to prove, we just have to prove not(Q) ⇒ not(P) is true !!! or in other words that both not(P) and not(Q) are true<br /> </p> </div> </div> <div id="outline-container-org81cb388" class="outline-4"> <h4 id="org81cb388">Reasoning by counter example:</h4> <div class="outline-text-4" id="text-org81cb388"> <p> To prove that a proposition ∀x ∈ E, P(x) is false, all we have to do is find a single value of x from E such as not(P(x)) is true<br /> </p> </div> </div> </div> </div> <div id="outline-container-orgc2178b8" class="outline-2"> <h2 id="orgc2178b8">3eme Cours : <i>Oct 9</i></h2> <div class="outline-text-2" id="text-orgc2178b8"> </div> <div id="outline-container-org4855f6f" class="outline-4"> <h4 id="org4855f6f">Reasoning by recurrence :</h4> <div class="outline-text-4" id="text-org4855f6f"> <p> P is a propriety dependent of <b>n ∈ ℕ</b>. If for n0 ∈ ℕ P(n0) is true, and if for n ≥ n0 (P(n) ⇒ P(n+1)) is true. Then P(n) is true for n ≥ n0<br /> </p> </div> <ul class="org-ul"> <li><a id="orga792d9c"></a>Example:<br /> <div class="outline-text-5" id="text-orga792d9c"> <p> Let&rsquo;s prove that ∀ n ≥ 1 , (n,k=1)Σk = [n(n+1)]/2<br /> </p> <p> P(n) : (n,k=1)Σk = [n(n+1)]/2<br /> </p> <p> <b>Pour n = 1:</b> (1,k=1)Σk = 1 ; [n(n+1)]/2 = 1 . <b>So P(1) is true</b><br /> </p> <p> For n ≥ 1. We assume that P(n) is true, OR : <b>(n, k=1)Σk = n(n+1)/2</b>. We now have to prove that P(n+1) is true, Or : <b>(n+1, k=1)Σk = (n+1)(n+2)/2</b><br /> </p> <p> (n+1, k=1)Σk = 1 + 2 + &#x2026;. + n + (n+1) ; (n+1, k=1)Σk = (n, k=1)Σk + (n+1) ; = n(n+1)/2 + (n+1) ; = [n(n+1) + 2(n+1)]/2 ; = <b>[(n+2)(n+1)]/2</b> <i>WHICH IS WHAT WE NEEDED TO FIND</i><br /> </p> <p> <b>Conclusion: ∀n ≥ 1 , (n,k=1)Σk = n(n+1)/2</b><br /> </p> </div> </li> </ul> </div> </div> <div id="outline-container-orgde6bfac" class="outline-2"> <h2 id="orgde6bfac">4eme Cours : Chapitre 2 : Sets and Operations</h2> <div class="outline-text-2" id="text-orgde6bfac"> </div> <div id="outline-container-orgfe8000a" class="outline-3"> <h3 id="orgfe8000a">Definition of a set :</h3> <div class="outline-text-3" id="text-orgfe8000a"> <p> A set is a collection of objects that share the sane propriety<br /> </p> </div> </div> <div id="outline-container-orgfe04671" class="outline-3"> <h3 id="orgfe04671">Belonging, inclusion, and equality :</h3> <div class="outline-text-3" id="text-orgfe04671"> <ol class="org-ol"> <li>Let E be a set. If x is an element of E, we say that x belongs to E we write <b>x ∈ E</b>, and if it doesn&rsquo;t, we write <b>x ∉ E</b><br /></li> <li>A set E is included in a set F if all elements of E are elements of F and we write <b>E ⊂ F ⇔ (∀x , x ∈ E ⇒ x ∈ F)</b>. We say that E is a subset of F, or a part of F. The negation of this propriety is : <b>E ⊄ F ⇔ ∃x , x ∈ E and x ⊄ F</b><br /></li> <li>E and F are equal if E is included in F and F is included in E, and we write <b>E = F ⇔ (E ⊂ F) et (F ⊂ E)</b><br /></li> <li>The empty set (symbolized by ∅) is a set without elements, and is included in all sets (by convention) : <b>∅ ⊂ E</b><br /></li> </ol> </div> </div> <div id="outline-container-orga2eb99d" class="outline-3"> <h3 id="orga2eb99d">Intersections and reunions :</h3> <div class="outline-text-3" id="text-orga2eb99d"> </div> <div id="outline-container-org560d563" class="outline-4"> <h4 id="org560d563">Intersection:</h4> <div class="outline-text-4" id="text-org560d563"> <p> E ∩ F = {x / x ∈ E AND x ∈ F} ; x ∈ E ∩ F ⇔ x ∈ F AND x ∈ F<br /> </p> <p> x ∉ E ∩ F ⇔ x ∉ E OR x ∉ F<br /> </p> </div> </div> <div id="outline-container-org7147bc3" class="outline-4"> <h4 id="org7147bc3">Union:</h4> <div class="outline-text-4" id="text-org7147bc3"> <p> E ∪ F = {x / x ∈ E OR x ∈ F} ; x ∈ E ∪ F ⇔ x ∈ F OR x ∈ F<br /> </p> <p> x ∉ E ∪ F ⇔ x ∉ E AND x ∉ F<br /> </p> </div> </div> <div id="outline-container-org16b5ab2" class="outline-4"> <h4 id="org16b5ab2">Difference between two sets:</h4> <div class="outline-text-4" id="text-org16b5ab2"> <p> E(Which is also written as : E - F) = {x / x ∈ E and x ∉ F}<br /> </p> </div> </div> <div id="outline-container-orgdac190b" class="outline-4"> <h4 id="orgdac190b">Complimentary set:</h4> <div class="outline-text-4" id="text-orgdac190b"> <p> If F ⊂ E. E - F is the complimentary of F in E.<br /> </p> <p> FCE = {x /x ∈ E AND x ∉ F} <b>ONLY WHEN F IS A SUBSET OF E</b><br /> </p> </div> </div> <div id="outline-container-org4e0b111" class="outline-4"> <h4 id="org4e0b111">Symmetrical difference</h4> <div class="outline-text-4" id="text-org4e0b111"> <p> E Δ F = (E - F) ∪ (F - E) ; = (E ∪ F) - (E ∩ F)<br /> </p> </div> </div> </div> <div id="outline-container-org691c863" class="outline-3"> <h3 id="org691c863">Proprieties :</h3> <div class="outline-text-3" id="text-org691c863"> <p> Let E,F and G be 3 sets. We have :<br /> </p> </div> <div id="outline-container-org9cc9f31" class="outline-4"> <h4 id="org9cc9f31">Commutativity:</h4> <div class="outline-text-4" id="text-org9cc9f31"> <p> E ∩ F = F ∩ E<br /> E ∪ F = F ∪ E<br /> </p> </div> </div> <div id="outline-container-org471083b" class="outline-4"> <h4 id="org471083b">Associativity:</h4> <div class="outline-text-4" id="text-org471083b"> <p> E ∩ (F ∩ G) = (E ∩ F) ∩ G<br /> E ∪ (F ∪ G) = (E ∪ F) ∪ G<br /> </p> </div> </div> <div id="outline-container-orge63be10" class="outline-4"> <h4 id="orge63be10">Distributivity:</h4> <div class="outline-text-4" id="text-orge63be10"> <p> E ∩ (F ∪ G) = (E ∩ F) ∪ (E ∩ G)<br /> E ∪ (F ∩ G) = (E ∪ F) ∩ (E ∪ G)<br /> </p> </div> </div> <div id="outline-container-orgfb01947" class="outline-4"> <h4 id="orgfb01947">Lois de Morgan:</h4> <div class="outline-text-4" id="text-orgfb01947"> <p> If E ⊂ G and F ⊂ G ;<br /> </p> <p> (E ∩ F)CG = ECG ∪ FCG ; (E ∪ F)CG = ECG ∩ FCG<br /> </p> </div> </div> <div id="outline-container-orge1a41eb" class="outline-4"> <h4 id="orge1a41eb">An other one:</h4> <div class="outline-text-4" id="text-orge1a41eb"> <p> E - (F ∩ G) = (E-F) ∪ (E-G) ; E - (F ∪ G) = (E-F) ∩ (E-G)<br /> </p> </div> </div> <div id="outline-container-org9939b0f" class="outline-4"> <h4 id="org9939b0f">An other one:</h4> <div class="outline-text-4" id="text-org9939b0f"> <p> E ∩ ∅ = ∅ ; E ∪ ∅ = E<br /> </p> </div> </div> <div id="outline-container-org90bfdc4" class="outline-4"> <h4 id="org90bfdc4">And an other one:</h4> <div class="outline-text-4" id="text-org90bfdc4"> <p> E ∩ (F Δ G) = (E ∩ F) Δ (E ∩ G)<br /> </p> </div> </div> <div id="outline-container-org1e49001" class="outline-4"> <h4 id="org1e49001">And the last one:</h4> <div class="outline-text-4" id="text-org1e49001"> <p> E Δ ∅ = E ; E Δ E = ∅<br /> </p> </div> </div> </div> </div> <div id="outline-container-org272eca3" class="outline-2"> <h2 id="org272eca3">5eme cours: L&rsquo;ensemble des parties d&rsquo;un ensemble <i>Oct 16</i></h2> <div class="outline-text-2" id="text-org272eca3"> <p> Let E be a set. We define P(E) as the set of all parts of E : <b>P(E) = {X/X ⊂ E}</b><br /> </p> </div> <div id="outline-container-org5b29e32" class="outline-4"> <h4 id="org5b29e32">Notes :</h4> <div class="outline-text-4" id="text-org5b29e32"> <p> ∅ ∈ P(E) ; E ∈ P(E)<br /> </p> <p> cardinal E = n <i>The number of terms in E</i> , cardinal P(E) = 2^n <i>The number of all parts of E</i><br /> </p> </div> </div> <div id="outline-container-org5636bd8" class="outline-4"> <h4 id="org5636bd8">Examples :</h4> <div class="outline-text-4" id="text-org5636bd8"> <p> E = {a,b,c} ; P(E)={∅, {a}, {b}, {c}, {a,b}, {b,c}, {a,c}, {a,b,c}}<br /> </p> </div> </div> <div id="outline-container-orgd8cb2c3" class="outline-3"> <h3 id="orgd8cb2c3">Partition of a set :</h3> <div class="outline-text-3" id="text-orgd8cb2c3"> <p> We say that <b>A</b> is a partition of E if:<br /> </p> <ol class="org-ol"> <li>∀ x ∈ A , x ≠ 0<br /></li> <li>All the elements of <b>A</b> are two by two disjoint. Or in other terms, there should not be two elements that intersects with each other.<br /></li> <li>The reunion of all elements of <b>A</b> is equal to E<br /></li> </ol> </div> </div> <div id="outline-container-orgf40404d" class="outline-3"> <h3 id="orgf40404d">Cartesian products :</h3> <div class="outline-text-3" id="text-orgf40404d"> <p> Let E and F be two sets, the set EXF = {(x,y)/ x ∈ E AND y ∈ F} is called the Cartesian product of E and F<br /> </p> </div> <div id="outline-container-orgd526cb8" class="outline-4"> <h4 id="orgd526cb8">Example :</h4> <div class="outline-text-4" id="text-orgd526cb8"> <p> A = {4,5} ; B= {4,5,6} ; AxB = {(4,4), (4,5), (4,6), (5,4), (5,5), (5,6)}<br /> </p> <p> BxA = {(4,4), (4,5), (5,4), (5,5), (6,4), (6,5)} ; Therefore AxB ≠ BxA<br /> </p> </div> </div> <div id="outline-container-org56dd088" class="outline-4"> <h4 id="org56dd088">Some proprieties:</h4> <div class="outline-text-4" id="text-org56dd088"> <ol class="org-ol"> <li>ExF = ∅ ⇔ E=∅ OR F=∅<br /></li> <li>ExF = FxE ⇔ E=F OR E=∅ OR F=∅<br /></li> <li>E x (F∪G) = (ExF) ∪ (ExG)<br /></li> <li>(E∪F) x G = (ExG) ∪ (FxG)<br /></li> <li>(E∪F) ∩ (GxH) = (E ∩ G) x (F ∩ H)<br /></li> <li>Generally speaking : (ExF) ∪ (GxH) ≠ (E∪G) x (F∪H)<br /></li> </ol> </div> </div> </div> </div> <div id="outline-container-org5ee4278" class="outline-2"> <h2 id="org5ee4278">Binary relations in a set :</h2> <div class="outline-text-2" id="text-org5ee4278"> </div> <div id="outline-container-orgddc9af6" class="outline-3"> <h3 id="orgddc9af6">Definition :</h3> <div class="outline-text-3" id="text-orgddc9af6"> <p> Let E be a set and x,y ∈ E. If there exists a link between x and y, we say that they are tied by a relation <b>R</b> and we write <b>xRy</b><br /> </p> </div> </div> <div id="outline-container-orge65424e" class="outline-3"> <h3 id="orge65424e">Proprieties :</h3> <div class="outline-text-3" id="text-orge65424e"> <p> Let E be a set and R a relation defined in E<br /> </p> <ol class="org-ol"> <li>We say that R is reflexive if ∀ x ∈ E, xRx (for any element x in E,x is related to itself)<br /></li> <li>We say that R is symmetrical if ∀ x,y ∈ E , xRy ⇒ yRx<br /></li> <li>We say that R is transitive if ∀ x,y,z ∈ E (xRy , yRz) ⇒ xRz<br /></li> <li>We say that R is anti-symmetrical if ∀ x,y ∈ E xRy AND yRx ⇒ x = y<br /></li> </ol> </div> </div> <div id="outline-container-orgd7877d3" class="outline-3"> <h3 id="orgd7877d3">Equivalence relationship :</h3> <div class="outline-text-3" id="text-orgd7877d3"> <p> We say that R is a relation of equivalence in E if its reflexive, symetrical and transitive<br /> </p> </div> <div id="outline-container-org85cf025" class="outline-4"> <h4 id="org85cf025">Equivalence class :</h4> <div class="outline-text-4" id="text-org85cf025"> <p> Let R be a relation of equivalence in E and a ∈ E, we call equivalence class of <b>a</b>, and we write ̅a or ȧ, or cl a the following set :<br /> </p> <p> <b>a̅ = {y ∈ E/ y R a}</b><br /> </p> </div> <ul class="org-ul"> <li><a id="orga316a01"></a>The quotient set :<br /> <div class="outline-text-5" id="text-orga316a01"> <p> E/R = {̅a , a ∈ E}<br /> </p> </div> </li> </ul> </div> </div> <div id="outline-container-orge18dcc7" class="outline-3"> <h3 id="orge18dcc7">Order relationship :</h3> <div class="outline-text-3" id="text-orge18dcc7"> <p> Let E be a set and R be a relation defined in E. We say that R is a relation of order if its reflexive, anti-symetrical and transitive.<br /> </p> <ol class="org-ol"> <li>The order R is called total if ∀ x,y ∈ E xRy OR yRx<br /></li> <li>The order R is called partial if ∃ x,y ∈ E xR̅y AND yR̅x<br /></li> </ol> </div> <div id="outline-container-org60d471a" class="outline-4"> <h4 id="org60d471a"><span class="todo TODO">TODO</span> Examples :</h4> <div class="outline-text-4" id="text-org60d471a"> <p> ∀x,y ∈ ℝ , xRy ⇔ x²-y²=x-y<br /> </p> <ol class="org-ol"> <li>Prove that R is an equivalence relation<br /></li> <li>Let a ∈ ℝ, find ̅a<br /></li> </ol> </div> </div> </div> </div> <div id="outline-container-org77de6e3" class="outline-2"> <h2 id="org77de6e3">TP exercices <i>Oct 20</i> :</h2> <div class="outline-text-2" id="text-org77de6e3"> </div> <div id="outline-container-org3ca8006" class="outline-3"> <h3 id="org3ca8006">Exercice 3 :</h3> <div class="outline-text-3" id="text-org3ca8006"> </div> <div id="outline-container-orgad95ec3" class="outline-4"> <h4 id="orgad95ec3">Question 3</h4> <div class="outline-text-4" id="text-orgad95ec3"> <p> Montrer par l&rsquo;absurde que P : ∀x ∈ ℝ*, √(4+x³) ≠ 2 + x³/4 est vraies<br /> </p> <p class="verse"> On suppose que ∃ x ∈ ℝ* , √(4+x³) = 2 + x³/4<br /> 4+x³ = (2 + x³/4)²<br /> 4+x³ = 4 + x⁶/16 + 4*(x³/4)<br /> 4+x³ = 4 + x⁶/16 + x³<br /> x⁶/16 = 0<br /> x⁶ = 0<br /> x = 0 . Or, x appartiens a ℝ\{0}, donc P̅ est fausse. Ce qui est equivalent a dire que P est vraie<br /> </p> </div> </div> </div> <div id="outline-container-org8180ae0" class="outline-3"> <h3 id="org8180ae0">Exercice 4 :</h3> <div class="outline-text-3" id="text-org8180ae0"> </div> <div id="outline-container-orgfe0b1e2" class="outline-4"> <h4 id="orgfe0b1e2"><span class="done DONE">DONE</span> Question 1 :</h4> <div class="outline-text-4" id="text-orgfe0b1e2"> <p class="verse"> ∀ n ∈ ℕ* , (n ,k=1)Σ1/k(k+1) = 1 - 1/1+n<br /> P(n) : (n ,k=1)Σ1/k(k+1) = 1 - 1/1+n<br /> 1. <b>On vérifie P(n) pour n = 1</b><br /> (1 ,k=1)Σ1/k(k+1) = 1/1(1+1)<br /> &#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;= 1/2 &#x2014; (1)<br /> 1 - 1/1+1 = 1 - 1/2<br /> &#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;= 1/2 &#x2014; (2)<br /> De (1) et (2), P(0) est vraie -&#x2014; (a)<br /> <br /> 2. <b>On suppose que P(n) est vraie pour n ≥ n1 puis on vérifie pour n+1</b><br /> (n ,k=1)Σ1/k(k+1) = 1 - 1/1+n<br /> (n ,k=1)Σ1/k(k+1) + 1/(n+1)(n+2) = 1 - (1/(1+n)) + 1/(n+1)(n+2)<br /> (n+1 ,k=1)Σ1/k(k+1) = 1 - 1/(n+1) + 1/[(n+1)(n+2)]<br /> (n+1 ,k=1)Σ1/k(k+1) = 1 + 1/[(n+1)(n+2)] - (n+2)/[(n+1)(n+2)]<br /> (n+1 ,k=1)Σ1/k(k+1) = 1 + [1-(n+2)]/[(n+1)(n+2)]<br /> (n+1 ,k=1)Σ1/k(k+1) = 1 + [-n-1]/[(n+1)(n+2)]<br /> (n+1 ,k=1)Σ1/k(k+1) = 1 - [n+1]/[(n+1)(n+2)]<br /> (n+1 ,k=1)Σ1/k(k+1) = 1 - 1/(n+1+1) <b>CQFD</b><br /> <br /> Donc P(n+1) est vraie. -&#x2014; (b)<br /> De (a) et (b) on conclus que la proposition de départ est vraie<br /> </p> </div> </div> </div> </div> <div id="outline-container-org2d6e0ba" class="outline-2"> <h2 id="org2d6e0ba">Chapter 3 : Applications</h2> <div class="outline-text-2" id="text-org2d6e0ba"> </div> <div id="outline-container-orga5be12f" class="outline-3"> <h3 id="orga5be12f">3.1 Generalities about applications :</h3> <div class="outline-text-3" id="text-orga5be12f"> </div> <div id="outline-container-org805d7bc" class="outline-4"> <h4 id="org805d7bc">Definition :</h4> <div class="outline-text-4" id="text-org805d7bc"> <p> Let E and F be two sets.<br /> </p> <ol class="org-ol"> <li>We call a function of the set E to the set F any relation from E to F such as for any element of E, we can find <span class="underline">at most one</span> element of F that corresponds to it.<br /></li> <li>We call an application of the set E to the set F a relation from E to F such as for any element of E, we can find <span class="underline">one and only one</span> element of F that corresponds to it.<br /></li> <li><p> f: E<sub>1</sub> &#x2014;&gt; F<sub>1</sub> ; g: E<sub>2</sub> &#x2014;&gt; F<sub>2</sub> ; f ≡ g ⇔ [E<sub>1 </sub>= E<sub>2</sub> ; F<sub>1</sub> = F<sub>2</sub> ; f(x) = g(x) ∀x ∈ E<sub>1</sub><br /> </p> <p> Generally speaking, we schematize a function or an application by this writing :<br /> </p> <p class="verse"> f : E &#x2014;&gt; F<br /> &#xa0;&#xa0;&#xa0;&#xa0;x &#x2014;&gt; f(x)=y<br /> &#xa0;&#xa0;&#xa0;Γ = {(x , f(x))/ x ∈ E ; f(x) ∈ F} is the graph of f<br /> </p></li> </ol> </div> <ul class="org-ul"> <li><a id="org2936c19"></a>Some examples :<br /> <ul class="org-ul"> <li><a id="orgd77c836"></a>Ex1:<br /> <div class="outline-text-6" id="text-orgd77c836"> <p class="verse"> f : ℝ &#x2014;&gt;<br /> &#xa0;&#xa0;&#xa0;&#xa0;x &#x2014;&gt; f(x) = (x-1)/x<br /> is a function, because 0 does NOT have a corresponding element using that relation.<br /> </p> </div> </li> <li><a id="orga45fd32"></a>Ex2:<br /> <div class="outline-text-6" id="text-orga45fd32"> <p class="verse"> f : ℝ<sup>*</sup> &#x2014;&gt;<br /> &#xa0;&#xa0;&#xa0;&#xa0;x &#x2014;&gt; f(x)= (x-1)/x<br /> is, however, an application<br /> </p> </div> </li> </ul> </li> </ul> </div> <div id="outline-container-org7947331" class="outline-4"> <h4 id="org7947331">Restriction and prolongation of an application :</h4> <div class="outline-text-4" id="text-org7947331"> <p> Let f : E -&gt; F an application and E<sub>1</sub> ⊂ E therefore :<br /> </p> <p class="verse"> g : E<sub>1</sub> -&gt; F<br /> g(x) = f(x) ∀x ∈ E<sub>1</sub><br /> <br /> g is called the <b>restriction</b> of f to E<sub>1</sub>. And f is called the <b>prolongation</b> of g to E.<br /> </p> </div> <ul class="org-ul"> <li><a id="org7c848c6"></a>Example<br /> <div class="outline-text-5" id="text-org7c848c6"> <p class="verse"> f : ℝ &#x2014;&gt;<br /> &#xa0;&#xa0;&#xa0;&#xa0;x &#x2014;&gt; f(x) = x<sup>2</sup><br /> <br /> g : [0 , <del>∞[ &#x2014;&gt;<br /> &#xa0;&#xa0;&#xa0;&#xa0;x &#x2014;&gt; g(x) = x²<br /> <br /> g is called the <b>restriction</b> of f to ℝ^{</del>}. And f is called the <b>prolongation</b> of g to ℝ.<br /> </p> </div> </li> </ul> </div> <div id="outline-container-orgd94bc69" class="outline-4"> <h4 id="orgd94bc69">Composition of applications :</h4> <div class="outline-text-4" id="text-orgd94bc69"> <p> Let E,F, and G be three sets, f: E -&gt; F and g: F -&gt; G are two applications. We define their composition, symbolized by g<sub>o</sub>f as follow :<br /> </p> <p> g<sub>o</sub>f : E -&gt; G . ∀x ∈ E (g<sub>o</sub>f)<sub>(x)</sub>= g(f(x))<br /> </p> </div> </div> </div> <div id="outline-container-org257d05a" class="outline-3"> <h3 id="org257d05a">3.2 Injection, surjection and bijection :</h3> <div class="outline-text-3" id="text-org257d05a"> <p> Let f: E -&gt; F be an application :<br /> </p> <ol class="org-ol"> <li>We say that f is injective if : ∀x,x&rsquo; ∈ E : f(x) = f(x&rsquo;) ⇒ x = x&rsquo;<br /></li> <li>We say that f is surjective if : ∀ y ∈ F , ∃ x ∈ E : y = f(x)<br /></li> <li>We say that if is bijective if it&rsquo;s both injective and surjective at the same time.<br /></li> </ol> </div> <div id="outline-container-org1612e09" class="outline-4"> <h4 id="org1612e09">Proposition :</h4> <div class="outline-text-4" id="text-org1612e09"> <p> Let f : E -&gt; F be an application. Therefore:<br /> </p> <ol class="org-ol"> <li>f is injective ⇔ y = f(x) has at most one solution.<br /></li> <li>f is surjective ⇔ y = f(x) has at least one solution.<br /></li> <li>f is bijective ⇔ y = f(x) has a single and unique solution.<br /></li> </ol> </div> </div> </div> <div id="outline-container-orgebdf518" class="outline-3"> <h3 id="orgebdf518">3.3 Reciprocal applications :</h3> <div class="outline-text-3" id="text-orgebdf518"> </div> <div id="outline-container-orgf072e42" class="outline-4"> <h4 id="orgf072e42">Def :</h4> <div class="outline-text-4" id="text-orgf072e42"> <p> Let f : E -&gt; F a bijective application. So there exists an application named f<sup>-1</sup> : F -&gt; E such as : y = f(x) ⇔ x = f<sup>-1</sup>(y)<br /> </p> </div> </div> <div id="outline-container-org244b352" class="outline-4"> <h4 id="org244b352">Theorem :</h4> <div class="outline-text-4" id="text-org244b352"> <p> Let f : E -&gt; F be a bijective application. Therefore its reciprocal f<sup>-1</sup> verifies : f<sup>-1</sup><sub>o</sub>f=Id<sub>E </sub>; f<sub>o</sub>f<sup>-1</sup>=Id<sub>F</sub> Or :<br /> </p> <p> Id<sub>E</sub> : E -&gt; E ; x -&gt; Id<sub>E</sub>(x) = x<br /> </p> </div> </div> <div id="outline-container-org1479c0e" class="outline-4"> <h4 id="org1479c0e">Some proprieties :</h4> <div class="outline-text-4" id="text-org1479c0e"> <ol class="org-ol"> <li>(f<sup>-1</sup>)<sup>-1</sup> = f<br /></li> <li>(g<sub>o</sub>f)⁻¹ = f⁻¹<sub>o</sub>g⁻¹<br /></li> <li>The graphs of f and f⁻¹ are symmetrical to each other by the first bis-sectrice of the equation y = x<br /></li> </ol> </div> </div> </div> <div id="outline-container-orgaf81bb3" class="outline-3"> <h3 id="orgaf81bb3">3.4 Direct Image and reciprocal Image :</h3> <div class="outline-text-3" id="text-orgaf81bb3"> </div> <div id="outline-container-org87b91e2" class="outline-4"> <h4 id="org87b91e2">Direct Image :</h4> <div class="outline-text-4" id="text-org87b91e2"> <p> Let f: E-&gt; F be an application and A ⊂ E. We call a direct image of A by f, and we symbolize as f(A) the subset of F defined by :<br /> </p> <p> f(A) = {f(x)/ x ∈ A} ; = { y ∈ F ∃ x ∈ A y=f(x)}<br /> </p> </div> <ul class="org-ul"> <li><a id="orgb5bc08c"></a>Example :<br /> <div class="outline-text-5" id="text-orgb5bc08c"> <p class="verse"> f: ℝ -&gt;<br /> &#xa0;&#xa0;&#xa0;x -&gt; f(x) = x²<br /> A = {0,4}<br /> f(A) = {f(0), f(4)} = {0, 16}<br /> </p> </div> </li> </ul> </div> <div id="outline-container-org500bc40" class="outline-4"> <h4 id="org500bc40">Reciprocal image :</h4> <div class="outline-text-4" id="text-org500bc40"> <p> Let f: E -&gt; F be an application and B ⊂ F. We call the reciprocal image of E by F the subset f<sup>-1</sup>(B) :<br /> </p> <p> f<sup>-1</sup>(B) = {x ∈ E/f(x) ∈ B} ; x ∈ f<sup>-1</sup>(B) ⇔ f(x) ∈ B<br /> </p> </div> <ul class="org-ul"> <li><a id="org885d21d"></a>Example :<br /> <div class="outline-text-5" id="text-org885d21d"> <p class="verse"> f: ℝ -&gt;<br /> &#xa0;&#xa0;&#xa0;x -&gt; f(x) = x²<br /> B = {1,9,4}<br /> f<sup>-1</sup>(B) = {1,-1,2,-2,3,-3}<br /> &#xa0;&#xa0;&#xa0;&#xa0;&#xa0;&#xa0;= {x ∈ ℝ/x² ∈ {1,4,9}}<br /> </p> </div> </li> </ul> </div> </div> </div> </div> <div id="postamble" class="status"> <p class="author">Author: Crystal</p> <p class="date">Created: 2023-11-01 Wed 20:17</p> </div> </body> </html>