max_stars_repo_path stringlengths 4 261 | max_stars_repo_name stringlengths 6 106 | max_stars_count int64 0 38.8k | id stringlengths 1 6 | text stringlengths 7 1.05M |
|---|---|---|---|---|
data/pokemon/palettes.asm | opiter09/ASM-Machina | 1 | 15008 | <gh_stars>1-10
MonsterPalettes:
table_width 1, MonsterPalettes
db PAL_MEWMON ; MISSINGNO
db PAL_GREENMON ; BULBASAUR
db PAL_GREENMON ; IVYSAUR
db PAL_GREENMON ; VENUSAUR
db PAL_REDMON ; CHARMANDER
db PAL_REDMON ; CHARMELEON
db PAL_REDMON ; CHARIZARD
db PAL_CYANMON ; SQUIRTLE
db PAL_CYANMON ; WARTORTLE
db PAL_CYANMON ; BLASTOISE
db PAL_GREENMON ; CATERPIE
db PAL_GREENMON ; METAPOD
db PAL_CYANMON ; BUTTERFREE
db PAL_YELLOWMON ; WEEDLE
db PAL_YELLOWMON ; KAKUNA
db PAL_YELLOWMON ; BEEDRILL
db PAL_BROWNMON ; PIDGEY
db PAL_BROWNMON ; PIDGEOTTO
db PAL_BROWNMON ; PIDGEOT
db PAL_GREYMON ; RATTATA
db PAL_GREYMON ; RATICATE
db PAL_BROWNMON ; SPEAROW
db PAL_BROWNMON ; FEAROW
db PAL_PURPLEMON ; EKANS
db PAL_PURPLEMON ; ARBOK
db PAL_YELLOWMON ; PIKACHU
db PAL_YELLOWMON ; RAICHU
db PAL_BROWNMON ; SANDSHREW
db PAL_BROWNMON ; SANDSLASH
db PAL_BLUEMON ; NIDORAN_F
db PAL_BLUEMON ; NIDORINA
db PAL_BLUEMON ; NIDOQUEEN
db PAL_PURPLEMON ; NIDORAN_M
db PAL_PURPLEMON ; NIDORINO
db PAL_PURPLEMON ; NIDOKING
db PAL_PINKMON ; CLEFAIRY
db PAL_PINKMON ; CLEFABLE
db PAL_REDMON ; VULPIX
db PAL_YELLOWMON ; NINETALES
db PAL_PINKMON ; JIGGLYPUFF
db PAL_PINKMON ; WIGGLYTUFF
db PAL_BLUEMON ; ZUBAT
db PAL_BLUEMON ; GOLBAT
db PAL_GREENMON ; ODDISH
db PAL_REDMON ; GLOOM
db PAL_REDMON ; VILEPLUME
db PAL_REDMON ; PARAS
db PAL_REDMON ; PARASECT
db PAL_PURPLEMON ; VENONAT
db PAL_PURPLEMON ; VENOMOTH
db PAL_BROWNMON ; DIGLETT
db PAL_BROWNMON ; DUGTRIO
db PAL_YELLOWMON ; MEOWTH
db PAL_YELLOWMON ; PERSIAN
db PAL_YELLOWMON ; PSYDUCK
db PAL_CYANMON ; GOLDUCK
db PAL_BROWNMON ; MANKEY
db PAL_BROWNMON ; PRIMEAPE
db PAL_BROWNMON ; GROWLITHE
db PAL_REDMON ; ARCANINE
db PAL_BLUEMON ; POLIWAG
db PAL_BLUEMON ; POLIWHIRL
db PAL_BLUEMON ; POLIWRATH
db PAL_YELLOWMON ; ABRA
db PAL_YELLOWMON ; KADABRA
db PAL_YELLOWMON ; ALAKAZAM
db PAL_GREYMON ; MACHOP
db PAL_GREYMON ; MACHOKE
db PAL_GREYMON ; MACHAMP
db PAL_GREENMON ; BELLSPROUT
db PAL_GREENMON ; WEEPINBELL
db PAL_GREENMON ; VICTREEBEL
db PAL_CYANMON ; TENTACOOL
db PAL_CYANMON ; TENTACRUEL
db PAL_GREYMON ; GEODUDE
db PAL_GREYMON ; GRAVELER
db PAL_GREYMON ; GOLEM
db PAL_REDMON ; PONYTA
db PAL_REDMON ; RAPIDASH
db PAL_PINKMON ; SLOWPOKE
db PAL_PINKMON ; SLOWBRO
db PAL_GREYMON ; MAGNEMITE
db PAL_GREYMON ; MAGNETON
db PAL_BROWNMON ; FARFETCHD
db PAL_BROWNMON ; DODUO
db PAL_BROWNMON ; DODRIO
db PAL_BLUEMON ; SEEL
db PAL_BLUEMON ; DEWGONG
db PAL_PURPLEMON ; GRIMER
db PAL_PURPLEMON ; MUK
db PAL_GREYMON ; SHELLDER
db PAL_GREYMON ; CLOYSTER
db PAL_PURPLEMON ; GASTLY
db PAL_PURPLEMON ; HAUNTER
db PAL_PURPLEMON ; GENGAR
db PAL_GREYMON ; ONIX
db PAL_YELLOWMON ; DROWZEE
db PAL_YELLOWMON ; HYPNO
db PAL_REDMON ; KRABBY
db PAL_REDMON ; KINGLER
db PAL_YELLOWMON ; VOLTORB
db PAL_YELLOWMON ; ELECTRODE
db PAL_PINKMON ; EXEGGCUTE
db PAL_GREENMON ; EXEGGUTOR
db PAL_GREYMON ; CUBONE
db PAL_GREYMON ; MAROWAK
db PAL_BROWNMON ; HITMONLEE
db PAL_BROWNMON ; HITMONCHAN
db PAL_PINKMON ; LICKITUNG
db PAL_PURPLEMON ; KOFFING
db PAL_PURPLEMON ; WEEZING
db PAL_GREYMON ; RHYHORN
db PAL_GREYMON ; RHYDON
db PAL_PINKMON ; CHANSEY
db PAL_BLUEMON ; TANGELA
db PAL_BROWNMON ; KANGASKHAN
db PAL_CYANMON ; HORSEA
db PAL_CYANMON ; SEADRA
db PAL_REDMON ; GOLDEEN
db PAL_REDMON ; SEAKING
db PAL_REDMON ; STARYU
db PAL_GREYMON ; STARMIE
db PAL_PINKMON ; MR_MIME
db PAL_GREENMON ; SCYTHER
db PAL_MEWMON ; JYNX
db PAL_YELLOWMON ; ELECTABUZZ
db PAL_REDMON ; MAGMAR
db PAL_BROWNMON ; PINSIR
db PAL_GREYMON ; TAUROS
db PAL_REDMON ; MAGIKARP
db PAL_BLUEMON ; GYARADOS
db PAL_CYANMON ; LAPRAS
db PAL_GREYMON ; DITTO
db PAL_GREYMON ; EEVEE
db PAL_CYANMON ; VAPOREON
db PAL_YELLOWMON ; JOLTEON
db PAL_REDMON ; FLAREON
db PAL_GREYMON ; PORYGON
db PAL_BLUEMON ; OMANYTE
db PAL_BLUEMON ; OMASTAR
db PAL_BROWNMON ; KABUTO
db PAL_BROWNMON ; KABUTOPS
db PAL_GREYMON ; AERODACTYL
db PAL_PINKMON ; SNORLAX
db PAL_BLUEMON ; ARTICUNO
db PAL_YELLOWMON ; ZAPDOS
db PAL_REDMON ; MOLTRES
db PAL_GREYMON ; DRATINI
db PAL_BLUEMON ; DRAGONAIR
db PAL_BROWNMON ; DRAGONITE
db PAL_MEWMON ; MEWTWO
db PAL_MEWMON ; MEW
assert_table_length NUM_POKEMON + 1
|
test/Common/Prelude.agda | larrytheliquid/agda | 1 | 11059 | <filename>test/Common/Prelude.agda
module Common.Prelude where
{-# IMPORT Common.FFI #-}
import Common.Level
data ⊥ : Set where
record ⊤ : Set where
postulate Char : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
postulate String : Set
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
{-# COMPILED_DATA Nat Common.FFI.Nat Common.FFI.Zero Common.FFI.Suc #-}
{-# COMPILED_JS Nat function (x,v) { return (x < 1? v.zero(): v.suc(x-1)); } #-}
{-# COMPILED_JS zero 0 #-}
{-# COMPILED_JS suc function (x) { return x+1; } #-}
_+_ : Nat → Nat → Nat
zero + n = n
suc m + n = suc (m + n)
{-# COMPILED_JS _+_ function (x) { return function (y) { return x+y; }; } #-}
_∸_ : Nat → Nat → Nat
m ∸ zero = m
zero ∸ _ = zero
suc m ∸ suc n = m ∸ n
{-# COMPILED_JS _∸_ function (x) { return function (y) { return Math.max(0,x-y); }; } #-}
pred : Nat → Nat
pred zero = zero
pred (suc n) = n
data List A : Set where
[] : List A
_∷_ : A → List A → List A
infixr 40 _∷_ _++_
_++_ : ∀ {A : Set} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _∷_ #-}
{-# COMPILED_DATA List [] [] (:) #-}
data Bool : Set where
true false : Bool
if_then_else_ : ∀ {A : Set} → Bool → A → A → A
if true then t else f = t
if false then t else f = f
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
{-# COMPILED_DATA Bool Bool True False #-}
{-# COMPILED_JS Bool function (x,v) { return (x? v["true"](): v["false"]()); } #-}
{-# COMPILED_JS true true #-}
{-# COMPILED_JS false false #-}
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () () #-}
postulate
IO : Set → Set
{-# COMPILED_TYPE IO IO #-}
{-# BUILTIN IO IO #-}
|
decreasoner.macosx/software/relsat-dist/gmp-3.1/mpn/alpha/ev5/rshift.asm | problem-frames/openpf | 1 | 96647 | dnl Alpha EV5 __gmpn_rshift -- Shift a number right.
dnl Copyright (C) 1994, 1995, 2000 Free Software Foundation, Inc.
dnl This file is part of the GNU MP Library.
dnl The GNU MP Library is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU Lesser General Public License as published by
dnl the Free Software Foundation; either version 2.1 of the License, or (at your
dnl option) any later version.
dnl The GNU MP Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
dnl License for more details.
dnl You should have received a copy of the GNU Lesser General Public License
dnl along with the GNU MP Library; see the file COPYING.LIB. If not, write to
dnl the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
dnl MA 02111-1307, USA.
include(`../config.m4')
dnl INPUT PARAMETERS
dnl res_ptr r16
dnl s1_ptr r17
dnl size r18
dnl cnt r19
dnl This code runs at 3.25 cycles/limb on the EV5.
ASM_START()
PROLOGUE(mpn_rshift)
ldq r4,0(r17) C load first limb
subq r31,r19,r20
subq r18,1,r18
and r18,4-1,r28 C number of limbs in first loop
sll r4,r20,r0 C compute function result
beq r28,$L0
subq r18,r28,r18
ALIGN(8)
$Loop0: ldq r3,8(r17)
addq r16,8,r16
srl r4,r19,r5
addq r17,8,r17
subq r28,1,r28
sll r3,r20,r6
bis r3,r3,r4
bis r5,r6,r8
stq r8,-8(r16)
bne r28,$Loop0
$L0: srl r4,r19,r24
beq r18,$Lend
C warm up phase 1
ldq r1,8(r17)
subq r18,4,r18
ldq r2,16(r17)
ldq r3,24(r17)
ldq r4,32(r17)
beq r18,$Lend1
C warm up phase 2
sll r1,r20,r7
srl r1,r19,r21
sll r2,r20,r8
ldq r1,40(r17)
srl r2,r19,r22
ldq r2,48(r17)
sll r3,r20,r5
bis r7,r24,r7
srl r3,r19,r23
bis r8,r21,r8
sll r4,r20,r6
ldq r3,56(r17)
srl r4,r19,r24
ldq r4,64(r17)
subq r18,4,r18
beq r18,$Lend2
ALIGN(16)
C main loop
$Loop: stq r7,0(r16)
bis r5,r22,r5
stq r8,8(r16)
bis r6,r23,r6
sll r1,r20,r7
subq r18,4,r18
srl r1,r19,r21
unop C ldq r31,-96(r17)
sll r2,r20,r8
ldq r1,72(r17)
srl r2,r19,r22
ldq r2,80(r17)
stq r5,16(r16)
bis r7,r24,r7
stq r6,24(r16)
bis r8,r21,r8
sll r3,r20,r5
unop C ldq r31,-96(r17)
srl r3,r19,r23
addq r16,32,r16
sll r4,r20,r6
ldq r3,88(r17)
srl r4,r19,r24
ldq r4,96(r17)
addq r17,32,r17
bne r18,$Loop
C cool down phase 2/1
$Lend2: stq r7,0(r16)
bis r5,r22,r5
stq r8,8(r16)
bis r6,r23,r6
sll r1,r20,r7
srl r1,r19,r21
sll r2,r20,r8
srl r2,r19,r22
stq r5,16(r16)
bis r7,r24,r7
stq r6,24(r16)
bis r8,r21,r8
sll r3,r20,r5
srl r3,r19,r23
sll r4,r20,r6
srl r4,r19,r24
C cool down phase 2/2
stq r7,32(r16)
bis r5,r22,r5
stq r8,40(r16)
bis r6,r23,r6
stq r5,48(r16)
stq r6,56(r16)
C cool down phase 2/3
stq r24,64(r16)
ret r31,(r26),1
C cool down phase 1/1
$Lend1: sll r1,r20,r7
srl r1,r19,r21
sll r2,r20,r8
srl r2,r19,r22
sll r3,r20,r5
bis r7,r24,r7
srl r3,r19,r23
bis r8,r21,r8
sll r4,r20,r6
srl r4,r19,r24
C cool down phase 1/2
stq r7,0(r16)
bis r5,r22,r5
stq r8,8(r16)
bis r6,r23,r6
stq r5,16(r16)
stq r6,24(r16)
stq r24,32(r16)
ret r31,(r26),1
$Lend: stq r24,0(r16)
ret r31,(r26),1
EPILOGUE(mpn_rshift)
ASM_END()
|
memsim-master/src/simplify_memory.adb | strenkml/EE368 | 0 | 16476 |
with Ada.Assertions; use Ada.Assertions;
with Device; use Device;
with Memory.Container; use Memory.Container;
with Memory.Transform; use Memory.Transform;
with Memory.Transform.Offset; use Memory.Transform.Offset;
with Memory.Transform.EOR; use Memory.Transform.EOR;
with Memory.Transform.Shift; use Memory.Transform.Shift;
with Memory.Transform.Flip; use Memory.Transform.Flip;
with Memory.Split; use Memory.Split;
with Memory.Join; use Memory.Join;
with Memory.SPM; use Memory.SPM;
with Util; use Util;
function Simplify_Memory(mem : Memory_Pointer) return Memory_Pointer is
function Needs_Split(ptr : Memory_Pointer;
offset : Address_Type) return Boolean is
tp : Memory_Pointer := ptr;
begin
while tp.all not in Join_Type'Class loop
if tp.all not in SPM_Type'Class then
return True;
end if;
declare
sp : constant SPM_Pointer := SPM_Pointer(tp);
size : constant Natural := Get_Size(sp.all);
begin
if Address_Type(size) > offset then
return True;
end if;
tp := Get_Memory(sp.all);
end;
end loop;
return False;
end Needs_Split;
procedure Replace_Join(bank : in Memory_Pointer;
next : in Memory_Pointer) is
last : Container_Pointer := null;
tp : Memory_Pointer := bank;
begin
while tp.all not in Join_Type'Class loop
last := Container_Pointer(tp);
tp := Get_Memory(last.all);
end loop;
Set_Memory(last.all, next);
Destroy(tp);
end Replace_Join;
function Simplify_Split(ptr : Split_Pointer) return Memory_Pointer is
sp : Split_Pointer := ptr;
b0 : Memory_Pointer := Get_Bank(sp.all, 0);
b1 : Memory_Pointer := Get_Bank(sp.all, 1);
n : Memory_Pointer := Get_Memory(sp.all);
o : constant Address_Type := Get_Offset(sp.all);
abits : constant Natural := Get_Address_Bits;
begin
b0 := Simplify_Memory(b0);
Set_Bank(sp.all, 0, b0);
b1 := Simplify_Memory(b1);
Set_Bank(sp.all, 1, b1);
n := Simplify_Memory(n);
if b0.all in Join_Type'Class and b1.all in Join_Type'Class then
-- Empty split; remove it.
Set_Memory(sp.all, null);
Destroy(Memory_Pointer(sp));
return n;
elsif b0.all in Join_Type'Class and then
not Needs_Split(b1, Address_Type'Last) then
-- Split used as an offset; convert to an offset with a bank.
declare
op : constant Offset_Pointer := Create_Offset;
jp : constant Join_Pointer := Find_Join(b1);
begin
Set_Bank(sp.all, 1, null);
Set_Memory(sp.all, null);
Set_Parent(jp.all, op);
Set_Bank(op.all, b1);
Set_Memory(op.all, n);
Destroy(Memory_Pointer(sp));
if (o and Address_Type(2) ** (abits - 1)) = 0 then
Set_Value(op.all, Long_Integer(o));
else
Set_Value(op.all, -Long_Integer(Address_Type(2) ** abits - o));
end if;
return Memory_Pointer(op);
end;
elsif b1.all in Join_Type'Class and then not Needs_Split(b0, o) then
-- Split not needed; remove it.
Set_Bank(sp.all, 0, null);
Set_Memory(sp.all, null);
Destroy(Memory_Pointer(sp));
Replace_Join(b0, n);
return b0;
else
Set_Memory(sp.all, n);
return Memory_Pointer(ptr);
end if;
end Simplify_Split;
function Is_Similar_Transform(a : Transform_Pointer;
b : Memory_Pointer) return Boolean is
begin
if a.all in Offset_Type'Class and b.all in Offset_Type'Class then
return True;
elsif a.all in EOR_Type'Class and b.all in EOR_Type'Class then
return True;
elsif a.all in Shift_Type'Class and b.all in Shift_Type'Class then
return True;
elsif a.all in Flip_Type'Class and b.all in Flip_Type'Class then
return True;
else
return False;
end if;
end Is_Similar_Transform;
function "xor"(a : Long_Integer; b : Long_Integer) return Long_Integer is
type MType is mod 2 ** Long_Integer'Size;
ma : constant MType := MType'Mod(a);
mb : constant MType := MType'Mod(b);
mr : constant MType := ma xor mb;
begin
if (mr and 2 ** (MType'Size - 1)) /= 0 then
return -Long_Integer(0 - mr);
else
return Long_Integer(mr);
end if;
end "xor";
function Combine_Transforms(a : Transform_Pointer;
b : Memory_Pointer) return Long_Integer is
va : constant Long_Integer := Get_Value(a.all);
tb : constant Transform_Pointer := Transform_Pointer(b);
vb : constant Long_Integer := Get_Value(tb.all);
begin
if a.all in Offset_Type'Class then
return va + vb;
elsif a.all in EOR_Type'Class then
return va xor vb;
elsif a.all in Shift_Type'Class then
return va + vb;
elsif a.all in Flip_Type'Class then
return 0;
else
Assert(False, "unhandled transform type in Combine_Transforms");
return 0;
end if;
end Combine_Transforms;
function Simplify_Transform(ptr : Transform_Pointer)
return Memory_Pointer is
tp : Transform_Pointer := ptr;
bank : Memory_Pointer := Get_Bank(tp.all);
next : Memory_Pointer := Get_Memory(tp.all);
begin
next := Simplify_Memory(next);
if bank /= null then
bank := Simplify_Memory(bank);
Set_Bank(tp.all, bank);
end if;
if bank = null and then Is_Similar_Transform(tp, next) then
declare
nt : Transform_Pointer := Transform_Pointer(next);
begin
Set_Value(tp.all, Combine_Transforms(tp, next));
next := Get_Memory(nt.all);
Set_Memory(nt.all, null);
Destroy(Memory_Pointer(nt));
Set_Memory(tp.all, next);
return Memory_Pointer(tp);
end;
end if;
if bank /= null and then bank.all in Join_Type'Class then
Set_Memory(tp.all, null);
Destroy(Memory_Pointer(tp));
return next;
end if;
if tp.Is_Empty then
if bank = null or else bank.all in Join_Type'Class then
Set_Memory(tp.all, null);
Destroy(Memory_Pointer(tp));
return next;
else
Set_Memory(tp.all, null);
Set_Bank(tp.all, null);
Destroy(Memory_Pointer(tp));
Replace_Join(bank, next);
return bank;
end if;
else
Set_Memory(tp.all, next);
return Memory_Pointer(ptr);
end if;
end Simplify_Transform;
begin
if mem.all in Split_Type'Class then
return Simplify_Split(Split_Pointer(mem));
elsif mem.all in Transform_Type'Class then
return Simplify_Transform(Transform_Pointer(mem));
elsif mem.all in Container_Type'Class then
declare
cp : constant Container_Pointer := Container_Pointer(mem);
n : Memory_Pointer := Get_Memory(cp.all);
begin
n := Simplify_Memory(n);
Set_Memory(cp.all, n);
return mem;
end;
else
return mem;
end if;
end Simplify_Memory;
|
src/asis/asis-clauses.adb | My-Colaborations/dynamo | 15 | 30303 | ------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . C L A U S E S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2012, Free Software Foundation, Inc. --
-- --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adac<EMAIL>.com). --
-- --
------------------------------------------------------------------------------
with Asis.Errors; use Asis.Errors;
with Asis.Exceptions; use Asis.Exceptions;
with Asis.Set_Get; use Asis.Set_Get;
with A4G.Mapping; use A4G.Mapping;
with A4G.Vcheck; use A4G.Vcheck;
with Atree; use Atree;
with Namet; use Namet;
with Nlists; use Nlists;
with Sinfo; use Sinfo;
with Snames; use Snames;
package body Asis.Clauses is
Package_Name : constant String := "Asis.Clauses.";
------------------
-- Clause_Names --
------------------
function Clause_Names (Clause : Asis.Element) return Asis.Element_List is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Result_List : List_Id;
Result_Len : Natural := 1;
Withed_Uname : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Clause_Names");
if not (Arg_Kind = A_Use_Package_Clause or else
Arg_Kind = A_Use_Type_Clause or else
Arg_Kind = A_Use_All_Type_Clause or else -- Ada 2012
Arg_Kind = A_With_Clause)
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Clause_Names",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
if Arg_Kind = A_With_Clause then
-- first, computing the number of names listed in the argument
-- with clause
-- Note that we should skip implicit with cleause that may be added
-- by front-end
while not (Comes_From_Source (Arg_Node)
and then
Last_Name (Arg_Node))
loop
if Comes_From_Source (Arg_Node) then
Result_Len := Result_Len + 1;
end if;
Arg_Node := Next (Arg_Node);
end loop;
declare
Result_List : Asis.Element_List (1 .. Result_Len);
begin
Arg_Node := Node (Clause);
for I in 1 .. Result_Len loop
Withed_Uname := Sinfo.Name (Arg_Node);
Result_List (I) := Node_To_Element_New
(Starting_Element => Clause,
Node => Withed_Uname);
Arg_Node := Next (Arg_Node);
while Present (Arg_Node)
and then
not Comes_From_Source (Arg_Node)
loop
Arg_Node := Next (Arg_Node);
end loop;
end loop;
return Result_List;
end;
else
if Nkind (Arg_Node) = N_Use_Package_Clause then
Result_List := Names (Arg_Node);
else
Result_List := Subtype_Marks (Arg_Node);
end if;
return N_To_E_List_New (List => Result_List,
Starting_Element => Clause);
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Clause_Names",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Clause_Names",
Ex => Ex,
Arg_Element => Clause);
end Clause_Names;
-------------------------------
-- Component_Clause_Position --
-------------------------------
function Component_Clause_Position
(Clause : Asis.Component_Clause)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Component_Clause_Position");
if not (Arg_Kind = A_Component_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Component_Clause_Position",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
return Node_To_Element_New (Node => Position (Arg_Node),
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Component_Clause_Position",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Clause_Position",
Ex => Ex,
Arg_Element => Clause);
end Component_Clause_Position;
----------------------------
-- Component_Clause_Range --
----------------------------
function Component_Clause_Range
(Clause : Asis.Component_Clause)
return Asis.Discrete_Range
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Component_Clause_Range");
if not (Arg_Kind = A_Component_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Component_Clause_Range",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
return Node_To_Element_New
(Node => Arg_Node,
Internal_Kind => A_Discrete_Simple_Expression_Range,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Component_Clause_Range",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Clause_Range",
Ex => Ex,
Arg_Element => Clause);
end Component_Clause_Range;
-----------------------
-- Component_Clauses --
-----------------------
function Component_Clauses
(Clause : Asis.Representation_Clause;
Include_Pragmas : Boolean := False)
return Asis.Component_Clause_List
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Component_Clauses");
if not (Arg_Kind = A_Record_Representation_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Component_Clauses",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
return N_To_E_List_New
(List => Component_Clauses (Arg_Node),
Include_Pragmas => Include_Pragmas,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Component_Clauses",
Argument => Clause,
Bool_Par => Include_Pragmas);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Component_Clauses",
Ex => Ex,
Arg_Element => Clause,
Bool_Par_ON => Include_Pragmas);
end Component_Clauses;
---------------------------
-- Mod_Clause_Expression --
---------------------------
function Mod_Clause_Expression
(Clause : Asis.Representation_Clause)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Mod_Clause_Node : Node_Id;
begin
Check_Validity (Clause, Package_Name & "Mod_Clause_Expression");
if not (Arg_Kind = A_Record_Representation_Clause) then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Mod_Clause_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
Mod_Clause_Node := Next (Arg_Node);
if Nkind (Mod_Clause_Node) = N_Attribute_Definition_Clause and then
From_At_Mod (Mod_Clause_Node)
then
Mod_Clause_Node := Sinfo.Expression (Mod_Clause_Node);
else
Mod_Clause_Node := Empty;
end if;
if No (Mod_Clause_Node) then
return Asis.Nil_Element;
else
return Node_To_Element_New
(Node => Mod_Clause_Node,
Starting_Element => Clause);
end if;
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Mod_Clause_Expression",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Mod_Clause_Expression",
Ex => Ex,
Arg_Element => Clause);
end Mod_Clause_Expression;
--------------------------------------
-- Representation_Clause_Expression --
--------------------------------------
function Representation_Clause_Expression
(Clause : Asis.Representation_Clause)
return Asis.Expression
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Kind : Internal_Element_Kinds := Not_An_Element;
begin
Check_Validity (Clause,
Package_Name & "Representation_Clause_Expression");
if not (Arg_Kind = An_Attribute_Definition_Clause or else
Arg_Kind = An_Enumeration_Representation_Clause or else
Arg_Kind = An_At_Clause)
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Representation_Clause_Expression",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
if Nkind (Arg_Node) = N_Enumeration_Representation_Clause then
Result_Node := Array_Aggregate (Arg_Node);
if Present (Expressions (Result_Node)) then
Result_Kind := A_Positional_Array_Aggregate;
else
Result_Kind := A_Named_Array_Aggregate;
end if;
else
Result_Node := Sinfo.Expression (Arg_Node);
end if;
return Node_To_Element_New (Node => Result_Node,
Internal_Kind => Result_Kind,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Representation_Clause_Expression",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Representation_Clause_Expression",
Ex => Ex,
Arg_Element => Clause);
end Representation_Clause_Expression;
--------------------------------
-- Representation_Clause_Name --
--------------------------------
function Representation_Clause_Name
(Clause : Asis.Clause)
return Asis.Name
is
Arg_Kind : constant Internal_Element_Kinds := Int_Kind (Clause);
Arg_Node : Node_Id;
Result_Node : Node_Id;
Result_Element : Element;
Result_Kind : Internal_Element_Kinds := Not_An_Element;
Attr_Des : Name_Id;
-- needed for special processing of attribute definition clause
begin
Check_Validity (Clause, Package_Name & "Representation_Clause_Name");
if not (Arg_Kind = An_Attribute_Definition_Clause or else
Arg_Kind = An_Enumeration_Representation_Clause or else
Arg_Kind = A_Record_Representation_Clause or else
Arg_Kind = An_At_Clause or else
Arg_Kind = A_Component_Clause)
then
Raise_ASIS_Inappropriate_Element
(Package_Name & "Representation_Clause_Name",
Wrong_Kind => Arg_Kind);
end if;
Arg_Node := Node (Clause);
if Nkind (Arg_Node) = N_Attribute_Definition_Clause then
-- for An_Attribute_Definition_Clause argument we have to return
-- as the result the Element of An_Attribute_Reference kind.
-- The tree does not contain the structures for attribute reference
-- in this case (and it should not, because, according to RM 95,
-- there is no attribute reference in the syntax structure of
-- an attribute definition clause, so we have to "emulate"
-- the result Elemet of An_Attribute_Reference kind on the base
-- of the same node
-- first, we have to define the exact kind of the "artificial"
-- attribute reference to be returned
Attr_Des := Chars (Arg_Node);
case Attr_Des is
when Name_Address =>
Result_Kind := An_Address_Attribute;
when Name_Alignment =>
Result_Kind := An_Alignment_Attribute;
when Name_Bit_Order =>
Result_Kind := A_Bit_Order_Attribute;
when Name_Component_Size =>
Result_Kind := A_Component_Size_Attribute;
when Name_External_Tag =>
Result_Kind := An_External_Tag_Attribute;
when Name_Input =>
Result_Kind := An_Input_Attribute;
when Name_Machine_Radix =>
Result_Kind := A_Machine_Radix_Attribute;
when Name_Output =>
Result_Kind := An_Output_Attribute;
when Name_Read =>
Result_Kind := A_Read_Attribute;
when Name_Size =>
Result_Kind := A_Size_Attribute;
when Name_Small =>
Result_Kind := A_Small_Attribute;
when Name_Storage_Size =>
Result_Kind := A_Storage_Size_Attribute;
when Name_Storage_Pool =>
Result_Kind := A_Storage_Pool_Attribute;
when Name_Write =>
Result_Kind := A_Write_Attribute;
when others =>
-- "others" means Name_Object_Size and Name_Value_Size
Result_Kind := An_Implementation_Defined_Attribute;
end case;
Result_Element := Clause;
Set_Int_Kind (Result_Element, Result_Kind);
return Result_Element;
elsif Nkind (Arg_Node) = N_Component_Clause then
Result_Node := Component_Name (Arg_Node);
else
Result_Node := Sinfo.Identifier (Arg_Node);
end if;
return Node_To_Element_New (Node => Result_Node,
Starting_Element => Clause);
exception
when ASIS_Inappropriate_Element =>
raise;
when ASIS_Failed =>
if Status_Indicator = Unhandled_Exception_Error then
Add_Call_Information
(Outer_Call => Package_Name & "Representation_Clause_Name",
Argument => Clause);
end if;
raise;
when Ex : others =>
Report_ASIS_Bug
(Query_Name => Package_Name & "Representation_Clause_Name",
Ex => Ex,
Arg_Element => Clause);
end Representation_Clause_Name;
end Asis.Clauses;
|
src/main/antlr4/liquid/parser/v4/LiquidLexer.g4 | jvanzyl/Liqp | 104 | 5724 | lexer grammar LiquidLexer;
@lexer::members {
private boolean stripSpacesAroundTags = false;
private boolean stripSingleLine = false;
private java.util.LinkedList<Token> tokens = new java.util.LinkedList<>();
public LiquidLexer(CharStream charStream, boolean stripSpacesAroundTags) {
this(charStream, stripSpacesAroundTags, false);
}
public LiquidLexer(CharStream charStream, boolean stripSpacesAroundTags, boolean stripSingleLine) {
this(charStream);
this.stripSpacesAroundTags = stripSpacesAroundTags;
this.stripSingleLine = stripSingleLine;
}
@Override
public void emit(Token t) {
super.setToken(t);
tokens.offer(t);
}
@Override
public Token nextToken() {
Token next = super.nextToken();
return tokens.isEmpty() ? next : tokens.poll();
}
private void handleIdChain(String chain) {
String[] ids = chain.split("\\.");
int start = this.getCharIndex() - chain.getBytes().length;
for (int i = 0; i < ids.length; i++) {
int stop = start + ids[i].getBytes().length - 1;
this.emit(new CommonToken(this._tokenFactorySourcePair, Id, DEFAULT_TOKEN_CHANNEL, start, stop));
if (i < ids.length - 1) {
stop += 1;
this.emit(new CommonToken(this._tokenFactorySourcePair, Dot, DEFAULT_TOKEN_CHANNEL, stop, stop));
}
start = stop + 1;
}
}
}
OutStart
: ( SpaceOrTab* '{{' {stripSpacesAroundTags && stripSingleLine}?
| WhitespaceChar* '{{' {stripSpacesAroundTags && !stripSingleLine}?
| WhitespaceChar* '{{-'
| '{{'
) -> pushMode(IN_TAG)
;
TagStart
: ( SpaceOrTab* '{%' {stripSpacesAroundTags && stripSingleLine}?
| WhitespaceChar* '{%' {stripSpacesAroundTags && !stripSingleLine}?
| WhitespaceChar* '{%-'
| '{%'
) -> pushMode(IN_TAG)
;
Other
: .
;
fragment SStr : '\'' ~'\''* '\'';
fragment DStr : '"' ~'"'* '"';
fragment WhitespaceChar : [ \t\r\n];
fragment SpaceOrTab : [ \t];
fragment LineBreak : '\r'? '\n' | '\r';
fragment Letter : [a-zA-Z];
fragment Digit : [0-9];
mode IN_TAG;
OutStart2 : '{{' -> pushMode(IN_TAG);
TagStart2 : '{%' -> pushMode(IN_TAG);
OutEnd
: ( '}}' SpaceOrTab* LineBreak? {stripSpacesAroundTags && stripSingleLine}?
| '}}' WhitespaceChar* {stripSpacesAroundTags && !stripSingleLine}?
| '-}}' WhitespaceChar*
| '}}'
) -> popMode
;
TagEnd
: ( '%}' SpaceOrTab* LineBreak? {stripSpacesAroundTags && stripSingleLine}?
| '%}' WhitespaceChar* {stripSpacesAroundTags && !stripSingleLine}?
| '-%}' WhitespaceChar*
| '%}'
) -> popMode
;
Str : SStr | DStr;
DotDot : '..';
Dot : '.';
NEq : '!=' | '<>';
Eq : '==';
EqSign : '=';
GtEq : '>=';
Gt : '>';
LtEq : '<=';
Lt : '<';
Minus : '-';
Pipe : '|';
Col : ':';
Comma : ',';
OPar : '(';
CPar : ')';
OBr : '[';
CBr : ']';
QMark : '?';
PathSep : [/\\];
DoubleNum
: '-'? Digit+ '.' Digit+
| '-'? Digit+ '.' {_input.LA(1) != '.'}?
;
LongNum : '-'? Digit+;
WS : WhitespaceChar+ -> channel(HIDDEN);
CaptureStart : 'capture';
CaptureEnd : 'endcapture';
CommentStart : 'comment';
CommentEnd : 'endcomment';
RawStart : 'raw' WhitespaceChar* '%}' -> pushMode(IN_RAW);
IfStart : 'if';
Elsif : 'elsif';
IfEnd : 'endif';
UnlessStart : 'unless';
UnlessEnd : 'endunless';
Else : 'else';
Contains : 'contains';
CaseStart : 'case';
CaseEnd : 'endcase';
When : 'when';
Cycle : 'cycle';
ForStart : 'for';
ForEnd : 'endfor';
In : 'in';
And : 'and';
Or : 'or';
TableStart : 'tablerow';
TableEnd : 'endtablerow';
Assign : 'assign';
True : 'true';
False : 'false';
Nil : 'nil' | 'null';
Include : 'include';
With : 'with';
Offset : 'offset';
Continue : 'continue';
Reversed : 'reversed';
Empty : 'empty';
Blank : 'blank';
EndId : 'end' Id;
IdChain
: [a-zA-Z_] [a-zA-Z_0-9]* ( '.' [a-zA-Z_0-9]+ )+ {handleIdChain(getText());} -> skip
;
Id : ( Letter | '_' ) (Letter | '_' | '-' | Digit)*;
mode IN_RAW;
RawEnd : '{%' WhitespaceChar* 'endraw' -> popMode;
OtherRaw : . ;
|
gcc-gcc-7_3_0-release/gcc/testsuite/ada/acats/tests/c3/c38005a.ada | best08618/asylo | 7 | 7728 | -- C38005A.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- CHECK THAT ALL (UNINITIALIZED) ACCESS OBJECTS ARE INITIALIZED
-- TO NULL BY DEFAULT. VARIABLES, ARRAYS, RECORDS, ARRAYS OF RECORDS,
-- ARRAYS OF ARRAYS, RECORDS WITH ARRAYS AND RECORD COMPONENTS
-- ARE ALL CHECKED.
-- FUNCTION RESULTS (I.E. RETURNED FROM IMPLICIT FUNCTION RETURN)
-- ARE NOT CHECKED.
-- DAT 3/6/81
-- VKG 1/5/83
-- SPS 2/17/83
WITH REPORT; USE REPORT;
PROCEDURE C38005A IS
TYPE REC;
TYPE ACC_REC IS ACCESS REC;
TYPE VECTOR IS ARRAY ( NATURAL RANGE <> ) OF ACC_REC;
TYPE REC IS RECORD
VECT : VECTOR (3 .. 5);
END RECORD;
TYPE ACC_VECT IS ACCESS VECTOR;
TYPE ARR_REC IS ARRAY (1 .. 2) OF REC;
TYPE REC2;
TYPE ACC_REC2 IS ACCESS REC2;
TYPE REC2 IS RECORD
C1 : ACC_REC;
C2 : ACC_VECT;
C3 : ARR_REC;
C4 : REC;
C5 : ACC_REC2;
END RECORD;
N_REC : REC;
N_ACC_REC : ACC_REC;
N_VEC : VECTOR (3 .. IDENT_INT (5));
N_ACC_VECT : ACC_VECT;
N_ARR_REC : ARR_REC;
N_REC2 : REC2;
N_ACC_REC2 : ACC_REC2;
N_ARR : ARRAY (1..2) OF VECTOR (1..2);
Q : REC2 :=
(C1 => NEW REC,
C2 => NEW VECTOR'(NEW REC, NEW REC'(N_REC)),
C3 => (1 | 2 => (VECT=>(3|4=> NEW REC,
5=>N_ACC_REC)
)),
C4 => N_REC2.C4,
C5 => NEW REC2'(N_REC2));
BEGIN
TEST ("C38005A", "DEFAULT VALUE FOR ACCESS OBJECTS IS NULL");
IF N_REC /= REC'(VECT => (3..5 => NULL))
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 1");
END IF;
IF N_ACC_REC /= NULL
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 2");
END IF;
IF N_VEC /= N_REC.VECT
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 3");
END IF;
IF N_ARR /= ((NULL, NULL), (NULL, NULL))
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 4");
END IF;
IF N_ACC_VECT /= NULL
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 5");
END IF;
IF N_ARR_REC /= (N_REC, N_REC)
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 6");
END IF;
IF N_REC2 /= (NULL, NULL, N_ARR_REC, N_REC, NULL)
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 7");
END IF;
IF N_ACC_REC2 /= NULL
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 8");
END IF;
IF Q /= (Q.C1, Q.C2, (Q.C3(1), Q.C3(2)), N_REC, Q.C5)
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 9");
END IF;
IF Q.C1.ALL /= N_REC
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 10");
END IF;
IF Q.C2.ALL(0).ALL /= N_REC
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 11");
END IF;
IF Q.C2(1).VECT /= N_VEC
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 12");
END IF;
IF Q.C3(2).VECT /= (3 => Q.C3(2).VECT(3),
4 => Q.C3(2).VECT(4),
5=>NULL)
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 13");
END IF;
IF Q.C3(2).VECT(3).ALL /= N_REC
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 14");
END IF;
IF Q.C5.ALL /= N_REC2
THEN
FAILED ("INCORRECT ACCESS TYPE INITIALIZATION - 15");
END IF;
DECLARE
PROCEDURE T (R : OUT REC2) IS
BEGIN
NULL;
END T;
BEGIN
N_REC2 := Q;
T(Q);
IF Q /= N_REC2 THEN
FAILED ("INCORRECT OUT PARM INIT 2");
END IF;
END;
RESULT;
END C38005A;
|
Task/Execute-a-system-command/Ada/execute-a-system-command-3.ada | LaudateCorpus1/RosettaCodeData | 1 | 9901 | <filename>Task/Execute-a-system-command/Ada/execute-a-system-command-3.ada
with Ada.Text_IO; use Ada.Text_IO;
with System.OS_Lib; use System.OS_Lib;
procedure Execute_Synchronously is
Result : Integer;
Arguments : Argument_List :=
( 1=> new String'("cmd.exe"),
2=> new String'("/C dir c:\temp\*.adb")
);
begin
Spawn
( Program_Name => "cmd.exe",
Args => Arguments,
Output_File_Descriptor => Standout,
Return_Code => Result
);
for Index in Arguments'Range loop
Free (Arguments (Index)); -- Free the argument list
end loop;
end Execute_Synchronously;
|
Transynther/x86/_processed/NC/_zr_/i7-8650U_0xd2.log_12600_903.asm | ljhsiun2/medusa | 9 | 105557 | .global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0x97f, %rsi
lea addresses_normal_ht+0x147f, %rdi
nop
xor %r11, %r11
mov $82, %rcx
rep movsw
cmp %r14, %r14
lea addresses_normal_ht+0x1e37f, %rbx
nop
nop
nop
sub %rdi, %rdi
mov $0x6162636465666768, %rsi
movq %rsi, (%rbx)
nop
sub $39691, %rdi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r13
push %r15
push %r8
push %r9
push %rax
push %rbx
// Store
lea addresses_RW+0xca1f, %rax
nop
nop
add $11078, %r8
mov $0x5152535455565758, %r10
movq %r10, %xmm0
vmovups %ymm0, (%rax)
nop
nop
nop
nop
nop
and %r8, %r8
// Store
lea addresses_normal+0x937f, %r10
sub %r15, %r15
mov $0x5152535455565758, %r9
movq %r9, %xmm3
movups %xmm3, (%r10)
nop
xor %r8, %r8
// Faulty Load
mov $0x42b3db000000017f, %rax
clflush (%rax)
nop
sub %r9, %r9
mov (%rax), %r15d
lea oracles, %r9
and $0xff, %r15
shlq $12, %r15
mov (%r9,%r15,1), %r15
pop %rbx
pop %rax
pop %r9
pop %r8
pop %r15
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False, 'NT': True, 'congruent': 9, 'same': False}}
{'00': 12600}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
Transynther/x86/_processed/AVXALIGN/_st_zr_4k_sm_/i9-9900K_12_0xca_notsx.log_21829_1920.asm | ljhsiun2/medusa | 9 | 102253 | <gh_stars>1-10
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r13
push %r9
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0xc1f5, %rsi
lea addresses_D_ht+0x14b17, %rdi
nop
nop
cmp $42632, %r10
mov $66, %rcx
rep movsl
and $25704, %r13
lea addresses_WT_ht+0x117f5, %r11
nop
nop
nop
sub %r9, %r9
mov $0x6162636465666768, %rcx
movq %rcx, (%r11)
nop
add %r10, %r10
lea addresses_normal_ht+0x33f5, %r9
nop
nop
nop
add %rdi, %rdi
mov $0x6162636465666768, %r10
movq %r10, %xmm5
movups %xmm5, (%r9)
nop
nop
nop
add $12011, %r11
lea addresses_WC_ht+0x1c8d1, %rsi
lea addresses_WC_ht+0xa7f5, %rdi
nop
xor %r11, %r11
mov $103, %rcx
rep movsl
nop
inc %r13
lea addresses_UC_ht+0xebf5, %rsi
nop
nop
xor $31252, %rcx
movups (%rsi), %xmm1
vpextrq $1, %xmm1, %r9
dec %rdi
lea addresses_WC_ht+0x1d78d, %r13
nop
nop
nop
nop
nop
cmp %rcx, %rcx
mov $0x6162636465666768, %r9
movq %r9, (%r13)
inc %rdi
lea addresses_A_ht+0x7ff5, %rsi
lea addresses_A_ht+0x8fb, %rdi
nop
nop
nop
nop
nop
sub %rdx, %rdx
mov $56, %rcx
rep movsl
nop
nop
nop
nop
nop
mfence
lea addresses_WC_ht+0x8ada, %r9
sub $12825, %rdi
and $0xffffffffffffffc0, %r9
movaps (%r9), %xmm1
vpextrq $0, %xmm1, %r11
and $7839, %r10
lea addresses_WT_ht+0xba8e, %rsi
lea addresses_UC_ht+0x81f5, %rdi
nop
nop
nop
nop
add %r13, %r13
mov $109, %rcx
rep movsb
nop
nop
nop
nop
cmp $19059, %r10
lea addresses_WC_ht+0xf6f5, %rcx
nop
sub %r13, %r13
movups (%rcx), %xmm4
vpextrq $1, %xmm4, %rdx
nop
nop
nop
nop
nop
xor $33632, %rsi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r9
pop %r13
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r15
push %rax
push %rcx
push %rdx
push %rsi
// Load
lea addresses_US+0x1b5f5, %rsi
nop
nop
nop
cmp %r13, %r13
mov (%rsi), %eax
nop
cmp %r14, %r14
// Store
lea addresses_RW+0x33dd, %rax
nop
nop
nop
nop
nop
cmp $29296, %rcx
movb $0x51, (%rax)
nop
inc %rdx
// Load
lea addresses_normal+0x8875, %rcx
nop
nop
nop
nop
and $15573, %r15
mov (%rcx), %esi
nop
nop
nop
nop
nop
and $23380, %r14
// Store
mov $0x57f42b00000009f5, %r13
nop
cmp $12132, %rcx
movl $0x51525354, (%r13)
nop
nop
nop
dec %r14
// Store
lea addresses_US+0x14875, %rsi
nop
nop
nop
nop
sub $27980, %r14
mov $0x5152535455565758, %rax
movq %rax, (%rsi)
nop
nop
nop
nop
xor $35394, %r13
// Store
lea addresses_D+0xaff5, %rdx
nop
add %r14, %r14
mov $0x5152535455565758, %rax
movq %rax, (%rdx)
nop
nop
nop
and $63572, %r14
// Store
mov $0x7f5, %rcx
clflush (%rcx)
xor $25457, %r15
movl $0x51525354, (%rcx)
nop
nop
nop
and %rsi, %rsi
// Faulty Load
mov $0x7f5, %r13
nop
cmp %r14, %r14
movaps (%r13), %xmm2
vpextrq $0, %xmm2, %rsi
lea oracles, %r14
and $0xff, %rsi
shlq $12, %rsi
mov (%r14,%rsi,1), %rsi
pop %rsi
pop %rdx
pop %rcx
pop %rax
pop %r15
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_P', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 6}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_RW', 'NT': False, 'AVXalign': True, 'size': 1, 'congruent': 1}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 4}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_NC', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 6}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_D', 'NT': True, 'AVXalign': True, 'size': 8, 'congruent': 11}}
{'OP': 'STOR', 'dst': {'same': True, 'type': 'addresses_P', 'NT': True, 'AVXalign': True, 'size': 4, 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_P', 'NT': False, 'AVXalign': True, 'size': 16, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_WT_ht'}, 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_D_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 10}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 11, 'type': 'addresses_WC_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 2}}
{'OP': 'REPM', 'src': {'same': True, 'congruent': 10, 'type': 'addresses_A_ht'}, 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_A_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': True, 'size': 16, 'congruent': 0}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_WT_ht'}, 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_UC_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 5}}
{'00': 263, '54': 21566}
54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 00 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54
*/
|
sharding-core/src/main/antlr4/imports/PostgreSQLDropIndex.g4 | chuanandongxu/sharding-sphere | 0 | 5886 | <filename>sharding-core/src/main/antlr4/imports/PostgreSQLDropIndex.g4
grammar PostgreSQLDropIndex;
import PostgreSQLKeyword, Keyword, PostgreSQLBase, BaseRule;
dropIndex
: DROP INDEX (CONCURRENTLY)? (IF EXISTS)? indexNames
; |
msp430-gcc-tics/msp430-gcc-7.3.1.24-source-full/gcc/gcc/testsuite/gnat.dg/opt29.ads | TUDSSL/TICS | 7 | 3992 | <gh_stars>1-10
package Opt29 is
type Word is mod 2**16;
type PID is record
W1, W2: Word;
end record;
type Root1 is tagged record
Id: PID;
end record;
type Root1_Ptr is access all Root1'Class;
type Root2 is tagged null record;
type Root2_Ptr is access all Root2'class;
type Derived2 is new Root2 with record
Id: PID;
end record;
type Rec is record
F1: Root1_Ptr;
F2: Root2_Ptr;
end record;
procedure Proc (T : Rec);
end Opt29;
|
src/main/antlr/net/alexjeffery/preppy/parser/Preppy.g4 | alexj136/preppy | 0 | 2276 | <reponame>alexj136/preppy<filename>src/main/antlr/net/alexjeffery/preppy/parser/Preppy.g4
grammar Preppy;
@parser::header {
import net.alexjeffery.preppy.syntax.Declaration;
import net.alexjeffery.preppy.syntax.Statement;
import net.alexjeffery.preppy.syntax.Expression;
}
declarations returns [List<Declaration> out]
: declaration ds=declarations { $out = $ds.out; $out.add(0, $declaration.out); }
| declaration EOF { $out = new ArrayList<>(); $out.add($declaration.out); }
;
declaration returns [Declaration out]
: KwInt Ident '(' params ')' statement { $out = new Declaration($Ident.text, $params.out, $statement.out); }
;
params returns [List<String> out]
: /* empty */ { $out = new ArrayList<>(); }
| params_ne { $out = $params_ne.out; }
;
params_ne returns [List<String> out]
: KwInt Ident ',' params { $out = $params.out; $out.add(0, $Ident.text); }
| KwInt Ident { $out = new ArrayList<>(); $out.add($Ident.text); }
;
statement returns [Statement out]
: '{' statements ';' '}' { $out = new Statement.Block($statements.out); }
| Ident '=' expression { $out = new Statement.Assignment($Ident.text, $expression.out); }
| KwWhile '(' expression ')' statement { $out = new Statement.While($expression.out, $statement.out); }
| KwReturn expression { $out = new Statement.Return($expression.out); }
| KwIf '(' expression ')' t=statement KwElse f=statement { $out = new Statement.Cond($expression.out, $t.out, $f.out); }
;
statements returns [List<Statement> out]
: statement ';' statements { $out = $statements.out; $out.add(0, $statement.out); }
| statement { $out = new ArrayList<>(); $out.add($statement.out); }
;
expression returns [Expression out]
: Digit { $out = new Expression.IntLiteral(Integer.parseInt($Digit.text)); }
| Ident { $out = new Expression.Variable($Ident.text); }
| l=expression binop r=expression { $out = new Expression.BinOp($l.out, $r.out, $binop.out); }
| Ident '(' args ')' { $out = new Expression.Call($Ident.text, $args.out); }
;
args returns [List<Expression> out]
: /* empty */ { $out = new ArrayList<>(); }
| args_ne { $out = $args_ne.out; }
;
args_ne returns [List<Expression> out]
: expression ',' args { $out = $args.out; $out.add(0, $expression.out); }
| expression { $out = new ArrayList<>(); $out.add($expression.out); }
;
binop returns [Expression.BinOp.Type out]
: '+' { $out = Expression.BinOp.Type.ADD; }
| '-' { $out = Expression.BinOp.Type.SUB; }
| '*' { $out = Expression.BinOp.Type.MUL; }
| '/' { $out = Expression.BinOp.Type.DIV; }
| '%' { $out = Expression.BinOp.Type.MOD; }
| '==' { $out = Expression.BinOp.Type.EQ; }
;
KwIf : 'if';
KwElse : 'else';
KwInt : 'int' ;
KwWhile : 'while' ;
KwReturn : 'return' ;
Lower : ('a'..'z') ;
Upper : ('A'..'Z') ;
Digit : ('0'..'9') ;
Alpha : Lower | Upper ;
AlNum : Alpha | Digit ;
Ident : (AlNum | '_')+ ;
Whitespace : [ \t\r\n]+ -> skip ;
|
programs/oeis/078/A078609.asm | karttu/loda | 1 | 101331 | <reponame>karttu/loda<gh_stars>1-10
; A078609: Least positive integer x such that 2*x^n>(x+3)^n.
; 8,12,16,21,25,29,34,38,42,47,51,55,60,64,68,73,77,81,86,90,94,99,103,107,112,116,120,125,129,133,138,142,146,150,155,159,163,168,172,176,181,185,189,194,198,202,207,211,215,220,224,228,233,237,241,246,250
mov $2,$0
add $0,4
mul $0,18
sub $0,7
div $0,55
mov $1,1
mul $1,$0
add $1,7
mov $3,$2
mul $3,4
add $1,$3
|
target/cos_117/disasm/iop_overlay1/D4ECC.asm | jrrk2/cray-sim | 49 | 81483 | 0x0000 (0x000000) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0001 (0x000002) 0x291B- f:00024 d: 283 | OR[283] = A
0x0002 (0x000004) 0x1010- f:00010 d: 16 | A = 16 (0x0010)
0x0003 (0x000006) 0x291C- f:00024 d: 284 | OR[284] = A
0x0004 (0x000008) 0x2119- f:00020 d: 281 | A = OR[281]
0x0005 (0x00000A) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008)
0x0006 (0x00000C) 0x2913- f:00024 d: 275 | OR[275] = A
0x0007 (0x00000E) 0x2113- f:00020 d: 275 | A = OR[275]
0x0008 (0x000010) 0x1408- f:00012 d: 8 | A = A + 8 (0x0008)
0x0009 (0x000012) 0x2914- f:00024 d: 276 | OR[276] = A
0x000A (0x000014) 0x2113- f:00020 d: 275 | A = OR[275]
0x000B (0x000016) 0x2714- f:00023 d: 276 | A = A - OR[276]
0x000C (0x000018) 0x8405- f:00102 d: 5 | P = P + 5 (0x0011), A = 0
0x000D (0x00001A) 0x3113- f:00030 d: 275 | A = (OR[275])
0x000E (0x00001C) 0x866C- f:00103 d: 108 | P = P + 108 (0x007A), A # 0
0x000F (0x00001E) 0x2D13- f:00026 d: 275 | OR[275] = OR[275] + 1
0x0010 (0x000020) 0x7206- f:00071 d: 6 | P = P - 6 (0x000A)
0x0011 (0x000022) 0x211C- f:00020 d: 284 | A = OR[284]
0x0012 (0x000024) 0x845D- f:00102 d: 93 | P = P + 93 (0x006F), A = 0
0x0013 (0x000026) 0x211C- f:00020 d: 284 | A = OR[284]
0x0014 (0x000028) 0x1604- f:00013 d: 4 | A = A - 4 (0x0004)
0x0015 (0x00002A) 0x291C- f:00024 d: 284 | OR[284] = A
0x0016 (0x00002C) 0x3119- f:00030 d: 281 | A = (OR[281])
0x0017 (0x00002E) 0x291A- f:00024 d: 282 | OR[282] = A
0x0018 (0x000030) 0x8454- f:00102 d: 84 | P = P + 84 (0x006C), A = 0
0x0019 (0x000032) 0x1005- f:00010 d: 5 | A = 5 (0x0005)
0x001A (0x000034) 0x2913- f:00024 d: 275 | OR[275] = A
0x001B (0x000036) 0x2113- f:00020 d: 275 | A = OR[275]
0x001C (0x000038) 0x840B- f:00102 d: 11 | P = P + 11 (0x0027), A = 0
0x001D (0x00003A) 0x211A- f:00020 d: 282 | A = OR[282]
0x001E (0x00003C) 0x0C01- f:00006 d: 1 | A = A >> 1 (0x0001)
0x001F (0x00003E) 0x291A- f:00024 d: 282 | OR[282] = A
0x0020 (0x000040) 0x8202- f:00101 d: 2 | P = P + 2 (0x0022), C = 1
0x0021 (0x000042) 0x7004- f:00070 d: 4 | P = P + 4 (0x0025)
0x0022 (0x000044) 0x211A- f:00020 d: 282 | A = OR[282]
0x0023 (0x000046) 0x1640- f:00013 d: 64 | A = A - 64 (0x0040)
0x0024 (0x000048) 0x8256- f:00101 d: 86 | P = P + 86 (0x007A), C = 1
0x0025 (0x00004A) 0x2F13- f:00027 d: 275 | OR[275] = OR[275] - 1
0x0026 (0x00004C) 0x720B- f:00071 d: 11 | P = P - 11 (0x001B)
0x0027 (0x00004E) 0x3119- f:00030 d: 281 | A = (OR[281])
0x0028 (0x000050) 0x291A- f:00024 d: 282 | OR[282] = A
0x0029 (0x000052) 0x2119- f:00020 d: 281 | A = OR[281]
0x002A (0x000054) 0x1401- f:00012 d: 1 | A = A + 1 (0x0001)
0x002B (0x000056) 0x2908- f:00024 d: 264 | OR[264] = A
0x002C (0x000058) 0x3108- f:00030 d: 264 | A = (OR[264])
0x002D (0x00005A) 0x291D- f:00024 d: 285 | OR[285] = A
0x002E (0x00005C) 0x211D- f:00020 d: 285 | A = OR[285]
0x002F (0x00005E) 0x1E00-0x0800 f:00017 d: 0 | A = A - 2048 (0x0800)
0x0031 (0x000062) 0x8002- f:00100 d: 2 | P = P + 2 (0x0033), C = 0
0x0032 (0x000064) 0x7032- f:00070 d: 50 | P = P + 50 (0x0064)
0x0033 (0x000066) 0x100C- f:00010 d: 12 | A = 12 (0x000C)
0x0034 (0x000068) 0x2913- f:00024 d: 275 | OR[275] = A
0x0035 (0x00006A) 0x2118- f:00020 d: 280 | A = OR[280]
0x0036 (0x00006C) 0x251D- f:00022 d: 285 | A = A + OR[285]
0x0037 (0x00006E) 0x2914- f:00024 d: 276 | OR[276] = A
0x0038 (0x000070) 0x2113- f:00020 d: 275 | A = OR[275]
0x0039 (0x000072) 0x842A- f:00102 d: 42 | P = P + 42 (0x0063), A = 0
0x003A (0x000074) 0x2113- f:00020 d: 275 | A = OR[275]
0x003B (0x000076) 0x1604- f:00013 d: 4 | A = A - 4 (0x0004)
0x003C (0x000078) 0x2913- f:00024 d: 275 | OR[275] = A
0x003D (0x00007A) 0x2113- f:00020 d: 275 | A = OR[275]
0x003E (0x00007C) 0x5800- f:00054 d: 0 | B = A
0x003F (0x00007E) 0x211A- f:00020 d: 282 | A = OR[282]
0x0040 (0x000080) 0x4800- f:00044 d: 0 | A = A > B
0x0041 (0x000082) 0x120F- f:00011 d: 15 | A = A & 15 (0x000F)
0x0042 (0x000084) 0x2915- f:00024 d: 277 | OR[277] = A
0x0043 (0x000086) 0x211C- f:00020 d: 284 | A = OR[284]
0x0044 (0x000088) 0x5800- f:00054 d: 0 | B = A
0x0045 (0x00008A) 0x2115- f:00020 d: 277 | A = OR[277]
0x0046 (0x00008C) 0x4A00- f:00045 d: 0 | A = A < B
0x0047 (0x00008E) 0x2915- f:00024 d: 277 | OR[277] = A
0x0048 (0x000090) 0x3114- f:00030 d: 276 | A = (OR[276])
0x0049 (0x000092) 0x2917- f:00024 d: 279 | OR[279] = A
0x004A (0x000094) 0x1800-0xFFFF f:00014 d: 0 | A = 65535 (0xFFFF)
0x004C (0x000098) 0x2717- f:00023 d: 279 | A = A - OR[279]
0x004D (0x00009A) 0x2315- f:00021 d: 277 | A = A & OR[277]
0x004E (0x00009C) 0x290D- f:00024 d: 269 | OR[269] = A
0x004F (0x00009E) 0x1800-0xFFFF f:00014 d: 0 | A = 65535 (0xFFFF)
0x0051 (0x0000A2) 0x2715- f:00023 d: 277 | A = A - OR[277]
0x0052 (0x0000A4) 0x2317- f:00021 d: 279 | A = A & OR[279]
0x0053 (0x0000A6) 0x250D- f:00022 d: 269 | A = A + OR[269]
0x0054 (0x0000A8) 0x2917- f:00024 d: 279 | OR[279] = A
0x0055 (0x0000AA) 0x2117- f:00020 d: 279 | A = OR[279]
0x0056 (0x0000AC) 0x3914- f:00034 d: 276 | (OR[276]) = A
0x0057 (0x0000AE) 0x2D14- f:00026 d: 276 | OR[276] = OR[276] + 1
0x0058 (0x0000B0) 0x8414- f:00102 d: 20 | P = P + 20 (0x006C), A = 0
0x0059 (0x0000B2) 0x2118- f:00020 d: 280 | A = OR[280]
0x005A (0x0000B4) 0x1C00-0x07FF f:00016 d: 0 | A = A + 2047 (0x07FF)
0x005C (0x0000B8) 0x2908- f:00024 d: 264 | OR[264] = A
0x005D (0x0000BA) 0x2114- f:00020 d: 276 | A = OR[276]
0x005E (0x0000BC) 0x2708- f:00023 d: 264 | A = A - OR[264]
0x005F (0x0000BE) 0x8003- f:00100 d: 3 | P = P + 3 (0x0062), C = 0
0x0060 (0x0000C0) 0x8402- f:00102 d: 2 | P = P + 2 (0x0062), A = 0
0x0061 (0x0000C2) 0x700B- f:00070 d: 11 | P = P + 11 (0x006C)
0x0062 (0x0000C4) 0x722A- f:00071 d: 42 | P = P - 42 (0x0038)
0x0063 (0x0000C6) 0x7009- f:00070 d: 9 | P = P + 9 (0x006C)
0x0064 (0x0000C8) 0x211D- f:00020 d: 285 | A = OR[285]
0x0065 (0x0000CA) 0x1E00-0x0809 f:00017 d: 0 | A = A - 2057 (0x0809)
0x0067 (0x0000CE) 0x8002- f:00100 d: 2 | P = P + 2 (0x0069), C = 0
0x0068 (0x0000D0) 0x7003- f:00070 d: 3 | P = P + 3 (0x006B)
0x0069 (0x0000D2) 0x7003- f:00070 d: 3 | P = P + 3 (0x006C)
0x006A (0x0000D4) 0x7002- f:00070 d: 2 | P = P + 2 (0x006C)
0x006B (0x0000D6) 0x700F- f:00070 d: 15 | P = P + 15 (0x007A)
0x006C (0x0000D8) 0x1002- f:00010 d: 2 | A = 2 (0x0002)
0x006D (0x0000DA) 0x2B19- f:00025 d: 281 | OR[281] = A + OR[281]
0x006E (0x0000DC) 0x725D- f:00071 d: 93 | P = P - 93 (0x0011)
0x006F (0x0000DE) 0x2005- f:00020 d: 5 | A = OR[5]
0x0070 (0x0000E0) 0x1406- f:00012 d: 6 | A = A + 6 (0x0006)
0x0071 (0x0000E2) 0x2908- f:00024 d: 264 | OR[264] = A
0x0072 (0x0000E4) 0x211B- f:00020 d: 283 | A = OR[283]
0x0073 (0x0000E6) 0x3908- f:00034 d: 264 | (OR[264]) = A
0x0074 (0x0000E8) 0x102A- f:00010 d: 42 | A = 42 (0x002A)
0x0075 (0x0000EA) 0x291E- f:00024 d: 286 | OR[286] = A
0x0076 (0x0000EC) 0x111E- f:00010 d: 286 | A = 286 (0x011E)
0x0077 (0x0000EE) 0x5800- f:00054 d: 0 | B = A
0x0078 (0x0000F0) 0x1000- f:00010 d: 0 | A = 0 (0x0000)
0x0079 (0x0000F2) 0x7C09- f:00076 d: 9 | R = OR[9]
0x007A (0x0000F4) 0x1001- f:00010 d: 1 | A = 1 (0x0001)
0x007B (0x0000F6) 0x291B- f:00024 d: 283 | OR[283] = A
0x007C (0x0000F8) 0x720D- f:00071 d: 13 | P = P - 13 (0x006F)
0x007D (0x0000FA) 0x0000- f:00000 d: 0 | PASS
0x007E (0x0000FC) 0x0000- f:00000 d: 0 | PASS
0x007F (0x0000FE) 0x0000- f:00000 d: 0 | PASS
|
Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0x48.log_21829_262.asm | ljhsiun2/medusa | 9 | 22534 | <reponame>ljhsiun2/medusa
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r15
push %r8
push %r9
push %rax
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x1cf19, %rdi
nop
nop
nop
and $43600, %rbp
movw $0x6162, (%rdi)
nop
nop
nop
nop
nop
dec %r10
lea addresses_UC_ht+0x15419, %r9
nop
nop
nop
sub $33205, %r15
mov (%r9), %ax
add %r10, %r10
lea addresses_WT_ht+0x2e19, %r15
nop
nop
nop
nop
dec %r10
mov $0x6162636465666768, %rax
movq %rax, %xmm7
movups %xmm7, (%r15)
nop
nop
nop
xor %rax, %rax
lea addresses_D_ht+0x3a19, %rsi
lea addresses_D_ht+0xcb19, %rdi
nop
nop
nop
nop
xor %rax, %rax
mov $28, %rcx
rep movsq
nop
nop
nop
nop
cmp %rcx, %rcx
lea addresses_A_ht+0x7619, %rsi
lea addresses_normal_ht+0x68d9, %rdi
nop
nop
cmp %r9, %r9
mov $104, %rcx
rep movsb
nop
nop
and $34456, %rax
lea addresses_D_ht+0xbe19, %rax
nop
dec %rsi
movups (%rax), %xmm4
vpextrq $0, %xmm4, %rcx
nop
nop
nop
nop
inc %rcx
lea addresses_UC_ht+0x1dbcb, %rsi
lea addresses_A_ht+0x3f19, %rdi
clflush (%rsi)
nop
nop
nop
nop
add %r15, %r15
mov $122, %rcx
rep movsb
nop
nop
dec %r8
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r9
pop %r8
pop %r15
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r15
push %rax
push %rbp
// Faulty Load
lea addresses_D+0xd319, %rax
nop
nop
sub %r14, %r14
movups (%rax), %xmm2
vpextrq $1, %xmm2, %r15
lea oracles, %r13
and $0xff, %r15
shlq $12, %r15
mov (%r13,%r15,1), %r15
pop %rbp
pop %rax
pop %r15
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 10, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 4, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 8, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 11, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 6, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
antigo/ap1/grammars/Hello.g4 | natalisso/compilers-cin | 24 | 7148 | <filename>antigo/ap1/grammars/Hello.g4
grammar Hello;
r : 'hello' 'world';
ID : [a-z]+;
WS : [ \t\r\n]+ -> skip; |
var_viewer.applescript | kevin-funderburg/alfred-search-keyboard-maestro-vars | 8 | 4290 | --
-- Created by: <NAME>
-- Created on: 9/11/20
--
-- Copyright © 2020 funderburg, All Rights Reserved
--
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
use script "Dialog Toolkit Plus"
property ICON_KM : "/System/Volumes/Data/Applications/Keyboard Maestro.app/Contents/Resources/Variable.icns"
on run argv
if class of argv = script then
set argv to {"_path", "System/Volumes/Data/Applications/Keyboard Maestro.app/Contents/Resources/Variable.icn"}
end if
set {_name, val} to argv
set {width, height} to screensize()
set maxFieldHeight to height * 0.75
set lineCount to count of paragraphs of val
set fieldHeight to 15 * lineCount
if fieldHeight > maxFieldHeight then
set fieldHeight to maxFieldHeight
end if
set maxWidth to 550
set minWidth to 400
set accWidth to getLongestLine(val)
set accWidth to (accWidth / 1.5) * 10
if accWidth > maxWidth then
set accWidth to maxWidth
else if accWidth < minWidth then
set accWidth to minWidth
end if
set accViewWidth to accWidth
set {theButtons, minWidth} to ¬
create buttons {"Cancel", "Delete", "OK"} ¬
button keys {"", "d", ""} ¬
default button 3 ¬
cancel button 1
if minWidth > accViewWidth then set accViewWidth to minWidth -- make sure buttons fit
set {theField, theTop} to ¬
create field (val) ¬
placeholder text ("Enter your text here") ¬
bottom 0 ¬
field width accViewWidth ¬
extra height fieldHeight ¬
with accepts linebreak and tab
set {regLabel, theTop} to ¬
create label ("OK:" & tab & tab & "Dismiss or set variable to new value" & return & ¬
"Delete:" & tab & "Delete variable from Keyboard Maestro (⌘D)" & return & ¬
"Cancel:" & tab & "⎋") ¬
bottom theTop + 10 ¬
max width accViewWidth ¬
left inset 75 ¬
control size regular size ¬
aligns left aligned
set {theRule, theTop} to ¬
create rule (theTop + 12) ¬
left inset 75 ¬
rule width accViewWidth - 60
set {boldLabel, theTop} to ¬
create label ("View or edit the Keyboard Maestro variable here.") ¬
bottom theTop + 10 ¬
max width accViewWidth ¬
left inset 75 ¬
control size regular size ¬
aligns left aligned ¬
with bold type
set {imgView, theTop} to ¬
create image view (ICON_KM) ¬
left inset 10 ¬
bottom theTop - 50 ¬
view width 50 ¬
view height 50 ¬
scale image scale proportionally ¬
align image top left aligned
set {buttonName, controlsResults} to ¬
display enhanced window ("Keyboard Maestro Variable Viewer") ¬
acc view width accViewWidth ¬
acc view height theTop + 5 ¬
acc view controls {theField, regLabel, theRule, boldLabel, imgView} ¬
buttons theButtons ¬
active field theField ¬
initial position {0, 0} ¬
with align cancel button
if buttonName = "OK" then
set newVal to item 1 of controlsResults
if newVal ≠ val then
tell application "Keyboard Maestro Engine"
setvariable _name to newVal
end tell
display notification ("'" & _name & "' updated to " & newVal)
end if
end if
end run
on getLongestLine(txt)
set max to 0
repeat with p in paragraphs of txt
if (count of characters of contents of p) > max then
set max to count of characters of contents of p
end if
end repeat
return max
end getLongestLine
on screensize()
set theScreen to current application's NSScreen's mainScreen()
set theFrame to theScreen's visibleFrame()
set width to item 1 of item 2 of theFrame
set height to item 2 of item 2 of theFrame
return {width, height}
end screensize
|
oeis/255/A255225.asm | neoneye/loda-programs | 11 | 171039 | <filename>oeis/255/A255225.asm
; A255225: Number of (n+2)X(5+2) 0..1 arrays with no 3x3 subblock diagonal sum 0 and no antidiagonal sum 0 and no row sum 2 and no column sum 2
; Submitted by <NAME>(w2)
; 61,67,76,88,106,133,172,229,313,436,616,880,1267,1834,2665,3883,5668,8284,12118,17737,25972,38041,55729,81652,119644,175324,256927,376522,551797,808675,1185148,1736896,2545522,3730621,5467468,8012941,11743513,17210932,25223824,36967288,54178171,79401946,116369185,170547307,249949204,366318340,536865598,786814753,1153133044,1689998593,2476813297,3629946292,5319944836,7796758084,11426704327,16746649114,24543407149,35970111427,52716760492,77260167592,113230278970,165947039413,243207206956
add $0,5
seq $0,930 ; Narayana's cows sequence: a(0) = a(1) = a(2) = 1; thereafter a(n) = a(n-1) + a(n-3).
mul $0,3
add $0,49
|
STLC.agda | pedagand/typechecker-evolution | 43 | 5306 | -- Type-checker for the simply-typed lambda calculus
--
-- Where we make sure that failing to typecheck a term is justified by
-- an "ill-typing judgment", which erases to the original term.
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.List hiding ([_])
open import Data.Nat hiding (_*_ ; _+_ ; _≟_)
open import Data.Product
open import Relation.Nullary
open import Relation.Binary hiding (_⇒_)
open import Relation.Binary.PropositionalEquality hiding ([_])
infix 5 _⊢?_∋_
infix 5 _⊢?_∈
infix 19 _↪_
infixr 30 _+_
infixr 35 _*_
infixr 40 _⇒_
infix 50 _∈_
infix 50 _∈
infix 50 _∋_
infixl 150 _▹_
-- * Types
data type : Set where
unit nat : type
_*_ _+_ _⇒_ : (A B : type) → type
bool : type
bool = unit + unit
-- TODO: automate this definition using reflection of Agda in Agda
-- see https://github.com/UlfNorell/agda-prelude/blob/master/src/Tactic/Deriving/Eq.agda
_≟_ : Decidable {A = type} _≡_
unit ≟ unit = yes refl
nat ≟ nat = yes refl
(A₁ + B₁) ≟ (A₂ + B₂)
with A₁ ≟ A₂ | B₁ ≟ B₂
... | yes refl | yes refl = yes refl
... | yes refl | no ¬p = no (λ { refl → ¬p refl })
... | no ¬p | _ = no (λ { refl → ¬p refl })
(A₁ ⇒ B₁) ≟ (A₂ ⇒ B₂)
with A₁ ≟ A₂ | B₁ ≟ B₂
... | yes refl | yes refl = yes refl
... | yes _ | no ¬p = no λ { refl → ¬p refl }
... | no ¬p | _ = no λ { refl → ¬p refl }
(A₁ * B₁) ≟ (A₂ * B₂)
with A₁ ≟ A₂ | B₁ ≟ B₂
... | yes refl | yes refl = yes refl
... | yes _ | no ¬p = no λ { refl → ¬p refl }
... | no ¬p | q₂ = no λ { refl → ¬p refl }
unit ≟ (_ ⇒ _) = no λ {()}
unit ≟ (_ * _) = no λ {()}
unit ≟ nat = no λ {()}
unit ≟ (_ + _) = no λ {()}
nat ≟ (_ ⇒ _) = no λ {()}
nat ≟ (_ * _) = no λ {()}
nat ≟ unit = no λ {()}
nat ≟ (_ + _) = no λ {()}
(_ + _) ≟ (_ ⇒ _) = no λ {()}
(_ + _) ≟ (_ * _) = no λ {()}
(_ + _) ≟ nat = no λ {()}
(_ + _) ≟ unit = no λ {()}
(_ ⇒ _) ≟ unit = no λ {()}
(_ ⇒ _) ≟ nat = no λ {()}
(_ ⇒ _) ≟ (_ * _) = no λ {()}
(_ ⇒ _) ≟ (_ + _) = no λ {()}
(_ * _) ≟ unit = no λ {()}
(_ * _) ≟ nat = no λ {()}
(_ * _) ≟ (_ ⇒ _) = no λ {()}
(_ * _) ≟ (_ + _) = no λ {()}
-- * Syntax of terms
data dir : Set where
⇑ ⇓ : dir
data can (T : Set) : Set where
tt : can T
pair : (t₁ t₂ : T) → can T
lam : (b : T) → can T
ze : can T
su : (t : T) → can T
inj₁ inj₂ : (t : T) → can T
data elim (T : Set) : dir → Set where
apply : (s : T) → elim T ⇑
fst snd : elim T ⇑
split : (c₁ c₂ : T) → elim T ⇓
data term : dir → Set where
C : (c : can (term ⇓)) → term ⇓
inv : (t : term ⇑) → term ⇓
var : (k : ℕ) → term ⇑
_#_ : ∀ {d} → (n : term ⇑)(args : elim (term ⇓) d) → term d
[_:∋:_] : (T : type)(t : term ⇓) → term ⇑
pattern Ctt = C tt
pattern Cze = C ze
pattern Csu x = C (su x)
pattern Cpair x y = C (pair x y)
pattern Clam b = C (lam b)
pattern Cinj₁ x = C (inj₁ x)
pattern Cinj₂ x = C (inj₂ x)
-- ** Tests
true : term ⇓
true = Cinj₁ Ctt
false : term ⇓
false = Cinj₂ Ctt
t1 : term ⇓
t1 = inv ([ nat ⇒ nat :∋: Clam {- x -} (inv (var {- x -} 0)) ] # apply (Csu (Csu Cze)))
t2 : term ⇓
t2 = Clam {-x-} (var {- x -} 0 # split true false)
-- * Type system
context = List type
pattern _▹_ Γ T = T ∷ Γ
pattern ε = []
data _∈_ (T : type) : context → Set where
here : ∀ {Γ} →
---------
T ∈ Γ ▹ T
there : ∀ {Γ T'} →
T ∈ Γ
→ ----------
T ∈ Γ ▹ T'
mutual
data _C⊢[_]_ : context → dir → type → Set where
lam : ∀ {Γ A B} →
Γ ▹ A ⊢[ ⇓ ] B
→ ---------------
Γ C⊢[ ⇓ ] A ⇒ B
tt : ∀ {Γ} →
--------------
Γ C⊢[ ⇓ ] unit
ze : ∀ {Γ} →
-------------
Γ C⊢[ ⇓ ] nat
su : ∀ {Γ} →
Γ ⊢[ ⇓ ] nat
→ -------------
Γ C⊢[ ⇓ ] nat
inj₁ : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] A
→ ---------------
Γ C⊢[ ⇓ ] A + B
inj₂ : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] B
→ ---------------
Γ C⊢[ ⇓ ] A + B
pair : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] A →
Γ ⊢[ ⇓ ] B
→ ---------------
Γ C⊢[ ⇓ ] A * B
data _E⊢[_]_↝_ : context → dir → type → type → Set where
apply : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] A
→ -------------------
Γ E⊢[ ⇑ ] A ⇒ B ↝ B
fst : ∀ {Γ A B} →
-------------------
Γ E⊢[ ⇑ ] A * B ↝ A
snd : ∀ {Γ A B} →
-------------------
Γ E⊢[ ⇑ ] A * B ↝ B
iter : ∀ {Γ A} →
Γ ▹ A ⊢[ ⇓ ] A →
Γ ⊢[ ⇓ ] A
→ -----------------
Γ E⊢[ ⇓ ] nat ↝ A
case : ∀ {Γ A B C} →
Γ ▹ A ⊢[ ⇓ ] C →
Γ ▹ B ⊢[ ⇓ ] C
→ -------------------
Γ E⊢[ ⇓ ] A + B ↝ C
data _⊢[_]_ : context → dir → type → Set where
C : ∀ {Γ d T} →
Γ C⊢[ d ] T
→ -----------
Γ ⊢[ d ] T
inv : ∀ {Γ T} →
Γ ⊢[ ⇑ ] T
→ ----------
Γ ⊢[ ⇓ ] T
var : ∀ {Γ T} →
T ∈ Γ
→ ----------
Γ ⊢[ ⇑ ] T
_#_ : ∀ {Γ d I O} →
Γ ⊢[ ⇑ ] I →
Γ E⊢[ d ] I ↝ O
→ ---------------
Γ ⊢[ d ] O
[_:∋:_by_] : ∀ {Γ A} →
(B : type) → Γ ⊢[ ⇓ ] B → A ≡ B
→ -------------------------------
Γ ⊢[ ⇑ ] A
-- ** Tests
⊢true : [] ⊢[ ⇓ ] bool
⊢true = C (inj₁ (C tt))
⊢false : [] ⊢[ ⇓ ] bool
⊢false = C (inj₂ (C tt))
⊢t1 : [] ⊢[ ⇓ ] nat
⊢t1 = inv ([ (nat ⇒ nat) :∋: (C (lam (inv (var here)))) by refl ]
# (apply (C (su (C (su (C ze)))))))
-- * Relating typing and terms
record _↪_ (S T : Set) : Set where
field
⌊_⌋ : S → T
open _↪_ {{...}} public
instance
VarRaw : ∀ {T Γ} → T ∈ Γ ↪ ℕ
⌊_⌋ {{ VarRaw }} here = zero
⌊_⌋ {{ VarRaw }} (there x) = suc ⌊ x ⌋
OTermRaw : ∀ {Γ T d} → Γ ⊢[ d ] T ↪ term d
⌊_⌋ {{OTermRaw}} (C (lam b)) = C (lam ⌊ b ⌋)
⌊_⌋ {{OTermRaw}} (C tt) = C tt
⌊_⌋ {{OTermRaw}} (C ze) = C ze
⌊_⌋ {{OTermRaw}} (C (su t)) = C (su ⌊ t ⌋)
⌊_⌋ {{OTermRaw}} (C (inj₁ t)) = C (inj₁ ⌊ t ⌋)
⌊_⌋ {{OTermRaw}} (C (inj₂ t)) = C (inj₂ ⌊ t ⌋)
⌊_⌋ {{OTermRaw}} (C (pair t₁ t₂)) = C (pair ⌊ t₁ ⌋ ⌊ t₂ ⌋)
⌊_⌋ {{OTermRaw}} (inv t) = inv ⌊ t ⌋
⌊_⌋ {{OTermRaw}} (var x) = var ⌊ x ⌋
⌊_⌋ {{OTermRaw}} (f # (apply s)) = ⌊ f ⌋ # apply ⌊ s ⌋
⌊_⌋ {{OTermRaw}} (p # fst) = ⌊ p ⌋ # fst
⌊_⌋ {{OTermRaw}} (p # snd) = ⌊ p ⌋ # snd
⌊_⌋ {{OTermRaw}} (t # case x y) = ⌊ t ⌋ # split ⌊ x ⌋ ⌊ y ⌋
⌊_⌋ {{OTermRaw}} (t # iter fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ ⌊ fz ⌋
⌊_⌋ {{OTermRaw}} [ T :∋: t by refl ] = [ T :∋: ⌊ t ⌋ ]
data _⊢_∋_ (Γ : context)(T : type){d} : term d → Set where
well-typed : (Δ : Γ ⊢[ d ] T ) → Γ ⊢ T ∋ ⌊ Δ ⌋
-- TODO: one could prove that `Γ ⊢ T ∋ t` is H-prop when `t : term ⇓`, ie. we have
-- lemma-proof-irr : ∀ {Γ T}{t : term ⇓} → ∀ (pf₁ pf₂ : Γ ⊢ T ∋ t) → → pf₁ ≅ pf₂
-- but this requires proving that `⌊_⌋` is injective.
-- TODO: conversely, one should be able to prove that `Γ ⊢ T ∋ t` is
-- equivalent to `type` when `t : term ⇑` but I haven't tried.
-- ** Tests
bool∋true : [] ⊢ bool ∋ true
bool∋true = well-typed ⊢true
bool∋false : [] ⊢ bool ∋ false
bool∋false = well-typed ⊢false
nat∋t1 : [] ⊢ nat ∋ t1
nat∋t1 = well-typed ⊢t1
-- * Ill-type system
data Canonical {X} : type → can X → Set where
can-unit-tt : Canonical unit tt
can-nat-ze : Canonical nat ze
can-nat-su : ∀ {a} → Canonical nat (su a)
can-sum-inj₁ : ∀ {A B a} → Canonical (A + B) (inj₁ a)
can-sum-inj₂ : ∀ {A B b} → Canonical (A + B) (inj₂ b)
can-prod-pair : ∀ {A B a b} → Canonical (A * B) (pair a b)
data IsProduct : type → Set where
is-product : ∀ {A B} → IsProduct (A * B)
data IsArrow : type → Set where
is-arrow : ∀ {A B} → IsArrow (A ⇒ B)
data IsSplit : type → Set where
is-split-nat : IsSplit nat
is-split-sum : ∀ {A B} → IsSplit (A + B)
mtype : dir → Set
mtype ⇑ = ⊤
mtype ⇓ = type
data _B⊬[_]_ (Γ : context) : (d : dir) → mtype d → Set where
not-canonical : ∀ {c : can (term ⇓)}{T} →
¬ Canonical T c
→ ---------------
Γ B⊬[ ⇓ ] T
unsafe-inv : ∀ {A B} →
Γ ⊢[ ⇑ ] A → A ≢ B
→ -------------------
Γ B⊬[ ⇓ ] B
bad-split : ∀ {A B}{c₁ c₂ : term ⇓} →
Γ ⊢[ ⇑ ] A → ¬ IsSplit A
→ -------------------------
Γ B⊬[ ⇓ ] B
out-of-scope : ∀ {x : ℕ} →
x ≥ length Γ
→ ------------
Γ B⊬[ ⇑ ] _
bad-function : ∀ {T}{s : term ⇓} →
Γ ⊢[ ⇑ ] T → ¬ IsArrow T
→ ------------------------
Γ B⊬[ ⇑ ] _
bad-fst : ∀ {T} →
Γ ⊢[ ⇑ ] T → ¬ IsProduct T
→ --------------------------
Γ B⊬[ ⇑ ] _
bad-snd : ∀ {T} →
Γ ⊢[ ⇑ ] T → ¬ IsProduct T
→ --------------------------
Γ B⊬[ ⇑ ] _
-- TODO: automate this "trisection & free monad" construction by meta-programming
-- see: "The gentle art of levitation", Chapman et al. for the free monad
-- see: "Clowns to the left of me, jokers to the right", McBride for the dissection
mutual
data _C⊬[_]_ : context → (d : dir) → mtype d → Set where
lam : ∀ {Γ A B} → Γ ▹ A ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A ⇒ B
su : ∀ {Γ} → Γ ⊬[ ⇓ ] nat → Γ C⊬[ ⇓ ] nat
inj₁ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → Γ C⊬[ ⇓ ] A + B
inj₂ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A + B
pair₁ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → term ⇓ → Γ C⊬[ ⇓ ] A * B
pair₂ : ∀ {Γ A B} → Γ ⊢[ ⇓ ] A → Γ ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A * B
data _E⊬[_]_↝_ : context → (d : dir) → type → mtype d → Set where
apply : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → Γ E⊬[ ⇑ ] A ⇒ B ↝ _
iter₁ : ∀ {Γ T} → Γ ▹ T ⊬[ ⇓ ] T → term ⇓ → Γ E⊬[ ⇓ ] nat ↝ T
iter₂ : ∀ {Γ T} → Γ ▹ T ⊢[ ⇓ ] T → Γ ⊬[ ⇓ ] T → Γ E⊬[ ⇓ ] nat ↝ T
case₁ : ∀ {Γ A B C} → Γ ▹ A ⊬[ ⇓ ] C → term ⇓ → Γ E⊬[ ⇓ ] A + B ↝ C
case₂ : ∀ {Γ A B C} → Γ ▹ A ⊢[ ⇓ ] C → Γ ▹ B ⊬[ ⇓ ] C → Γ E⊬[ ⇓ ] A + B ↝ C
data _⊬[_]_ : context → (d : dir) → mtype d → Set where
because : ∀ {Γ d T} → Γ B⊬[ d ] T → Γ ⊬[ d ] T
C : ∀ {Γ d T} → Γ C⊬[ d ] T → Γ ⊬[ d ] T
inv : ∀ {Γ T} → Γ ⊬[ ⇑ ] _ → Γ ⊬[ ⇓ ] T
_#₁_ : ∀ {Γ d T} → Γ ⊬[ ⇑ ] _ → elim (term ⇓) d → Γ ⊬[ d ] T
_#₂_ : ∀ {Γ d I O} → Γ ⊢[ ⇑ ] I → Γ E⊬[ d ] I ↝ O → Γ ⊬[ d ] O
[_:∋:_] : ∀ {Γ} → (T : type) → Γ ⊬[ ⇓ ] T → Γ ⊬[ ⇑ ] _
instance
BTermRaw : ∀ {Γ d T} → Γ B⊬[ d ] T ↪ term d
⌊_⌋ {{BTermRaw}} (not-canonical {c} x) = C c
⌊_⌋ {{BTermRaw}} (unsafe-inv q _) = inv ⌊ q ⌋
⌊_⌋ {{BTermRaw}} (bad-split {c₁ = c₁} {c₂} t _) = ⌊ t ⌋ # split c₁ c₂
⌊_⌋ {{BTermRaw}} (out-of-scope {x} _) = var x
⌊_⌋ {{BTermRaw}} (bad-function {s = s} f _) = ⌊ f ⌋ # apply s
⌊_⌋ {{BTermRaw}} (bad-fst p _) = ⌊ p ⌋ # fst
⌊_⌋ {{BTermRaw}} (bad-snd p _) = ⌊ p ⌋ # snd
ETermRaw : ∀ {Γ d T} → Γ ⊬[ d ] T ↪ term d
⌊_⌋ {{ETermRaw}} (because e) = ⌊ e ⌋
⌊_⌋ {{ETermRaw}} (C (lam b)) = C (lam ⌊ b ⌋)
⌊_⌋ {{ETermRaw}} (C (su t)) = C (su ⌊ t ⌋)
⌊_⌋ {{ETermRaw}} (C (inj₁ t)) = C (inj₁ ⌊ t ⌋)
⌊_⌋ {{ETermRaw}} (C (inj₂ t)) = C (inj₂ ⌊ t ⌋)
⌊_⌋ {{ETermRaw}} (C (pair₁ t₁ t₂)) = C (pair ⌊ t₁ ⌋ t₂)
⌊_⌋ {{ETermRaw}} (C (pair₂ t₁ t₂)) = C (pair ⌊ t₁ ⌋ ⌊ t₂ ⌋)
⌊_⌋ {{ETermRaw}} (inv t) = inv ⌊ t ⌋
⌊_⌋ {{ETermRaw}} [ T :∋: t ] = [ T :∋: ⌊ t ⌋ ]
⌊_⌋ {{ETermRaw}} (t #₁ e) = ⌊ t ⌋ # e
⌊_⌋ {{ETermRaw}} (t #₂ apply x) = ⌊ t ⌋ # apply ⌊ x ⌋
⌊_⌋ {{ETermRaw}} (t #₂ iter₁ fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ fz
⌊_⌋ {{ETermRaw}} (t #₂ iter₂ fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ ⌊ fz ⌋
⌊_⌋ {{ETermRaw}} (t #₂ case₁ cX cY) = ⌊ t ⌋ # split ⌊ cX ⌋ cY
⌊_⌋ {{ETermRaw}} (t #₂ case₂ cX cY) = ⌊ t ⌋ # split ⌊ cX ⌋ ⌊ cY ⌋
-- * Type-checking
-- ** View on variable lookup
data _∈-view_ : ℕ → context → Set where
yes : ∀ {T Γ} → (x : T ∈ Γ) → ⌊ x ⌋ ∈-view Γ
no : ∀ {Γ n} → n ≥ length Γ → n ∈-view Γ
_∈?_ : ∀ n Γ → n ∈-view Γ
_ ∈? ε = no z≤n
zero ∈? Γ ▹ T = yes here
suc n ∈? Γ ▹ T
with n ∈? Γ
... | yes t = yes (there t)
... | no q = no (s≤s q)
-- ** View on typing
data Dir : dir → Set where
_∈ : term ⇑ → Dir ⇑
_∋_ : type → term ⇓ → Dir ⇓
instance
DirRaw : ∀ {Γ d T} → Γ ⊢[ d ] T ↪ Dir d
⌊_⌋ {{DirRaw {d = ⇑}}} e = ⌊ e ⌋ ∈
⌊_⌋ {{DirRaw {d = ⇓}{T}}} e = T ∋ ⌊ e ⌋
EDirRaw : ∀ {Γ d T} → Γ ⊬[ d ] T ↪ Dir d
⌊_⌋ {{EDirRaw {d = ⇑}}} e = ⌊ e ⌋ ∈
⌊_⌋ {{EDirRaw {d = ⇓}{T}}} e = T ∋ ⌊ e ⌋
data _⊢[_]-view_ (Γ : context)(d : dir) : Dir d → Set where
yes : ∀ {T} (Δ : Γ ⊢[ d ] T) → Γ ⊢[ d ]-view ⌊ Δ ⌋
no : ∀ {T} (¬Δ : Γ ⊬[ d ] T) → Γ ⊢[ d ]-view ⌊ ¬Δ ⌋
isYes : ∀ {Γ T t} → Γ ⊢[ ⇓ ]-view T ∋ t → Set
isYes (yes Δ) = ⊤
isYes (no ¬Δ) = ⊥
lemma : ∀ {Γ T t} → (pf : Γ ⊢[ ⇓ ]-view T ∋ t) → isYes pf → Γ ⊢ T ∋ t
lemma (yes Δ) tt = well-typed Δ
lemma (no _) ()
-- XXX: Mutually-recursive to please the termination checker
_⊢?_∋_ : (Γ : context)(T : type)(t : term ⇓) → Γ ⊢[ ⇓ ]-view T ∋ t
_⊢?_∈ : (Γ : context)(t : term ⇑) → Γ ⊢[ ⇑ ]-view t ∈
_⊢?_∋C_ : (Γ : context)(T : type)(t : can (term ⇓)) → Γ ⊢[ ⇓ ]-view T ∋ C t
_!_∋_⊢?_∋#_ : (Γ : context)(I : type)(Δt : Γ ⊢[ ⇑ ] I)(T : type)(e : elim (term ⇓) ⇓) → Γ ⊢[ ⇓ ]-view T ∋ (⌊ Δt ⌋ # e)
_!_∋_⊢?_∈# : (Γ : context)(T : type)(Δt : Γ ⊢[ ⇑ ] T)(e : elim (term ⇓) ⇑) → Γ ⊢[ ⇑ ]-view (⌊ Δt ⌋ # e) ∈
Γ ⊢? T ∋ C t = Γ ⊢? T ∋C t
Γ ⊢? T ∋ inv t
with Γ ⊢? t ∈
... | no ¬Δ = no (inv ¬Δ)
... | yes {T'} Δ
with T' ≟ T
... | yes refl = yes (inv Δ)
... | no ¬p = no (because (unsafe-inv Δ ¬p))
Γ ⊢? A ∋ t # e
with Γ ⊢? t ∈
... | no ¬Δt = no (¬Δt #₁ e)
... | yes {T} Δt = Γ ! T ∋ Δt ⊢? A ∋# e
Γ ⊢? var k ∈
with k ∈? Γ
... | yes x = yes (var x)
... | no ¬q = no (because (out-of-scope ¬q))
Γ ⊢? t # e ∈
with Γ ⊢? t ∈
... | no ¬Δt = no (¬Δt #₁ e)
... | yes {T} Δt = Γ ! T ∋ Δt ⊢? e ∈#
Γ ⊢? [ T :∋: t ] ∈
with Γ ⊢? T ∋ t
... | yes Δt = yes [ T :∋: Δt by refl ]
... | no ¬Δt = no [ T :∋: ¬Δt ]
Γ ⊢? unit ∋C tt = yes (C tt)
Γ ⊢? unit ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C su _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C pair t₁ t₂
with Γ ⊢? A ∋ t₁ | Γ ⊢? B ∋ t₂
... | yes Δ₁ | yes Δ₂ = yes (C (pair Δ₁ Δ₂))
... | yes Δ₁ | no ¬Δ₂ = no (C (pair₂ Δ₁ ¬Δ₂))
... | no ¬Δ₁ | _ = no (C (pair₁ ¬Δ₁ t₂))
Γ ⊢? A * B ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C su _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C lam b
with Γ ▹ A ⊢? B ∋ b
... | yes Δ = yes (C (lam Δ))
... | no ¬Δ = no (C (lam ¬Δ))
Γ ⊢? A ⇒ B ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C su x = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C ze = yes (C ze)
Γ ⊢? nat ∋C su n
with Γ ⊢? nat ∋ n
... | yes Δ = yes (C (su Δ))
... | no ¬Δ = no (C (su ¬Δ))
Γ ⊢? nat ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C inj₁ t
with Γ ⊢? A ∋ t
... | yes Δ = yes (C (inj₁ Δ))
... | no ¬Δ = no (C (inj₁ ¬Δ))
Γ ⊢? A + B ∋C inj₂ t
with Γ ⊢? B ∋ t
... | yes Δ = yes (C (inj₂ Δ))
... | no ¬Δ = no (C (inj₂ ¬Δ))
Γ ⊢? A + B ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C su _ = no (because (not-canonical (λ {()})))
Γ ! nat ∋ Δt ⊢? A ∋# split fs fz
with Γ ▹ A ⊢? A ∋ fs | Γ ⊢? A ∋ fz
... | yes Δfs | yes Δfz = yes (Δt # iter Δfs Δfz)
... | yes Δfs | no ¬Δfz = no (Δt #₂ iter₂ Δfs ¬Δfz)
... | no ¬Δfs | _ = no (Δt #₂ iter₁ ¬Δfs fz)
Γ ! X + Y ∋ Δt ⊢? A ∋# split cX cY
with (X ∷ Γ) ⊢? A ∋ cX | (Y ∷ Γ) ⊢? A ∋ cY
... | yes ΔcX | yes ΔcY = yes (Δt # case ΔcX ΔcY)
... | yes ΔcX | no ¬ΔcY = no (Δt #₂ case₂ ΔcX ¬ΔcY)
... | no ¬ΔcX | _ = no (Δt #₂ case₁ ¬ΔcX cY)
Γ ! unit ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))
Γ ! _ ⇒ _ ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))
Γ ! _ * _ ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))
Γ ! A ⇒ B ∋ Δf ⊢? apply s ∈#
with Γ ⊢? A ∋ s
... | yes Δs = yes (Δf # apply Δs)
... | no ¬Δs = no (Δf #₂ apply ¬Δs)
Γ ! unit ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! nat ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! _ + _ ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! _ * _ ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! A * B ∋ Δp ⊢? fst ∈# = yes (Δp # fst)
Γ ! unit ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! nat ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! _ + _ ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! _ ⇒ _ ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! A * B ∋ Δp ⊢? snd ∈# = yes (Δp # snd)
Γ ! unit ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
Γ ! nat ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
Γ ! _ + _ ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
Γ ! _ ⇒ _ ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
-- ** Tests
nat∋t1' : [] ⊢ nat ∋ t1
nat∋t1' = lemma ([] ⊢? nat ∋ t1) tt
T1 : type
T1 = nat ⇒ (unit + unit)
T2 : type
T2 = (nat + unit) ⇒ (unit + unit)
T1∋t2 : [] ⊢ T1 ∋ t2
T1∋t2 = lemma ([] ⊢? T1 ∋ t2) tt
T2∋t2 : [] ⊢ T2 ∋ t2
T2∋t2 = lemma ([] ⊢? T2 ∋ t2) tt
|
gcc-gcc-7_3_0-release/gcc/ada/xr_tabls.ads | best08618/asylo | 7 | 20183 | <filename>gcc-gcc-7_3_0-release/gcc/ada/xr_tabls.ads
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- X R _ T A B L S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1998-2014, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- We need comment here saying what this package is???
with GNAT.OS_Lib;
package Xr_Tabls is
-------------------
-- Project files --
-------------------
function ALI_File_Name (Ada_File_Name : String) return String;
-- Returns the ali file name corresponding to Ada_File_Name
procedure Create_Project_File (Name : String);
-- Open and parse a new project file. If the file Name could not be
-- opened or is not a valid project file, then a project file associated
-- with the standard default directories is returned
function Next_Obj_Dir return String;
-- Returns the next directory to visit to find related ali files
-- If there are no more such directories, returns a null string.
function Current_Obj_Dir return String;
-- Returns the obj_dir which was returned by the last Next_Obj_Dir call
procedure Reset_Obj_Dir;
-- Reset the iterator for Obj_Dir
------------
-- Tables --
------------
type Declaration_Reference is private;
Empty_Declaration : constant Declaration_Reference;
type Declaration_Array is array (Natural range <>) of Declaration_Reference;
type Declaration_Array_Access is access Declaration_Array;
type File_Reference is private;
Empty_File : constant File_Reference;
type Reference is private;
Empty_Reference : constant Reference;
type Reference_Array is array (Natural range <>) of Reference;
type Reference_Array_Access is access Reference_Array;
procedure Free (Arr : in out Reference_Array_Access);
function Add_Declaration
(File_Ref : File_Reference;
Symbol : String;
Line : Natural;
Column : Natural;
Decl_Type : Character;
Is_Parameter : Boolean := False;
Remove_Only : Boolean := False;
Symbol_Match : Boolean := True)
return Declaration_Reference;
-- Add a new declaration in the table and return the index to it. Decl_Type
-- is the type of the entity Any previous instance of this entity in the
-- htable is removed. If Remove_Only is True, then any previous instance is
-- removed, but the new entity is never inserted. Symbol_Match should be
-- set to False if the name of the symbol doesn't match the pattern from
-- the command line. In that case, the entity will not be output by
-- gnatfind. If Symbol_Match is True, the entity will only be output if
-- the file name itself matches. Is_Parameter should be set to True if
-- the entity is known to be a subprogram parameter.
procedure Add_Parent
(Declaration : in out Declaration_Reference;
Symbol : String;
Line : Natural;
Column : Natural;
File_Ref : File_Reference);
-- The parent declaration (Symbol in file File_Ref at position Line and
-- Column) information is added to Declaration.
function Add_To_Xref_File
(File_Name : String;
Visited : Boolean := True;
Emit_Warning : Boolean := False;
Gnatchop_File : String := "";
Gnatchop_Offset : Integer := 0)
return File_Reference;
-- Add a new reference to a file in the table. Ref is used to return the
-- index in the table where this file is stored. Visited is the value which
-- will be used in the table (if True, the file will not be returned by
-- Next_Unvisited_File). If Emit_Warning is True and the ali file does
-- not exist or does not have cross-referencing information, then a
-- warning will be emitted. Gnatchop_File is the name of the file that
-- File_Name was extracted from through a call to "gnatchop -r" (using
-- pragma Source_Reference). Gnatchop_Offset should be the index of the
-- first line of File_Name within the Gnatchop_File.
procedure Add_Line
(File : File_Reference;
Line : Natural;
Column : Natural);
-- Add a new reference in a file, which the user has provided on the
-- command line. This is used for an optimized matching algorithm.
procedure Add_Reference
(Declaration : Declaration_Reference;
File_Ref : File_Reference;
Line : Natural;
Column : Natural;
Ref_Type : Character;
Labels_As_Ref : Boolean);
-- Add a new reference (Ref_Type = 'r'), body (Ref_Type = 'b') or
-- modification (Ref_Type = 'm') to an entity. If Labels_As_Ref is True,
-- then the references to the entity after the end statements ("end Foo")
-- are counted as actual references. This means that the entity will never
-- be reported as unreferenced (for instance in the case of gnatxref -u).
function Get_Declarations
(Sorted : Boolean := True)
return Declaration_Array_Access;
-- Return a sorted list of all the declarations in the application.
-- Freeing this array is the responsibility of the caller, however it
-- shouldn't free the actual contents of the array, which are pointers
-- to internal data
function References_Count
(Decl : Declaration_Reference;
Get_Reads : Boolean := False;
Get_Writes : Boolean := False;
Get_Bodies : Boolean := False)
return Natural;
-- Return the number of references in Decl for the categories specified
-- by the Get_* parameters (read-only accesses, write accesses and bodies)
function Get_References
(Decl : Declaration_Reference;
Get_Reads : Boolean := False;
Get_Writes : Boolean := False;
Get_Bodies : Boolean := False)
return Reference_Array_Access;
-- Return a sorted list of all references to the entity in decl. The
-- parameters Get_* are used to specify what kind of references should be
-- merged and returned (read-only accesses, write accesses and bodies).
function Get_Column (Decl : Declaration_Reference) return String;
function Get_Column (Ref : Reference) return String;
function Get_Declaration
(File_Ref : File_Reference;
Line : Natural;
Column : Natural)
return Declaration_Reference;
-- Returns reference to the declaration found in file File_Ref at the
-- given Line and Column
function Get_Parent
(Decl : Declaration_Reference)
return Declaration_Reference;
-- Returns reference to Decl's parent declaration
function Get_Emit_Warning (File : File_Reference) return Boolean;
-- Returns the Emit_Warning field of the structure
function Get_Gnatchop_File
(File : File_Reference;
With_Dir : Boolean := False)
return String;
function Get_Gnatchop_File
(Ref : Reference;
With_Dir : Boolean := False)
return String;
function Get_Gnatchop_File
(Decl : Declaration_Reference;
With_Dir : Boolean := False)
return String;
-- Return the name of the file that File was extracted from through a
-- call to "gnatchop -r". The file name for File is returned if File
-- was not extracted from such a file. The directory will be given only
-- if With_Dir is True.
function Get_File
(Decl : Declaration_Reference;
With_Dir : Boolean := False) return String;
pragma Inline (Get_File);
-- Extract column number or file name from reference
function Get_File
(Ref : Reference;
With_Dir : Boolean := False) return String;
pragma Inline (Get_File);
function Get_File
(File : File_Reference;
With_Dir : Boolean := False;
Strip : Natural := 0) return String;
-- Returns the file name (and its directory if With_Dir is True or the user
-- has used the -f switch on the command line. If Strip is not 0, then the
-- last Strip-th "-..." substrings are removed first. For instance, with
-- Strip=2, a file name "parent-child1-child2-child3.ali" would be returned
-- as "parent-child1.ali". This is used when looking for the ALI file to
-- use for a package, since for separates with have to use the parent's
-- ALI. The null string is returned if there is no such parent unit.
--
-- Note that this version of Get_File is not inlined
function Get_File_Ref (Ref : Reference) return File_Reference;
function Get_Line (Decl : Declaration_Reference) return String;
function Get_Line (Ref : Reference) return String;
function Get_Symbol (Decl : Declaration_Reference) return String;
function Get_Type (Decl : Declaration_Reference) return Character;
function Is_Parameter (Decl : Declaration_Reference) return Boolean;
-- Functions that return the contents of a declaration
function Get_Source_Line (Ref : Reference) return String;
function Get_Source_Line (Decl : Declaration_Reference) return String;
-- Return the source line associated with the reference
procedure Grep_Source_Files;
-- Parse all the source files which have at least one reference, and grep
-- the appropriate source lines so that we'll be able to display them. This
-- function should be called once all the .ali files have been parsed, and
-- only if the appropriate user switch
-- has been used (gnatfind -s).
--
-- Note: To save memory, the strings for the source lines are shared. Thus
-- it is no longer possible to free the references, or we would free the
-- same chunk multiple times. It doesn't matter, though, since this is only
-- called once, prior to exiting gnatfind.
function Longest_File_Name return Natural;
-- Returns the longest file name found
function Match (Decl : Declaration_Reference) return Boolean;
-- Return True if the declaration matches
function Match
(File : File_Reference;
Line : Natural;
Column : Natural)
return Boolean;
-- Returns True if File:Line:Column was given on the command line
-- by the user
function Next_Unvisited_File return File_Reference;
-- Returns the next unvisited library file in the list If there is no more
-- unvisited file, return Empty_File. Two calls to this subprogram will
-- return different files.
procedure Set_Default_Match (Value : Boolean);
-- Set the default value for match in declarations.
-- This is used so that if no file was provided in the
-- command line, then every file match
procedure Reset_Directory (File : File_Reference);
-- Reset the cached directory for file. Next time Get_File is called, the
-- directory will be recomputed.
procedure Set_Unvisited (File_Ref : File_Reference);
-- Set File_Ref as unvisited. So Next_Unvisited_File will return it
procedure Read_File
(File_Name : String;
Contents : out GNAT.OS_Lib.String_Access);
-- Reads File_Name into the newly allocated string Contents. Types.EOF
-- character will be added to the returned Contents to simplify parsing.
-- Name_Error is raised if the file was not found. End_Error is raised if
-- the file could not be read correctly. For most systems correct reading
-- means that the number of bytes read is equal to the file size.
private
type Project_File (Src_Dir_Length, Obj_Dir_Length : Natural) is record
Src_Dir : String (1 .. Src_Dir_Length);
Src_Dir_Index : Integer;
Obj_Dir : String (1 .. Obj_Dir_Length);
Obj_Dir_Index : Integer;
Last_Obj_Dir_Start : Natural;
end record;
type Project_File_Ptr is access all Project_File;
-- This is actually a list of all the directories to be searched,
-- either for source files or for library files
type Ref_In_File;
type Ref_In_File_Ptr is access all Ref_In_File;
type Ref_In_File is record
Line : Natural;
Column : Natural;
Next : Ref_In_File_Ptr := null;
end record;
type File_Record;
type File_Reference is access all File_Record;
Empty_File : constant File_Reference := null;
type Cst_String_Access is access constant String;
procedure Free (Str : in out Cst_String_Access);
type File_Record is record
File : Cst_String_Access;
Dir : GNAT.OS_Lib.String_Access;
Lines : Ref_In_File_Ptr := null;
Visited : Boolean := False;
Emit_Warning : Boolean := False;
Gnatchop_File : GNAT.OS_Lib.String_Access := null;
Gnatchop_Offset : Integer := 0;
Next : File_Reference := null;
end record;
-- Holds a reference to a source file, that was referenced in at least one
-- ALI file. Gnatchop_File will contain the name of the file that File was
-- extracted From. Gnatchop_Offset contains the index of the first line of
-- File within Gnatchop_File. These two fields are used to properly support
-- gnatchop files and pragma Source_Reference.
--
-- Lines is used for files that were given on the command line, to
-- memorize the lines and columns that the user specified.
type Reference_Record;
type Reference is access all Reference_Record;
Empty_Reference : constant Reference := null;
type Reference_Record is record
File : File_Reference;
Line : Natural;
Column : Natural;
Source_Line : Cst_String_Access;
Next : Reference := null;
end record;
-- File is a reference to the Ada source file
-- Source_Line is the Line as it appears in the source file. This
-- field is only used when the switch is set on the command line of
-- gnatfind.
type Declaration_Record;
type Declaration_Reference is access all Declaration_Record;
Empty_Declaration : constant Declaration_Reference := null;
type Declaration_Record (Symbol_Length : Natural) is record
Key : Cst_String_Access;
Symbol : String (1 .. Symbol_Length);
Decl : Reference;
Is_Parameter : Boolean := False; -- True if entity is subprog param
Decl_Type : Character;
Body_Ref : Reference := null;
Ref_Ref : Reference := null;
Modif_Ref : Reference := null;
Match : Boolean := False;
Par_Symbol : Declaration_Reference := null;
Next : Declaration_Reference := null;
end record;
-- The lists of referenced (Body_Ref, Ref_Ref and Modif_Ref) are
-- kept unsorted until the results needs to be printed. This saves
-- lots of time while the internal tables are created.
pragma Inline (Get_Column);
pragma Inline (Get_Emit_Warning);
pragma Inline (Get_File_Ref);
pragma Inline (Get_Line);
pragma Inline (Get_Symbol);
pragma Inline (Get_Type);
pragma Inline (Longest_File_Name);
end Xr_Tabls;
|
alloy4fun_models/trashltl/models/4/gHKNfZq2yAkrBDxTE.als | Kaixi26/org.alloytools.alloy | 0 | 2838 | open main
pred idgHKNfZq2yAkrBDxTE_prop5 {
some File eventually File not in File'
}
pred __repair { idgHKNfZq2yAkrBDxTE_prop5 }
check __repair { idgHKNfZq2yAkrBDxTE_prop5 <=> prop5o } |
Source/Nostromo/Things.asm | benryves/Nostromo | 0 | 170374 | <gh_stars>0
.module Things
Code:
; ==========================================================================
; SubSectorStack.Push
; --------------------------------------------------------------------------
; Pushes information about the subsector to draw to the stack.
; --------------------------------------------------------------------------
; Inputs: IX: Pointer to the subsector containing the things to draw.
; Destroyed: AF, BC, DE, HL.
; ==========================================================================
SubSectorStack.Push:
; --------------------------------------------------------------------------
; Check that we have space on the stack.
; --------------------------------------------------------------------------
ld a,(SubSectorStack.EntriesFree)
or a
ret z
dec a
ld (SubSectorStack.EntriesFree),a
; --------------------------------------------------------------------------
; Move the stack pointer.
; --------------------------------------------------------------------------
ld hl,(SubSectorStack.Current)
ld de,-SubSectorStack.EntrySize
add hl,de
ld (SubSectorStack.Current),hl
; --------------------------------------------------------------------------
; Store the subsector pointer.
; --------------------------------------------------------------------------
push ix
pop de
ld (hl),e
inc hl
ld (hl),d
inc hl
; --------------------------------------------------------------------------
; Store the top edge clipping regions.
; --------------------------------------------------------------------------
ex de,hl
ld hl,TopEdgeClip
ld bc,96
ldir
; --------------------------------------------------------------------------
; Store the bottom edge clipping regions.
; --------------------------------------------------------------------------
ld hl,BottomEdgeClip
ld bc,96
ldir
ret
; ==========================================================================
; Draw
; --------------------------------------------------------------------------
; Draws all things.
; --------------------------------------------------------------------------
; Destroyed: AF, BC, DE, HL, IX.
; ==========================================================================
Draw:
ld a,(SubSectorStack.EntriesFree)
ld b,a
ld a,(SubSectorStack.MaximumCapacity)
sub b
ret z
ld b,a
Draw.Loop:
push bc
; --------------------------------------------------------------------------
; Fetch (and advance for the next loop) the stack pointer.
; --------------------------------------------------------------------------
ld hl,(SubSectorStack.Current)
push hl
ld de,SubSectorStack.EntrySize
add hl,de
ld (SubSectorStack.Current),hl
pop hl
; --------------------------------------------------------------------------
; Retrieve the pointer to the subsector to draw.
; --------------------------------------------------------------------------
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld (DrawingSubSector),de
; --------------------------------------------------------------------------
; Restore the upper clipping region.
; --------------------------------------------------------------------------
ld de,TopEdgeClip
ld bc,96
ldir
; --------------------------------------------------------------------------
; Restore the lower clipping region.
; --------------------------------------------------------------------------
ld de,BottomEdgeClip
ld bc,96
ldir
; --------------------------------------------------------------------------
; We have not yet added anything to the sorted sprite buffer.
; --------------------------------------------------------------------------
xor a
ld (SortedSpriteBuffer.Count),a
; --------------------------------------------------------------------------
; Find the things to draw in turn.
; --------------------------------------------------------------------------
ld hl,(DrawingSubSector)
inc hl
ld l,(hl)
; --------------------------------------------------------------------------
; We have the index of the thing to draw in L.
; --------------------------------------------------------------------------
SortNextThing:
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld de,(Level.Things)
add hl,de
; --------------------------------------------------------------------------
; Fetch the pointer to the next thing.
; --------------------------------------------------------------------------
ld a,(hl)
ld (NextThing.Index),a
inc hl
; --------------------------------------------------------------------------
; Look up the thing's type.
; --------------------------------------------------------------------------
push hl
ld l,(hl)
ld h,0
add hl,hl
ld de,Thing.Types
add hl,de
ld e,(hl)
inc hl
ld d,(hl)
ld (Appearance.Offset),de
pop hl
inc hl
; --------------------------------------------------------------------------
; Skip over the two reserved bytes.
; --------------------------------------------------------------------------
inc hl
inc hl
; --------------------------------------------------------------------------
; Get the coordinates of the thing.
; --------------------------------------------------------------------------
ld c,(hl) \ inc hl
ld b,(hl) \ inc hl
ld e,(hl) \ inc hl
ld d,(hl)
; --------------------------------------------------------------------------
; Transform it.
; --------------------------------------------------------------------------
call Vertices.Transform
; --------------------------------------------------------------------------
; Is it behind the camera?
; --------------------------------------------------------------------------
ld a,d
or a
jp m,Buffer.Skip
; --------------------------------------------------------------------------
; Store the transformed position.
; --------------------------------------------------------------------------
ld (Transformed.X),bc
ld (Transformed.Y),de
; --------------------------------------------------------------------------
; Fudge the distance factor to allow the centre of the sprite object to
; appear beyond the left or right edge of the display rather than vanish
; when there's still half of it to display.
; --------------------------------------------------------------------------
inc d
; --------------------------------------------------------------------------
; Is it outside Y=+X?
; --------------------------------------------------------------------------
ld l,c
ld a,b \ xor $80 \ ld h,a
ld a,d \ xor $80 \ ld d,a
or a
sbc hl,de
jp nc,Buffer.Skip
; --------------------------------------------------------------------------
; Is it outside Y=-X?
; --------------------------------------------------------------------------
add hl,de
neg_de()
or a
sbc hl,de
jp c,Buffer.Skip
; --------------------------------------------------------------------------
; Now we have the thing to draw, we need to add it to our sorting buffer.
; --------------------------------------------------------------------------
ld de,SortedSpriteBuffer
ld a,(SortedSpriteBuffer.Count)
or a
jr z,SortedSpriteBuffer.Add
; --------------------------------------------------------------------------
; We need to find somewhere to add the sprite.
; --------------------------------------------------------------------------
ld b,a
FindInsertionPoint:
ex de,hl
ld e,(hl)
inc hl
ld d,(hl)
dec hl
ex de,hl
push bc
ld bc,(Transformed.Y)
or a
sbc hl,bc
pop bc
jr nc,IsCloser
; --------------------------------------------------------------------------
; The sprite is further from the camera than the one at (DE).
; --------------------------------------------------------------------------
IsFurther:
push de
ld l,b
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld b,h \ ld c,l
; BC = number of bytes to move.
ld a,(SortedSpriteBuffer.Count)
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld de,SortedSpriteBuffer-1
add hl,de
; HL->Current end of buffer.
push hl
ld de,8
add hl,de
ex de,hl
pop hl
; DE->End of buffer + 8
lddr
pop de
jr SortedSpriteBuffer.Add
IsCloser:
ld hl,8
add hl,de
ex de,hl
djnz FindInsertionPoint
; --------------------------------------------------------------------------
; Add the sorted sprite to the buffer.
; --------------------------------------------------------------------------
SortedSpriteBuffer.Add:
push bc
ld hl,Transformed.Y
ldi \ ldi ; Y
ldi \ ldi ; X
ld hl,Appearance.Offset
ldi \ ldi
ldi \ ldi ; (Dummy)
pop bc
; --------------------------------------------------------------------------
; We have one more item in the sprite buffer.
; --------------------------------------------------------------------------
ld a,(SortedSpriteBuffer.Count)
inc a
ld (SortedSpriteBuffer.Count),a
; --------------------------------------------------------------------------
; Do we have any more things to sort?
; --------------------------------------------------------------------------
Buffer.Skip:
ld a,(NextThing.Index)
or a
jr z,+
ld l,a
jp SortNextThing
+:
; --------------------------------------------------------------------------
; We now have a buffer full of sorted sprites. Draw them!
; --------------------------------------------------------------------------
ld a,(SortedSpriteBuffer.Count)
or a
jp z,AdvanceToNextSubsector
ld b,a
ld hl,SortedSpriteBuffer
DrawSortedSprite.Loop:
push bc
ld de,Transformed.Y
ldi \ ldi ; Y
ldi \ ldi ; X
ld de,Appearance.Offset
ldi \ ldi
inc hl \ inc hl
push hl
; --------------------------------------------------------------------------
; Get the sprite appearance information.
; --------------------------------------------------------------------------
ld hl,(Appearance.Offset)
ld de,Appearance
ld bc,Appearance.Size
ldir
ld (Sprite.Data),hl
; --------------------------------------------------------------------------
; Project to X.
; --------------------------------------------------------------------------
; 48 * X / Y
ld hl,(Transformed.X)
call Maths.Mul.S48
ld b,h \ ld c,l
ld de,(Transformed.Y)
call Maths.Div.S24S16
; Offset by the centre of the screen.
ld a,c
add a,48
ld (Projected.X),a
; --------------------------------------------------------------------------
; Project to Y.
; --------------------------------------------------------------------------
ld hl,(DrawingSubSector)
ld l,(hl)
ld h,0
.if Sector.DataSize != 4
.echoln "Sectors are no longer 4 bytes (fix this)"
.endif
add hl,hl
add hl,hl
ld de,(Level.Sectors)
add hl,de
ld e,(hl)
inc hl
ld d,(hl)
ld hl,(Render.Camera.Z)
add hl,de
ld de,(Transformed.Y)
call Maths.Div.S16S16
call Wall.Clip24To16
ld hl,(Render.Camera.YShear)
or a
sbc hl,bc
ld (Sprite.Column.Bottom),hl
call Wall.Clip16ToRowPlusOne
inc a
ld (Sprite.Column.Bottom.Clipped),a
; --------------------------------------------------------------------------
; Calculate the height and therefore top.
; --------------------------------------------------------------------------
ld hl,(Appearance.WorldHeight)
call Maths.Div.S16S16
call Wall.Clip24To16
ld a,b
or a
jp nz,Draw.Skip
ld a,c
or a
jp m,Draw.Skip
jp z,Draw.Skip
ld (Projected.Height),a
or a
jp z,Draw.Skip
ld hl,(Sprite.Column.Bottom)
sbc hl,bc
ld (Sprite.Column.Top),hl
call Wall.Clip16ToRowPlusOne
inc a
ld (Sprite.Column.Top.Clipped),a
; --------------------------------------------------------------------------
; Calculate the width.
; --------------------------------------------------------------------------
ld hl,(Appearance.WorldWidth)
ld de,(Transformed.Y)
call Maths.Div.S16S16
call Wall.Clip24To16
ld a,b
or a
jp nz,Draw.Skip
ld a,c
or a
jp m,Draw.Skip
jp z,Draw.Skip
ld (Projected.Width),a
; --------------------------------------------------------------------------
; Copy the width and height values over.
; --------------------------------------------------------------------------
ld a,(Projected.Height)
ld (Sprite.Column.DestinationHeight),a
ld a,(Appearance.SpriteHeight)
ld (Sprite.Column.SourceHeight),a
ld a,(Projected.Width)
ld (Delta.DestinationWidth),a
ld a,(Appearance.SpriteWidth)
ld (Delta.SourceWidth),a
ld a,(Delta.DestinationWidth)
ld (ColumnError),a
; --------------------------------------------------------------------------
; Draw the thing.
; --------------------------------------------------------------------------
ld a,(Projected.X)
ld l,a
ld a,(Projected.Width)
ld h,a
srl a
neg
add a,l
ld l,a
; --------------------------------------------------------------------------
; Initialise the per-row source offset.
; --------------------------------------------------------------------------
ld de,(Sprite.Data)
ld (Sprite.Column.SourceData),de
; --------------------------------------------------------------------------
; Draw a column.
; --------------------------------------------------------------------------
ColumnLoop:
push hl
call Sprite.DrawColumn
SkipColumn:
; --------------------------------------------------------------------------
; Advance to the next column if required.
; --------------------------------------------------------------------------
ColumnError = $+1
ld a,0
Delta.DestinationWidth = $+1
Delta.SourceWidth = $+2
ld de,0
sub d
jp p,NoAdvanceColumn
ld hl,(Sprite.Column.SourceData)
ld bc,(Appearance.ColumnStride)
-: add hl,bc
add a,e
jp m,-
ld (Sprite.Column.SourceData),hl
NoAdvanceColumn:
ld (ColumnError),a
pop hl
inc l
dec h
jp nz,ColumnLoop
Draw.Skip:
pop hl
pop bc
djnz +
jr AdvanceToNextSubsector
+: jp DrawSortedSprite.Loop
AdvanceToNextSubsector:
pop bc
djnz +
ret
+: jp Draw.Loop
; ==========================================================================
; GetPointerFromIndex
; --------------------------------------------------------------------------
; Gets a pointer to the thing's data by its index.
; --------------------------------------------------------------------------
; Inputs: A: Thing index.
; Outputs: HL: Pointer to the thing's data.
; Destroyed: F, DE.
; ==========================================================================
GetPointerFromIndex:
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld de,(Level.Things)
add hl,de
ret
; ==========================================================================
; SetPosition
; --------------------------------------------------------------------------
; Sets a thing's position.
; --------------------------------------------------------------------------
; Inputs: A: Thing index.
; HL: X coordinate of the thing's position.
; DE: Y coordinate of the thing's position.
; Destroyed: AF, BC, DE, HL, IX.
; ==========================================================================
SetPosition:
; --------------------------------------------------------------------------
; Store the index and destination position for later use.
; --------------------------------------------------------------------------
ld (Move.Index),a
ld (Move.X),hl
ld (Move.Y),de
; --------------------------------------------------------------------------
; Get the pointer to the thing to move.
; --------------------------------------------------------------------------
call GetPointerFromIndex
ld (Move.Pointer),hl
; --------------------------------------------------------------------------
; Get the current thing position.
; --------------------------------------------------------------------------
ld de,4
add hl,de
ld c,(hl) \ inc hl
ld b,(hl) \ inc hl
ld e,(hl) \ inc hl
ld d,(hl)
ld l,c \ ld h,b
; --------------------------------------------------------------------------
; Walk the BSP tree to determine which leaf the thing is currently in.
; --------------------------------------------------------------------------
call SetPosition.FindLeaf
ld (Move.SourceLeaf),ix
; --------------------------------------------------------------------------
; Walk the BSP tree to determine which leaf the thing is moving to.
; --------------------------------------------------------------------------
ld hl,(Move.X)
ld de,(Move.Y)
call SetPosition.FindLeaf
ld (Move.DestinationLeaf),ix
; --------------------------------------------------------------------------
; Have we moved from one leaf to another?
; --------------------------------------------------------------------------
ld hl,(Move.DestinationLeaf)
ld de,(Move.SourceLeaf)
or a
sbc hl,de
jr z,SetPosition.SkipMoveLeaf
; --------------------------------------------------------------------------
; Remove the thing from the old leaf.
; --------------------------------------------------------------------------
ex de,hl
inc hl ; Node type.
inc hl ; Sector index.
-: ld a,(Move.Index)
cp (hl)
jr z,SetPosition.FoundOldLeafIndex
ld a,(hl)
call GetPointerFromIndex
jr -
SetPosition.FoundOldLeafIndex:
; --------------------------------------------------------------------------
; HL points to the index of the thing in the current subsector.
; Replace this index with the index of the *next* thing.
; --------------------------------------------------------------------------
push hl
ld a,(hl)
call GetPointerFromIndex
ld a,(hl)
pop hl
ld (hl),a
; --------------------------------------------------------------------------
; Insert the thing to the head of the list in the new leaf.
; --------------------------------------------------------------------------
ld hl,(Move.DestinationLeaf)
inc hl ; Node type.
inc hl ; Sector index.
ld a,(hl)
push af
ld a,(Move.Index)
ld (hl),a
pop af
ld hl,(Move.Pointer)
ld (hl),a
jr SetPosition.ChangedLeaf
SetPosition.SkipMoveLeaf:
; --------------------------------------------------------------------------
; We didn't move the thing to a new leaf.
; --------------------------------------------------------------------------
ld hl,(Move.Pointer)
SetPosition.ChangedLeaf:
ld de,4
add hl,de
; --------------------------------------------------------------------------
; Write the new position to the thing.
; --------------------------------------------------------------------------
ld de,(Move.X)
ld (hl),e \ inc hl
ld (hl),d \ inc hl
ld de,(Move.Y)
ld (hl),e \ inc hl
ld (hl),d
ret
SetPosition.FindLeaf:
ld bc,SetPosition.FindLeafFunction
ld (SetPosition.FindLeafFunction.SP),sp
ld ix,(Level.Tree)
jp Tree.Walk
SetPosition.FindLeafFunction:
SetPosition.FindLeafFunction.SP = $+1
ld sp,0
ret
.if Options.ReportModuleSizes \ .echoln strformat("Things module: {0:N0} bytes.", $-Code) \ .endif
.endmodule |
projects/07/StackArithmetic/SimpleAdd/SimpleAdd.asm | azaslavsky/nand2tetris | 0 | 26629 | <reponame>azaslavsky/nand2tetris<filename>projects/07/StackArithmetic/SimpleAdd/SimpleAdd.asm
// push constant 7:
@7
D=A
@SP
A=M
M=D
@SP
M=M+1
// push constant 8:
@8
D=A
@SP
A=M
M=D
@SP
M=M+1
// add:
@SP
M=M-1
@SP
A=M
D=M
@SP
M=M-1
@SP
A=M
D=D+M
@SP
A=M
M=D
@SP
M=M+1
|
pipFiles/ifElse6.asm | hwheeler01/comp150 | 0 | 19339 | ; The new part here is the inequality test not with 0: rewrite
; if y > x: ; only can compare to 0! so rewrite: 0 > x - y
; x = x*2 ; rest is like others
; else:
; y = y*2
; z = x + y
; initialize x, y by hand in the simulator!
LOD x ; if y > x ; same as 0 > x - y
SUB y ; acc = x-y
STO temp ; temp = x-y ; CPL requires a memory variable
CPL temp ; if temp < 0: acc = 1 else: acc = 0
; if x-y < 0: ...
JMZ ELSE ; if acc == 0 jump to ELSE
; if not x-y < 0 jump to ELSE
LOD x ; acc = x (part if true)
MUL #2 ; acc = acc*2 (=x*2)
STO x ; x = acc (so x = x*2)
JMP PAST ; (avoid else part)
ELSE: LOD y ; acc = y (part if false)
MUL #2 ; acc = acc*2 (=y*2)
STO y ; y = acc (so y = y*2)
PAST: LOD x ; acc = x
ADD y ; acc = acc + y (= x+y)
STO z ; z = acc (=x+y)
HLT
|
programs/oeis/064/A064400.asm | jmorken/loda | 1 | 169241 | <filename>programs/oeis/064/A064400.asm
; A064400: Number of ordered pairs a,b of elements in the dihedral group D_2n such that the subgroup generated by the pair a,b is the entire group D_2n.
; 3,6,18,24,60,36,126,96,162,120,330,144,468,252,360,384,816,324,1026,480,756,660,1518,576,1500,936,1458,1008,2436,720,2790,1536,1980,1632,2520,1296,3996,2052,2808,1920,4920,1512,5418,2640,3240,3036,6486,2304,6174,3000,4896,3744,8268,2916,6600,4032,6156,4872,10266,2880,10980,5580,6804,6144,9360,3960,13266,6528,9108,5040,14910,5184,15768,7992,9000,8208,13860,5616,18486,7680,13122,9840,20418,6048,16320,10836,14616,10560,23496,6480,19656,12144,16740,12972,20520,9216,27936,12348,17820,12000,30300,9792,31518,14976,15120,16536,34026,11664,35316,13200,23976,16128,37968,12312,30360,19488,25272,20532,34272,11520,39930,21960,29520,22320,37500,13608,48006,24576,32508,18720,51090,15840,43092,26532,29160,26112,55896,18216,57546,20160,38916,29820,51480,20736,48720,31536,37044,31968,66156,18000,67950,32832,44064,27720,55800,22464,73476,36972,49608,30720,63756,26244,79218,39360,39600,40836,83166,24192,79092,32640,55404,43344,89268,29232,63000,42240,61596,46992,95586,25920,97740,39312,65880,48576,79920,33480,89760,51888,61236,41040,108870,36864,111168,55872,56160,49392,115836,35640,118206,48000,79596,60600,102312,39168,98400,63036,81972,59904,112860,30240,132930,66144,89460,68052,108360,46656,117180,70632,94608,52800,127296,47952,148518,64512,81000,75936,153906,49248,156636,60720,83160,77952,162168,50544,129720,82128,110916,68544,170646,46080,173520,79860,118098,87840,123480,59040,160056,89280,122508,75000
mov $2,$0
add $0,2
mul $0,$2
cal $0,10 ; Euler totient function phi(n): count numbers <= n and prime to n.
mul $0,2
mov $1,14
add $1,$0
sub $1,16
div $1,2
mul $1,3
add $1,3
|
src/evaluate.ads | hgrodriguez/embedded-dashboard-console | 0 | 23476 | --===========================================================================
--
-- This is the root package for the different evaluations for the different
-- available dashboard elements.
--
--===========================================================================
--
-- Copyright 2021 (C) <NAME>
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with Transport;
package Evaluate is
--------------------------------------------------------------------------
-- Definitions of area selectors for the different areas available
--------------------------------------------------------------------------
LED_Prefix : constant Transport.Area_Selector := Transport.Led;
Matrix_Prefix : constant Transport.Area_Selector := Transport.Matrix;
end Evaluate;
|
Transynther/x86/_processed/NONE/_st_/i9-9900K_12_0xca.log_21829_586.asm | ljhsiun2/medusa | 9 | 2903 | .global s_prepare_buffers
s_prepare_buffers:
push %r15
push %r8
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0x6921, %rax
nop
nop
nop
nop
nop
sub $33753, %r8
movl $0x61626364, (%rax)
nop
nop
xor %rcx, %rcx
lea addresses_UC_ht+0x14121, %rsi
lea addresses_WC_ht+0xf161, %rdi
nop
nop
nop
nop
add %rdx, %rdx
mov $78, %rcx
rep movsq
nop
xor $9660, %r15
lea addresses_WC_ht+0xeb21, %rcx
nop
nop
nop
nop
nop
add $43662, %rsi
vmovups (%rcx), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $1, %xmm6, %rdx
nop
nop
nop
nop
nop
xor %rcx, %rcx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r15
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r15
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
// Store
mov $0x35, %r15
nop
add %rsi, %rsi
mov $0x5152535455565758, %rbx
movq %rbx, (%r15)
nop
nop
nop
nop
and %rdi, %rdi
// Store
lea addresses_PSE+0x112a1, %rsi
nop
nop
nop
dec %rbx
mov $0x5152535455565758, %r15
movq %r15, %xmm3
vmovups %ymm3, (%rsi)
nop
nop
nop
and $1820, %rdi
// Store
lea addresses_PSE+0x55a1, %rdx
xor $56430, %rcx
movl $0x51525354, (%rdx)
add %r12, %r12
// Store
lea addresses_normal+0xfd21, %rdx
nop
nop
nop
and %r15, %r15
mov $0x5152535455565758, %rsi
movq %rsi, %xmm5
movups %xmm5, (%rdx)
add $41285, %rcx
// Store
lea addresses_US+0x10911, %rsi
clflush (%rsi)
nop
nop
nop
xor %rdx, %rdx
movl $0x51525354, (%rsi)
nop
nop
nop
nop
nop
cmp $25529, %rdi
// Load
lea addresses_UC+0x1de61, %rsi
nop
nop
nop
nop
nop
and %r12, %r12
mov (%rsi), %rdi
nop
nop
cmp %r15, %r15
// Store
lea addresses_US+0x6921, %r15
nop
nop
nop
nop
add %rdi, %rdi
movb $0x51, (%r15)
nop
nop
nop
nop
xor $3638, %rsi
// Faulty Load
lea addresses_WT+0xbd21, %rdx
nop
sub %r15, %r15
mov (%rdx), %di
lea oracles, %r12
and $0xff, %rdi
shlq $12, %rdi
mov (%r12,%rdi,1), %rdi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r15
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_WT', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_P', 'same': False, 'AVXalign': True, 'congruent': 1}}
{'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_PSE', 'same': False, 'AVXalign': False, 'congruent': 6}}
{'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_PSE', 'same': False, 'AVXalign': False, 'congruent': 7}}
{'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_normal', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_US', 'same': False, 'AVXalign': False, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_UC', 'same': False, 'AVXalign': False, 'congruent': 4}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_US', 'same': False, 'AVXalign': False, 'congruent': 9}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_WT', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 10}, 'dst': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 6}}
{'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_WC_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'58': 21829}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
src/apsepp-output_class.ads | thierr26/ada-apsepp | 0 | 7767 | -- Copyright (C) 2019 <NAME> <<EMAIL>>
-- MIT license. Please refer to the LICENSE file.
package Apsepp.Output_Class is
pragma Pure (Output_Class);
type Output_Interfa is limited interface;
not overriding
procedure Put_Line (Obj : in out Output_Interfa; S : String) is null;
end Apsepp.Output_Class;
|
agda/Container/List/Syntax.agda | oisdk/combinatorics-paper | 6 | 9387 | <gh_stars>1-10
{-# OPTIONS --cubical --safe #-}
module Container.List.Syntax where
open import Prelude
open import Container
open import Container.List
open import Data.Fin
record ListSyntax {a b} (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where
field [_] : B → List A
open ListSyntax ⦃ ... ⦄ public
instance
cons : ⦃ _ : ListSyntax A B ⦄ → ListSyntax A (A × B)
[_] ⦃ cons ⦄ (x , xs) .fst = suc ([ xs ] .fst)
[_] ⦃ cons ⦄ (x , xs) .snd f0 = x
[_] ⦃ cons ⦄ (x , xs) .snd (fs n) = [ xs ] .snd n
instance
sing : ListSyntax A A
[_] ⦃ sing ⦄ x = 1 , const x
|
src/agda/FRP/JS/Size.agda | agda/agda-frp-js | 63 | 63 | <filename>src/agda/FRP/JS/Size.agda
module FRP.JS.Size where
postulate
Size : Set
↑_ : Size → Size
∞ : Size
{-# BUILTIN SIZE Size #-}
{-# BUILTIN SIZESUC ↑_ #-}
{-# BUILTIN SIZEINF ∞ #-}
{-# COMPILED_JS ↑_ function(x) { return null; } #-}
{-# COMPILED_JS ∞ null #-}
|
notes/FOT/FOTC/Program/Mirror/MirrorListTerminatingSL.agda | asr/fotc | 11 | 14283 | <reponame>asr/fotc
------------------------------------------------------------------------------
-- Terminating mirror function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Mirror.MirrorListTerminatingSL where
open import Data.List
------------------------------------------------------------------------------
-- The rose tree type.
data Tree (A : Set) : Set where
tree : A → List (Tree A) → Tree A
------------------------------------------------------------------------------
-- An alternative and terminating definition of mirror. Adapted from
-- http://stackoverflow.com/questions/9146928/termination-of-structural-induction
-- The mirror function.
mirror : {A : Set} → Tree A → Tree A
mirrorBranch : {A : Set} → List (Tree A) → List (Tree A)
mirror (tree a ts) = tree a (reverse (mirrorBranch ts))
mirrorBranch [] = []
mirrorBranch (t ∷ ts) = mirror t ∷ mirrorBranch ts
|
src/bootc/start.asm | devcfei/bootstrap-x86 | 0 | 244576 | extern kmain
[bits 32]
_start:
call kmain |
Application Support/BBEdit/Packages/dStyle.bbpackage/Contents/Scripts/Window/04)Split Vertical.applescript | bhdicaire/bbeditSetup | 0 | 2379 | -- Emulate splitting a window vertically by opening the active document
-- in a new window and arranging both windows side by side
on run
tell application "BBEdit"
set w to text window 1
set w1 to ID of w
-- Calculate the bounds for source window
-- bounds are left, top, right, bottom
set b to bounds of w
set x1 to (item 3 of b) + 4
set y1 to (item 2 of b)
set x2 to x1 + ((item 3 of b) - (item 1 of b))
set y2 to (item 4 of b)
-- Adjust for file list if visible
if files visible of w is true then
set x2 to (x2 - 222)
end if
-- Create new window
set w2 to make new text window with properties {bounds:{x1, y1, x2, y2}}
-- Get untitled doc id created with w
set udoc to ID of document 1 of w2
-- Put the active document of
move document 1 of text window id w1 to w2
-- Cleanup
set files visible of w2 to false
close document id udoc
select w2
end tell
end run |
src/Function-universe.agda | nad/equality | 3 | 5220 | <gh_stars>1-10
------------------------------------------------------------------------
-- A universe which includes several kinds of functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
module Function-universe
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq as Bijection using (_↔_; module _↔_)
open Derived-definitions-and-properties eq
open import Embedding eq as Emb using (Is-embedding; Embedding)
open import Equality.Decidable-UIP eq
open import Equality.Decision-procedures eq
open import Equivalence eq as Eq using (_≃_; module _≃_; Is-equivalence)
import Equivalence.Contractible-preimages eq as CP
open import Equivalence.Erased.Basics eq as EEq using (_≃ᴱ_)
import Equivalence.Half-adjoint eq as HA
open import Erased.Basics as E using (Erased)
open import H-level eq as H-level
open import H-level.Closure eq
open import Injection eq as Injection using (_↣_; module _↣_; Injective)
open import Logical-equivalence as L using (_⇔_; module _⇔_)
open import Nat eq hiding (_≟_)
open import Preimage eq using (_⁻¹_)
open import Prelude as P hiding (id) renaming (_∘_ to _⊚_)
open import Surjection eq as Surjection using (_↠_; Split-surjective)
------------------------------------------------------------------------
-- The universe
-- The universe includes implications, logical equivalences,
-- injections, embeddings, surjections, bijections, equivalences, and
-- equivalences with erased proofs.
data Kind : Type where
implication
logical-equivalence
injection
embedding
surjection
bijection
equivalence
equivalenceᴱ : Kind
-- The interpretation of the universe.
infix 0 _↝[_]_
_↝[_]_ : ∀ {ℓ₁ ℓ₂} → Type ℓ₁ → Kind → Type ℓ₂ → Type _
A ↝[ implication ] B = A → B
A ↝[ logical-equivalence ] B = A ⇔ B
A ↝[ injection ] B = A ↣ B
A ↝[ embedding ] B = Embedding A B
A ↝[ surjection ] B = A ↠ B
A ↝[ bijection ] B = A ↔ B
A ↝[ equivalence ] B = A ≃ B
A ↝[ equivalenceᴱ ] B = A ≃ᴱ B
-- Equivalences can be converted to all kinds of functions.
from-equivalence : ∀ {k a b} {A : Type a} {B : Type b} →
A ≃ B → A ↝[ k ] B
from-equivalence {implication} = _≃_.to
from-equivalence {logical-equivalence} = _≃_.logical-equivalence
from-equivalence {injection} = _≃_.injection
from-equivalence {embedding} = Emb.≃→Embedding
from-equivalence {surjection} = _≃_.surjection
from-equivalence {bijection} = _≃_.bijection
from-equivalence {equivalence} = P.id
from-equivalence {equivalenceᴱ} = EEq.≃→≃ᴱ
-- Bijections can be converted to all kinds of functions.
from-bijection : ∀ {k a b} {A : Type a} {B : Type b} →
A ↔ B → A ↝[ k ] B
from-bijection {implication} = _↔_.to
from-bijection {logical-equivalence} = _↔_.logical-equivalence
from-bijection {injection} = _↔_.injection
from-bijection {embedding} = from-equivalence ⊚ Eq.↔⇒≃
from-bijection {surjection} = _↔_.surjection
from-bijection {bijection} = P.id
from-bijection {equivalence} = Eq.↔⇒≃
from-bijection {equivalenceᴱ} = EEq.≃→≃ᴱ ⊚ Eq.↔⇒≃
-- All kinds of functions can be converted to implications.
to-implication : ∀ {k a b} {@0 A : Type a} {@0 B : Type b} →
A ↝[ k ] B → A → B
to-implication {implication} f =
f
to-implication {logical-equivalence} f =
let record { to = to } = f in to
to-implication {injection} f =
let record { to = to } = f in to
to-implication {embedding} f =
let record { to = to } = f in to
to-implication {surjection} f =
let record
{ logical-equivalence = record
{ to = to
}
} = f
in to
to-implication {bijection} f =
let record
{ surjection = record
{ logical-equivalence = record
{ to = to
}
}
} = f
in to
to-implication {equivalence} f =
let record { to = to } = f in to
to-implication {equivalenceᴱ} f =
_≃ᴱ_.to f
------------------------------------------------------------------------
-- A sub-universe of symmetric kinds of functions
data Symmetric-kind : Type where
logical-equivalence bijection equivalence equivalenceᴱ :
Symmetric-kind
⌊_⌋-sym : Symmetric-kind → Kind
⌊ logical-equivalence ⌋-sym = logical-equivalence
⌊ bijection ⌋-sym = bijection
⌊ equivalence ⌋-sym = equivalence
⌊ equivalenceᴱ ⌋-sym = equivalenceᴱ
inverse : ∀ {k a b} {A : Type a} {B : Type b} →
A ↝[ ⌊ k ⌋-sym ] B → B ↝[ ⌊ k ⌋-sym ] A
inverse {logical-equivalence} = L.inverse
inverse {bijection} = Bijection.inverse
inverse {equivalence} = Eq.inverse
inverse {equivalenceᴱ} = EEq.inverse
-- If there is a symmetric kind of function from A to B, then A and B
-- are logically equivalent.
sym→⇔ :
∀ {k a b} {A : Type a} {B : Type b} →
A ↝[ ⌊ k ⌋-sym ] B → A ⇔ B
sym→⇔ {k = logical-equivalence} = P.id
sym→⇔ {k = bijection} = from-bijection
sym→⇔ {k = equivalence} = from-equivalence
sym→⇔ {k = equivalenceᴱ} = _≃ᴱ_.logical-equivalence
------------------------------------------------------------------------
-- A sub-universe of isomorphisms
data Isomorphism-kind : Type where
bijection equivalence : Isomorphism-kind
⌊_⌋-iso : Isomorphism-kind → Kind
⌊ bijection ⌋-iso = bijection
⌊ equivalence ⌋-iso = equivalence
infix 0 _↔[_]_
_↔[_]_ : ∀ {ℓ₁ ℓ₂} → Type ℓ₁ → Isomorphism-kind → Type ℓ₂ → Type _
A ↔[ k ] B = A ↝[ ⌊ k ⌋-iso ] B
from-isomorphism : ∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
A ↔[ k₁ ] B → A ↝[ k₂ ] B
from-isomorphism {bijection} = from-bijection
from-isomorphism {equivalence} = from-equivalence
-- Lemma: to-implication after from-isomorphism is the same as
-- to-implication.
to-implication∘from-isomorphism :
∀ {a b} {A : Type a} {B : Type b} k₁ k₂ {A↔B : A ↔[ k₁ ] B} →
to-implication A↔B ≡
to-implication (from-isomorphism {k₂ = k₂} A↔B)
to-implication∘from-isomorphism {A = A} {B} = t∘f
where
t∘f : ∀ k₁ k₂ {A↔B : A ↔[ k₁ ] B} →
to-implication A↔B ≡
to-implication (from-isomorphism {k₂ = k₂} A↔B)
t∘f bijection implication = refl _
t∘f bijection logical-equivalence = refl _
t∘f bijection injection = refl _
t∘f bijection embedding = refl _
t∘f bijection surjection = refl _
t∘f bijection bijection = refl _
t∘f bijection equivalence = refl _
t∘f bijection equivalenceᴱ = refl _
t∘f equivalence implication = refl _
t∘f equivalence logical-equivalence = refl _
t∘f equivalence injection = refl _
t∘f equivalence embedding = refl _
t∘f equivalence surjection = refl _
t∘f equivalence bijection = refl _
t∘f equivalence equivalence = refl _
t∘f equivalence equivalenceᴱ = refl _
------------------------------------------------------------------------
-- Preorder
-- All the different kinds of functions form preorders.
-- Composition.
infixr 9 _∘_
_∘_ : ∀ {k a b c} {A : Type a} {B : Type b} {C : Type c} →
B ↝[ k ] C → A ↝[ k ] B → A ↝[ k ] C
_∘_ {implication} = λ f g → f ⊚ g
_∘_ {logical-equivalence} = L._∘_
_∘_ {injection} = Injection._∘_
_∘_ {embedding} = Emb._∘_
_∘_ {surjection} = Surjection._∘_
_∘_ {bijection} = Bijection._∘_
_∘_ {equivalence} = Eq._∘_
_∘_ {equivalenceᴱ} = EEq._∘_
-- Identity.
id : ∀ {k a} {A : Type a} → A ↝[ k ] A
id {implication} = P.id
id {logical-equivalence} = L.id
id {injection} = Injection.id
id {embedding} = Emb.id
id {surjection} = Surjection.id
id {bijection} = Bijection.id
id {equivalence} = Eq.id
id {equivalenceᴱ} = EEq.id
-- "Equational" reasoning combinators.
infix -1 finally-↝ finally-↔
infix -1 _□
infixr -2 step-↝ step-↔ _↔⟨⟩_
infix -3 $⟨_⟩_
-- For an explanation of why step-↝ and step-↔ are defined in this
-- way, see Equality.step-≡.
step-↝ : ∀ {k a b c} (A : Type a) {B : Type b} {C : Type c} →
B ↝[ k ] C → A ↝[ k ] B → A ↝[ k ] C
step-↝ _ = _∘_
syntax step-↝ A B↝C A↝B = A ↝⟨ A↝B ⟩ B↝C
step-↔ : ∀ {k₁ k₂ a b c} (A : Type a) {B : Type b} {C : Type c} →
B ↝[ k₂ ] C → A ↔[ k₁ ] B → A ↝[ k₂ ] C
step-↔ _ B↝C A↔B = step-↝ _ B↝C (from-isomorphism A↔B)
syntax step-↔ A B↝C A↔B = A ↔⟨ A↔B ⟩ B↝C
_↔⟨⟩_ : ∀ {k a b} (A : Type a) {B : Type b} →
A ↝[ k ] B → A ↝[ k ] B
_ ↔⟨⟩ A↝B = A↝B
_□ : ∀ {k a} (A : Type a) → A ↝[ k ] A
A □ = id
finally-↝ : ∀ {k a b} (A : Type a) (B : Type b) →
A ↝[ k ] B → A ↝[ k ] B
finally-↝ _ _ A↝B = A↝B
syntax finally-↝ A B A↝B = A ↝⟨ A↝B ⟩□ B □
finally-↔ : ∀ {k₁ k₂ a b} (A : Type a) (B : Type b) →
A ↔[ k₁ ] B → A ↝[ k₂ ] B
finally-↔ _ _ A↔B = from-isomorphism A↔B
syntax finally-↔ A B A↔B = A ↔⟨ A↔B ⟩□ B □
$⟨_⟩_ : ∀ {k a b} {@0 A : Type a} {@0 B : Type b} →
A → A ↝[ k ] B → B
$⟨ a ⟩ A↝B = to-implication A↝B a
-- Lemma: to-implication maps id to the identity function.
to-implication-id :
∀ {a} {A : Type a} k →
to-implication {k = k} id ≡ id {A = A}
to-implication-id implication = refl _
to-implication-id logical-equivalence = refl _
to-implication-id injection = refl _
to-implication-id embedding = refl _
to-implication-id surjection = refl _
to-implication-id bijection = refl _
to-implication-id equivalence = refl _
to-implication-id equivalenceᴱ = refl _
-- Lemma: to-implication is homomorphic with respect to _∘_.
to-implication-∘ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
(k : Kind) {f : A ↝[ k ] B} {g : B ↝[ k ] C} →
to-implication (g ∘ f) ≡ to-implication g ∘ to-implication f
to-implication-∘ implication = refl _
to-implication-∘ logical-equivalence = refl _
to-implication-∘ injection = refl _
to-implication-∘ embedding = refl _
to-implication-∘ surjection = refl _
to-implication-∘ bijection = refl _
to-implication-∘ equivalence = refl _
to-implication-∘ equivalenceᴱ = refl _
-- Lemma: to-implication maps inverse id to the identity function.
to-implication-inverse-id :
∀ {a} {A : Type a} k →
to-implication (inverse {k = k} id) ≡ id {A = A}
to-implication-inverse-id logical-equivalence = refl _
to-implication-inverse-id bijection = refl _
to-implication-inverse-id equivalence = refl _
to-implication-inverse-id equivalenceᴱ = refl _
------------------------------------------------------------------------
-- Conditional extensionality
-- Code that provides support for proving general statements about
-- functions of different kinds, in which the statements involve
-- assumptions of extensionality for some kinds of functions, but not
-- all. For some examples, see ∀-cong and ∀-intro.
-- Kinds for which extensionality is not provided.
data Without-extensionality : Type where
implication logical-equivalence : Without-extensionality
⌊_⌋-without : Without-extensionality → Kind
⌊ implication ⌋-without = implication
⌊ logical-equivalence ⌋-without = logical-equivalence
-- Kinds for which erased extensionality is not provided.
data With-erased-extensionality : Type where
equivalenceᴱ : With-erased-extensionality
⌊_⌋-with-erased : With-erased-extensionality → Kind
⌊ equivalenceᴱ ⌋-with-erased = equivalenceᴱ
-- Kinds for which extensionality is provided.
data With-extensionality : Type where
injection embedding surjection bijection equivalence :
With-extensionality
⌊_⌋-with : With-extensionality → Kind
⌊ injection ⌋-with = injection
⌊ embedding ⌋-with = embedding
⌊ surjection ⌋-with = surjection
⌊ bijection ⌋-with = bijection
⌊ equivalence ⌋-with = equivalence
-- Kinds annotated with information about what kind of extensionality
-- is provided, if any.
data Extensionality-kind : Kind → Type where
without-extensionality : (k : Without-extensionality) →
Extensionality-kind ⌊ k ⌋-without
with-erased-extensionality : (k : With-erased-extensionality) →
Extensionality-kind ⌊ k ⌋-with-erased
with-extensionality : (k : With-extensionality) →
Extensionality-kind ⌊ k ⌋-with
-- Is extensionality provided for the given kind?
extensionality? : (k : Kind) → Extensionality-kind k
extensionality? implication = without-extensionality implication
extensionality? logical-equivalence = without-extensionality
logical-equivalence
extensionality? injection = with-extensionality injection
extensionality? embedding = with-extensionality embedding
extensionality? surjection = with-extensionality surjection
extensionality? bijection = with-extensionality bijection
extensionality? equivalence = with-extensionality equivalence
extensionality? equivalenceᴱ = with-erased-extensionality
equivalenceᴱ
-- Extensionality, but only for certain kinds of functions, and
-- possibly erased.
Extensionality? : Kind → (a b : Level) → Type (lsuc (a ⊔ b))
Extensionality? k a b with extensionality? k
... | without-extensionality _ = ↑ _ ⊤
... | with-erased-extensionality _ = Erased (Extensionality a b)
... | with-extensionality _ = Extensionality a b
-- A variant of _↝[_]_. A ↝[ c ∣ d ] B means that A ↝[ k ] B can be
-- proved for all kinds k, in some cases assuming extensionality (for
-- the levels c and d).
infix 0 _↝[_∣_]_
_↝[_∣_]_ :
∀ {a b} →
Type a → (c d : Level) → Type b → Type (a ⊔ b ⊔ lsuc (c ⊔ d))
A ↝[ c ∣ d ] B = ∀ {k} → Extensionality? k c d → A ↝[ k ] B
-- A variant of _↝[_∣_]_ with erased extensionality assumptions.
infix 0 _↝[_∣_]ᴱ_
_↝[_∣_]ᴱ_ :
∀ {a b} →
Type a → (c d : Level) → Type b → Type (a ⊔ b ⊔ lsuc (c ⊔ d))
A ↝[ c ∣ d ]ᴱ B = ∀ {k} → @0 Extensionality? k c d → A ↝[ k ] B
-- Turns extensionality into conditional extensionality.
forget-ext? : ∀ k {a b} → Extensionality a b → Extensionality? k a b
forget-ext? k with extensionality? k
... | without-extensionality _ = _
... | with-erased-extensionality _ = E.[_]→
... | with-extensionality _ = id
-- A variant of lower-extensionality.
lower-extensionality? :
∀ k {a b} â b̂ →
Extensionality? k (a ⊔ â) (b ⊔ b̂) → Extensionality? k a b
lower-extensionality? k â b̂ with extensionality? k
... | without-extensionality _ = _
... | with-erased-extensionality _ = E.map (lower-extensionality â b̂)
... | with-extensionality _ = lower-extensionality â b̂
-- Some functions that can be used to generalise results.
generalise-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
(A⇔B : A ⇔ B) →
(Extensionality c d →
let open _⇔_ A⇔B in
(∀ x → to (from x) ≡ x) ×
(∀ x → from (to x) ≡ x)) →
A ↝[ c ∣ d ] B
generalise-ext? A⇔B hyp {k = k} with extensionality? k
... | without-extensionality implication =
λ _ → _⇔_.to A⇔B
... | without-extensionality logical-equivalence =
λ _ → A⇔B
... | with-extensionality _ = λ ext →
from-bijection record
{ surjection = record
{ logical-equivalence = A⇔B
; right-inverse-of = hyp ext .proj₁
}
; left-inverse-of = hyp ext .proj₂
}
... | with-erased-extensionality equivalenceᴱ = λ (E.[ ext ]) →
EEq.↔→≃ᴱ (_⇔_.to A⇔B) (_⇔_.from A⇔B) (hyp ext .proj₁) (hyp ext .proj₂)
generalise-erased-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
A ⇔ B →
(@0 Extensionality c d → A ↔ B) →
A ↝[ c ∣ d ]ᴱ B
generalise-erased-ext? f⇔ f↔ {k = k} with extensionality? k
... | without-extensionality implication =
λ _ → _⇔_.to f⇔
... | without-extensionality logical-equivalence =
λ _ → f⇔
... | with-extensionality _ = λ ext →
from-isomorphism (f↔ ext)
... | with-erased-extensionality _ = λ ext →
from-isomorphism (f↔ (E.erased ext))
generalise-ext?-prop :
∀ {a b c d} {A : Type a} {B : Type b} →
A ⇔ B →
(Extensionality c d → Is-proposition A) →
(Extensionality c d → Is-proposition B) →
A ↝[ c ∣ d ] B
generalise-ext?-prop f⇔ A-prop B-prop =
generalise-ext?
f⇔
(λ ext →
(λ _ → B-prop ext _ _)
, (λ _ → A-prop ext _ _))
generalise-erased-ext?-prop :
∀ {a b c d} {A : Type a} {B : Type b} →
A ⇔ B →
(@0 Extensionality c d → Is-proposition A) →
(@0 Extensionality c d → Is-proposition B) →
A ↝[ c ∣ d ]ᴱ B
generalise-erased-ext?-prop f⇔ A-prop B-prop =
generalise-erased-ext?
f⇔
(λ ext → _≃_.bijection $
_↠_.from (Eq.≃↠⇔ (A-prop ext) (B-prop ext)) f⇔)
generalise-ext?-sym :
∀ {a b c d} {A : Type a} {B : Type b} →
(∀ {k} → Extensionality? ⌊ k ⌋-sym c d → A ↝[ ⌊ k ⌋-sym ] B) →
A ↝[ c ∣ d ] B
generalise-ext?-sym hyp {k = k} ext with extensionality? k
... | without-extensionality implication =
_⇔_.to $ hyp {k = logical-equivalence} ext
... | without-extensionality logical-equivalence =
hyp {k = logical-equivalence} ext
... | with-extensionality _ =
from-bijection $ hyp {k = bijection} ext
... | with-erased-extensionality equivalenceᴱ =
hyp {k = equivalenceᴱ} ext
generalise-erased-ext?-sym :
∀ {a b c d} {A : Type a} {B : Type b} →
(∀ {k} → @0 Extensionality? ⌊ k ⌋-sym c d → A ↝[ ⌊ k ⌋-sym ] B) →
A ↝[ c ∣ d ]ᴱ B
generalise-erased-ext?-sym hyp = generalise-erased-ext? (hyp _) hyp
-- General results of the kind produced by generalise-ext? are
-- symmetric.
inverse-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
A ↝[ c ∣ d ] B → B ↝[ c ∣ d ] A
inverse-ext? hyp = generalise-ext?-sym (inverse ⊚ hyp)
inverse-erased-ext? :
∀ {a b c d} {A : Type a} {B : Type b} →
A ↝[ c ∣ d ]ᴱ B → B ↝[ c ∣ d ]ᴱ A
inverse-erased-ext? hyp =
generalise-erased-ext?-sym (λ ext → inverse (hyp ext))
------------------------------------------------------------------------
-- Lots of properties
------------------------------------------------------------------------
-- Properties of the form A ↝[ k ] B, for arbitrary k, are only stated
-- for bijections or equivalences; converting to the other forms is
-- easy.
------------------------------------------------------------------------
-- Equalities can be converted to all kinds of functions
≡⇒↝ : ∀ k {ℓ} {A B : Type ℓ} → A ≡ B → A ↝[ k ] B
≡⇒↝ k = elim (λ {A B} _ → A ↝[ k ] B) (λ _ → id)
abstract
-- Some lemmas that can be used to manipulate expressions involving
-- ≡⇒↝ and refl/sym/trans.
≡⇒↝-refl : ∀ {k a} {A : Type a} →
≡⇒↝ k (refl A) ≡ id
≡⇒↝-refl {k} = elim-refl (λ {A B} _ → A ↝[ k ] B) _
≡⇒↝-sym : ∀ k {ℓ} {A B : Type ℓ} {eq : A ≡ B} →
to-implication (≡⇒↝ ⌊ k ⌋-sym (sym eq)) ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym eq))
≡⇒↝-sym k {A = A} {eq = eq} = elim¹
(λ eq → to-implication (≡⇒↝ ⌊ k ⌋-sym (sym eq)) ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym eq)))
(to-implication (≡⇒↝ ⌊ k ⌋-sym (sym (refl A))) ≡⟨ cong (to-implication ∘ ≡⇒↝ ⌊ k ⌋-sym) sym-refl ⟩
to-implication (≡⇒↝ ⌊ k ⌋-sym (refl A)) ≡⟨ cong (to-implication {k = ⌊ k ⌋-sym}) ≡⇒↝-refl ⟩
to-implication {k = ⌊ k ⌋-sym} id ≡⟨ to-implication-id ⌊ k ⌋-sym ⟩
id ≡⟨ sym $ to-implication-inverse-id k ⟩
to-implication (inverse {k = k} id) ≡⟨ cong (to-implication ∘ inverse {k = k}) $ sym ≡⇒↝-refl ⟩∎
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (refl A))) ∎)
eq
≡⇒↝-trans : ∀ k {ℓ} {A B C : Type ℓ} {A≡B : A ≡ B} {B≡C : B ≡ C} →
to-implication (≡⇒↝ k (trans A≡B B≡C)) ≡
to-implication (≡⇒↝ k B≡C ∘ ≡⇒↝ k A≡B)
≡⇒↝-trans k {B = B} {A≡B = A≡B} = elim¹
(λ B≡C → to-implication (≡⇒↝ k (trans A≡B B≡C)) ≡
to-implication (≡⇒↝ k B≡C ∘ ≡⇒↝ k A≡B))
(to-implication (≡⇒↝ k (trans A≡B (refl B))) ≡⟨ cong (to-implication ∘ ≡⇒↝ k) $ trans-reflʳ _ ⟩
to-implication (≡⇒↝ k A≡B) ≡⟨ sym $ cong (λ f → f ∘ to-implication (≡⇒↝ k A≡B)) $ to-implication-id k ⟩
to-implication {k = k} id ∘ to-implication (≡⇒↝ k A≡B) ≡⟨ sym $ to-implication-∘ k ⟩
to-implication (id ∘ ≡⇒↝ k A≡B) ≡⟨ sym $ cong (λ f → to-implication (f ∘ ≡⇒↝ k A≡B)) ≡⇒↝-refl ⟩∎
to-implication (≡⇒↝ k (refl B) ∘ ≡⇒↝ k A≡B) ∎)
_
-- One can sometimes "push" ≡⇒↝ through cong.
--
-- This is a generalisation of a lemma due to Thierry Coquand.
≡⇒↝-cong : ∀ {k ℓ p A B} {eq : A ≡ B}
(P : Type ℓ → Type p)
(P-cong : ∀ {A B} → A ↝[ k ] B → P A ↝[ k ] P B) →
P-cong (id {A = A}) ≡ id →
≡⇒↝ _ (cong P eq) ≡ P-cong (≡⇒↝ _ eq)
≡⇒↝-cong {eq = eq} P P-cong P-cong-id = elim¹
(λ eq → ≡⇒↝ _ (cong P eq) ≡ P-cong (≡⇒↝ _ eq))
(≡⇒↝ _ (cong P (refl _)) ≡⟨ cong (≡⇒↝ _) $ cong-refl P ⟩
≡⇒↝ _ (refl _) ≡⟨ elim-refl (λ {A B} _ → A ↝[ _ ] B) _ ⟩
id ≡⟨ sym P-cong-id ⟩
P-cong id ≡⟨ cong P-cong $ sym $
elim-refl (λ {A B} _ → A ↝[ _ ] B) _ ⟩∎
P-cong (≡⇒↝ _ (refl _)) ∎)
eq
-- One can express ≡⇒↝ in terms of subst.
≡⇒↝-in-terms-of-subst :
∀ k {ℓ} {A B : Type ℓ} (A≡B : A ≡ B) →
≡⇒↝ k A≡B ≡ subst (A ↝[ k ]_) A≡B id
≡⇒↝-in-terms-of-subst k {B = B} = elim₁
(λ {A} A≡B → ≡⇒↝ k A≡B ≡ subst (A ↝[ k ]_) A≡B id)
(≡⇒↝ k (refl B) ≡⟨ ≡⇒↝-refl ⟩
id ≡⟨ sym $ subst-refl _ _ ⟩∎
subst (B ↝[ k ]_) (refl B) id ∎)
≡⇒↝-in-terms-of-subst-sym :
∀ k {ℓ} {A B : Type ℓ} (A≡B : A ≡ B) →
≡⇒↝ k A≡B ≡ subst (_↝[ k ] B) (sym A≡B) id
≡⇒↝-in-terms-of-subst-sym k {B = B} = elim₁
(λ {A} A≡B → ≡⇒↝ k A≡B ≡ subst (_↝[ k ] B) (sym A≡B) id)
(≡⇒↝ k (refl B) ≡⟨ ≡⇒↝-refl ⟩
id ≡⟨ sym $ subst-refl _ _ ⟩
subst (_↝[ k ] B) (refl B) id ≡⟨ cong (flip (subst _) _) $ sym sym-refl ⟩∎
subst (_↝[ k ] B) (sym (refl B)) id ∎)
-- One can express subst in terms of ≡⇒↝.
subst-in-terms-of-≡⇒↝ :
∀ k {a p} {A : Type a} {x y} (x≡y : x ≡ y) (P : A → Type p) p →
subst P x≡y p ≡ to-implication (≡⇒↝ k (cong P x≡y)) p
subst-in-terms-of-≡⇒↝ k x≡y P p = elim¹
(λ eq → subst P eq p ≡ to-implication (≡⇒↝ k (cong P eq)) p)
(subst P (refl _) p ≡⟨ subst-refl P p ⟩
p ≡⟨ sym $ cong (_$ p) (to-implication-id k) ⟩
to-implication {k = k} id p ≡⟨ sym $ cong (λ f → to-implication {k = k} f p) ≡⇒↝-refl ⟩
to-implication (≡⇒↝ k (refl _)) p ≡⟨ sym $ cong (λ eq → to-implication (≡⇒↝ k eq) p) $ cong-refl P ⟩∎
to-implication (≡⇒↝ k (cong P (refl _))) p ∎)
x≡y
subst-in-terms-of-inverse∘≡⇒↝ :
∀ k {a p} {A : Type a} {x y} (x≡y : x ≡ y) (P : A → Type p) p →
subst P (sym x≡y) p ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (cong P x≡y))) p
subst-in-terms-of-inverse∘≡⇒↝ k x≡y P p =
subst P (sym x≡y) p ≡⟨ subst-in-terms-of-≡⇒↝ ⌊ k ⌋-sym (sym x≡y) P p ⟩
to-implication (≡⇒↝ ⌊ k ⌋-sym (cong P (sym x≡y))) p ≡⟨ cong (λ eq → to-implication (≡⇒↝ ⌊ k ⌋-sym eq) p) (cong-sym P _) ⟩
to-implication (≡⇒↝ ⌊ k ⌋-sym (sym $ cong P x≡y)) p ≡⟨ cong (_$ p) (≡⇒↝-sym k) ⟩∎
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (cong P x≡y))) p ∎
-- One can express subst id in terms of ≡⇒↝.
subst-id-in-terms-of-≡⇒↝ :
∀ k {a} {A B : Type a} {A≡B : A ≡ B} {x} →
subst id A≡B x ≡ to-implication (≡⇒↝ k A≡B) x
subst-id-in-terms-of-≡⇒↝ k {A≡B = A≡B} {x = x} =
subst id A≡B x ≡⟨ subst-in-terms-of-≡⇒↝ k _ _ _ ⟩
to-implication (≡⇒↝ k (cong id A≡B)) x ≡⟨ cong (λ eq → to-implication (≡⇒↝ k eq) x) $ sym $ cong-id _ ⟩∎
to-implication (≡⇒↝ k A≡B) x ∎
subst-id-in-terms-of-inverse∘≡⇒↝ :
∀ k {a} {A B : Type a} {A≡B : A ≡ B} {y} →
subst id (sym A≡B) y ≡
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym A≡B)) y
subst-id-in-terms-of-inverse∘≡⇒↝ k {A≡B = A≡B} {y = y} =
subst id (sym A≡B) y ≡⟨ subst-in-terms-of-inverse∘≡⇒↝ k _ _ _ ⟩
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym (cong id A≡B))) y ≡⟨ cong (λ eq → to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym eq)) y) $ sym $ cong-id _ ⟩∎
to-implication (inverse (≡⇒↝ ⌊ k ⌋-sym A≡B)) y ∎
to-implication-≡⇒↝ :
∀ k {ℓ} {A B : Type ℓ} (eq : A ≡ B) →
to-implication (≡⇒↝ k eq) ≡ ≡⇒↝ implication eq
to-implication-≡⇒↝ k =
elim (λ eq → to-implication (≡⇒↝ k eq) ≡ ≡⇒↝ implication eq)
(λ A → to-implication (≡⇒↝ k (refl A)) ≡⟨ cong to-implication (≡⇒↝-refl {k = k}) ⟩
to-implication {k = k} id ≡⟨ to-implication-id k ⟩
id ≡⟨ sym ≡⇒↝-refl ⟩∎
≡⇒↝ implication (refl A) ∎)
------------------------------------------------------------------------
-- One can replace the "to" and "from" functions with extensionally
-- equal functions
-- One can replace the "to" function with an extensionally equal
-- function.
with-other-function :
∀ {k a b} {A : Type a} {B : Type b}
(A↝B : A ↝[ k ] B) (f : A → B) →
(∀ x → to-implication A↝B x ≡ f x) →
A ↝[ k ] B
with-other-function {k = implication} _ f _ = f
with-other-function {k = logical-equivalence} A⇔B f _ = record
{ to = f
; from = _⇔_.from A⇔B
}
with-other-function {k = injection} A↣B f ≡f = record
{ to = f
; injective = λ {x = x} {y = y} →
f x ≡ f y →⟨ flip trans (sym $ ≡f y) ∘ trans (≡f x) ⟩
_↣_.to A↣B x ≡ _↣_.to A↣B y →⟨ _↣_.injective A↣B ⟩□
x ≡ y □
}
with-other-function {k = embedding} A↣B f ≡f = record
{ to = f
; is-embedding = λ x y →
_≃_.is-equivalence $
Eq.with-other-function
(x ≡ y ↝⟨ Eq.⟨ _ , Embedding.is-embedding A↣B x y ⟩ ⟩
Embedding.to A↣B x ≡ Embedding.to A↣B y ↝⟨ ≡⇒↝ _ $ cong₂ _≡_ (≡f x) (≡f y) ⟩□
f x ≡ f y □)
(cong f)
(elim
(λ {x = x} {y = y} x≡y →
_≃_.to (≡⇒↝ _ (cong₂ _≡_ (≡f x) (≡f y)))
(cong (Embedding.to A↣B) x≡y) ≡
cong f x≡y)
(λ x →
_≃_.to (≡⇒↝ _ (cong₂ _≡_ (≡f x) (≡f x)))
(cong (Embedding.to A↣B) (refl _)) ≡⟨ cong (_≃_.to (≡⇒↝ _ _)) $
cong-refl _ ⟩
_≃_.to (≡⇒↝ _ (cong₂ _≡_ (≡f x) (≡f x))) (refl _) ≡⟨ cong (_$ _) $
≡⇒↝-trans equivalence ⟩
_≃_.to (≡⇒↝ _ (cong (_ ≡_) (≡f x)))
(_≃_.to (≡⇒↝ _ (cong (_≡ _) (≡f x))) (refl _)) ≡⟨ sym $
trans (subst-in-terms-of-≡⇒↝ equivalence _ _ _) $
cong (_≃_.to (≡⇒↝ _ _)) $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst (_ ≡_) (≡f x) (subst (_≡ _) (≡f x) (refl _)) ≡⟨ trans (cong (subst (_ ≡_) (≡f x)) $
trans subst-trans-sym $
trans-reflʳ _) $
sym trans-subst ⟩
trans (sym (≡f x)) (≡f x) ≡⟨ trans-symˡ _ ⟩
refl (f x) ≡⟨ sym $ cong-refl _ ⟩∎
cong f (refl x) ∎))
}
with-other-function {k = surjection} A↠B f ≡f = record
{ logical-equivalence = record
{ to = f
; from = _↠_.from A↠B
}
; right-inverse-of = λ x →
f (_↠_.from A↠B x) ≡⟨ sym $ ≡f _ ⟩
_↠_.to A↠B (_↠_.from A↠B x) ≡⟨ _↠_.right-inverse-of A↠B _ ⟩∎
x ∎
}
with-other-function {k = bijection} = Bijection.with-other-function
with-other-function {k = equivalence} = Eq.with-other-function
with-other-function {k = equivalenceᴱ} A≃ᴱB f ≡f =
EEq.with-other-function A≃ᴱB f ≡f
-- The function with-other-function changes the "to" function in the
-- advertised way.
to-implication-with-other-function :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ k ] B} {f : A → B}
{≡f : ∀ x → to-implication A↝B x ≡ f x} {x} →
to-implication (with-other-function A↝B f ≡f) x ≡ f x
to-implication-with-other-function implication = refl _
to-implication-with-other-function logical-equivalence = refl _
to-implication-with-other-function injection = refl _
to-implication-with-other-function embedding = refl _
to-implication-with-other-function surjection = refl _
to-implication-with-other-function bijection = refl _
to-implication-with-other-function equivalence = refl _
to-implication-with-other-function equivalenceᴱ = refl _
-- The function with-other-function does not change the "from"
-- function (if any).
to-implication-inverse-with-other-function :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ ⌊ k ⌋-sym ] B}
{f : A → B} {≡f : ∀ x → to-implication A↝B x ≡ f x} {x} →
to-implication (inverse (with-other-function A↝B f ≡f)) x ≡
to-implication (inverse A↝B) x
to-implication-inverse-with-other-function logical-equivalence = refl _
to-implication-inverse-with-other-function bijection = refl _
to-implication-inverse-with-other-function equivalence = refl _
to-implication-inverse-with-other-function equivalenceᴱ = refl _
-- One can replace the "from" function with an extensionally equal
-- function.
with-other-inverse :
∀ {k a b} {A : Type a} {B : Type b}
(A↝B : A ↝[ ⌊ k ⌋-sym ] B) (f : B → A) →
(∀ x → to-implication (inverse A↝B) x ≡ f x) →
A ↝[ ⌊ k ⌋-sym ] B
with-other-inverse {k = logical-equivalence} A⇔B f _ = record
{ to = _⇔_.to A⇔B
; from = f
}
with-other-inverse {k = bijection} = Bijection.with-other-inverse
with-other-inverse {k = equivalence} = Eq.with-other-inverse
with-other-inverse {k = equivalenceᴱ} A≃ᴱB f ≡f =
EEq.with-other-inverse A≃ᴱB f ≡f
-- The function with-other-inverse does not change the "to" function.
to-implication-with-other-inverse :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ ⌊ k ⌋-sym ] B}
{f : B → A} {≡f : ∀ x → to-implication (inverse A↝B) x ≡ f x} {x} →
to-implication (with-other-inverse A↝B f ≡f) x ≡
to-implication A↝B x
to-implication-with-other-inverse logical-equivalence = refl _
to-implication-with-other-inverse bijection = refl _
to-implication-with-other-inverse equivalence = refl _
to-implication-with-other-inverse equivalenceᴱ = refl _
-- The function with-other-inverse changes the "from" function in the
-- advertised way.
to-implication-inverse-with-other-inverse :
∀ k {a b} {A : Type a} {B : Type b} {A↝B : A ↝[ ⌊ k ⌋-sym ] B}
{f : B → A} {≡f : ∀ x → to-implication (inverse A↝B) x ≡ f x} {x} →
to-implication (inverse (with-other-inverse A↝B f ≡f)) x ≡ f x
to-implication-inverse-with-other-inverse logical-equivalence = refl _
to-implication-inverse-with-other-inverse bijection = refl _
to-implication-inverse-with-other-inverse equivalence = refl _
to-implication-inverse-with-other-inverse equivalenceᴱ = refl _
------------------------------------------------------------------------
-- _⊎_ is a commutative monoid
-- _⊎_ preserves all kinds of functions.
private
⊎-cong-inj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↣ A₂ → B₁ ↣ B₂ → A₁ ⊎ B₁ ↣ A₂ ⊎ B₂
⊎-cong-inj A₁↣A₂ B₁↣B₂ = record
{ to = to′
; injective = injective′
}
where
open _↣_
to′ = ⊎-map (to A₁↣A₂) (to B₁↣B₂)
abstract
injective′ : Injective to′
injective′ {x = inj₁ x} {y = inj₁ y} = cong inj₁ ⊚ injective A₁↣A₂ ⊚ ⊎.cancel-inj₁
injective′ {x = inj₂ x} {y = inj₂ y} = cong inj₂ ⊚ injective B₁↣B₂ ⊚ ⊎.cancel-inj₂
injective′ {x = inj₁ x} {y = inj₂ y} = ⊥-elim ⊚ ⊎.inj₁≢inj₂
injective′ {x = inj₂ x} {y = inj₁ y} = ⊥-elim ⊚ ⊎.inj₁≢inj₂ ⊚ sym
⊎-cong-emb : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
Embedding A₁ A₂ → Embedding B₁ B₂ →
Embedding (A₁ ⊎ B₁) (A₂ ⊎ B₂)
⊎-cong-emb A₁↣A₂ B₁↣B₂ = record
{ to = to′
; is-embedding = is-embedding′
}
where
open Embedding
to′ = ⊎-map (to A₁↣A₂) (to B₁↣B₂)
is-embedding′ : Is-embedding to′
is-embedding′ (inj₁ x) (inj₁ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₁ x ≡ inj₁ y ↔⟨ inverse Bijection.≡↔inj₁≡inj₁ ⟩
x ≡ y ↝⟨ Eq.⟨ _ , is-embedding A₁↣A₂ _ _ ⟩ ⟩
to A₁↣A₂ x ≡ to A₁↣A₂ y ↔⟨ Bijection.≡↔inj₁≡inj₁ ⟩□
inj₁ (to A₁↣A₂ x) ≡ inj₁ (to A₁↣A₂ y) □)
_
(λ eq →
cong inj₁ (cong (to A₁↣A₂) (⊎.cancel-inj₁ eq)) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₁ ⊚ to A₁↣A₂) (⊎.cancel-inj₁ eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₁ ⊚ to A₁↣A₂ ⊚ [ id , const x ]) eq ≡⟨ sym $ trans-reflʳ _ ⟩
trans (cong (inj₁ ⊚ to A₁↣A₂ ⊚ [ id , const x ]) eq) (refl _) ≡⟨ cong-respects-relevant-equality
{f = inj₁ ⊚ to A₁↣A₂ ⊚ [ id , const x ]}
(if_then true else false)
[ (λ _ _ → refl _) , (λ _ ()) ] ⟩
trans (refl _) (cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq) ≡⟨ trans-reflˡ _ ⟩∎
cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq ∎)
is-embedding′ (inj₂ x) (inj₂ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₂ x ≡ inj₂ y ↔⟨ inverse Bijection.≡↔inj₂≡inj₂ ⟩
x ≡ y ↝⟨ Eq.⟨ _ , is-embedding B₁↣B₂ _ _ ⟩ ⟩
to B₁↣B₂ x ≡ to B₁↣B₂ y ↔⟨ Bijection.≡↔inj₂≡inj₂ ⟩□
inj₂ (to B₁↣B₂ x) ≡ inj₂ (to B₁↣B₂ y) □)
_
(λ eq →
cong inj₂ (cong (to B₁↣B₂) (⊎.cancel-inj₂ eq)) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₂ ⊚ to B₁↣B₂) (⊎.cancel-inj₂ eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (inj₂ ⊚ to B₁↣B₂ ⊚ [ const x , id ]) eq ≡⟨ sym $ trans-reflʳ _ ⟩
trans (cong (inj₂ ⊚ to B₁↣B₂ ⊚ [ const x , id ]) eq) (refl _) ≡⟨ cong-respects-relevant-equality
{f = inj₂ ⊚ to B₁↣B₂ ⊚ [ const x , id ]}
(if_then false else true)
[ (λ _ ()) , (λ _ _ → refl _) ] ⟩
trans (refl _) (cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq) ≡⟨ trans-reflˡ _ ⟩∎
cong (⊎-map (to A₁↣A₂) (to B₁↣B₂)) eq ∎)
is-embedding′ (inj₁ x) (inj₂ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₁ x ≡ inj₂ y ↔⟨ inverse $ Bijection.⊥↔uninhabited ⊎.inj₁≢inj₂ ⟩
⊥₀ ↔⟨ Bijection.⊥↔uninhabited ⊎.inj₁≢inj₂ ⟩□
inj₁ (to A₁↣A₂ x) ≡ inj₂ (to B₁↣B₂ y) □)
_
(⊥-elim ⊚ ⊎.inj₁≢inj₂)
is-embedding′ (inj₂ x) (inj₁ y) =
_≃_.is-equivalence $
Eq.with-other-function
(inj₂ x ≡ inj₁ y ↔⟨ inverse $ Bijection.⊥↔uninhabited (⊎.inj₁≢inj₂ ⊚ sym) ⟩
⊥₀ ↔⟨ Bijection.⊥↔uninhabited (⊎.inj₁≢inj₂ ⊚ sym) ⟩□
inj₂ (to B₁↣B₂ x) ≡ inj₁ (to A₁↣A₂ y) □)
_
(⊥-elim ⊚ ⊎.inj₁≢inj₂ ⊚ sym)
⊎-cong-surj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↠ A₂ → B₁ ↠ B₂ → A₁ ⊎ B₁ ↠ A₂ ⊎ B₂
⊎-cong-surj A₁↠A₂ B₁↠B₂ = record
{ logical-equivalence =
_↠_.logical-equivalence A₁↠A₂
L.⊎-cong
_↠_.logical-equivalence B₁↠B₂
; right-inverse-of =
[ cong inj₁ ⊚ _↠_.right-inverse-of A₁↠A₂
, cong inj₂ ⊚ _↠_.right-inverse-of B₁↠B₂
]
}
⊎-cong-bij : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↔ A₂ → B₁ ↔ B₂ → A₁ ⊎ B₁ ↔ A₂ ⊎ B₂
⊎-cong-bij A₁↔A₂ B₁↔B₂ = record
{ surjection = ⊎-cong-surj (_↔_.surjection A₁↔A₂)
(_↔_.surjection B₁↔B₂)
; left-inverse-of =
[ cong inj₁ ⊚ _↔_.left-inverse-of A₁↔A₂
, cong inj₂ ⊚ _↔_.left-inverse-of B₁↔B₂
]
}
⊎-cong-≃ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ ⊎ B₁) ≃ (A₂ ⊎ B₂)
⊎-cong-≃ A₁≃A₂ B₁≃B₂ =
from-bijection $ ⊎-cong-bij (from-equivalence A₁≃A₂)
(from-equivalence B₁≃B₂)
⊎-cong-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ᴱ A₂ → B₁ ≃ᴱ B₂ → (A₁ ⊎ B₁) ≃ᴱ (A₂ ⊎ B₂)
⊎-cong-≃ᴱ f g =
EEq.[≃]→≃ᴱ (EEq.[proofs] (⊎-cong-≃ (EEq.≃ᴱ→≃ f) (EEq.≃ᴱ→≃ g)))
infixr 1 _⊎-cong_
_⊎-cong_ : ∀ {k a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↝[ k ] A₂ → B₁ ↝[ k ] B₂ → A₁ ⊎ B₁ ↝[ k ] A₂ ⊎ B₂
_⊎-cong_ {implication} = ⊎-map
_⊎-cong_ {logical-equivalence} = L._⊎-cong_
_⊎-cong_ {injection} = ⊎-cong-inj
_⊎-cong_ {embedding} = ⊎-cong-emb
_⊎-cong_ {surjection} = ⊎-cong-surj
_⊎-cong_ {bijection} = ⊎-cong-bij
_⊎-cong_ {equivalence} = ⊎-cong-≃
_⊎-cong_ {equivalenceᴱ} = ⊎-cong-≃ᴱ
-- _⊎_ is commutative.
⊎-comm : ∀ {a b} {A : Type a} {B : Type b} → A ⊎ B ↔ B ⊎ A
⊎-comm = record
{ surjection = record
{ logical-equivalence = record
{ to = [ inj₂ , inj₁ ]
; from = [ inj₂ , inj₁ ]
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
-- _⊎_ is associative.
⊎-assoc : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
A ⊎ (B ⊎ C) ↔ (A ⊎ B) ⊎ C
⊎-assoc = record
{ surjection = record
{ logical-equivalence = record
{ to = [ inj₁ ⊚ inj₁ , [ inj₁ ⊚ inj₂ , inj₂ ] ]
; from = [ [ inj₁ , inj₂ ⊚ inj₁ ] , inj₂ ⊚ inj₂ ]
}
; right-inverse-of =
[ [ refl ⊚ inj₁ ⊚ inj₁ , refl ⊚ inj₁ ⊚ inj₂ ] , refl ⊚ inj₂ ]
}
; left-inverse-of =
[ refl ⊚ inj₁ , [ refl ⊚ inj₂ ⊚ inj₁ , refl ⊚ inj₂ ⊚ inj₂ ] ]
}
-- ⊥ is a left and right identity of _⊎_.
⊎-left-identity : ∀ {a ℓ} {A : Type a} → ⊥ {ℓ = ℓ} ⊎ A ↔ A
⊎-left-identity = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (inj₁ ()); (inj₂ x) → x }
; from = inj₂
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (inj₁ ()); (inj₂ x) → refl (inj₂ x) }
}
⊎-right-identity : ∀ {a ℓ} {A : Type a} → A ⊎ ⊥ {ℓ = ℓ} ↔ A
⊎-right-identity {A = A} =
A ⊎ ⊥ ↔⟨ ⊎-comm ⟩
⊥ ⊎ A ↔⟨ ⊎-left-identity ⟩□
A □
-- For logical equivalences _⊎_ is also idempotent. (This lemma could
-- be generalised to cover surjections and implications.)
⊎-idempotent : ∀ {a} {A : Type a} → A ⊎ A ⇔ A
⊎-idempotent = record
{ to = [ id , id ]
; from = inj₁
}
-- Lemmas that can be used to simplify binary sums where one of the
-- two type arguments is related to the empty type.
drop-⊥-right :
∀ {k a b} {A : Type a} {B : Type b} →
B ↝[ k ] ⊥₀ → A ⊎ B ↝[ k ] A
drop-⊥-right {A = A} {B} B↔⊥ =
A ⊎ B ↝⟨ id ⊎-cong B↔⊥ ⟩
A ⊎ ⊥ ↔⟨ ⊎-right-identity ⟩□
A □
drop-⊥-left :
∀ {k a b} {A : Type a} {B : Type b} →
A ↝[ k ] ⊥₀ → A ⊎ B ↝[ k ] B
drop-⊥-left {A = A} {B} A↔⊥ =
A ⊎ B ↔⟨ ⊎-comm ⟩
B ⊎ A ↝⟨ drop-⊥-right A↔⊥ ⟩□
B □
------------------------------------------------------------------------
-- _×_ is a commutative monoid with a zero
-- Σ preserves embeddings. (This definition is used in the proof of
-- _×-cong_.)
Σ-preserves-embeddings :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂}
(A₁↣A₂ : Embedding A₁ A₂) →
(∀ x → Embedding (B₁ x) (B₂ (Embedding.to A₁↣A₂ x))) →
Embedding (Σ A₁ B₁) (Σ A₂ B₂)
Σ-preserves-embeddings {B₁ = B₁} {B₂} A₁↣A₂ B₁↣B₂ = record
{ to = Σ-map (to A₁↣A₂) (to (B₁↣B₂ _))
; is-embedding = λ { (x₁ , x₂) (y₁ , y₂) →
_≃_.is-equivalence $
Eq.with-other-function
((x₁ , x₂) ≡ (y₁ , y₂) ↝⟨ inverse $ Eq.↔⇒≃ Bijection.Σ-≡,≡↔≡ ⟩
(∃ λ (eq : x₁ ≡ y₁) → subst B₁ eq x₂ ≡ y₂) ↝⟨ Eq.Σ-preserves (Embedding.equivalence A₁↣A₂) (λ eq →
subst B₁ eq x₂ ≡ y₂ ↝⟨ Embedding.equivalence (B₁↣B₂ y₁) ⟩
to (B₁↣B₂ y₁) (subst B₁ eq x₂) ≡ to (B₁↣B₂ y₁) y₂ ↝⟨ ≡⇒↝ _ (cong (_≡ _) $ lemma₁ eq _ y₂) ⟩□
subst B₂ (cong (to A₁↣A₂) eq) (to (B₁↣B₂ x₁) x₂) ≡
to (B₁↣B₂ y₁) y₂ □) ⟩
(∃ λ (eq : to A₁↣A₂ x₁ ≡ to A₁↣A₂ y₁) →
subst B₂ eq (to (B₁↣B₂ x₁) x₂) ≡ to (B₁↣B₂ y₁) y₂) ↝⟨ Eq.↔⇒≃ Bijection.Σ-≡,≡↔≡ ⟩□
(to A₁↣A₂ x₁ , to (B₁↣B₂ x₁) x₂) ≡
(to A₁↣A₂ y₁ , to (B₁↣B₂ y₁) y₂) □)
_
(elim
(λ { {y = _ , y₂} eq →
uncurry Σ-≡,≡→≡
(Σ-map (cong (to A₁↣A₂))
(_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ _ _ y₂)) ⊚
cong (to (B₁↣B₂ _)))
(Σ-≡,≡←≡ eq)) ≡
cong (Σ-map (to A₁↣A₂) (to (B₁↣B₂ _))) eq })
(λ _ →
uncurry Σ-≡,≡→≡
(Σ-map (cong (to A₁↣A₂))
(_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ _ _ _)) ⊚
cong (to (B₁↣B₂ _)))
(Σ-≡,≡←≡ (refl _))) ≡⟨ cong (λ eq → uncurry Σ-≡,≡→≡
(Σ-map _
(_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ _ _ _)) ⊚
cong (to (B₁↣B₂ _)))
eq))
Σ-≡,≡←≡-refl ⟩
Σ-≡,≡→≡
(cong (to A₁↣A₂) (refl _))
(_≃_.to (≡⇒↝ _ (cong (_≡ to (B₁↣B₂ _) _) $ lemma₁ _ _ _))
(cong (to (B₁↣B₂ _)) (subst-refl B₁ _))) ≡⟨ Σ-≡,≡→≡-cong (cong-refl _) (lemma₂ _ _) ⟩
Σ-≡,≡→≡ (refl _) (subst-refl B₂ _) ≡⟨ Σ-≡,≡→≡-refl-subst-refl ⟩
refl _ ≡⟨ sym $ cong-refl _ ⟩∎
cong (Σ-map (to A₁↣A₂) (to (B₁↣B₂ _))) (refl _) ∎)) }
}
where
open Embedding using (to)
lemma₁ : ∀ {x₁ y₁} (_ : x₁ ≡ y₁) → _
lemma₁ = elim
(λ {x₁ y₁} eq → (x₂ : B₁ x₁) (y₂ : B₁ y₁) →
to (B₁↣B₂ y₁) (subst B₁ eq x₂) ≡
subst B₂ (cong (to A₁↣A₂) eq) (to (B₁↣B₂ x₁) x₂))
(λ z₁ x₂ y₂ →
to (B₁↣B₂ z₁) (subst B₁ (refl z₁) x₂) ≡⟨ cong (to (B₁↣B₂ z₁)) $ subst-refl _ _ ⟩
to (B₁↣B₂ z₁) x₂ ≡⟨ sym $ subst-refl _ _ ⟩
subst B₂ (refl (to A₁↣A₂ z₁)) (to (B₁↣B₂ z₁) x₂) ≡⟨ cong (λ eq → subst B₂ eq _) (sym $ cong-refl _) ⟩∎
subst B₂ (cong (to A₁↣A₂) (refl z₁)) (to (B₁↣B₂ z₁) x₂) ∎)
lemma₂ = λ x y →
let eq₁ = cong (flip (subst B₂) _) (sym (cong-refl _))
eq₂ = cong (to (B₁↣B₂ x)) (subst-refl B₁ y)
in
trans eq₁ (_≃_.to (≡⇒↝ _ (cong (_≡ _) $ lemma₁ (refl x) y y)) eq₂) ≡⟨ cong (λ eq → trans eq₁ (_≃_.to (≡⇒↝ _ (cong (_≡ _) (eq y y))) eq₂)) $
elim-refl (λ {x₁ y₁} eq → (x₂ : B₁ x₁) (y₂ : B₁ y₁) →
to (B₁↣B₂ y₁) (subst B₁ eq x₂) ≡
subst B₂ (cong (to A₁↣A₂) eq) (to (B₁↣B₂ x₁) x₂))
_ ⟩
trans eq₁ (_≃_.to (≡⇒↝ _ $ cong (_≡ _) $
trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (trans _) $ sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
trans eq₁ (subst (_≡ _)
(trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (λ eq → trans eq₁ (subst (_≡ _) eq eq₂)) $
sym $ sym-sym (trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁)) ⟩
trans eq₁ (subst (_≡ _)
(sym $ sym $
trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (trans _) $ subst-trans _ ⟩
trans eq₁ (trans
(sym $ trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁))
eq₂) ≡⟨ cong (λ eq → trans eq₁ (trans eq eq₂)) $
sym-trans eq₂ (trans (sym $ subst-refl B₂ _) eq₁) ⟩
trans eq₁ (trans (trans (sym $ trans (sym $ subst-refl B₂ _) eq₁)
(sym eq₂))
eq₂) ≡⟨ cong (trans _) $ trans-[trans-sym]- _ _ ⟩
trans eq₁ (sym $ trans (sym $ subst-refl B₂ _) eq₁) ≡⟨ cong (trans _) $ sym-trans _ _ ⟩
trans eq₁ (trans (sym eq₁) (sym $ sym $ subst-refl B₂ _)) ≡⟨ trans--[trans-sym] _ _ ⟩
sym $ sym $ subst-refl B₂ _ ≡⟨ sym-sym _ ⟩∎
subst-refl B₂ _ ∎
-- _×_ preserves all kinds of functions.
private
×-cong-inj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↣ A₂ → B₁ ↣ B₂ → A₁ × B₁ ↣ A₂ × B₂
×-cong-inj {A₁ = A₁} {A₂} {B₁} {B₂} A₁↣A₂ B₁↣B₂ = record
{ to = to′
; injective = injective′
}
where
open _↣_
to′ : A₁ × B₁ → A₂ × B₂
to′ = Σ-map (to A₁↣A₂) (to B₁↣B₂)
abstract
injective′ : Injective to′
injective′ to′-x≡to′-y =
cong₂ _,_ (injective A₁↣A₂ (cong proj₁ to′-x≡to′-y))
(injective B₁↣B₂ (cong proj₂ to′-x≡to′-y))
×-cong-surj : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↠ A₂ → B₁ ↠ B₂ → A₁ × B₁ ↠ A₂ × B₂
×-cong-surj A₁↠A₂ B₁↠B₂ = record
{ logical-equivalence =
_↠_.logical-equivalence A₁↠A₂
L.×-cong
_↠_.logical-equivalence B₁↠B₂
; right-inverse-of = uncurry λ x y →
cong₂ _,_ (_↠_.right-inverse-of A₁↠A₂ x)
(_↠_.right-inverse-of B₁↠B₂ y)
}
×-cong-bij : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↔ A₂ → B₁ ↔ B₂ → A₁ × B₁ ↔ A₂ × B₂
×-cong-bij A₁↔A₂ B₁↔B₂ = record
{ surjection = ×-cong-surj (_↔_.surjection A₁↔A₂)
(_↔_.surjection B₁↔B₂)
; left-inverse-of = uncurry λ x y →
cong₂ _,_ (_↔_.left-inverse-of A₁↔A₂ x)
(_↔_.left-inverse-of B₁↔B₂ y)
}
×-cong-≃ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ A₂ → B₁ ≃ B₂ → (A₁ × B₁) ≃ (A₂ × B₂)
×-cong-≃ A₁≃A₂ B₁≃B₂ =
from-bijection $ ×-cong-bij (from-equivalence A₁≃A₂)
(from-equivalence B₁≃B₂)
×-cong-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ≃ᴱ A₂ → B₁ ≃ᴱ B₂ → (A₁ × B₁) ≃ᴱ (A₂ × B₂)
×-cong-≃ᴱ f g =
EEq.[≃]→≃ᴱ (EEq.[proofs] (×-cong-≃ (EEq.≃ᴱ→≃ f) (EEq.≃ᴱ→≃ g)))
infixr 2 _×-cong_
_×-cong_ : ∀ {k a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : Type b₁} {B₂ : Type b₂} →
A₁ ↝[ k ] A₂ → B₁ ↝[ k ] B₂ → A₁ × B₁ ↝[ k ] A₂ × B₂
_×-cong_ {implication} = λ f g → Σ-map f g
_×-cong_ {logical-equivalence} = L._×-cong_
_×-cong_ {injection} = ×-cong-inj
_×-cong_ {embedding} = λ A₁↣A₂ B₁↣B₂ →
Σ-preserves-embeddings
A₁↣A₂ (λ _ → B₁↣B₂)
_×-cong_ {surjection} = ×-cong-surj
_×-cong_ {bijection} = ×-cong-bij
_×-cong_ {equivalence} = ×-cong-≃
_×-cong_ {equivalenceᴱ} = ×-cong-≃ᴱ
-- The function to-implication is homomorphic with respect to
-- _×-cong_/Σ-map.
to-implication-×-cong :
∀ k {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d}
{A↝B : A ↝[ k ] B} {C↝D : C ↝[ k ] D} →
to-implication (A↝B ×-cong C↝D) ≡
Σ-map (to-implication A↝B) (to-implication C↝D)
to-implication-×-cong implication = refl _
to-implication-×-cong logical-equivalence = refl _
to-implication-×-cong injection = refl _
to-implication-×-cong embedding = refl _
to-implication-×-cong surjection = refl _
to-implication-×-cong bijection = refl _
to-implication-×-cong equivalence = refl _
to-implication-×-cong equivalenceᴱ = refl _
-- _×_ is commutative.
×-comm : ∀ {a b} {A : Type a} {B : Type b} → A × B ↔ B × A
×-comm = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry λ x y → (y , x)
; from = uncurry λ x y → (y , x)
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Σ is associative.
open Bijection public using (Σ-assoc)
-- _×_ is associative.
×-assoc : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
A × (B × C) ↔ (A × B) × C
×-assoc = Σ-assoc
-- ⊤ is a left and right identity of _×_ and Σ.
Σ-left-identity : ∀ {a} {A : ⊤ → Type a} → Σ ⊤ A ↔ A tt
Σ-left-identity = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₂
; from = λ x → (tt , x)
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
×-left-identity : ∀ {a} {A : Type a} → ⊤ × A ↔ A
×-left-identity = Σ-left-identity
×-right-identity : ∀ {a} {A : Type a} → A × ⊤ ↔ A
×-right-identity {A = A} =
A × ⊤ ↔⟨ ×-comm ⟩
⊤ × A ↔⟨ ×-left-identity ⟩□
A □
-- ⊥ is a left and right zero of _×_ and Σ.
Σ-left-zero : ∀ {ℓ₁ a ℓ₂} {A : ⊥ {ℓ = ℓ₁} → Type a} →
Σ ⊥ A ↔ ⊥ {ℓ = ℓ₂}
Σ-left-zero = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (() , _) }
; from = λ ()
}
; right-inverse-of = λ ()
}
; left-inverse-of = λ { (() , _) }
}
×-left-zero : ∀ {a ℓ₁ ℓ₂} {A : Type a} → ⊥ {ℓ = ℓ₁} × A ↔ ⊥ {ℓ = ℓ₂}
×-left-zero = Σ-left-zero
×-right-zero : ∀ {a ℓ₁ ℓ₂} {A : Type a} → A × ⊥ {ℓ = ℓ₁} ↔ ⊥ {ℓ = ℓ₂}
×-right-zero {A = A} =
A × ⊥ ↔⟨ ×-comm ⟩
⊥ × A ↔⟨ ×-left-zero ⟩□
⊥ □
------------------------------------------------------------------------
-- Some lemmas related to Σ/∃/_×_
-- See also Σ-left-zero and Σ-right-zero above.
-- Σ preserves isomorphisms in its first argument and all kinds of
-- functions in its second argument.
Σ-cong : ∀ {k₁ k₂ a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
Σ A₁ B₁ ↝[ k₂ ] Σ A₂ B₂
Σ-cong {equivalence} {implication} = λ A₁≃A₂ B₁→B₂ →
Σ-map (from-isomorphism A₁≃A₂) (B₁→B₂ _)
Σ-cong {bijection} {implication} = λ A₁↔A₂ B₁→B₂ →
Σ-map (from-isomorphism A₁↔A₂) (B₁→B₂ _)
Σ-cong {equivalence} {logical-equivalence} = Surjection.Σ-cong-⇔ ⊚ from-isomorphism
Σ-cong {bijection} {logical-equivalence} = Surjection.Σ-cong-⇔ ⊚ from-isomorphism
Σ-cong {equivalence} {injection} = Eq.∃-preserves-injections
Σ-cong {bijection} {injection} = Eq.∃-preserves-injections ⊚ from-isomorphism
Σ-cong {equivalence} {embedding} = Σ-preserves-embeddings ⊚ from-isomorphism
Σ-cong {bijection} {embedding} = Σ-preserves-embeddings ⊚ from-isomorphism
Σ-cong {equivalence} {surjection} = Surjection.Σ-cong ⊚ from-isomorphism
Σ-cong {bijection} {surjection} = Surjection.Σ-cong ⊚ from-isomorphism
Σ-cong {equivalence} {bijection} = Eq.∃-preserves-bijections
Σ-cong {bijection} {bijection} = Eq.∃-preserves-bijections ⊚ from-isomorphism
Σ-cong {equivalence} {equivalence} = Eq.Σ-preserves
Σ-cong {bijection} {equivalence} = Eq.Σ-preserves ⊚ from-isomorphism
Σ-cong {equivalence} {equivalenceᴱ}
{B₂ = B₂} = λ f g →
EEq.[≃]→≃ᴱ
{to = λ (x , y) → _≃_.to f x , _≃ᴱ_.to (g x) y}
{from = λ (x , y) →
_≃_.from f x
, _≃ᴱ_.from (g (_≃_.from f x))
(subst B₂ (sym (_≃_.right-inverse-of f x)) y)}
(EEq.[proofs]
(Eq.Σ-preserves f (EEq.≃ᴱ→≃ ⊚ g)))
Σ-cong {bijection} {equivalenceᴱ}
{B₂ = B₂} = λ f g →
EEq.[≃]→≃ᴱ
{to = λ (x , y) → _↔_.to f x , _≃ᴱ_.to (g x) y}
{from = λ (x , y) →
_↔_.from f x
, _≃ᴱ_.from (g (_↔_.from f x))
(subst B₂
(sym (_≃_.right-inverse-of (Eq.↔⇒≃ f) x))
y)}
(EEq.[proofs]
(Eq.Σ-preserves (from-isomorphism f)
(EEq.≃ᴱ→≃ ⊚ g)))
-- A variant of Σ-cong.
Σ-cong-contra :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
Σ A₁ B₁ ↝[ k₂ ] Σ A₂ B₂
Σ-cong-contra {k₁} {k₂} {A₁ = A₁} {A₂} {B₁} {B₂} A₂↔A₁ B₁↝B₂ =
Σ-cong A₁↔A₂ B₁↝B₂′
where
A₁↔A₂ : A₁ ↔ A₂
A₁↔A₂ = inverse $ from-isomorphism A₂↔A₁
B₁↝B₂′ : ∀ x → B₁ x ↝[ k₂ ] B₂ (_↔_.to A₁↔A₂ x)
B₁↝B₂′ x =
B₁ x ↝⟨ ≡⇒↝ _ $ cong B₁ $ sym $ _↔_.left-inverse-of A₁↔A₂ _ ⟩
B₁ (_↔_.from A₁↔A₂ (_↔_.to A₁↔A₂ x)) ↝⟨ ≡⇒↝ _ $ cong (λ f → B₁ (f (_↔_.to A₁↔A₂ x))) $ sym $
to-implication∘from-isomorphism k₁ bijection ⟩
B₁ (to-implication A₂↔A₁ (_↔_.to A₁↔A₂ x)) ↝⟨ B₁↝B₂ (_↔_.to A₁↔A₂ x) ⟩□
B₂ (_↔_.to A₁↔A₂ x) □
-- Variants of special cases of Σ-cong-contra.
Σ-cong-contra-→ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) → B₂ x) →
Σ A₁ B₁ → Σ A₂ B₂
Σ-cong-contra-→ {B₁ = B₁} A₂↠A₁ B₁→B₂ =
Σ-map (_↠_.from A₂↠A₁)
(B₁→B₂ _ ∘ subst B₁ (sym $ _↠_.right-inverse-of A₂↠A₁ _))
Σ-cong-contra-⇔ :
∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) ⇔ B₂ x) →
Σ A₁ B₁ ⇔ Σ A₂ B₂
Σ-cong-contra-⇔ A₂↠A₁ B₁⇔B₂ =
inverse $
Surjection.Σ-cong-⇔ A₂↠A₁ (inverse ⊚ B₁⇔B₂)
-- ∃ preserves all kinds of functions. One could define
-- ∃-cong = Σ-cong Bijection.id, but the resulting "from" functions
-- would contain an unnecessary use of substitutivity, and I want to
-- avoid that.
private
∃-cong-impl : ∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x → B₂ x) → ∃ B₁ → ∃ B₂
∃-cong-impl B₁→B₂ = Σ-map id (λ {x} → B₁→B₂ x)
∃-cong-surj : ∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↠ B₂ x) → ∃ B₁ ↠ ∃ B₂
∃-cong-surj B₁↠B₂ = record
{ logical-equivalence = L.∃-cong (_↠_.logical-equivalence ⊚ B₁↠B₂)
; right-inverse-of = uncurry λ x y →
cong (_,_ x) (_↠_.right-inverse-of (B₁↠B₂ x) y)
}
∃-cong-bij : ∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↔ B₂ x) → ∃ B₁ ↔ ∃ B₂
∃-cong-bij B₁↔B₂ = record
{ surjection = ∃-cong-surj (_↔_.surjection ⊚ B₁↔B₂)
; left-inverse-of = uncurry λ x y →
cong (_,_ x) (_↔_.left-inverse-of (B₁↔B₂ x) y)
}
∃-cong-≃ᴱ :
∀ {a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ≃ᴱ B₂ x) → ∃ B₁ ≃ᴱ ∃ B₂
∃-cong-≃ᴱ f = EEq.[≃]→≃ᴱ (EEq.[proofs] (Eq.∃-cong (EEq.≃ᴱ→≃ ⊚ f)))
∃-cong : ∀ {k a b₁ b₂}
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↝[ k ] B₂ x) → ∃ B₁ ↝[ k ] ∃ B₂
∃-cong {implication} = ∃-cong-impl
∃-cong {logical-equivalence} = L.∃-cong
∃-cong {injection} = Σ-cong Bijection.id
∃-cong {embedding} = Σ-preserves-embeddings Emb.id
∃-cong {surjection} = ∃-cong-surj
∃-cong {bijection} = ∃-cong-bij
∃-cong {equivalence} = Eq.∃-cong
∃-cong {equivalenceᴱ} = ∃-cong-≃ᴱ
private
-- ∃-cong also works for _×_, in which case it is a more general
-- variant of id ×-cong_:
×-cong₂ : ∀ {k a b₁ b₂}
{A : Type a} {B₁ : Type b₁} {B₂ : Type b₂} →
(A → B₁ ↝[ k ] B₂) → A × B₁ ↝[ k ] A × B₂
×-cong₂ = ∃-cong
-- The following lemma is a more general variant of _×-cong id.
×-cong₁ : ∀ {k a₁ a₂ b}
{A₁ : Type a₁} {A₂ : Type a₂} {B : Type b} →
(B → A₁ ↝[ k ] A₂) → A₁ × B ↝[ k ] A₂ × B
×-cong₁ {A₁ = A₁} {A₂} {B} A₁↔A₂ =
A₁ × B ↔⟨ ×-comm ⟩
B × A₁ ↝⟨ ∃-cong A₁↔A₂ ⟩
B × A₂ ↔⟨ ×-comm ⟩□
A₂ × B □
-- Lemmas that can be used to simplify sigma types where one of the
-- two type arguments is (conditionally) related to the unit type.
drop-⊤-right : ∀ {k a b} {A : Type a} {B : A → Type b} →
((x : A) → B x ↝[ k ] ⊤) → Σ A B ↝[ k ] A
drop-⊤-right {A = A} {B} B↝⊤ =
Σ A B ↝⟨ ∃-cong B↝⊤ ⟩
A × ⊤ ↔⟨ ×-right-identity ⟩□
A □
drop-⊤-left-× : ∀ {k a b} {A : Type a} {B : Type b} →
(B → A ↝[ k ] ⊤) → A × B ↝[ k ] B
drop-⊤-left-× {A = A} {B} A↝⊤ =
A × B ↔⟨ ×-comm ⟩
B × A ↝⟨ drop-⊤-right A↝⊤ ⟩□
B □
drop-⊤-left-Σ : ∀ {a b} {A : Type a} {B : A → Type b} →
(A↔⊤ : A ↔ ⊤) →
Σ A B ↔ B (_↔_.from A↔⊤ tt)
drop-⊤-left-Σ {A = A} {B} A↔⊤ =
Σ A B ↝⟨ inverse $ Σ-cong (inverse A↔⊤) (λ _ → id) ⟩
Σ ⊤ (B ∘ _↔_.from A↔⊤) ↝⟨ Σ-left-identity ⟩□
B (_↔_.from A↔⊤ tt) □
-- Currying.
currying :
∀ {a b c} {A : Type a} {B : A → Type b} {C : Σ A B → Type c} →
((p : Σ A B) → C p) ↔ ((x : A) (y : B x) → C (x , y))
currying = record
{ surjection = record
{ logical-equivalence = record { to = curry; from = uncurry }
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Some lemmas relating functions from binary sums and pairs of
-- functions.
Π⊎↠Π×Π :
∀ {a b c} {A : Type a} {B : Type b} {C : A ⊎ B → Type c} →
((x : A ⊎ B) → C x)
↠
((x : A) → C (inj₁ x)) × ((y : B) → C (inj₂ y))
Π⊎↠Π×Π = record
{ logical-equivalence = record
{ to = λ f → f ⊚ inj₁ , f ⊚ inj₂
; from = uncurry [_,_]
}
; right-inverse-of = refl
}
Π⊎↔Π×Π :
∀ {a b c} {A : Type a} {B : Type b} {C : A ⊎ B → Type c} →
((x : A ⊎ B) → C x)
↝[ a ⊔ b ∣ c ]
((x : A) → C (inj₁ x)) × ((y : B) → C (inj₂ y))
Π⊎↔Π×Π =
generalise-ext?
(_↠_.logical-equivalence Π⊎↠Π×Π)
(λ ext →
refl
, (λ _ → apply-ext ext [ refl ⊚ _ , refl ⊚ _ ]))
-- ∃ distributes "from the left" over _⊎_.
∃-⊎-distrib-left :
∀ {a b c} {A : Type a} {B : A → Type b} {C : A → Type c} →
(∃ λ x → B x ⊎ C x) ↔ ∃ B ⊎ ∃ C
∃-⊎-distrib-left = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry λ x → [ inj₁ ⊚ _,_ x , inj₂ ⊚ _,_ x ]
; from = [ Σ-map id inj₁ , Σ-map id inj₂ ]
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of =
uncurry λ x → [ refl ⊚ _,_ x ⊚ inj₁ , refl ⊚ _,_ x ⊚ inj₂ ]
}
-- ∃ also distributes "from the right" over _⊎_.
∃-⊎-distrib-right :
∀ {a b c} {A : Type a} {B : Type b} {C : A ⊎ B → Type c} →
Σ (A ⊎ B) C ↔ Σ A (C ⊚ inj₁) ⊎ Σ B (C ⊚ inj₂)
∃-⊎-distrib-right {A = A} {B} {C} = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of = from∘to
}
where
to : Σ (A ⊎ B) C → Σ A (C ⊚ inj₁) ⊎ Σ B (C ⊚ inj₂)
to (inj₁ x , y) = inj₁ (x , y)
to (inj₂ x , y) = inj₂ (x , y)
from = [ Σ-map inj₁ id , Σ-map inj₂ id ]
from∘to : ∀ p → from (to p) ≡ p
from∘to (inj₁ x , y) = refl _
from∘to (inj₂ x , y) = refl _
-- ∃ is "commutative".
∃-comm : ∀ {a b c} {A : Type a} {B : Type b} {C : A → B → Type c} →
(∃ λ x → ∃ λ y → C x y) ↔ (∃ λ y → ∃ λ x → C x y)
∃-comm = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry λ x → uncurry λ y z → (y , (x , z))
; from = uncurry λ x → uncurry λ y z → (y , (x , z))
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- One can introduce an existential by also introducing an equality.
∃-intro : ∀ {a b} {A : Type a} (B : A → Type b) (x : A) →
B x ↔ ∃ λ y → B y × y ≡ x
∃-intro B x = _≃_.bijection $ Eq.↔→≃
(λ b → x , b , refl _)
(λ (y , b , y≡x) → subst B y≡x b)
(λ (y , b , y≡x) →
sym $
Σ-≡,≡→≡
y≡x
(subst (λ y → B y × y ≡ x) y≡x (b , y≡x) ≡⟨ push-subst-, _ _ ⟩
subst B y≡x b , subst (_≡ x) y≡x y≡x ≡⟨ cong (_ ,_) subst-trans-sym ⟩
subst B y≡x b , trans (sym y≡x) y≡x ≡⟨ cong (_ ,_) $ trans-symˡ _ ⟩∎
subst B y≡x b , refl x ∎))
(subst-refl B)
-- A variant of ∃-intro.
other-∃-intro :
∀ {a b} {A : Type a} (B : A → Type b) (x : A) →
B x ≃ ∃ λ y → B y × x ≡ y
other-∃-intro B x = Eq.↔→≃
(λ b → x , b , refl _)
(λ (y , b , x≡y) → subst B (sym x≡y) b)
(λ (y , b , x≡y) →
Σ-≡,≡→≡
x≡y
(subst (λ y → B y × x ≡ y) x≡y (subst B (sym x≡y) b , refl x) ≡⟨ push-subst-, _ _ ⟩
subst B x≡y (subst B (sym x≡y) b) , subst (x ≡_) x≡y (refl x) ≡⟨ cong₂ _,_
(subst-subst-sym _ _ _)
(trans (sym trans-subst) $
trans-reflˡ _) ⟩∎
b , x≡y ∎))
(λ b →
subst B (sym (refl _)) b ≡⟨ cong (flip (subst B) _) sym-refl ⟩
subst B (refl _) b ≡⟨ subst-refl _ _ ⟩∎
b ∎)
-- Another variant of ∃-intro.
∃-introduction :
∀ {a b} {A : Type a} {x : A} (B : (y : A) → x ≡ y → Type b) →
B x (refl x) ↔ ∃ λ y → ∃ λ (x≡y : x ≡ y) → B y x≡y
∃-introduction {x = x} B =
B x (refl x) ↝⟨ ∃-intro (uncurry B) _ ⟩
(∃ λ { (y , x≡y) → B y x≡y × (y , x≡y) ≡ (x , refl x) }) ↝⟨ (∃-cong λ _ → ∃-cong λ _ →
_⇔_.to contractible⇔↔⊤ $
⇒≡ 0 (other-singleton-contractible x)) ⟩
(∃ λ { (y , x≡y) → B y x≡y × ⊤ }) ↝⟨ (∃-cong λ _ → ×-right-identity) ⟩
(∃ λ { (y , x≡y) → B y x≡y }) ↝⟨ inverse Σ-assoc ⟩□
(∃ λ y → ∃ λ x≡y → B y x≡y) □
-- A non-dependent variant of Σ-≡,≡↔≡.
--
-- This property used to be defined in terms of Σ-≡,≡↔≡, but was
-- changed in order to make it compute in a different way.
≡×≡↔≡ : ∀ {a b} {A : Type a} {B : Type b} {p₁ p₂ : A × B} →
(proj₁ p₁ ≡ proj₁ p₂ × proj₂ p₁ ≡ proj₂ p₂) ↔ (p₁ ≡ p₂)
≡×≡↔≡ {B = B} {p₁} {p₂} = record
{ surjection = record
{ logical-equivalence = record
{ to = uncurry (cong₂ _,_)
; from = λ eq → cong proj₁ eq , cong proj₂ eq
}
; right-inverse-of = λ eq →
cong₂ _,_ (cong proj₁ eq) (cong proj₂ eq) ≡⟨ cong₂-cong-cong _ _ _,_ ⟩
cong (λ p → proj₁ p , proj₂ p) eq ≡⟨⟩
cong id eq ≡⟨ sym $ cong-id _ ⟩∎
eq ∎
}
; left-inverse-of = λ { (eq₁ , eq₂) →
cong proj₁ (cong₂ _,_ eq₁ eq₂) , cong proj₂ (cong₂ _,_ eq₁ eq₂) ≡⟨ cong₂ _,_ (cong-proj₁-cong₂-, eq₁ eq₂) (cong-proj₂-cong₂-, eq₁ eq₂) ⟩∎
eq₁ , eq₂ ∎
}
}
-- If one is given an equality between pairs, where the second
-- components of the pairs are propositional, then one can restrict
-- attention to the first components.
ignore-propositional-component :
∀ {a b} {A : Type a} {B : A → Type b} {p q : Σ A B} →
Is-proposition (B (proj₁ q)) →
(proj₁ p ≡ proj₁ q) ↔ (p ≡ q)
ignore-propositional-component {B = B} {p₁ , p₂} {q₁ , q₂} Bq₁-prop =
(p₁ ≡ q₁) ↝⟨ inverse ×-right-identity ⟩
(p₁ ≡ q₁ × ⊤) ↝⟨ ∃-cong (λ _ → inverse $ _⇔_.to contractible⇔↔⊤ (+⇒≡ Bq₁-prop)) ⟩
(∃ λ (eq : p₁ ≡ q₁) → subst B eq p₂ ≡ q₂) ↝⟨ Bijection.Σ-≡,≡↔≡ ⟩□
((p₁ , p₂) ≡ (q₁ , q₂)) □
-- Contractible commutes with _×_ (assuming extensionality).
Contractible-commutes-with-× :
∀ {x y} {X : Type x} {Y : Type y} →
Contractible (X × Y) ↝[ x ⊔ y ∣ x ⊔ y ]
(Contractible X × Contractible Y)
Contractible-commutes-with-× {x = x} {y} =
generalise-ext?-prop
(record
{ to = λ cX×Y →
lemma cX×Y ,
lemma (H-level.respects-surjection
(_↔_.surjection ×-comm) 0 cX×Y)
; from = λ { ((x , eq₁) , (y , eq₂)) →
(x , y) ,
λ { (x′ , y′) →
(x , y) ≡⟨ cong₂ _,_ (eq₁ x′) (eq₂ y′) ⟩∎
(x′ , y′) ∎ } }
})
Contractible-propositional
(λ ext → ×-closure 1 (Contractible-propositional
(lower-extensionality y y ext))
(Contractible-propositional
(lower-extensionality x x ext)))
where
lemma : ∀ {x y} {X : Type x} {Y : Type y} →
Contractible (X × Y) → Contractible X
lemma ((x , y) , eq) = x , λ x′ →
x ≡⟨⟩
proj₁ (x , y) ≡⟨ cong proj₁ (eq (x′ , y)) ⟩∎
proj₁ (x′ , y) ∎
------------------------------------------------------------------------
-- Some lemmas relating equality of certain kinds of functions to
-- pointwise equality of the underlying functions
-- Equality of equivalences is isomorphic to pointwise equality of the
-- underlying functions (assuming extensionality).
≃-to-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ≃ B} →
(∀ x → _≃_.to p x ≡ _≃_.to q x) ↔ p ≡ q
≃-to-≡↔≡ {a} {b} ext {p = p} {q} =
(∀ x → _≃_.to p x ≡ _≃_.to q x) ↔⟨ Eq.extensionality-isomorphism (lower-extensionality b a ext) ⟩
_≃_.to p ≡ _≃_.to q ↝⟨ ignore-propositional-component (Eq.propositional ext _) ⟩
(_≃_.to p , _≃_.is-equivalence p) ≡ (_≃_.to q , _≃_.is-equivalence q) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Eq.≃-as-Σ) ⟩□
p ≡ q □
-- A variant of the previous result for which both directions compute
-- in certain ways.
≃-to-≡≃≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
Extensionality a b →
{A : Type a} {B : Type b} {p q : A ≃ B} →
(∀ x → _≃_.to p x ≡ _≃_.to q x) ≃ (p ≡ q)
≃-to-≡≃≡ ext₁ ext₂ {p = p} {q = q} =
Eq.↔→≃
(Eq.lift-equality ext₁ ⊚ apply-ext (Eq.good-ext ext₂))
(flip $ cong ⊚ flip _≃_.to)
(elim¹
(λ p≡q →
Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂)
(λ x → cong (λ eq → _≃_.to eq x) p≡q)) ≡
p≡q)
(Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂)
(λ x → cong (λ eq → _≃_.to eq x) (refl _))) ≡⟨ (cong (Eq.lift-equality ext₁) $
cong (apply-ext (Eq.good-ext ext₂)) $
apply-ext ext₂ λ _ →
cong-refl _) ⟩
Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂) (λ _ → refl _)) ≡⟨ cong (Eq.lift-equality ext₁) $
Eq.good-ext-refl ext₂ _ ⟩
Eq.lift-equality ext₁ (refl _) ≡⟨ Eq.lift-equality-refl ext₁ ⟩
cong Eq.⟨ _≃_.to p ,_⟩ _ ≡⟨ cong (cong Eq.⟨ _≃_.to p ,_⟩) $
mono₁ 1 (Eq.propositional ext₁ _) _ _ ⟩
cong Eq.⟨ _≃_.to p ,_⟩ (refl _) ≡⟨ cong-refl _ ⟩∎
refl _ ∎))
(λ p≡q → apply-ext ext₂ λ x →
cong (λ eq → _≃_.to eq x)
(Eq.lift-equality ext₁
(apply-ext (Eq.good-ext ext₂) p≡q)) ≡⟨ elim¹
(λ {g} p≡g →
(eq : Is-equivalence g) →
cong (λ eq → _≃_.to eq x)
(Eq.lift-equality ext₁ {q = Eq.⟨ _ , eq ⟩} p≡g) ≡
ext⁻¹ p≡g x)
(λ eq →
cong (λ eq → _≃_.to eq x)
(Eq.lift-equality ext₁ (refl _)) ≡⟨ cong (cong _) $ Eq.lift-equality-refl ext₁ ⟩
cong (λ eq → _≃_.to eq x)
(cong Eq.⟨ _≃_.to p ,_⟩ _) ≡⟨ cong-∘ _ _ _ ⟩
cong (const (_≃_.to p x)) _ ≡⟨ cong-const _ ⟩
refl _ ≡⟨ sym $ cong-refl _ ⟩∎
ext⁻¹ (refl _) x ∎)
(apply-ext (Eq.good-ext ext₂) p≡q)
_ ⟩
ext⁻¹ (apply-ext (Eq.good-ext ext₂) p≡q) x ≡⟨ cong (_$ x) $
_≃_.left-inverse-of (Eq.extensionality-isomorphism ext₂) _ ⟩∎
p≡q x ∎)
-- Equality of equivalences is isomorphic to pointwise equality of the
-- underlying /inverse/ functions (assuming extensionality).
≃-from-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ≃ B} →
(∀ x → _≃_.from p x ≡ _≃_.from q x) ↔ p ≡ q
≃-from-≡↔≡ ext {p = p} {q} =
(∀ x → _≃_.from p x ≡ _≃_.from q x) ↝⟨ ≃-to-≡↔≡ ext ⟩
inverse p ≡ inverse q ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (Eq.inverse-isomorphism ext)) ⟩□
p ≡ q □
-- Equality of bijections between a set and a type is isomorphic to
-- pointwise equality of the underlying functions (assuming
-- extensionality).
↔-to-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ↔ B} →
Is-set A →
(∀ x → _↔_.to p x ≡ _↔_.to q x) ↔ p ≡ q
↔-to-≡↔≡ ext {p = p} {q} A-set =
(∀ x → _↔_.to p x ≡ _↔_.to q x) ↝⟨ id ⟩
(∀ x → _≃_.to (Eq.↔⇒≃ p) x ≡ _≃_.to (Eq.↔⇒≃ q) x) ↝⟨ ≃-to-≡↔≡ ext ⟩
Eq.↔⇒≃ p ≡ Eq.↔⇒≃ q ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (Eq.↔↔≃ ext A-set)) ⟩□
p ≡ q □
-- Equality of bijections between a set and a type is isomorphic to
-- pointwise equality of the underlying /inverse/ functions (assuming
-- extensionality).
↔-from-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : A ↔ B} →
Is-set A →
(∀ x → _↔_.from p x ≡ _↔_.from q x) ↔ p ≡ q
↔-from-≡↔≡ ext {p = p} {q} A-set =
(∀ x → _↔_.from p x ≡ _↔_.from q x) ↝⟨ id ⟩
(∀ x → _≃_.from (Eq.↔⇒≃ p) x ≡ _≃_.from (Eq.↔⇒≃ q) x) ↝⟨ ≃-from-≡↔≡ ext ⟩
Eq.↔⇒≃ p ≡ Eq.↔⇒≃ q ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (Eq.↔↔≃ ext A-set)) ⟩□
p ≡ q □
-- Equality of embeddings is isomorphic to pointwise equality of the
-- underlying functions (assuming extensionality).
Embedding-to-≡↔≡ :
∀ {a b} →
Extensionality (a ⊔ b) (a ⊔ b) →
{A : Type a} {B : Type b} {p q : Embedding A B} →
(∀ x → Embedding.to p x ≡ Embedding.to q x) ↔ p ≡ q
Embedding-to-≡↔≡ {a} {b} ext {p = p} {q} =
(∀ x → Embedding.to p x ≡ Embedding.to q x) ↔⟨ Eq.extensionality-isomorphism (lower-extensionality b a ext) ⟩
Embedding.to p ≡ Embedding.to q ↝⟨ ignore-propositional-component (Emb.Is-embedding-propositional ext) ⟩
(Embedding.to p , Embedding.is-embedding p) ≡
(Embedding.to q , Embedding.is-embedding q) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Emb.Embedding-as-Σ) ⟩□
p ≡ q □
------------------------------------------------------------------------
-- _⊎_ and _×_ form a commutative semiring
-- _×_ distributes from the left over _⊎_.
×-⊎-distrib-left : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
A × (B ⊎ C) ↔ (A × B) ⊎ (A × C)
×-⊎-distrib-left = ∃-⊎-distrib-left
-- _×_ distributes from the right over _⊎_.
×-⊎-distrib-right : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
(A ⊎ B) × C ↔ (A × C) ⊎ (B × C)
×-⊎-distrib-right = ∃-⊎-distrib-right
------------------------------------------------------------------------
-- Some lemmas related to functions
-- The non-dependent function space preserves non-dependent functions
-- (contravariantly for the domain).
→-cong-→ : ∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
(B → A) → (C → D) → (A → C) → (B → D)
→-cong-→ B→A C→D = (C→D ∘_) ∘ (_∘ B→A)
-- The non-dependent function space preserves split surjections
-- (assuming extensionality).
→-cong-↠ : ∀ {a b c d} → Extensionality b d →
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
A ↠ B → C ↠ D → (A → C) ↠ (B → D)
→-cong-↠ {a} {b} {c} {d} ext A↠B C↠D = record
{ logical-equivalence = logical-equiv
; right-inverse-of = right-inv
}
where
open _↠_
logical-equiv = L.→-cong (_↠_.logical-equivalence A↠B)
(_↠_.logical-equivalence C↠D)
abstract
right-inv :
∀ f → _⇔_.to logical-equiv (_⇔_.from logical-equiv f) ≡ f
right-inv f = apply-ext ext λ x →
to C↠D (from C↠D (f (to A↠B (from A↠B x)))) ≡⟨ right-inverse-of C↠D _ ⟩
f (to A↠B (from A↠B x)) ≡⟨ cong f $ right-inverse-of A↠B _ ⟩∎
f x ∎
private
-- Lemmas used in the implementation of →-cong.
→-cong-↔ : ∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Extensionality (a ⊔ b) (c ⊔ d) →
A ↔ B → C ↔ D → (A → C) ↔ (B → D)
→-cong-↔ {a} {b} {c} {d} ext A↔B C↔D = record
{ surjection = surj
; left-inverse-of = left-inv
}
where
open _↔_
surj = →-cong-↠ (lower-extensionality a c ext)
(_↔_.surjection A↔B)
(_↔_.surjection C↔D)
abstract
left-inv :
∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
left-inv f = apply-ext (lower-extensionality b d ext) λ x →
from C↔D (to C↔D (f (from A↔B (to A↔B x)))) ≡⟨ left-inverse-of C↔D _ ⟩
f (from A↔B (to A↔B x)) ≡⟨ cong f $ left-inverse-of A↔B _ ⟩∎
f x ∎
→-cong-≃ :
∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Extensionality (a ⊔ b) (c ⊔ d) →
A ≃ B → C ≃ D → (A → C) ≃ (B → D)
→-cong-≃ ext A≃B C≃D = record
{ to = to
; is-equivalence = from , proofs
}
where
A→C≃B→D =
Eq.↔⇒≃ (→-cong-↔ ext (_≃_.bijection A≃B) (_≃_.bijection C≃D))
to = _≃_.to A→C≃B→D
from = _≃_.from A→C≃B→D
abstract
proofs : HA.Proofs to from
proofs = proj₂ (_≃_.is-equivalence A→C≃B→D)
→-cong-≃ᴱ :
∀ {a b c d}
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Erased (Extensionality (a ⊔ b) (c ⊔ d)) →
A ≃ᴱ B → C ≃ᴱ D → (A → C) ≃ᴱ (B → D)
→-cong-≃ᴱ E.[ ext ] f g =
EEq.[≃]→≃ᴱ (EEq.[proofs] (→-cong-≃ ext (EEq.≃ᴱ→≃ f) (EEq.≃ᴱ→≃ g)))
-- The non-dependent function space preserves symmetric kinds of
-- functions (in some cases assuming extensionality).
→-cong : ∀ {k a b c d} →
Extensionality? ⌊ k ⌋-sym (a ⊔ b) (c ⊔ d) →
{A : Type a} {B : Type b} {C : Type c} {D : Type d} →
A ↝[ ⌊ k ⌋-sym ] B → C ↝[ ⌊ k ⌋-sym ] D →
(A → C) ↝[ ⌊ k ⌋-sym ] (B → D)
→-cong {logical-equivalence} _ = L.→-cong
→-cong {bijection} ext = →-cong-↔ ext
→-cong {equivalence} ext = →-cong-≃ ext
→-cong {equivalenceᴱ} ext = →-cong-≃ᴱ ext
-- A variant of →-cong.
→-cong₁ :
∀ {k₁ k₂ a b c} →
Extensionality? k₂ (a ⊔ b) c →
{A : Type a} {B : Type b} {C : Type c} →
A ↔[ k₁ ] B → (A → C) ↝[ k₂ ] (B → C)
→-cong₁ ext hyp = generalise-ext?-sym
(λ ext → →-cong ext (from-bijection (from-isomorphism hyp)) id)
ext
private
-- Lemmas used in the implementation of ∀-cong.
∀-cong-→ :
∀ {a b₁ b₂} {A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x → B₂ x) →
((x : A) → B₁ x) → ((x : A) → B₂ x)
∀-cong-→ B₁→B₂ = B₁→B₂ _ ⊚_
∀-cong-bij :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↔ B₂ x) →
((x : A) → B₁ x) ↔ ((x : A) → B₂ x)
∀-cong-bij {b₂ = b₂} ext B₁↔B₂ = record
{ surjection = surj
; left-inverse-of = left-inverse-of
}
where
surj = Surjection.∀-cong ext (_↔_.surjection ⊚ B₁↔B₂)
abstract
left-inverse-of : ∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
left-inverse-of = λ f →
apply-ext (lower-extensionality lzero b₂ ext) λ x →
_↔_.from (B₁↔B₂ x) (_↔_.to (B₁↔B₂ x) (f x)) ≡⟨ _↔_.left-inverse-of (B₁↔B₂ x) (f x) ⟩∎
f x ∎
∀-cong-eq :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ≃ B₂ x) →
((x : A) → B₁ x) ≃ ((x : A) → B₂ x)
∀-cong-eq ext = Eq.↔⇒≃ ⊚ ∀-cong-bij ext ⊚ (_≃_.bijection ⊚_)
∀-cong-eqᴱ :
∀ {a b₁ b₂} →
Erased (Extensionality a (b₁ ⊔ b₂)) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ≃ᴱ B₂ x) →
((x : A) → B₁ x) ≃ᴱ ((x : A) → B₂ x)
∀-cong-eqᴱ E.[ ext ] f =
EEq.[≃]→≃ᴱ (EEq.[proofs] (∀-cong-eq ext (EEq.≃ᴱ→≃ ⊚ f)))
∀-cong-inj :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↣ B₂ x) →
((x : A) → B₁ x) ↣ ((x : A) → B₂ x)
∀-cong-inj {b₁ = b₁} {b₂} ext B₁↣B₂ = record
{ to = to
; injective = injective
}
where
to = ∀-cong-→ (_↣_.to ⊚ B₁↣B₂)
abstract
injective : Injective to
injective {x = f} {y = g} =
(λ x → _↣_.to (B₁↣B₂ x) (f x)) ≡ (λ x → _↣_.to (B₁↣B₂ x) (g x)) ↔⟨ inverse $ Eq.extensionality-isomorphism
(lower-extensionality lzero b₁ ext) ⟩
(∀ x → _↣_.to (B₁↣B₂ x) (f x) ≡ _↣_.to (B₁↣B₂ x) (g x)) ↝⟨ ∀-cong-→ (λ x → _↣_.injective (B₁↣B₂ x)) ⟩
(∀ x → f x ≡ g x) ↔⟨ Eq.extensionality-isomorphism
(lower-extensionality lzero b₂ ext) ⟩□
f ≡ g □
∀-cong-emb :
∀ {a b₁ b₂} →
Extensionality a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → Embedding (B₁ x) (B₂ x)) →
Embedding ((x : A) → B₁ x) ((x : A) → B₂ x)
∀-cong-emb {b₁ = b₁} {b₂} ext B₁↣B₂ = record
{ to = to
; is-embedding = is-embedding
}
where
to = ∀-cong-→ (Embedding.to ⊚ B₁↣B₂)
ext₂ = lower-extensionality lzero b₁ ext
abstract
is-embedding : Is-embedding to
is-embedding f g = _≃_.is-equivalence $
Eq.with-other-function
(f ≡ g ↝⟨ inverse $ Eq.extensionality-isomorphism
(lower-extensionality lzero b₂ ext) ⟩
(∀ x → f x ≡ g x) ↝⟨ ∀-cong-eq ext (λ x →
Eq.⟨ _ , Embedding.is-embedding (B₁↣B₂ x) (f x) (g x) ⟩) ⟩
(∀ x → Embedding.to (B₁↣B₂ x) (f x) ≡
Embedding.to (B₁↣B₂ x) (g x)) ↝⟨ Eq.extensionality-isomorphism ext₂ ⟩□
(λ x → Embedding.to (B₁↣B₂ x) (f x)) ≡
(λ x → Embedding.to (B₁↣B₂ x) (g x)) □)
_
(λ f≡g →
apply-ext (Eq.good-ext ext₂)
(λ x → cong (Embedding.to (B₁↣B₂ x)) (ext⁻¹ f≡g x)) ≡⟨⟩
apply-ext (Eq.good-ext ext₂)
(λ x → cong (Embedding.to (B₁↣B₂ x)) (cong (_$ x) f≡g)) ≡⟨ cong (apply-ext (Eq.good-ext ext₂)) (apply-ext ext₂ λ _ →
cong-∘ _ _ _) ⟩
apply-ext (Eq.good-ext ext₂)
(λ x → cong (λ h → Embedding.to (B₁↣B₂ x) (h x)) f≡g) ≡⟨ cong (apply-ext (Eq.good-ext ext₂)) (apply-ext ext₂ λ _ → sym $
cong-∘ _ _ _) ⟩
apply-ext (Eq.good-ext ext₂)
(λ x → cong (_$ x)
(cong (λ h x → Embedding.to (B₁↣B₂ x) (h x))
f≡g)) ≡⟨⟩
apply-ext (Eq.good-ext ext₂)
(ext⁻¹ (cong (λ h x → Embedding.to (B₁↣B₂ x) (h x)) f≡g)) ≡⟨ _≃_.right-inverse-of (Eq.extensionality-isomorphism ext₂) _ ⟩∎
cong (λ h x → Embedding.to (B₁↣B₂ x) (h x)) f≡g ∎)
-- Π preserves all kinds of functions in its second argument (in some
-- cases assuming extensionality).
∀-cong :
∀ {k a b₁ b₂} →
Extensionality? k a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ x → B₁ x ↝[ k ] B₂ x) →
((x : A) → B₁ x) ↝[ k ] ((x : A) → B₂ x)
∀-cong {implication} = λ _ → ∀-cong-→
∀-cong {logical-equivalence} = λ _ → L.∀-cong
∀-cong {injection} = ∀-cong-inj
∀-cong {embedding} = ∀-cong-emb
∀-cong {surjection} = Surjection.∀-cong
∀-cong {bijection} = ∀-cong-bij
∀-cong {equivalence} = ∀-cong-eq
∀-cong {equivalenceᴱ} = ∀-cong-eqᴱ
-- The implicit variant of Π preserves all kinds of functions in its
-- second argument (in some cases assuming extensionality).
implicit-∀-cong :
∀ {k a b₁ b₂} →
Extensionality? k a (b₁ ⊔ b₂) →
{A : Type a} {B₁ : A → Type b₁} {B₂ : A → Type b₂} →
(∀ {x} → B₁ x ↝[ k ] B₂ x) →
({x : A} → B₁ x) ↝[ k ] ({x : A} → B₂ x)
implicit-∀-cong ext {A} {B₁} {B₂} B₁↝B₂ =
({x : A} → B₁ x) ↔⟨ Bijection.implicit-Π↔Π ⟩
((x : A) → B₁ x) ↝⟨ ∀-cong ext (λ _ → B₁↝B₂) ⟩
((x : A) → B₂ x) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
({x : A} → B₂ x) □
-- Two generalisations of ∀-cong for non-dependent functions.
Π-cong-contra-→ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂→A₁ : A₂ → A₁) →
(∀ x → B₁ (A₂→A₁ x) → B₂ x) →
((x : A₁) → B₁ x) → ((x : A₂) → B₂ x)
Π-cong-contra-→ {B₁ = B₁} {B₂} A₂→A₁ B₁→B₂ f x =
$⟨ f (A₂→A₁ x) ⟩
B₁ (A₂→A₁ x) ↝⟨ B₁→B₂ x ⟩
B₂ x □
Π-cong-→ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ x → B₁ x → B₂ (_↠_.to A₁↠A₂ x)) →
((x : A₁) → B₁ x) → ((x : A₂) → B₂ x)
Π-cong-→ {B₁ = B₁} {B₂} A₁↠A₂ B₁→B₂ f x =
$⟨ f (_↠_.from A₁↠A₂ x) ⟩
B₁ (_↠_.from A₁↠A₂ x) ↝⟨ B₁→B₂ (_↠_.from A₁↠A₂ x) ⟩
B₂ (_↠_.to A₁↠A₂ (_↠_.from A₁↠A₂ x)) ↝⟨ subst B₂ (_↠_.right-inverse-of A₁↠A₂ x) ⟩□
B₂ x □
-- Two generalisations of ∀-cong for logical equivalences.
Π-cong-⇔ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ x → B₁ x ⇔ B₂ (_↠_.to A₁↠A₂ x)) →
((x : A₁) → B₁ x) ⇔ ((x : A₂) → B₂ x)
Π-cong-⇔ {A₁ = A₁} {A₂} {B₁} {B₂} A₁↠A₂ B₁⇔B₂ = record
{ to = Π-cong-→ A₁↠A₂ (_⇔_.to ⊚ B₁⇔B₂)
; from = Π-cong-contra-→ (_↠_.to A₁↠A₂) (_⇔_.from ⊚ B₁⇔B₂)
}
Π-cong-contra-⇔ :
∀ {a₁ a₂ b₁ b₂}
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) ⇔ B₂ x) →
((x : A₁) → B₁ x) ⇔ ((x : A₂) → B₂ x)
Π-cong-contra-⇔ {A₁ = A₁} {A₂} {B₁} {B₂} A₂↠A₁ B₁⇔B₂ = record
{ to = Π-cong-contra-→ (_↠_.to A₂↠A₁) (_⇔_.to ⊚ B₁⇔B₂)
; from = Π-cong-→ A₂↠A₁ (_⇔_.from ⊚ B₁⇔B₂)
}
-- A generalisation of ∀-cong for split surjections.
Π-cong-↠ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₂ b₂ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↠A₂ : A₁ ↠ A₂) →
(∀ x → B₁ x ↠ B₂ (_↠_.to A₁↠A₂ x)) →
((x : A₁) → B₁ x) ↠ ((x : A₂) → B₂ x)
Π-cong-↠ ext {B₂ = B₂} A₁↠A₂ B₁↠B₂ = record
{ logical-equivalence = equiv
; right-inverse-of = to∘from
}
where
equiv = Π-cong-⇔ A₁↠A₂ (_↠_.logical-equivalence ⊚ B₁↠B₂)
abstract
to∘from : ∀ f → _⇔_.to equiv (_⇔_.from equiv f) ≡ f
to∘from f = apply-ext ext λ x →
subst B₂ (_↠_.right-inverse-of A₁↠A₂ x)
(_↠_.to (B₁↠B₂ (_↠_.from A₁↠A₂ x))
(_↠_.from (B₁↠B₂ (_↠_.from A₁↠A₂ x))
(f (_↠_.to A₁↠A₂ (_↠_.from A₁↠A₂ x))))) ≡⟨ cong (subst B₂ (_↠_.right-inverse-of A₁↠A₂ x)) $ _↠_.right-inverse-of (B₁↠B₂ _) _ ⟩
subst B₂ (_↠_.right-inverse-of A₁↠A₂ x)
(f (_↠_.to A₁↠A₂ (_↠_.from A₁↠A₂ x))) ≡⟨ dcong f _ ⟩∎
f x ∎
-- A generalisation of ∀-cong for injections.
Π-cong-contra-↣ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₁ b₁ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↠A₁ : A₂ ↠ A₁) →
(∀ x → B₁ (_↠_.to A₂↠A₁ x) ↣ B₂ x) →
((x : A₁) → B₁ x) ↣ ((x : A₂) → B₂ x)
Π-cong-contra-↣ ext A₂↠A₁ B₁↣B₂ = record
{ to = to
; injective = injective
}
where
to = Π-cong-contra-→ (_↠_.to A₂↠A₁) (_↣_.to ⊚ B₁↣B₂)
abstract
injective : Injective to
injective {x = f} {y = g} to-f≡to-g = apply-ext ext λ x →
let x′ = _↠_.to A₂↠A₁ (_↠_.from A₂↠A₁ x) in
$⟨ to-f≡to-g ⟩
(λ x → _↣_.to (B₁↣B₂ x) (f (_↠_.to A₂↠A₁ x))) ≡
(λ x → _↣_.to (B₁↣B₂ x) (g (_↠_.to A₂↠A₁ x))) ↝⟨ cong (_$ _) ⟩
_↣_.to (B₁↣B₂ (_↠_.from A₂↠A₁ x)) (f x′) ≡
_↣_.to (B₁↣B₂ (_↠_.from A₂↠A₁ x)) (g x′) ↝⟨ _↣_.injective (B₁↣B₂ _) ⟩
f x′ ≡ g x′ ↝⟨ subst (λ x → f x ≡ g x) $ _↠_.right-inverse-of A₂↠A₁ x ⟩□
f x ≡ g x □
private
-- Lemmas used in the implementations of Π-cong and Π-cong-contra.
Π-cong-contra-↠ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₂ b₂ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ↠ B₂ x) →
((x : A₁) → B₁ x) ↠ ((x : A₂) → B₂ x)
Π-cong-contra-↠ ext {B₁ = B₁} A₂≃A₁ B₁↠B₂ = record
{ logical-equivalence = equiv
; right-inverse-of = to∘from
}
where
equiv = Π-cong-contra-⇔ (_≃_.surjection A₂≃A₁)
(_↠_.logical-equivalence ⊚ B₁↠B₂)
abstract
to∘from : ∀ f → _⇔_.to equiv (_⇔_.from equiv f) ≡ f
to∘from f = apply-ext ext λ x →
_↠_.to (B₁↠B₂ x)
(subst B₁ (_≃_.right-inverse-of A₂≃A₁ (_≃_.to A₂≃A₁ x))
(_↠_.from (B₁↠B₂ (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x)))
(f (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x))))) ≡⟨ cong (λ eq → _↠_.to (B₁↠B₂ x)
(subst B₁ eq (_↠_.from (B₁↠B₂ _) (f _)))) $ sym $
_≃_.left-right-lemma A₂≃A₁ _ ⟩
_↠_.to (B₁↠B₂ x)
(subst B₁ (cong (_≃_.to A₂≃A₁) $ _≃_.left-inverse-of A₂≃A₁ x)
(_↠_.from (B₁↠B₂ (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x)))
(f (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x))))) ≡⟨ cong (_↠_.to (B₁↠B₂ x)) $ sym $ subst-∘ _ _ _ ⟩
_↠_.to (B₁↠B₂ x)
(subst (B₁ ∘ _≃_.to A₂≃A₁) (_≃_.left-inverse-of A₂≃A₁ x)
(_↠_.from (B₁↠B₂ (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x)))
(f (_≃_.from A₂≃A₁ (_≃_.to A₂≃A₁ x))))) ≡⟨ cong (_↠_.to (B₁↠B₂ x)) $
dcong (λ x → _↠_.from (B₁↠B₂ x) (f x)) _ ⟩
_↠_.to (B₁↠B₂ x) (_↠_.from (B₁↠B₂ x) (f x)) ≡⟨ _↠_.right-inverse-of (B₁↠B₂ x) _ ⟩∎
f x ∎
Π-cong-↔ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ↔ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ↔ ((x : A₂) → B₂ x)
Π-cong-↔ {a₁} {a₂} {b₁} {b₂} ext {B₂ = B₂} A₁≃A₂ B₁↔B₂ = record
{ surjection = surj
; left-inverse-of = from∘to
}
where
surj = Π-cong-↠ (lower-extensionality a₁ b₁ ext)
(_≃_.surjection A₁≃A₂) (_↔_.surjection ⊚ B₁↔B₂)
abstract
from∘to : ∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
from∘to =
_↠_.right-inverse-of $
Π-cong-contra-↠ (lower-extensionality a₂ b₂ ext)
{B₁ = B₂}
A₁≃A₂
(_↔_.surjection ⊚ inverse ⊚ B₁↔B₂)
Π-cong-contra-↔ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ↔ B₂ x) →
((x : A₁) → B₁ x) ↔ ((x : A₂) → B₂ x)
Π-cong-contra-↔ {a₁} {a₂} {b₁} {b₂} ext {B₂ = B₂} A₂≃A₁ B₁↔B₂ = record
{ surjection = surj
; left-inverse-of = from∘to
}
where
surj = Π-cong-contra-↠ (lower-extensionality a₁ b₁ ext)
A₂≃A₁ (_↔_.surjection ⊚ B₁↔B₂)
abstract
from∘to : ∀ f → _↠_.from surj (_↠_.to surj f) ≡ f
from∘to =
_↠_.right-inverse-of $
Π-cong-↠ (lower-extensionality a₂ b₂ ext)
(_≃_.surjection A₂≃A₁)
(_↔_.surjection ⊚ inverse ⊚ B₁↔B₂)
Π-cong-≃ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ≃ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ≃ ((x : A₂) → B₂ x)
Π-cong-≃ ext A₁≃A₂ =
from-isomorphism ⊚ Π-cong-↔ ext A₁≃A₂ ⊚ (from-isomorphism ⊚_)
Π-cong-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} →
Erased (Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂)) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ≃ᴱ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ≃ᴱ ((x : A₂) → B₂ x)
Π-cong-≃ᴱ E.[ ext ] {B₂ = B₂} f g =
EEq.[≃]→≃ᴱ
{to = λ h x → subst B₂ (_≃_.right-inverse-of f x)
(_≃ᴱ_.to (g (_≃_.from f x)) (h (_≃_.from f x)))}
{from = λ h x → _≃ᴱ_.from (g x) (h (_≃_.to f x))}
(EEq.[proofs] (Π-cong-≃ ext f (EEq.≃ᴱ→≃ ⊚ g)))
Π-cong-contra-≃ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ≃ B₂ x) →
((x : A₁) → B₁ x) ≃ ((x : A₂) → B₂ x)
Π-cong-contra-≃ ext A₂≃A₁ =
from-isomorphism ⊚ Π-cong-contra-↔ ext A₂≃A₁ ⊚ (from-isomorphism ⊚_)
Π-cong-contra-≃ᴱ :
∀ {a₁ a₂ b₁ b₂} →
Erased (Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂)) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → B₁ (_≃_.to A₂≃A₁ x) ≃ᴱ B₂ x) →
((x : A₁) → B₁ x) ≃ᴱ ((x : A₂) → B₂ x)
Π-cong-contra-≃ᴱ E.[ ext ] {B₁ = B₁} f g =
EEq.[≃]→≃ᴱ
{to = λ h x → _≃ᴱ_.to (g x) (h (_≃_.to f x))}
{from = λ h x → subst B₁ (_≃_.right-inverse-of f x)
(_≃ᴱ_.from (g (_≃_.from f x))
(h (_≃_.from f x)))}
(EEq.[proofs] (Π-cong-contra-≃ ext f (EEq.≃ᴱ→≃ ⊚ g)))
Π-cong-↣ :
∀ {a₁ a₂ b₁ b₂} →
Extensionality a₁ b₁ →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → B₁ x ↣ B₂ (_≃_.to A₁≃A₂ x)) →
((x : A₁) → B₁ x) ↣ ((x : A₂) → B₂ x)
Π-cong-↣ ext {A₁} {A₂} {B₁} {B₂} A₁≃A₂ =
(∀ x → B₁ x ↣ B₂ (_≃_.to A₁≃A₂ x)) ↝⟨ Π-cong-contra-→ (_≃_.from A₁≃A₂) (λ _ → id) ⟩
(∀ x → B₁ (_≃_.from A₁≃A₂ x) ↣ B₂ (_≃_.to A₁≃A₂ (_≃_.from A₁≃A₂ x))) ↝⟨ (∀-cong _ λ _ →
subst ((B₁ _ ↣_) ⊚ B₂) (_≃_.right-inverse-of A₁≃A₂ _)) ⟩
(∀ x → B₁ (_≃_.from A₁≃A₂ x) ↣ B₂ x) ↝⟨ Π-cong-contra-↣ ext (_≃_.surjection $ inverse A₁≃A₂) ⟩□
((x : A₁) → B₁ x) ↣ ((x : A₂) → B₂ x) □
Π-cong-contra-Emb :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂≃A₁ : A₂ ≃ A₁) →
(∀ x → Embedding (B₁ (_≃_.to A₂≃A₁ x)) (B₂ x)) →
Embedding ((x : A₁) → B₁ x) ((x : A₂) → B₂ x)
Π-cong-contra-Emb {a₁} {a₂} {b₁} {b₂} ext A₂≃A₁ B₁↣B₂ = record
{ to = to
; is-embedding = is-embedding
}
where
to = Π-cong-contra-→ (_≃_.to A₂≃A₁) (Embedding.to ⊚ B₁↣B₂)
abstract
ext₁₁ : Extensionality a₁ b₁
ext₁₁ = lower-extensionality a₂ b₂ ext
ext₂₁ : Extensionality a₂ b₁
ext₂₁ = lower-extensionality a₁ b₂ ext
ext₂₂ : Extensionality a₂ b₂
ext₂₂ = lower-extensionality a₁ b₁ ext
is-embedding : Is-embedding to
is-embedding f g =
_≃_.is-equivalence $
Eq.with-other-function
(f ≡ g ↝⟨ inverse $ Eq.extensionality-isomorphism ext₁₁ ⟩
(∀ x → f x ≡ g x) ↝⟨ (inverse $ Π-cong-≃ ext A₂≃A₁ λ x →
inverse $ Embedding.equivalence (B₁↣B₂ x)) ⟩
(∀ x → Embedding.to (B₁↣B₂ x) (f (_≃_.to A₂≃A₁ x)) ≡
Embedding.to (B₁↣B₂ x) (g (_≃_.to A₂≃A₁ x))) ↝⟨ Eq.extensionality-isomorphism ext₂₂ ⟩
(λ {x} → Embedding.to (B₁↣B₂ x)) ⊚ f ⊚ _≃_.to A₂≃A₁ ≡
(λ {x} → Embedding.to (B₁↣B₂ x)) ⊚ g ⊚ _≃_.to A₂≃A₁ ↔⟨⟩
to f ≡ to g □)
_
(λ f≡g →
apply-ext (Eq.good-ext ext₂₂)
(cong (Embedding.to (B₁↣B₂ _)) ⊚
ext⁻¹ f≡g ⊚ _≃_.to A₂≃A₁) ≡⟨ sym $ Eq.cong-post-∘-good-ext ext₂₁ ext₂₂ _ ⟩
cong (Embedding.to (B₁↣B₂ _) ⊚_)
(apply-ext (Eq.good-ext ext₂₁)
(ext⁻¹ f≡g ⊚ _≃_.to A₂≃A₁)) ≡⟨ cong (cong (Embedding.to (B₁↣B₂ _) ⊚_)) $ sym $
Eq.cong-pre-∘-good-ext ext₂₁ ext₁₁ _ ⟩
cong (Embedding.to (B₁↣B₂ _) ⊚_)
(cong (_⊚ _≃_.to A₂≃A₁)
(apply-ext (Eq.good-ext ext₁₁) (ext⁻¹ f≡g))) ≡⟨ cong-∘ _ _ _ ⟩
cong to (apply-ext (Eq.good-ext ext₁₁) (ext⁻¹ f≡g)) ≡⟨ cong (cong to) $
_≃_.right-inverse-of (Eq.extensionality-isomorphism ext₁₁) _ ⟩∎
cong to f≡g ∎)
Π-cong-Emb :
∀ {a₁ a₂ b₁ b₂} →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
∀ {A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁≃A₂ : A₁ ≃ A₂) →
(∀ x → Embedding (B₁ x) (B₂ (_≃_.to A₁≃A₂ x))) →
Embedding ((x : A₁) → B₁ x) ((x : A₂) → B₂ x)
Π-cong-Emb ext {A₁} {A₂} {B₁} {B₂} A₁≃A₂ =
(∀ x → Embedding (B₁ x) (B₂ (_≃_.to A₁≃A₂ x))) ↝⟨ Π-cong-contra-→ (_≃_.from A₁≃A₂) (λ _ → id) ⟩
(∀ x → Embedding (B₁ (_≃_.from A₁≃A₂ x))
(B₂ (_≃_.to A₁≃A₂ (_≃_.from A₁≃A₂ x)))) ↝⟨ (∀-cong _ λ _ → subst (Embedding (B₁ _) ⊚ B₂) (_≃_.right-inverse-of A₁≃A₂ _)) ⟩
(∀ x → Embedding (B₁ (_≃_.from A₁≃A₂ x)) (B₂ x)) ↝⟨ Π-cong-contra-Emb ext (inverse A₁≃A₂) ⟩□
Embedding ((x : A₁) → B₁ x) ((x : A₂) → B₂ x) □
-- A generalisation of ∀-cong.
Π-cong :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
Π-cong {k₁} {k₂} {a₁} {a₂} {b₁} {b₂}
ext {A₁} {A₂} {B₁} {B₂} A₁↔A₂ B₁↝B₂ =
helper k₂ ext (B₁↝B₂′ k₁ A₁↔A₂ B₁↝B₂)
where
-- The first four clauses are included as optimisations intended to
-- make some proof terms easier to work with. These clauses cover
-- every possible use of B₁↝B₂′ in the expression above.
B₁↝B₂′ :
∀ k₁ (A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
∀ k x →
B₁ x ↝[ k₂ ] B₂ (to-implication {k = k} (from-isomorphism A₁↔A₂) x)
B₁↝B₂′ bijection _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ bijection _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ k₁ A₁↔A₂ B₁↝B₂ k = λ x →
B₁ x ↝⟨ B₁↝B₂ x ⟩
B₂ (to-implication A₁↔A₂ x) ↝⟨ ≡⇒↝ _ $ cong (λ f → B₂ (f x)) $
to-implication∘from-isomorphism k₁ k ⟩□
B₂ (to-implication {k = k} (from-isomorphism A₁↔A₂) x) □
A₁↝A₂ : ∀ {k} → A₁ ↝[ k ] A₂
A₁↝A₂ = from-isomorphism A₁↔A₂
l₁ = lower-extensionality a₁ b₁
l₂ = lower-extensionality a₂ b₂
helper :
∀ k₂ →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
(∀ k x → B₁ x ↝[ k₂ ]
B₂ (to-implication {k = k} (from-isomorphism A₁↔A₂) x)) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
helper implication _ = Π-cong-→ A₁↝A₂ ⊚ (_$ surjection)
helper logical-equivalence _ = Π-cong-⇔ A₁↝A₂ ⊚ (_$ surjection)
helper injection ext = Π-cong-↣ (l₂ ext) A₁↝A₂ ⊚ (_$ equivalence)
helper embedding ext = Π-cong-Emb ext A₁↝A₂ ⊚ (_$ equivalence)
helper surjection ext = Π-cong-↠ (l₁ ext) A₁↝A₂ ⊚ (_$ surjection)
helper bijection ext = Π-cong-↔ ext A₁↝A₂ ⊚ (_$ equivalence)
helper equivalence ext = Π-cong-≃ ext A₁↝A₂ ⊚ (_$ equivalence)
helper equivalenceᴱ ext = Π-cong-≃ᴱ ext A₁↝A₂ ⊚ (_$ equivalence)
-- A variant of Π-cong.
Π-cong-contra :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
Π-cong-contra {k₁} {k₂} {a₁} {a₂} {b₁} {b₂}
ext {A₁} {A₂} {B₁} {B₂} A₂↔A₁ B₁↝B₂ =
helper k₂ ext (B₁↝B₂′ k₁ A₂↔A₁ B₁↝B₂)
where
-- The first six clauses are included as optimisations intended to
-- make some proof terms easier to work with. These clauses cover
-- every possible use of B₁↝B₂′ in the expression above.
B₁↝B₂′ :
∀ k₁ (A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
∀ k x →
B₁ (to-implication {k = k} (from-isomorphism A₂↔A₁) x) ↝[ k₂ ] B₂ x
B₁↝B₂′ bijection _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ bijection _ B₁↝B₂ implication = B₁↝B₂
B₁↝B₂′ bijection _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ equivalence = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ implication = B₁↝B₂
B₁↝B₂′ equivalence _ B₁↝B₂ surjection = B₁↝B₂
B₁↝B₂′ k₁ A₂↔A₁ B₁↝B₂ k = λ x →
B₁ (to-implication {k = k} (from-isomorphism A₂↔A₁) x) ↝⟨ ≡⇒↝ _ $ cong (λ f → B₁ (f x)) $ sym $ to-implication∘from-isomorphism k₁ k ⟩
B₁ (to-implication A₂↔A₁ x) ↝⟨ B₁↝B₂ x ⟩□
B₂ x □
A₂↝A₁ : ∀ {k} → A₂ ↝[ k ] A₁
A₂↝A₁ = from-isomorphism A₂↔A₁
l₁ = lower-extensionality a₁ b₁
l₂ = lower-extensionality a₂ b₂
helper :
∀ k₂ →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
(∀ k x → B₁ (to-implication {k = k} (from-isomorphism A₂↔A₁) x)
↝[ k₂ ]
B₂ x) →
((x : A₁) → B₁ x) ↝[ k₂ ] ((x : A₂) → B₂ x)
helper implication _ = Π-cong-contra-→ A₂↝A₁ ⊚ (_$ implication)
helper logical-equivalence _ = Π-cong-contra-⇔ A₂↝A₁ ⊚ (_$ surjection)
helper injection ext = Π-cong-contra-↣ (l₂ ext) A₂↝A₁ ⊚ (_$ surjection)
helper embedding ext = Π-cong-contra-Emb ext A₂↝A₁ ⊚ (_$ equivalence)
helper surjection ext = Π-cong-contra-↠ (l₁ ext) A₂↝A₁ ⊚ (_$ equivalence)
helper bijection ext = Π-cong-contra-↔ ext A₂↝A₁ ⊚ (_$ equivalence)
helper equivalence ext = Π-cong-contra-≃ ext A₂↝A₁ ⊚ (_$ equivalence)
helper equivalenceᴱ ext = Π-cong-contra-≃ᴱ ext A₂↝A₁ ⊚ (_$ equivalence)
-- A variant of Π-cong for implicit Πs.
implicit-Π-cong :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂) →
(∀ x → B₁ x ↝[ k₂ ] B₂ (to-implication A₁↔A₂ x)) →
({x : A₁} → B₁ x) ↝[ k₂ ] ({x : A₂} → B₂ x)
implicit-Π-cong ext {A₁} {A₂} {B₁} {B₂} A₁↔A₂ B₁↝B₂ =
({x : A₁} → B₁ x) ↔⟨ Bijection.implicit-Π↔Π ⟩
((x : A₁) → B₁ x) ↝⟨ Π-cong ext A₁↔A₂ B₁↝B₂ ⟩
((x : A₂) → B₂ x) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
({x : A₂} → B₂ x) □
-- A variant of Π-cong-contra for implicit Πs.
implicit-Π-cong-contra :
∀ {k₁ k₂ a₁ a₂ b₁ b₂} →
Extensionality? k₂ (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
{A₁ : Type a₁} {A₂ : Type a₂}
{B₁ : A₁ → Type b₁} {B₂ : A₂ → Type b₂} →
(A₂↔A₁ : A₂ ↔[ k₁ ] A₁) →
(∀ x → B₁ (to-implication A₂↔A₁ x) ↝[ k₂ ] B₂ x) →
({x : A₁} → B₁ x) ↝[ k₂ ] ({x : A₂} → B₂ x)
implicit-Π-cong-contra ext {A₁} {A₂} {B₁} {B₂} A₁↔A₂ B₁↝B₂ =
({x : A₁} → B₁ x) ↔⟨ Bijection.implicit-Π↔Π ⟩
((x : A₁) → B₁ x) ↝⟨ Π-cong-contra ext A₁↔A₂ B₁↝B₂ ⟩
((x : A₂) → B₂ x) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□
({x : A₂} → B₂ x) □
Π-left-identity : ∀ {a} {A : ⊤ → Type a} → ((x : ⊤) → A x) ↔ A tt
Π-left-identity = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → f tt
; from = λ x _ → x
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- A variant of Π-left-identity.
Π-left-identity-↑ :
∀ {a ℓ} {A : ↑ ℓ ⊤ → Type a} → ((x : ↑ ℓ ⊤) → A x) ↔ A (lift tt)
Π-left-identity-↑ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → f (lift tt)
; from = λ x _ → x
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- A lemma that can be used to simplify a pi type where the domain is
-- isomorphic to the unit type.
drop-⊤-left-Π :
∀ {k a b} {A : Type a} {B : A → Type b} →
Extensionality? k a b →
(A↔⊤ : A ↔ ⊤) →
((x : A) → B x) ↝[ k ] B (_↔_.from A↔⊤ tt)
drop-⊤-left-Π {A = A} {B} ext A↔⊤ =
((x : A) → B x) ↝⟨ Π-cong-contra ext (inverse A↔⊤) (λ _ → id) ⟩
((x : ⊤) → B (_↔_.from A↔⊤ x)) ↔⟨ Π-left-identity ⟩□
B (_↔_.from A↔⊤ tt) □
→-right-zero : ∀ {a} {A : Type a} → (A → ⊤) ↔ ⊤
→-right-zero = record
{ surjection = record
{ logical-equivalence = record
{ to = λ _ → tt
; from = λ _ _ → tt
}
; right-inverse-of = λ _ → refl tt
}
; left-inverse-of = λ _ → refl (λ _ → tt)
}
-- A lemma relating function types with the empty type as domain and
-- the unit type.
Π⊥↔⊤ : ∀ {ℓ a} {A : ⊥ {ℓ = ℓ} → Type a} →
((x : ⊥) → A x) ↝[ ℓ ∣ a ] ⊤
Π⊥↔⊤ = generalise-ext?
(record
{ to = _
; from = λ _ x → ⊥-elim x
})
(λ ext →
(λ _ → refl _)
, (λ _ → apply-ext ext (λ x → ⊥-elim x)))
-- A lemma relating ¬ ⊥ and ⊤.
¬⊥↔⊤ : ∀ {ℓ} → ¬ ⊥ {ℓ = ℓ} ↝[ ℓ ∣ lzero ] ⊤
¬⊥↔⊤ = Π⊥↔⊤
-- Simplification lemmas for types of the form A → A → B.
→→↠→ :
∀ {a b} {A : Type a} {B : Type b} →
(A → A → B) ↠ (A → B)
→→↠→ = record
{ logical-equivalence = record
{ to = λ f x → f x x
; from = λ f x _ → f x
}
; right-inverse-of = refl
}
→→proposition↔→ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality a (a ⊔ b) →
Is-proposition B →
(A → A → B) ↔ (A → B)
→→proposition↔→ {a} ext B-prop = record
{ surjection = →→↠→
; left-inverse-of = λ f →
apply-ext ext λ x →
(Π-closure (lower-extensionality lzero a ext) 1 λ _ →
B-prop) _ _
}
-- If A is inhabited, then there is a split surjection from A → B to
-- B.
inhabited→↠ :
∀ {a b} {A : Type a} {B : Type b} →
A → (A → B) ↠ B
inhabited→↠ x = record
{ logical-equivalence = record
{ to = _$ x
; from = const
}
; right-inverse-of = refl
}
-- If A is inhabited and B is a proposition, then A → B and B are
-- isomorphic (assuming extensionality).
inhabited→proposition↔ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality a b →
Is-proposition B →
A → (A → B) ↔ B
inhabited→proposition↔ ext B-prop x = record
{ surjection = inhabited→↠ x
; left-inverse-of = λ f →
apply-ext ext λ y →
f x ≡⟨ B-prop _ _ ⟩∎
f y ∎
}
-- Π is "commutative".
Π-comm : ∀ {a b c} {A : Type a} {B : Type b} {C : A → B → Type c} →
(∀ x y → C x y) ↔ (∀ y x → C x y)
Π-comm = record
{ surjection = record
{ logical-equivalence = record { to = flip; from = flip }
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Π and Σ commute (in a certain sense).
open Bijection public using (ΠΣ-comm)
-- The implicit variant of Π and Σ commute (in a certain sense).
implicit-ΠΣ-comm :
∀ {a b c} {A : Type a} {B : A → Type b} {C : (x : A) → B x → Type c} →
(∀ {x} → ∃ λ (y : B x) → C x y)
↔
(∃ λ (f : ∀ {x} → B x) → ∀ {x} → C x f)
implicit-ΠΣ-comm {A = A} {B} {C} =
(∀ {x} → ∃ λ (y : B x) → C x y) ↝⟨ Bijection.implicit-Π↔Π ⟩
(∀ x → ∃ λ (y : B x) → C x y) ↝⟨ ΠΣ-comm ⟩
(∃ λ (f : ∀ x → B x) → ∀ x → C x (f x)) ↝⟨ inverse $ Σ-cong Bijection.implicit-Π↔Π (λ _ → Bijection.implicit-Π↔Π) ⟩□
(∃ λ (f : ∀ {x} → B x) → ∀ {x} → C x f) □
-- Some variants of De Morgan's laws.
¬⊎↠¬×¬ :
∀ {a b} {A : Type a} {B : Type b} →
¬ (A ⊎ B) ↠ ¬ A × ¬ B
¬⊎↠¬×¬ = record
{ logical-equivalence = record
{ to = λ ¬[A⊎B] → ¬[A⊎B] ∘ inj₁ , ¬[A⊎B] ∘ inj₂
; from = λ (¬A , ¬B) → [ ¬A , ¬B ]
}
; right-inverse-of = refl
}
¬⊎↔¬×¬ :
∀ {a b} {A : Type a} {B : Type b} →
¬ (A ⊎ B) ↝[ a ⊔ b ∣ lzero ] ¬ A × ¬ B
¬⊎↔¬×¬ = generalise-ext?
(_↠_.logical-equivalence ¬⊎↠¬×¬)
(λ ext →
refl
, (λ _ → apply-ext ext [ (λ _ → refl _) , (λ _ → refl _) ]))
¬⊎¬→׬ :
∀ {a b} {A : Type a} {B : Type b} →
¬ A ⊎ ¬ B → ¬ (A × B)
¬⊎¬→׬ = [ (_∘ proj₁) , (_∘ proj₂) ]
¬⊎¬⇔¬× :
∀ {a b} {A : Type a} {B : Type b} →
Dec (¬ A) → Dec (¬ B) →
¬ A ⊎ ¬ B ⇔ ¬ (A × B)
¬⊎¬⇔¬× (yes ¬A) _ = record
{ to = ¬⊎¬→׬
; from = λ _ → inj₁ ¬A
}
¬⊎¬⇔¬× _ (yes ¬B) = record
{ to = ¬⊎¬→׬
; from = λ _ → inj₂ ¬B
}
¬⊎¬⇔¬× (no ¬¬A) (no ¬¬B) = record
{ to = ¬⊎¬→׬
; from = λ ¬[A×B] →
⊥-elim $
¬¬A λ a →
¬¬B λ b →
¬[A×B] (a , b)
}
¬⊎¬↠¬× :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) lzero →
Dec (¬ A) → Dec (¬ B) →
¬ A ⊎ ¬ B ↠ ¬ (A × B)
¬⊎¬↠¬× ext dec-¬A dec-¬B = record
{ logical-equivalence = ¬⊎¬⇔¬× dec-¬A dec-¬B
; right-inverse-of = λ _ → ¬-propositional ext _ _
}
-- A variant of extensionality-isomorphism for functions with implicit
-- arguments.
implicit-extensionality-isomorphism :
∀ {k a b} →
Extensionality a b →
{A : Type a} {B : A → Type b} {f g : {x : A} → B x} →
(∀ x → f {x} ≡ g {x}) ↔[ k ] ((λ {x} → f {x}) ≡ g)
implicit-extensionality-isomorphism ext {f = f} {g} =
(∀ x → f {x} ≡ g {x}) ↔⟨ Eq.extensionality-isomorphism ext ⟩
((λ x → f {x}) ≡ (λ x → g {x})) ↔⟨ inverse $ Eq.≃-≡ (Eq.↔⇒≃ (inverse Bijection.implicit-Π↔Π)) ⟩□
((λ {x} → f {x}) ≡ g) □
private
-- The forward direction of
-- implicit-extensionality-isomorphism {k = bijection} computes in a
-- certain way.
--
-- Note that (at the time of writing) the proof below fails if the
-- two occurrences of "inverse" in the previous proof are removed.
to-implicit-extensionality-isomorphism :
∀ {a b}
(ext : Extensionality a b) {A : Type a} {B : A → Type b}
{f g : {x : A} → B x} (f≡g : ∀ x → f {x} ≡ g {x}) →
_↔_.to (implicit-extensionality-isomorphism ext) f≡g
≡
implicit-extensionality (Eq.good-ext ext) f≡g
to-implicit-extensionality-isomorphism _ _ = refl _
-- The Yoneda lemma, as given in the HoTT book, but specialised to the
-- opposite of the category of sets and functions, and with some
-- naturality properties omitted. (The proof uses extensionality.)
yoneda :
∀ {a b X} →
Extensionality (lsuc a) (lsuc a ⊔ b) →
(F : Set a → Set b) →
(map : ∀ {A B} → (⌞ A ⌟ → ⌞ B ⌟) → ⌞ F A ⌟ → ⌞ F B ⌟) →
(∀ {A} {x : ⌞ F A ⌟} → map id x ≡ x) →
(∀ {A B C f g x} →
(map {A = B} {B = C} f ∘ map {A = A} g) x ≡ map (f ∘ g) x) →
⌞ F X ⌟
↔
∃ λ (γ : ∀ Y → (⌞ X ⌟ → ⌞ Y ⌟) → ⌞ F Y ⌟) →
∀ Y₁ Y₂ f g → map f (γ Y₁ g) ≡ γ Y₂ (f ∘ g)
yoneda {a} {X = X} ext F map map-id map-∘ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ x → (λ _ f → map f x) , λ _ _ f g →
map f (map g x) ≡⟨ map-∘ ⟩∎
map (f ∘ g) x ∎
; from = λ { (γ , _) → γ X id }
}
; right-inverse-of = λ { (γ , h) → Σ-≡,≡→≡
((λ _ f → map f (γ X id)) ≡⟨ (apply-ext (lower-extensionality lzero (lsuc a) ext) λ Y →
apply-ext (lower-extensionality _ (lsuc a) ext) λ f →
h X Y f id) ⟩∎
(λ Y f → γ Y f) ∎)
((Π-closure ext 1 λ _ →
Π-closure (lower-extensionality lzero (lsuc a) ext) 1 λ Y₂ →
Π-closure (lower-extensionality _ (lsuc a) ext) 1 λ _ →
Π-closure (lower-extensionality _ (lsuc a) ext) 1 λ _ →
proj₂ (F Y₂)) _ _) }
}
; left-inverse-of = λ x →
map id x ≡⟨ map-id ⟩∎
x ∎
}
-- There is a (split) surjection from products of equality
-- isomorphisms to equalities.
Π≡↔≡-↠-≡ : ∀ k {a} {A : Type a} (x y : A) →
(∀ z → (z ≡ x) ↔[ k ] (z ≡ y)) ↠ (x ≡ y)
Π≡↔≡-↠-≡ k x y = record
{ logical-equivalence = record { to = to; from = from }
; right-inverse-of = to∘from
}
where
to : (∀ z → (z ≡ x) ↔[ k ] (z ≡ y)) → x ≡ y
to f = to-implication (f x) (refl x)
from′ : x ≡ y → ∀ z → (z ≡ x) ↔ (z ≡ y)
from′ x≡y z = record
{ surjection = record
{ logical-equivalence = record
{ to = λ z≡x → trans z≡x x≡y
; from = λ z≡y → trans z≡y (sym x≡y)
}
; right-inverse-of = λ z≡y → trans-[trans-sym]- z≡y x≡y
}
; left-inverse-of = λ z≡x → trans-[trans]-sym z≡x x≡y
}
from : x ≡ y → ∀ z → (z ≡ x) ↔[ k ] (z ≡ y)
from x≡y z = from-bijection (from′ x≡y z)
abstract
to∘from : ∀ x≡y → to (from x≡y) ≡ x≡y
to∘from x≡y =
to (from x≡y) ≡⟨ sym $ cong (λ f → f (refl x)) $ to-implication∘from-isomorphism bijection ⌊ k ⌋-iso ⟩
trans (refl x) x≡y ≡⟨ trans-reflˡ _ ⟩∎
x≡y ∎
-- Products of equivalences of equalities are isomorphic to equalities
-- (assuming extensionality).
Π≡≃≡-↔-≡ :
∀ {a} {A : Type a} (x y : A) →
(∀ z → (z ≡ x) ≃ (z ≡ y)) ↝[ a ∣ a ] (x ≡ y)
Π≡≃≡-↔-≡ {a = a} x y =
generalise-ext?
(_↠_.logical-equivalence surj)
(λ ext →
_↠_.right-inverse-of surj
, from∘to ext)
where
surj = Π≡↔≡-↠-≡ equivalence x y
open _↠_ surj
abstract
from∘to :
Extensionality a a →
∀ f → from (to f) ≡ f
from∘to ext f =
apply-ext ext λ z → Eq.lift-equality ext $ apply-ext ext λ z≡x →
trans z≡x (_≃_.to (f x) (refl x)) ≡⟨ elim (λ {u v} u≡v →
(f : ∀ z → (z ≡ v) ≃ (z ≡ y)) →
trans u≡v (_≃_.to (f v) (refl v)) ≡
_≃_.to (f u) u≡v)
(λ _ _ → trans-reflˡ _)
z≡x f ⟩∎
_≃_.to (f z) z≡x ∎
-- One can introduce a universal quantifier by also introducing an
-- equality (perhaps assuming extensionality).
∀-intro :
∀ {a b} {A : Type a} {x : A} (B : (y : A) → x ≡ y → Type b) →
B x (refl x) ↝[ a ∣ a ⊔ b ] (∀ y (x≡y : x ≡ y) → B y x≡y)
∀-intro {a = a} {b = b} {A = A} {x = x} B =
generalise-ext? ∀-intro-⇔ (λ ext → to∘from ext , from∘to ext)
where
∀-intro-⇔ : B x (refl x) ⇔ (∀ y (x≡y : x ≡ y) → B y x≡y)
∀-intro-⇔ = record
{ to = λ b y x≡y →
subst (uncurry B)
(proj₂ (other-singleton-contractible x) (y , x≡y))
b
; from = λ f → f x (refl x)
}
abstract
from∘to :
Extensionality a (a ⊔ b) →
∀ b → _⇔_.from ∀-intro-⇔ (_⇔_.to ∀-intro-⇔ b) ≡ b
from∘to ext b =
subst (uncurry B)
(proj₂ (other-singleton-contractible x) (x , refl x)) b ≡⟨ cong (λ eq → subst (uncurry B) eq b) $
other-singleton-contractible-refl x ⟩
subst (uncurry B) (refl (x , refl x)) b ≡⟨ subst-refl (uncurry B) _ ⟩∎
b ∎
to∘from :
Extensionality a (a ⊔ b) →
∀ b → _⇔_.to ∀-intro-⇔ (_⇔_.from ∀-intro-⇔ b) ≡ b
to∘from ext f =
apply-ext ext λ y →
apply-ext (lower-extensionality lzero a ext) λ x≡y →
elim¹ (λ {y} x≡y →
subst (uncurry B)
(proj₂ (other-singleton-contractible x)
(y , x≡y))
(f x (refl x)) ≡
f y x≡y)
(subst (uncurry B)
(proj₂ (other-singleton-contractible x)
(x , refl x))
(f x (refl x)) ≡⟨ from∘to ext (f x (refl x)) ⟩∎
f x (refl x) ∎)
x≡y
private
-- The following proof is perhaps easier to follow, but the
-- resulting "from" functions are more complicated than the one used
-- in ∀-intro. (If subst reduced in the usual way when applied to
-- refl, then the two functions would perhaps be definitionally
-- equal.)
--
-- This proof is based on one presented by <NAME> in "A type
-- theoretical Yoneda lemma"
-- (http://homotopytypetheory.org/2012/05/02/a-type-theoretical-yoneda-lemma/).
∀-intro′ :
∀ {a b} {A : Type a} {x : A} (B : (y : A) → x ≡ y → Type b) →
B x (refl x) ↝[ a ∣ a ⊔ b ] (∀ y (x≡y : x ≡ y) → B y x≡y)
∀-intro′ {a = a} {x = x} B {k = k} ext =
B x (refl x) ↔⟨ inverse Π-left-identity ⟩
(⊤ → B x (refl x)) ↝⟨ Π-cong-contra (lower-extensionality? k lzero a ext)
(_⇔_.to contractible⇔↔⊤ c) (λ _ → id) ⟩
((∃ λ y → x ≡ y) → B x (refl x)) ↔⟨ currying ⟩
(∀ y (x≡y : x ≡ y) → B x (refl x)) ↝⟨ (∀-cong ext λ y →
∀-cong (lower-extensionality? k lzero a ext) λ x≡y → from-isomorphism $
Eq.subst-as-equivalence (uncurry B) (proj₂ c (y , x≡y))) ⟩□
(∀ y (x≡y : x ≡ y) → B y x≡y) □
where
c : Contractible (∃ λ y → x ≡ y)
c = other-singleton-contractible x
-- One can introduce a (non-dependent) function argument of the same
-- type as another one if the codomain is propositional (assuming
-- extensionality).
→-intro :
∀ {a p} {A : Type a} {P : A → Type p} →
Extensionality a (a ⊔ p) →
(∀ x → Is-proposition (P x)) →
(∀ x → P x) ↔ (A → ∀ x → P x)
→-intro {a = a} ext P-prop = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f _ x → f x
; from = λ f x → f x x
}
; right-inverse-of = λ _ →
(Π-closure ext 1 λ _ →
Π-closure (lower-extensionality a a ext) 1 λ _ →
P-prop _) _ _
}
; left-inverse-of = refl
}
-- Logical equivalences can be expressed as pairs of functions.
⇔↔→×→ :
∀ {a b} {A : Type a} {B : Type b} →
(A ⇔ B) ↔ (A → B) × (B → A)
⇔↔→×→ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → _⇔_.to f , _⇔_.from f
; from = λ { (to , from) → record { to = to; from = from } }
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
------------------------------------------------------------------------
-- A lemma related to _≃_
-- The operator _⇔_ preserves symmetric kinds of functions.
⇔-cong :
∀ {k a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d} →
Extensionality? ⌊ k ⌋-sym (a ⊔ b ⊔ c ⊔ d) (a ⊔ b ⊔ c ⊔ d) →
A ↝[ ⌊ k ⌋-sym ] B → C ↝[ ⌊ k ⌋-sym ] D →
(A ⇔ C) ↝[ ⌊ k ⌋-sym ] (B ⇔ D)
⇔-cong {k = k} {a = a} {b = b} {c = c} {d = d}
{A = A} {B = B} {C = C} {D = D} ext A↝B C↝D =
A ⇔ C ↔⟨ ⇔↔→×→ ⟩
(A → C) × (C → A) ↝⟨ →-cong (lower-extensionality? ⌊ k ⌋-sym (c ⊔ d) (a ⊔ b) ext) A↝B C↝D
×-cong
→-cong (lower-extensionality? ⌊ k ⌋-sym (a ⊔ b) (c ⊔ d) ext) C↝D A↝B ⟩
(B → D) × (D → B) ↔⟨ inverse ⇔↔→×→ ⟩□
B ⇔ D □
------------------------------------------------------------------------
-- Some lemmas related to _≃_
-- Contractibility is isomorphic to equivalence to the unit type
-- (assuming extensionality).
contractible↔≃⊤ :
∀ {a} {A : Type a} →
Extensionality a a →
Contractible A ↔ (A ≃ ⊤)
contractible↔≃⊤ ext = record
{ surjection = record
{ logical-equivalence = record
{ to = Eq.↔⇒≃ ∘ _⇔_.to contractible⇔↔⊤
; from = _⇔_.from contractible⇔↔⊤ ∘ _≃_.bijection
}
; right-inverse-of = λ _ →
Eq.lift-equality ext (refl _)
}
; left-inverse-of = λ _ → Contractible-propositional ext _ _
}
-- Equivalence to the empty type is equivalent to not being inhabited
-- (assuming extensionality).
≃⊥≃¬ :
∀ {a ℓ} {A : Type a} →
Extensionality (a ⊔ ℓ) (a ⊔ ℓ) →
(A ≃ ⊥ {ℓ = ℓ}) ≃ (¬ A)
≃⊥≃¬ {ℓ = ℓ} {A} ext =
_↔_.to (Eq.⇔↔≃ ext (Eq.right-closure ext 0 ⊥-propositional)
(¬-propositional
(lower-extensionality ℓ _ ext))) (record
{ to = λ eq a → ⊥-elim (_≃_.to eq a)
; from = λ ¬a → A ↔⟨ inverse (Bijection.⊥↔uninhabited ¬a) ⟩□
⊥ □
})
-- If f and g are pointwise equal, then HA.Proofs f f⁻¹ and
-- HA.Proofs g f⁻¹ are equivalent (assuming extensionality).
Proofs-cong :
∀ {a b} {A : Type a} {B : Type b} {f g : A → B} {f⁻¹ : B → A} →
Extensionality (a ⊔ b) (a ⊔ b) →
(∀ x → f x ≡ g x) →
HA.Proofs f f⁻¹ ≃ HA.Proofs g f⁻¹
Proofs-cong
{a = a} {b = b} {f = f} {g = g} {f⁻¹ = f⁻¹} ext f≡g =
Σ-cong (∀-cong (lower-extensionality a a ext) λ _ →
≡⇒↝ equivalence $ cong (_≡ _) $ f≡g _) λ f-f⁻¹ →
Σ-cong (∀-cong (lower-extensionality b b ext) λ _ →
≡⇒↝ equivalence $ cong (_≡ _) $ cong f⁻¹ $ f≡g _) λ f⁻¹-f →
∀-cong (lower-extensionality b a ext) λ x → ≡⇒↝ _
(cong f (f⁻¹-f x) ≡ f-f⁻¹ (f x) ≡⟨ lemma f-f⁻¹ f⁻¹-f _ ⟩
trans (ext⁻¹ (ext″ f≡g) (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (ext⁻¹ (ext″ f≡g) x)))
(f⁻¹-f x))) ≡
f-f⁻¹ (g x) ≡⟨ cong (_≡ _) $
cong₂ (λ p q →
trans (p (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (q x))) (f⁻¹-f x))))
(_≃_.left-inverse-of (Eq.extensionality-isomorphism ext′) f≡g)
(_≃_.left-inverse-of (Eq.extensionality-isomorphism ext′) f≡g) ⟩
trans (f≡g (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (f≡g x))) (f⁻¹-f x))) ≡
f-f⁻¹ (g x) ≡⟨ [trans≡]≡[≡trans-symˡ] _ _ _ ⟩
cong g (trans (sym (cong f⁻¹ (f≡g x))) (f⁻¹-f x)) ≡
trans (sym (f≡g (f⁻¹ (g x)))) (f-f⁻¹ (g x)) ≡⟨ sym $ cong₂ (λ p q → cong g p ≡ q)
subst-trans-sym
subst-trans-sym ⟩
cong g (subst (_≡ x) (cong f⁻¹ (f≡g x)) (f⁻¹-f x)) ≡
subst (_≡ g x) (f≡g (f⁻¹ (g x))) (f-f⁻¹ (g x)) ≡⟨ cong₂ (λ p q → cong g p ≡ q)
(subst-in-terms-of-≡⇒↝ equivalence _ _ _)
(subst-in-terms-of-≡⇒↝ equivalence _ _ _) ⟩∎
cong g
(_≃_.to (≡⇒↝ _ (cong (_≡ x) (cong f⁻¹ (f≡g x)))) (f⁻¹-f x)) ≡
_≃_.to (≡⇒↝ _ (cong (_≡ g x) (f≡g (f⁻¹ (g x))))) (f-f⁻¹ (g x)) ∎)
where
ext′ = lower-extensionality b a ext
ext″ = apply-ext $ Eq.good-ext ext′
lemma :
∀ {x} f-f⁻¹ f⁻¹-f f≡g →
(cong f (f⁻¹-f x) ≡ f-f⁻¹ (f x))
≡
(trans (ext⁻¹ f≡g (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (ext⁻¹ f≡g x))) (f⁻¹-f x))) ≡
f-f⁻¹ (g x))
lemma {x = x} f-f⁻¹ f⁻¹-f = elim¹
(λ {g} f≡g →
(cong f (f⁻¹-f x) ≡ f-f⁻¹ (f x))
≡
(trans (ext⁻¹ f≡g (f⁻¹ (g x)))
(cong g (trans (sym (cong f⁻¹ (ext⁻¹ f≡g x))) (f⁻¹-f x))) ≡
f-f⁻¹ (g x)))
(cong (_≡ f-f⁻¹ (f x))
(cong f (f⁻¹-f x) ≡⟨ cong (cong f) $ sym $
trans (cong (flip trans _) $
trans (cong sym $ cong-refl _) $
sym-refl) $
trans-reflˡ _ ⟩
cong f (trans (sym (cong f⁻¹ (refl (f x)))) (f⁻¹-f x)) ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl (f (f⁻¹ (f x))))
(cong f (trans (sym (cong f⁻¹ (refl (f x)))) (f⁻¹-f x))) ≡⟨ sym $
cong₂ (λ p q →
trans p (cong f (trans (sym (cong f⁻¹ q)) (f⁻¹-f x))))
(ext⁻¹-refl _)
(ext⁻¹-refl _) ⟩∎
trans (ext⁻¹ (refl f) (f⁻¹ (f x)))
(cong f (trans (sym (cong f⁻¹ (ext⁻¹ (refl f) x))) (f⁻¹-f x))) ∎))
-- Is-equivalence preserves equality, if we see _≃_ as a form of
-- equality (assuming extensionality).
Is-equivalence-cong :
∀ {k a b} {A : Type a} {B : Type b} {f g : A → B} →
Extensionality? k (a ⊔ b) (a ⊔ b) →
(∀ x → f x ≡ g x) →
Is-equivalence f ↝[ k ] Is-equivalence g
Is-equivalence-cong ext f≡g =
generalise-ext?-prop
(record
{ to = Eq.respects-extensional-equality f≡g
; from = Eq.respects-extensional-equality (sym ⊚ f≡g)
})
(λ ext → Eq.propositional ext _)
(λ ext → Eq.propositional ext _)
ext
-- Is-equivalence is pointwise equivalent to CP.Is-equivalence
-- (assuming extensionality).
Is-equivalence≃Is-equivalence-CP :
∀ {a b} {A : Type a} {B : Type b} {f : A → B} →
Is-equivalence f ↝[ a ⊔ b ∣ a ⊔ b ] CP.Is-equivalence f
Is-equivalence≃Is-equivalence-CP =
generalise-ext?
HA.Is-equivalence⇔Is-equivalence-CP
(λ ext →
let bij = HA.Is-equivalence↔Is-equivalence-CP ext in
_↔_.right-inverse-of bij , _↔_.left-inverse-of bij)
-- Two notions of equivalence are pointwise equivalent (assuming
-- extensionality).
≃≃≃-CP :
∀ {a b} {A : Type a} {B : Type b} →
(A ≃ B) ↝[ a ⊔ b ∣ a ⊔ b ] (A CP.≃ B)
≃≃≃-CP {A = A} {B = B} ext =
A ≃ B ↔⟨ Eq.≃-as-Σ ⟩
(∃ λ (f : A → B) → Is-equivalence f) ↝⟨ (∃-cong λ _ → Is-equivalence≃Is-equivalence-CP ext) ⟩□
(∃ λ (f : A → B) → CP.Is-equivalence f) □
-- _≃_ is commutative (assuming extensionality).
≃-comm :
∀ {a b} {A : Type a} {B : Type b} →
A ≃ B ↝[ a ⊔ b ∣ a ⊔ b ] B ≃ A
≃-comm =
generalise-ext?
Eq.inverse-logical-equivalence
(λ ext →
let bij = Eq.inverse-isomorphism ext in
_↔_.right-inverse-of bij , _↔_.left-inverse-of bij)
-- Two consequences of the two-out-of-three property.
Is-equivalence≃Is-equivalence-∘ˡ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
{f : B → C} {g : A → B} →
Is-equivalence f →
Is-equivalence g ↝[ a ⊔ b ⊔ c ∣ a ⊔ b ⊔ c ] Is-equivalence (f ∘ g)
Is-equivalence≃Is-equivalence-∘ˡ {b = b} {c = c} f-eq =
generalise-ext?-prop
(record
{ to = flip (Eq.Two-out-of-three.f-g (Eq.two-out-of-three _ _))
f-eq
; from = Eq.Two-out-of-three.g-g∘f (Eq.two-out-of-three _ _) f-eq
})
(flip Eq.propositional _ ⊚ lower-extensionality c c)
(flip Eq.propositional _ ⊚ lower-extensionality b b)
Is-equivalence≃Is-equivalence-∘ʳ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
{f : B → C} {g : A → B} →
Is-equivalence g →
Is-equivalence f ↝[ a ⊔ b ⊔ c ∣ a ⊔ b ⊔ c ] Is-equivalence (f ∘ g)
Is-equivalence≃Is-equivalence-∘ʳ {a = a} {b = b} g-eq =
generalise-ext?-prop
(record
{ to = Eq.Two-out-of-three.f-g (Eq.two-out-of-three _ _) g-eq
; from = flip
(Eq.Two-out-of-three.g∘f-f (Eq.two-out-of-three _ _))
g-eq
})
(flip Eq.propositional _ ⊚ lower-extensionality a a)
(flip Eq.propositional _ ⊚ lower-extensionality b b)
------------------------------------------------------------------------
-- Lemmas related to _↠_
-- An alternative characterisation of split surjections.
↠↔∃-Split-surjective :
∀ {a b} {A : Type a} {B : Type b} →
(A ↠ B) ↔ ∃ λ (f : A → B) → Split-surjective f
↠↔∃-Split-surjective = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → _↠_.to f , _↠_.split-surjective f
; from = λ { (f , s) → record
{ logical-equivalence = record
{ to = f
; from = proj₁ ⊚ s
}
; right-inverse-of = proj₂ ⊚ s
} }
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
------------------------------------------------------------------------
-- Lemmas related to _↣_
-- An alternative characterisation of injections.
↣↔∃-Injective :
∀ {a b} {A : Type a} {B : Type b} →
(A ↣ B) ↔ ∃ λ (f : A → B) → Injective f
↣↔∃-Injective = record
{ surjection = record
{ logical-equivalence = record
{ to = λ f → _↣_.to f , _↣_.injective f
; from = λ (f , i) → record
{ to = f
; injective = i
}
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
------------------------------------------------------------------------
-- Lemmas related to _≡_
-- Equality is commutative.
open Bijection public using (≡-comm)
-- The following two lemmas are based on Example 2.4.8 in the HoTT
-- book.
-- The function trans x≡y is the to component of an isomorphism.
trans-isomorphism :
∀ {a} {A : Type a} {x y z : A} →
x ≡ y → y ≡ z ↔ x ≡ z
trans-isomorphism x≡y = record
{ surjection = record
{ logical-equivalence = record
{ to = trans x≡y
; from = trans (sym x≡y)
}
; right-inverse-of = trans--[trans-sym] _
}
; left-inverse-of = trans-sym-[trans] _
}
-- The function flip trans x≡y is the to component of an isomorphism.
flip-trans-isomorphism :
∀ {a} {A : Type a} {x y z : A} →
x ≡ y → z ≡ x ↔ z ≡ y
flip-trans-isomorphism x≡y = record
{ surjection = record
{ logical-equivalence = record
{ to = flip trans x≡y
; from = flip trans (sym x≡y)
}
; right-inverse-of = λ _ → trans-[trans-sym]- _ _
}
; left-inverse-of = λ _ → trans-[trans]-sym _ _
}
-- Equality expression rearrangement lemmas.
from≡↔≡to : ∀ {a b} →
{A : Type a} {B : Type b}
(A≃B : A ≃ B) {x : B} {y : A} →
(_≃_.from A≃B x ≡ y) ↔ (x ≡ _≃_.to A≃B y)
from≡↔≡to A≃B {x} {y} =
(_≃_.from A≃B x ≡ y) ↔⟨ inverse $ Eq.≃-≡ A≃B ⟩
(_≃_.to A≃B (_≃_.from A≃B x) ≡ _≃_.to A≃B y) ↝⟨ ≡⇒↝ _ $ cong (λ z → z ≡ _≃_.to A≃B y) $ _≃_.right-inverse-of A≃B x ⟩□
(x ≡ _≃_.to A≃B y) □
to∘≡↔≡from∘ : ∀ {a b c} →
Extensionality a (b ⊔ c) →
{A : Type a} {B : A → Type b} {C : A → Type c}
(B≃C : ∀ {x} → B x ≃ C x)
{f : (x : A) → B x} {g : (x : A) → C x} →
(_≃_.to B≃C ⊚ f ≡ g) ↔ (f ≡ _≃_.from B≃C ⊚ g)
to∘≡↔≡from∘ ext B≃C =
from≡↔≡to (∀-cong ext (λ _ → inverse B≃C))
∘from≡↔≡∘to : ∀ {a b c} →
Extensionality (a ⊔ b) c →
{A : Type a} {B : Type b} {C : Type c}
(A≃B : A ≃ B) {f : A → C} {g : B → C} →
(f ∘ _≃_.from A≃B ≡ g) ↔ (f ≡ g ∘ _≃_.to A≃B)
∘from≡↔≡∘to ext A≃B = from≡↔≡to (→-cong₁ ext (inverse A≃B))
∘from≡↔≡∘to′ :
∀ {a b c} →
Extensionality (a ⊔ b) c →
{A : Type a} {B : Type b} {C : A → Type c}
(A≃B : A ≃ B)
{f : (x : A) → C x} {g : (x : B) → C (_≃_.from A≃B x)} →
(f ⊚ _≃_.from A≃B ≡ g) ↔
(f ≡ subst C (_≃_.left-inverse-of A≃B _) ⊚ g ⊚ _≃_.to A≃B)
∘from≡↔≡∘to′ {a = a} {b = b} ext {C = C} A≃B {f = f} {g = g} =
f ⊚ _≃_.from A≃B ≡ g ↝⟨ ≡⇒↝ _ $ cong (_≡ g) $ apply-ext (lower-extensionality a lzero ext)
lemma ⟩
subst (C ⊚ _≃_.from A≃B) (_≃_.right-inverse-of A≃B _) ⊚
_≃_.from (≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B _)) ⊚
f ⊚ _≃_.from A≃B ≡
g ↝⟨ from≡↔≡to
(Π-cong-contra ext A≃B λ x →
≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B x)) ⟩
f ≡
_≃_.to (≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B _)) ⊚ g ⊚ _≃_.to A≃B ↝⟨ (≡⇒↝ _ $ cong (f ≡_) $ apply-ext (lower-extensionality b lzero ext) λ _ →
sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _) ⟩□
f ≡ subst C (_≃_.left-inverse-of A≃B _) ⊚ g ⊚ _≃_.to A≃B □
where
lemma : ∀ _ → _
lemma x =
f (_≃_.from A≃B x) ≡⟨ sym $ _≃_.right-inverse-of equiv _ ⟩
_≃_.to equiv (_≃_.from equiv (f (_≃_.from A≃B x))) ≡⟨ sym $ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst C (_≃_.left-inverse-of A≃B (_≃_.from A≃B x))
(_≃_.from equiv (f (_≃_.from A≃B x))) ≡⟨ cong (λ eq → subst C eq (_≃_.from equiv (f (_≃_.from A≃B x)))) $ sym $
_≃_.right-left-lemma A≃B _ ⟩
subst C (cong (_≃_.from A≃B) (_≃_.right-inverse-of A≃B x))
(_≃_.from equiv (f (_≃_.from A≃B x))) ≡⟨ sym $ subst-∘ _ _ (_≃_.right-inverse-of A≃B x) ⟩∎
subst (C ⊚ _≃_.from A≃B) (_≃_.right-inverse-of A≃B x)
(_≃_.from equiv (f (_≃_.from A≃B x))) ∎
where
equiv = ≡⇒↝ _ $ cong C (_≃_.left-inverse-of A≃B (_≃_.from A≃B x))
------------------------------------------------------------------------
-- Some lemmas related to _⁻¹_
-- A fibre of a composition can be expressed as a pair of fibres.
∘⁻¹≃ :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c} {z} →
(f : B → C) (g : A → B) →
f ∘ g ⁻¹ z ≃ ∃ λ ((y , _) : f ⁻¹ z) → g ⁻¹ y
∘⁻¹≃ {z = z} f g =
f ∘ g ⁻¹ z ↔⟨⟩
(∃ λ a → f (g a) ≡ z) ↔⟨ (∃-cong λ _ → other-∃-intro _ _) ⟩
(∃ λ a → ∃ λ y → f y ≡ z × g a ≡ y) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩
(∃ λ a → ∃ λ ((y , _) : f ⁻¹ z) → g a ≡ y) ↔⟨ ∃-comm ⟩□
(∃ λ ((y , _) : f ⁻¹ z) → g ⁻¹ y) □
-- The type of fibres of Σ-map P.id f over a pair is equivalent to the
-- fibres of f over the pair's second component.
--
-- This is Theorem 4.7.6 from the HoTT book.
Σ-map-id-⁻¹≃⁻¹ :
∀ {a p q} {A : Type a} {P : A → Type p} {Q : A → Type q}
{f : ∀ {x} → P x → Q x} {x : A} {y : Q x} →
Σ-map P.id f ⁻¹ _,_ {B = Q} x y ≃ f ⁻¹ y
Σ-map-id-⁻¹≃⁻¹ {Q = Q} {f = f} {x = x} {y = y} =
Σ-map P.id f ⁻¹ (x , y) ↔⟨⟩
(∃ λ (u , v) → (u , f v) ≡ (x , y)) ↔⟨ inverse Bijection.Σ-assoc ⟩
(∃ λ u → ∃ λ v → (u , f v) ≡ (x , y)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → inverse
Bijection.Σ-≡,≡↔≡) ⟩
(∃ λ u → ∃ λ v → ∃ λ (p : u ≡ x) → subst Q p (f v) ≡ y) ↔⟨ (∃-cong λ _ → ∃-comm) ⟩
(∃ λ u → ∃ λ (p : u ≡ x) → ∃ λ v → subst Q p (f v) ≡ y) ↔⟨ Bijection.Σ-assoc ⟩
(∃ λ ((_ , p) : ∃ λ u → u ≡ x) → ∃ λ v → subst Q p (f v) ≡ y) ↔⟨ drop-⊤-left-Σ $
_⇔_.to contractible⇔↔⊤ $
singleton-contractible _ ⟩
(∃ λ v → subst Q (refl _) (f v) ≡ y) ↝⟨ (∃-cong λ _ → ≡⇒↝ _ $ cong (_≡ _) $
subst-refl _ _) ⟩
(∃ λ v → f v ≡ y) ↔⟨⟩
f ⁻¹ y □
------------------------------------------------------------------------
-- Lemmas related to ↑
-- ↑ _ preserves all kinds of functions.
private
↑-cong-→ :
∀ {a b c} {B : Type b} {C : Type c} →
(B → C) → ↑ a B → ↑ a C
↑-cong-→ B→C = lift ⊚ B→C ⊚ lower
↑-cong-↣ :
∀ {a b c} {B : Type b} {C : Type c} →
B ↣ C → ↑ a B ↣ ↑ a C
↑-cong-↣ {a} B↣C = record
{ to = to′
; injective = injective′
}
where
open _↣_ B↣C
to′ = ↑-cong-→ {a = a} to
abstract
injective′ : Injective to′
injective′ = cong lift ⊚ injective ⊚ cong lower
↑-cong-Embedding :
∀ {a b c} {B : Type b} {C : Type c} →
Embedding B C → Embedding (↑ a B) (↑ a C)
↑-cong-Embedding {a} {B = B} B↣C = record
{ to = ↑-cong-→ to
; is-embedding = λ x y →
_≃_.is-equivalence $
Eq.with-other-function
(x ≡ y ↔⟨⟩
lift (lower x) ≡ lift (lower y) ↔⟨ inverse lift-lemma ⟩
lower x ≡ lower y ↝⟨ Eq.⟨ _ , is-embedding _ _ ⟩ ⟩
to (lower x) ≡ to (lower y) ↔⟨ lift-lemma ⟩□
lift (to (lower x)) ≡ lift (to (lower y)) □)
_
(λ p → cong lift (cong to (cong lower p)) ≡⟨ cong-∘ _ _ _ ⟩
cong (lift ⊚ to) (cong lower p) ≡⟨ cong-∘ _ _ _ ⟩∎
cong (lift ⊚ to ⊚ lower) p ∎)
}
where
open Embedding B↣C
lift-lemma : ∀ {ℓ a} {A : Type a} {x y : A} →
(x ≡ y) ↔ (lift {ℓ = ℓ} x ≡ lift y)
lift-lemma {ℓ} = record
{ surjection = record
{ logical-equivalence = record
{ to = cong lift
; from = cong lower
}
; right-inverse-of = λ eq →
cong lift (cong lower eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (lift ⊚ lower) eq ≡⟨ sym (cong-id _) ⟩∎
eq ∎
}
; left-inverse-of = λ eq →
cong lower (cong lift eq) ≡⟨ cong-∘ _ _ _ ⟩
cong (lower {ℓ = ℓ} ⊚ lift) eq ≡⟨ sym (cong-id _) ⟩∎
eq ∎
}
↑-cong-↠ :
∀ {a b c} {B : Type b} {C : Type c} →
B ↠ C → ↑ a B ↠ ↑ a C
↑-cong-↠ {a} B↠C = record
{ logical-equivalence = logical-equivalence′
; right-inverse-of = right-inverse-of′
}
where
open _↠_ B↠C renaming (logical-equivalence to logical-equiv)
logical-equivalence′ = L.↑-cong {a = a} logical-equiv
abstract
right-inverse-of′ : ∀ x →
_⇔_.to logical-equivalence′
(_⇔_.from logical-equivalence′ x) ≡
x
right-inverse-of′ = cong lift ⊚ right-inverse-of ⊚ lower
↑-cong-↔ :
∀ {a b c} {B : Type b} {C : Type c} →
B ↔ C → ↑ a B ↔ ↑ a C
↑-cong-↔ {a} B↔C = record
{ surjection = surjection′
; left-inverse-of = left-inverse-of′
}
where
open _↔_ B↔C renaming (surjection to surj)
surjection′ = ↑-cong-↠ {a = a} surj
abstract
left-inverse-of′ :
∀ x → _↠_.from surjection′ (_↠_.to surjection′ x) ≡ x
left-inverse-of′ = cong lift ⊚ left-inverse-of ⊚ lower
↑-cong-≃ :
∀ {a b c} {B : Type b} {C : Type c} →
B ≃ C → ↑ a B ≃ ↑ a C
↑-cong-≃ = from-bijection ∘ ↑-cong-↔ ∘ from-equivalence
↑-cong-≃ᴱ :
∀ {a b c} {B : Type b} {C : Type c} →
B ≃ᴱ C → ↑ a B ≃ᴱ ↑ a C
↑-cong-≃ᴱ f = EEq.[≃]→≃ᴱ (EEq.[proofs] (↑-cong-≃ (EEq.≃ᴱ→≃ f)))
↑-cong : ∀ {k a b c} {B : Type b} {C : Type c} →
B ↝[ k ] C → ↑ a B ↝[ k ] ↑ a C
↑-cong {implication} = ↑-cong-→
↑-cong {logical-equivalence} = L.↑-cong
↑-cong {injection} = ↑-cong-↣
↑-cong {embedding} = ↑-cong-Embedding
↑-cong {surjection} = ↑-cong-↠
↑-cong {bijection} = ↑-cong-↔
↑-cong {equivalence} = ↑-cong-≃
↑-cong {equivalenceᴱ} = ↑-cong-≃ᴱ
------------------------------------------------------------------------
-- Lemmas related to unit types
-- The type of equalities tt ≡ tt is isomorphic to the unit type.
tt≡tt↔⊤ : tt ≡ tt ↔ ⊤
tt≡tt↔⊤ = _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(mono (zero≤ 2) ⊤-contractible) (refl _)
-- Unit is equivalent to ⊤.
--
-- The forward direction of the equivalence returns the supplied value
-- of type Unit.
Unit≃⊤ : Unit → Unit ≃ ⊤
Unit≃⊤ x =
Eq.↔→≃ _ (λ _ → x) refl
(λ { ⊠ → unblock x (_≡ ⊠) (refl _) })
------------------------------------------------------------------------
-- Lemmas related to ⊥
-- All instances of ⊥ are isomorphic.
⊥↔⊥ : ∀ {ℓ₁ ℓ₂} → ⊥ {ℓ = ℓ₁} ↔ ⊥ {ℓ = ℓ₂}
⊥↔⊥ = Bijection.⊥↔uninhabited ⊥-elim
-- All instances of A → ⊥ are isomorphic to ¬ A.
¬↔→⊥ : ∀ {a ℓ} {A : Type a} →
¬ A ↝[ a ∣ ℓ ] (A → ⊥ {ℓ = ℓ})
¬↔→⊥ {A = A} ext =
(A → ⊥₀) ↝⟨ (∀-cong ext λ _ → from-isomorphism ⊥↔⊥) ⟩□
(A → ⊥) □
-- A type cannot be logically equivalent to its own negation.
¬[⇔¬] : ∀ {a} {A : Type a} → ¬ (A ⇔ ¬ A)
¬[⇔¬] {A = A} =
A ⇔ ¬ A ↝⟨ (λ eq → (λ a → _⇔_.to eq a a) , eq) ⟩
¬ A × (A ⇔ ¬ A) ↝⟨ (λ { (¬a , eq) → ¬a , _⇔_.from eq ¬a }) ⟩
¬ A × A ↝⟨ uncurry _$_ ⟩□
⊥ □
-- If two types are logically equivalent, then their negations are
-- equivalent (assuming extensionality).
¬-cong-⇔ :
∀ {a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) lzero →
A ⇔ B → (¬ A) ≃ (¬ B)
¬-cong-⇔ {a} {b} ext A⇔B =
_↠_.from
(Eq.≃↠⇔ (¬-propositional (lower-extensionality b lzero ext))
(¬-propositional (lower-extensionality a lzero ext)))
(→-cong _ A⇔B id)
-- Symmetric kinds of functions are preserved by ¬_ (assuming
-- extensionality).
¬-cong :
∀ {k a b} {A : Type a} {B : Type b} →
Extensionality (a ⊔ b) lzero →
A ↝[ ⌊ k ⌋-sym ] B → (¬ A) ↝[ ⌊ k ⌋-sym ] (¬ B)
¬-cong ext A↝B = from-equivalence (¬-cong-⇔ ext (sym→⇔ A↝B))
-- If B can be decided, given that A is inhabited, then A → B is
-- logically equivalent to ¬ B → ¬ A.
→⇔¬→¬ :
∀ {a b} {A : Type a} {B : Type b} →
(A → Dec B) →
(A → B) ⇔ (¬ B → ¬ A)
→⇔¬→¬ _ ._⇔_.to = flip _∘_
→⇔¬→¬ dec ._⇔_.from ¬B→¬A A with dec A
… | yes B = B
… | no ¬B = ⊥-elim $ ¬B→¬A ¬B A
-- If B is additionally a proposition (assuming that A is inhabited),
-- then the two types are equivalent (assuming extensionality).
→≃¬→¬ :
∀ {a b} {A : Type a} {B : Type b} →
(Extensionality (a ⊔ b) (a ⊔ b) → A → Is-proposition B) →
(A → Dec B) →
(A → B) ↝[ a ⊔ b ∣ a ⊔ b ] (¬ B → ¬ A)
→≃¬→¬ {a = a} {b = b} prop dec =
generalise-ext?-prop
(→⇔¬→¬ dec)
(λ ext → Π-closure (lower-extensionality b a ext) 1 (prop ext))
(λ ext → Π-closure (lower-extensionality a b ext) 1 λ _ →
¬-propositional (lower-extensionality b _ ext))
------------------------------------------------------------------------
-- Lemmas related to H-level
-- H-level and H-level′ are pointwise isomorphic (assuming
-- extensionality).
H-level↔H-level′ :
∀ {a} {A : Type a} {n} →
H-level n A ↝[ a ∣ a ] H-level′ n A
H-level↔H-level′ {n = n} =
generalise-ext?-prop
H-level⇔H-level′
(λ ext → H-level-propositional ext _)
(λ ext → H-level′-propositional ext n)
-- H-level n preserves isomorphisms (assuming extensionality).
H-level-cong :
∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
Extensionality? k₂ (a ⊔ b) (a ⊔ b) →
∀ n → A ↔[ k₁ ] B → H-level n A ↝[ k₂ ] H-level n B
H-level-cong {a = a} {b} ext n A↔B′ =
generalise-ext?-prop
(record
{ to = respects-surjection (_↔_.surjection A↔B) n
; from = respects-surjection (_↔_.surjection (inverse A↔B)) n
})
(λ ext → H-level-propositional (lower-extensionality b b ext) n)
(λ ext → H-level-propositional (lower-extensionality a a ext) n)
ext
where
A↔B = from-isomorphism A↔B′
-- H-level′ n preserves isomorphisms (assuming extensionality).
H-level′-cong :
∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
Extensionality? k₂ (a ⊔ b) (a ⊔ b) →
∀ n → A ↔[ k₁ ] B → H-level′ n A ↝[ k₂ ] H-level′ n B
H-level′-cong {k₂ = k₂} {a = a} {b = b} {A = A} {B = B} ext n A↔B =
H-level′ n A ↝⟨ inverse-ext? H-level↔H-level′ (lower-extensionality? k₂ b b ext) ⟩
H-level n A ↝⟨ H-level-cong ext n A↔B ⟩
H-level n B ↝⟨ H-level↔H-level′ (lower-extensionality? k₂ a a ext) ⟩□
H-level′ n B □
-- There is an isomorphism between (x y : A) → H-level n (x ≡ y) and
-- H-level (suc n) A (assuming extensionality).
≡↔+ :
∀ {a} {A : Type a} n →
((x y : A) → H-level n (x ≡ y)) ↝[ a ∣ a ] H-level (suc n) A
≡↔+ {A = A} n ext =
((x y : A) → H-level n (x ≡ y)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → H-level↔H-level′ ext) ⟩
((x y : A) → H-level′ n (x ≡ y)) ↔⟨⟩
H-level′ (suc n) A ↝⟨ inverse-ext? H-level↔H-level′ ext ⟩□
H-level (suc n) A □
-- Some lemmas relating equivalences A ≃ B with types of the form
-- ∀ C → H-level n C → (A → C) ≃ (B → C).
→≃→↠≃ :
∀ n {ℓ} {A B : Type ℓ} →
Extensionality ℓ ℓ →
(hA : H-level n A) (hB : H-level n B) →
(∃ λ (f : (C : Type ℓ) → H-level n C → (A → C) ≃ (B → C)) →
((C : Type ℓ) (hC : H-level n C) (g : A → C) →
g ∘ _≃_.to (f A hA) id ≡ _≃_.to (f C hC) g) ×
((C : Type ℓ) (hC : H-level n C) (g : B → C) →
g ∘ _≃_.from (f B hB) id ≡ _≃_.from (f C hC) g))
↠
(A ≃ B)
→≃→↠≃ _ {A = A} {B} ext hA hB = record
{ logical-equivalence = record
{ from = λ A≃B → (λ _ _ → →-cong₁ ext A≃B)
, (λ _ _ g → refl (g ∘ _≃_.from A≃B))
, (λ _ _ g → refl (g ∘ _≃_.to A≃B))
; to = λ { (A→≃B→ , ∘to≡ , ∘from≡) → Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = _≃_.from (A→≃B→ B hB) id
; from = _≃_.to (A→≃B→ A hA) id
}
; right-inverse-of = λ x →
_≃_.from (A→≃B→ B hB) id (_≃_.to (A→≃B→ A hA) id x) ≡⟨⟩
(_≃_.from (A→≃B→ B hB) id ∘ _≃_.to (A→≃B→ A hA) id) x ≡⟨ cong (_$ x) $ ∘to≡ _ _ _ ⟩
(_≃_.to (A→≃B→ B hB) (_≃_.from (A→≃B→ B hB) id)) x ≡⟨ cong (_$ x) $ _≃_.right-inverse-of (A→≃B→ B hB) _ ⟩∎
x ∎
}
; left-inverse-of = λ x →
_≃_.to (A→≃B→ A hA) id (_≃_.from (A→≃B→ B hB) id x) ≡⟨⟩
(_≃_.to (A→≃B→ A hA) id ∘ _≃_.from (A→≃B→ B hB) id) x ≡⟨ cong (_$ x) $ ∘from≡ _ _ _ ⟩
(_≃_.from (A→≃B→ A hA) (_≃_.to (A→≃B→ A hA) id)) x ≡⟨ cong (_$ x) $ _≃_.left-inverse-of (A→≃B→ A hA) _ ⟩∎
x ∎
}) }
}
; right-inverse-of = λ A≃B → _↔_.to (≃-to-≡↔≡ ext) λ x →
refl (_≃_.to A≃B x)
}
-- The following property can be generalised.
→≃→↔≃ :
∀ {ℓ} {A B : Type ℓ} →
Extensionality (lsuc ℓ) ℓ →
(hA : Is-set A) (hB : Is-set B) →
(∃ λ (f : (C : Type ℓ) → Is-set C → (A → C) ≃ (B → C)) →
((C : Type ℓ) (hC : Is-set C) (g : A → C) →
g ∘ _≃_.to (f A hA) id ≡ _≃_.to (f C hC) g) ×
((C : Type ℓ) (hC : Is-set C) (g : B → C) →
g ∘ _≃_.from (f B hB) id ≡ _≃_.from (f C hC) g))
↔
(A ≃ B)
→≃→↔≃ {A = A} {B} ext hA hB = record
{ surjection = →≃→↠≃ 2 ext′ hA hB
; left-inverse-of = λ { (A→≃B→ , ∘to≡ , _) →
Σ-≡,≡→≡
(apply-ext ext λ C →
apply-ext ext′ λ hC →
_↔_.to (≃-to-≡↔≡ ext′) λ f →
f ∘ _≃_.to (A→≃B→ A hA) id ≡⟨ ∘to≡ _ _ _ ⟩∎
_≃_.to (A→≃B→ C (hC {_})) f ∎)
((×-closure 1
(Π-closure ext 1 λ _ →
Π-closure ext′ 1 λ hC →
Π-closure ext′ 1 λ _ →
Π-closure ext′ 2 λ _ → hC {_})
(Π-closure ext 1 λ _ →
Π-closure ext′ 1 λ hC →
Π-closure ext′ 1 λ _ →
Π-closure ext′ 2 λ _ → hC {_})) _ _) }
}
where
ext′ = lower-extensionality _ lzero ext
------------------------------------------------------------------------
-- Lemmas related to Dec
-- A preservation lemma for Dec.
Dec-cong :
∀ {k a b} {A : Type a} {B : Type b} →
Extensionality? ⌊ k ⌋-sym (a ⊔ b) lzero →
A ↝[ ⌊ k ⌋-sym ] B →
Dec A ↝[ ⌊ k ⌋-sym ] Dec B
Dec-cong {A = A} {B = B} ext A↝B =
A ⊎ ¬ A ↝⟨ A↝B ⊎-cong →-cong ext A↝B id ⟩□
B ⊎ ¬ B □
-- A preservation lemma for Decidable.
Decidable-cong :
∀ {k₁ k₂ k₃ a₁ b₁ p₁ a₂ b₂ p₂}
{A₁ : Type a₁} {B₁ : Type b₁} {P₁ : A₁ → B₁ → Type p₁}
{A₂ : Type a₂} {B₂ : Type b₂} {P₂ : A₂ → B₂ → Type p₂} →
Extensionality? ⌊ k₃ ⌋-sym (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂ ⊔ p₁ ⊔ p₂)
(b₁ ⊔ b₂ ⊔ p₁ ⊔ p₂) →
(A₁↔A₂ : A₁ ↔[ k₁ ] A₂)
(B₁↔B₂ : B₁ ↔[ k₂ ] B₂) →
(∀ x y →
P₁ x y
↝[ ⌊ k₃ ⌋-sym ]
P₂ (to-implication A₁↔A₂ x) (to-implication B₁↔B₂ y)) →
Decidable P₁ ↝[ ⌊ k₃ ⌋-sym ] Decidable P₂
Decidable-cong
{k₃ = k₃} {a₁} {b₁} {p₁} {a₂} {b₂} {p₂} {P₁ = P₁} {P₂ = P₂}
ext A₁↔A₂ B₁↔B₂ P₁↝P₂ =
(∀ x y → Dec (P₁ x y)) ↝⟨ (Π-cong (lower-extensionality? ⌊ k₃ ⌋-sym (b₁ ⊔ b₂ ⊔ p₁ ⊔ p₂) lzero ext) A₁↔A₂ λ x →
Π-cong (lower-extensionality? ⌊ k₃ ⌋-sym (a₁ ⊔ a₂ ⊔ p₁ ⊔ p₂) (b₁ ⊔ b₂) ext) B₁↔B₂ λ y →
Dec-cong (lower-extensionality? ⌊ k₃ ⌋-sym (a₁ ⊔ a₂ ⊔ b₁ ⊔ b₂) _ ext) (P₁↝P₂ x y)) ⟩□
(∀ x y → Dec (P₂ x y)) □
-- A preservation lemma for Decidable-equality.
Decidable-equality-cong :
∀ {k₁ k₂ a b} {A : Type a} {B : Type b} →
Extensionality? k₂ (a ⊔ b) (a ⊔ b) →
A ↔[ k₁ ] B →
Decidable-equality A ↝[ k₂ ] Decidable-equality B
Decidable-equality-cong ext A↔B =
generalise-ext?
(Decidable-cong _ A≃B A≃B lemma)
(λ ext →
let bij = Decidable-cong ext A≃B A≃B lemma in
_↔_.right-inverse-of bij , _↔_.left-inverse-of bij)
ext
where
A≃B = from-isomorphism A↔B
lemma : ∀ {k} _ _ → _ ↝[ k ] _
lemma x y =
x ≡ y ↔⟨ inverse $ Eq.≃-≡ A≃B ⟩□
_≃_.to A≃B x ≡ _≃_.to A≃B y □
------------------------------------------------------------------------
-- Lemmas related to if
-- A generalisation of if-encoding (which is defined below).
if-lemma : ∀ {a b p} {A : Type a} {B : Type b} (P : Bool → Type p) →
A ↔ P true → B ↔ P false →
∀ b → T b × A ⊎ T (not b) × B ↔ P b
if-lemma {A = A} {B} P A↔ B↔ true =
⊤ × A ⊎ ⊥ × B ↔⟨ ×-left-identity ⊎-cong ×-left-zero ⟩
A ⊎ ⊥₀ ↔⟨ ⊎-right-identity ⟩
A ↔⟨ A↔ ⟩
P true □
if-lemma {A = A} {B} P A↔ B↔ false =
⊥ × A ⊎ ⊤ × B ↔⟨ ×-left-zero ⊎-cong ×-left-identity ⟩
⊥₀ ⊎ B ↔⟨ ⊎-left-identity ⟩
B ↔⟨ B↔ ⟩
P false □
-- An encoding of if_then_else_ in terms of _⊎_, _×_, T and not.
if-encoding : ∀ {ℓ} {A B : Type ℓ} →
∀ b → (if b then A else B) ↔ T b × A ⊎ T (not b) × B
if-encoding {A = A} {B} =
inverse ⊚ if-lemma (λ b → if b then A else B) id id
------------------------------------------------------------------------
-- Properties related to ℕ
-- The natural numbers are isomorphic to the natural numbers extended
-- with another element.
ℕ↔ℕ⊎⊤ : ℕ ↔ ℕ ⊎ ⊤
ℕ↔ℕ⊎⊤ = record
{ surjection = record
{ logical-equivalence = record
{ to = ℕ-rec (inj₂ tt) (λ n _ → inj₁ n)
; from = [ suc , const zero ]
}
; right-inverse-of = [ refl ⊚ inj₁ , refl ⊚ inj₂ ]
}
; left-inverse-of = ℕ-rec (refl 0) (λ n _ → refl (suc n))
}
private
-- Two consequences of ℕ↔ℕ⊎⊤.
Σℕ≃′ :
∀ {p} {P : ℕ → Type p} →
(∃ λ n → P n) ≃ (P zero ⊎ ∃ λ n → P (suc n))
Σℕ≃′ {P = P} =
(∃ λ n → P n) ↝⟨ (Σ-cong-contra (inverse ℕ↔ℕ⊎⊤) λ _ → id) ⟩
(∃ λ (x : ℕ ⊎ ⊤) → P (_↔_.from ℕ↔ℕ⊎⊤ x)) ↔⟨ ∃-⊎-distrib-right ⟩
(∃ λ (n : ℕ) → P (suc n)) ⊎ ⊤ × P zero ↔⟨ ⊎-comm ⟩
⊤ × P zero ⊎ (∃ λ (n : ℕ) → P (suc n)) ↔⟨ ×-left-identity ⊎-cong id ⟩□
P zero ⊎ (∃ λ (n : ℕ) → P (suc n)) □
Πℕ≃′ :
∀ {p} {P : ℕ → Type p} →
(∀ n → P n) ↝[ lzero ∣ p ] (P zero × ∀ n → P (suc n))
Πℕ≃′ {P = P} ext =
(∀ n → P n) ↝⟨ (Π-cong-contra ext (inverse ℕ↔ℕ⊎⊤) λ _ → id) ⟩
((x : ℕ ⊎ ⊤) → P (_↔_.from ℕ↔ℕ⊎⊤ x)) ↝⟨ Π⊎↔Π×Π ext ⟩
((n : ℕ) → P (suc n)) × (⊤ → P zero) ↔⟨ ×-comm ⟩
(⊤ → P zero) × ((n : ℕ) → P (suc n)) ↔⟨ Π-left-identity ×-cong id ⟩□
P zero × ((n : ℕ) → P (suc n)) □
-- Variants of Σℕ≃′ and Πℕ≃′ which, at the time of writing, have
-- "better" computational behaviour.
Σℕ≃ :
∀ {p} {P : ℕ → Type p} →
(∃ λ n → P n) ≃ (P zero ⊎ ∃ λ n → P (suc n))
Σℕ≃ {P = P} = Eq.↔→≃
(λ where
(zero , p) → inj₁ p
(suc n , p) → inj₂ (n , p))
[ (zero ,_) , Σ-map suc id ]
[ (λ _ → refl _) , (λ _ → refl _) ]
(λ where
(zero , _) → refl _
(suc _ , _) → refl _)
Πℕ≃ :
∀ {p} {P : ℕ → Type p} →
(∀ n → P n) ↝[ lzero ∣ p ] (P zero × ∀ n → P (suc n))
Πℕ≃ {P = P} =
generalise-ext?
Πℕ⇔
(λ ext →
refl
, (λ _ →
apply-ext ext $
ℕ-case (refl _) (λ _ → refl _)))
where
Πℕ⇔ : _ ⇔ _
Πℕ⇔ ._⇔_.to f = f zero , f ⊚ suc
Πℕ⇔ ._⇔_.from = uncurry ℕ-case
-- ℕ is isomorphic to ℕ ⊎ ℕ.
ℕ↔ℕ⊎ℕ : ℕ ↔ ℕ ⊎ ℕ
ℕ↔ℕ⊎ℕ = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
step : ℕ ⊎ ℕ → ℕ ⊎ ℕ
step = [ inj₂ , inj₁ ∘ suc ]
to : ℕ → ℕ ⊎ ℕ
to zero = inj₁ zero
to (suc n) = step (to n)
double : ℕ → ℕ
double zero = zero
double (suc n) = suc (suc (double n))
from : ℕ ⊎ ℕ → ℕ
from = [ double , suc ∘ double ]
from∘to : ∀ n → from (to n) ≡ n
from∘to zero = zero ∎
from∘to (suc n) with to n | from∘to n
... | inj₁ m | eq =
suc (double m) ≡⟨ cong suc eq ⟩∎
suc n ∎
... | inj₂ m | eq =
suc (suc (double m)) ≡⟨ cong suc eq ⟩∎
suc n ∎
to∘double : ∀ n → to (double n) ≡ inj₁ n
to∘double zero = inj₁ zero ∎
to∘double (suc n) =
to (double (suc n)) ≡⟨⟩
to (suc (suc (double n))) ≡⟨⟩
step (step (to (double n))) ≡⟨ cong (step ∘ step) (to∘double n) ⟩
step (step (inj₁ n)) ≡⟨⟩
inj₁ (suc n) ∎
to∘from : ∀ x → to (from x) ≡ x
to∘from =
[ to∘double
, (λ n →
to (from (inj₂ n)) ≡⟨⟩
to (suc (double n)) ≡⟨⟩
step (to (double n)) ≡⟨ cong step (to∘double n) ⟩
step (inj₁ n) ≡⟨⟩
inj₂ n ∎)
]
-- ℕ is isomorphic to ℕ².
ℕ↔ℕ² : ℕ ↔ ℕ × ℕ
ℕ↔ℕ² = record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
step : ℕ × ℕ → ℕ × ℕ
step (m , zero) = (zero , suc m)
step (m , suc n) = (suc m , n)
to : ℕ → ℕ × ℕ
to zero = (zero , zero)
to (suc n) = step (to n)
-- The function from′ is defined by lexicographic induction on first
-- sum, and then m.
from′ : (m n sum : ℕ) → n + m ≡ sum → ℕ
from′ zero zero _ _ = zero
from′ zero (suc n) zero eq = ⊥-elim (0≢+ (sym eq))
from′ zero (suc n) (suc sum) eq = suc (from′ n zero sum (cancel-suc
(suc n ≡⟨ cong suc (sym +-right-identity) ⟩
suc (n + 0) ≡⟨ eq ⟩∎
suc sum ∎)))
from′ (suc m) n sum eq = suc (from′ m (suc n) sum
(suc n + m ≡⟨ suc+≡+suc n ⟩
n + suc m ≡⟨ eq ⟩∎
sum ∎))
from : ℕ × ℕ → ℕ
from (m , n) = from′ m n _ (refl _)
from′-irr : ∀ m {n sum₁ eq₁ sum₂ eq₂} →
from′ m n sum₁ eq₁ ≡ from′ m n sum₂ eq₂
from′-irr m {n} {sum₁} {eq₁} {sum₂} {eq₂} =
from′ m n sum₁ eq₁ ≡⟨ cong (uncurry (from′ m n)) (Σ-≡,≡→≡ lemma (ℕ-set _ _)) ⟩∎
from′ m n sum₂ eq₂ ∎
where
lemma =
sum₁ ≡⟨ sym eq₁ ⟩
n + m ≡⟨ eq₂ ⟩∎
sum₂ ∎
from∘step : ∀ p → from (step p) ≡ suc (from p)
from∘step (m , zero) = from (zero , suc m) ≡⟨ cong suc (from′-irr m) ⟩∎
suc (from (m , zero)) ∎
from∘step (m , suc n) = from (suc m , n) ≡⟨ cong suc (from′-irr m) ⟩∎
suc (from (m , suc n)) ∎
from∘to : ∀ n → from (to n) ≡ n
from∘to zero = refl _
from∘to (suc n) =
from (to (suc n)) ≡⟨⟩
from (step (to n)) ≡⟨ from∘step (to n) ⟩
suc (from (to n)) ≡⟨ cong suc (from∘to n) ⟩∎
suc n ∎
to∘from′ : ∀ m n sum eq → to (from′ m n sum eq) ≡ (m , n)
to∘from′ zero zero _ _ = refl _
to∘from′ zero (suc n) zero eq = ⊥-elim (0≢+ (sym eq))
to∘from′ zero (suc n) (suc sum) eq =
step (to (from′ n zero _ _)) ≡⟨ cong step (to∘from′ n zero sum _) ⟩
step (n , zero) ≡⟨⟩
(zero , suc n) ∎
to∘from′ (suc m) n sum eq =
step (to (from′ m (suc n) _ _)) ≡⟨ cong step (to∘from′ m (suc n) sum _) ⟩
step (m , suc n) ≡⟨⟩
(suc m , n) ∎
to∘from : ∀ p → to (from p) ≡ p
to∘from _ = to∘from′ _ _ _ _
-- Some isomorphisms related to equality of natural numbers.
zero≡zero↔ : zero ≡ zero ↔ ⊤
zero≡zero↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ℕ-set (mono₁ 0 ⊤-contractible)) $
record { to = _; from = λ _ → refl _ }
zero≡suc↔ : ∀ {n} → zero ≡ suc n ↔ ⊥₀
zero≡suc↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ℕ-set ⊥-propositional) $
record { to = 0≢+; from = ⊥-elim }
suc≡zero↔ : ∀ {m} → suc m ≡ zero ↔ ⊥₀
suc≡zero↔ {m} =
suc m ≡ zero ↝⟨ ≡-comm ⟩
zero ≡ suc m ↝⟨ zero≡suc↔ ⟩□
⊥ □
suc≡suc↔ : ∀ {m n} → suc m ≡ suc n ↔ m ≡ n
suc≡suc↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ℕ-set ℕ-set) $
record { to = cancel-suc; from = cong suc }
-- The equality test Nat._==_ gives the right result.
T[==]↔≡ : {m n : ℕ} → T (m == n) ↔ m ≡ n
T[==]↔≡ {m = zero} {n = zero} =
T (zero == zero) ↔⟨⟩
⊤ ↝⟨ inverse zero≡zero↔ ⟩□
zero ≡ zero □
T[==]↔≡ {m = zero} {n = suc n} =
T (zero == suc n) ↔⟨⟩
⊥ ↝⟨ inverse zero≡suc↔ ⟩□
zero ≡ suc n □
T[==]↔≡ {m = suc m} {n = zero} =
T (suc m == zero) ↔⟨⟩
⊥ ↝⟨ inverse suc≡zero↔ ⟩□
suc m ≡ zero □
T[==]↔≡ {m = suc m} {n = suc n} =
T (suc m == suc n) ↔⟨⟩
T (m == n) ↝⟨ T[==]↔≡ ⟩
m ≡ n ↝⟨ inverse suc≡suc↔ ⟩□
suc m ≡ suc n □
-- Some isomorphisms related to the ordering of natural numbers.
zero≤↔ : ∀ {n} → zero ≤ n ↔ ⊤
zero≤↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional (mono₁ 0 ⊤-contractible)) $
record { to = _; from = λ _ → zero≤ _ }
<zero↔ : ∀ {n} → n < zero ↔ ⊥
<zero↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ⊥-propositional) $
record { to = ≮0 _; from = ⊥-elim }
suc≤suc↔ : ∀ {m n} → suc m ≤ suc n ↔ m ≤ n
suc≤suc↔ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ≤-propositional) $
record { to = suc≤suc⁻¹; from = suc≤suc }
≤↔<⊎≡ : ∀ {m n} → m ≤ n ↔ m < n ⊎ m ≡ n
≤↔<⊎≡ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional
(⊎-closure-propositional
<→≢ ≤-propositional ℕ-set)) $
record { to = ≤→<⊎≡; from = [ <→≤ , ≤-refl′ ] }
≤↔≡0⊎0<×≤ : ∀ {m n} → m ≤ n ↔ m ≡ 0 ⊎ 0 < m × m ≤ n
≤↔≡0⊎0<×≤ {zero} {n} =
0 ≤ n ↝⟨ zero≤↔ ⟩
⊤ ↝⟨ inverse ⊎-right-identity ⟩
⊤ ⊎ ⊥₀ ↝⟨ id ⊎-cong inverse ×-left-zero ⟩
⊤ ⊎ (⊥ × 0 ≤ n) ↝⟨ inverse (_⇔_.to contractible⇔↔⊤ (propositional⇒inhabited⇒contractible ℕ-set (refl _)))
⊎-cong
inverse <zero↔ ×-cong id ⟩□
0 ≡ 0 ⊎ 0 < 0 × 0 ≤ n □
≤↔≡0⊎0<×≤ {suc m} {n} =
m < n ↝⟨ inverse ×-left-identity ⟩
⊤ × m < n ↝⟨ inverse zero≤↔ ×-cong id ⟩
0 ≤ m × m < n ↝⟨ inverse ⊎-left-identity ⟩
⊥₀ ⊎ 0 ≤ m × m < n ↝⟨ Bijection.⊥↔uninhabited (0≢+ ∘ sym) ⊎-cong inverse suc≤suc↔ ×-cong id ⟩□
1 + m ≡ 0 ⊎ 0 < 1 + m × m < n □
≤↔min≡ : ∀ {m n} → m ≤ n ↔ min m n ≡ m
≤↔min≡ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ℕ-set) $
≤⇔min≡
≤↔max≡ : ∀ {m n} → m ≤ n ↔ max m n ≡ n
≤↔max≡ =
_≃_.bijection $
_↠_.from (Eq.≃↠⇔ ≤-propositional ℕ-set) $
≤⇔max≡
∃0<↔∃suc :
∀ {p} {P : ℕ → Type p} →
(∃ λ n → 0 < n × P n) ↔ (∃ λ n → P (suc n))
∃0<↔∃suc {P = P} = record
{ surjection = record
{ logical-equivalence = record
{ to = Σ-map pred λ where
{zero} (0<0 , _) → ⊥-elim (≮0 _ 0<0)
{suc _} (_ , p) → p
; from = Σ-map suc (λ p → suc≤suc (zero≤ _) , p)
}
; right-inverse-of = refl
}
; left-inverse-of = λ where
(zero , 0<0 , p) → ⊥-elim (≮0 _ 0<0)
(suc n , 0<+ , p) →
Σ-≡,≡→≡ (refl _)
(trans (subst-refl _ _)
(_↔_.to ≡×≡↔≡
( ≤-propositional _ _
, refl _
)))
}
∃<↔∃0<×≤ : ∀ {n} → (∃ λ m → m < n) ↔ (∃ λ m → 0 < m × m ≤ n)
∃<↔∃0<×≤ {n} =
(∃ λ m → m < n) ↔⟨⟩
(∃ λ m → suc m ≤ n) ↝⟨ inverse ∃0<↔∃suc ⟩□
(∃ λ m → 0 < m × m ≤ n) □
-- The ordering test Nat._<=_ gives the right result.
T[<=]↔≤ : {m n : ℕ} → T (m <= n) ↔ m ≤ n
T[<=]↔≤ {m = zero} {n = n} =
T (zero <= n) ↔⟨⟩
⊤ ↝⟨ inverse zero≤↔ ⟩□
zero ≤ n □
T[<=]↔≤ {m = suc m} {n = zero} =
T (suc m <= zero) ↔⟨⟩
⊥ ↝⟨ inverse <zero↔ ⟩□
suc m ≤ zero □
T[<=]↔≤ {m = suc m} {n = suc n} =
T (suc m <= suc n) ↔⟨⟩
T (m <= n) ↝⟨ T[<=]↔≤ ⟩
m ≤ n ↝⟨ inverse suc≤suc↔ ⟩□
suc m ≤ suc n □
-- Equality or distinctness of two natural numbers is isomorphic to
-- the unit type.
≡⊎Distinct↔⊤ : ∀ m n → m ≡ n ⊎ Distinct m n ↔ ⊤
≡⊎Distinct↔⊤ m n =
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(⊎-closure-propositional
(λ m≡n m≢n → _⇔_.to Distinct⇔≢ m≢n m≡n)
ℕ-set
(Distinct-propositional m n))
(≡⊎Distinct m n)
-- Distinct is pointwise logically equivalent to _≢_, and in the
-- presence of extensionality the two definitions are pointwise
-- isomorphic.
Distinct↔≢ : ∀ {m n} → Distinct m n ↝[ lzero ∣ lzero ] m ≢ n
Distinct↔≢ {m = m} {n} =
generalise-ext?-prop
Distinct⇔≢
(λ _ → Distinct-propositional m n)
¬-propositional
------------------------------------------------------------------------
-- Left cancellation for _⊎_
-- In general _⊎_ is not left cancellative.
¬-⊎-left-cancellative :
∀ k → ¬ ((A B C : Type) → A ⊎ B ↝[ k ] A ⊎ C → B ↝[ k ] C)
¬-⊎-left-cancellative k cancel =
¬B→C $ to-implication $ cancel A B C (from-bijection A⊎B↔A⊎C)
where
A = ℕ
B = ⊤
C = ⊥
A⊎B↔A⊎C : A ⊎ B ↔ A ⊎ C
A⊎B↔A⊎C =
ℕ ⊎ ⊤ ↔⟨ inverse ℕ↔ℕ⊎⊤ ⟩
ℕ ↔⟨ inverse ⊎-right-identity ⟩
ℕ ⊎ ⊥ □
¬B→C : ¬ (B → C)
¬B→C B→C = B→C tt
-- However, it is left cancellative for certain well-behaved
-- bijections.
-- A function is "well-behaved" if any "left" element which is the
-- image of a "right" element is in turn not mapped to another "left"
-- element.
Well-behaved : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
(A ⊎ B → A ⊎ C) → Type _
Well-behaved f =
∀ {b a a′} → f (inj₂ b) ≡ inj₁ a → f (inj₁ a) ≢ inj₁ a′
private
-- Some helper functions.
module ⊎-left-cancellative
{a b c} {A : Type a} {B : Type b} {C : Type c}
(f : A ⊎ B → A ⊎ C)
(hyp : Well-behaved f)
where
mutual
g : B → C
g b = g′ (inspect (f (inj₂ b)))
g′ : ∀ {b} → Other-singleton (f (inj₂ b)) → C
g′ (inj₂ c , _) = c
g′ (inj₁ a , eq) = g″ eq (inspect (f (inj₁ a)))
g″ : ∀ {a b} →
f (inj₂ b) ≡ inj₁ a → Other-singleton (f (inj₁ a)) → C
g″ _ (inj₂ c , _) = c
g″ eq₁ (inj₁ _ , eq₂) = ⊥-elim $ hyp eq₁ eq₂
⊎-left-cancellative :
∀ {a b c} {A : Type a} {B : Type b} {C : Type c}
(f : A ⊎ B ↔ A ⊎ C) →
Well-behaved (_↔_.to f) →
Well-behaved (_↔_.from f) →
B ↔ C
⊎-left-cancellative {A = A} = λ inv to-hyp from-hyp → record
{ surjection = record
{ logical-equivalence = record
{ to = g (to inv) to-hyp
; from = g (from inv) from-hyp
}
; right-inverse-of = g∘g (inverse inv) from-hyp to-hyp
}
; left-inverse-of = g∘g inv to-hyp from-hyp
}
where
open _↔_
open ⊎-left-cancellative
abstract
g∘g : ∀ {b c} {B : Type b} {C : Type c}
(f : A ⊎ B ↔ A ⊎ C) →
(to-hyp : Well-behaved (to f)) →
(from-hyp : Well-behaved (from f)) →
∀ b → g (from f) from-hyp (g (to f) to-hyp b) ≡ b
g∘g f to-hyp from-hyp b = g∘g′
where
g∘g′ : g (from f) from-hyp (g (to f) to-hyp b) ≡ b
g∘g′ with inspect (to f (inj₂ b))
g∘g′ | inj₂ c , eq₁ with inspect (from f (inj₂ c))
g∘g′ | inj₂ c , eq₁ | inj₂ b′ , eq₂ = ⊎.cancel-inj₂ (
inj₂ b′ ≡⟨ sym eq₂ ⟩
from f (inj₂ c) ≡⟨ to-from f eq₁ ⟩∎
inj₂ b ∎)
g∘g′ | inj₂ c , eq₁ | inj₁ a , eq₂ = ⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ a ≡⟨ sym eq₂ ⟩
from f (inj₂ c) ≡⟨ to-from f eq₁ ⟩∎
inj₂ b ∎)
g∘g′ | inj₁ a , eq₁ with inspect (to f (inj₁ a))
g∘g′ | inj₁ a , eq₁ | inj₁ a′ , eq₂ = ⊥-elim $ to-hyp eq₁ eq₂
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ with inspect (from f (inj₂ c))
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₂ b′ , eq₃ = ⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ a ≡⟨ sym $ to-from f eq₂ ⟩
from f (inj₂ c) ≡⟨ eq₃ ⟩∎
inj₂ b′ ∎)
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ with inspect (from f (inj₁ a′))
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ | inj₁ a″ , eq₄ = ⊥-elim $ from-hyp eq₃ eq₄
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ | inj₂ b′ , eq₄ = ⊎.cancel-inj₂ (
let lemma =
inj₁ a′ ≡⟨ sym eq₃ ⟩
from f (inj₂ c) ≡⟨ to-from f eq₂ ⟩∎
inj₁ a ∎
in
inj₂ b′ ≡⟨ sym eq₄ ⟩
from f (inj₁ a′) ≡⟨ cong (from f ⊚ inj₁) $ ⊎.cancel-inj₁ lemma ⟩
from f (inj₁ a) ≡⟨ to-from f eq₁ ⟩∎
inj₂ b ∎)
-- _⊎_ is left cancellative (for bijections) if the left argument is
-- the unit type.
⊎-left-cancellative-⊤ :
∀ {a b} {A : Type a} {B : Type b} →
(⊤ ⊎ A) ↔ (⊤ ⊎ B) → A ↔ B
⊎-left-cancellative-⊤ = λ ⊤⊎A↔⊤⊎B →
⊎-left-cancellative ⊤⊎A↔⊤⊎B
(wb ⊤⊎A↔⊤⊎B)
(wb $ inverse ⊤⊎A↔⊤⊎B)
where
open _↔_
abstract
wb : ∀ {a b} {A : Type a} {B : Type b}
(⊤⊎A↔⊤⊎B : (⊤ ⊎ A) ↔ (⊤ ⊎ B)) →
Well-behaved (_↔_.to ⊤⊎A↔⊤⊎B)
wb ⊤⊎A↔⊤⊎B {b = b} eq₁ eq₂ = ⊎.inj₁≢inj₂ (
inj₁ tt ≡⟨ sym $ to-from ⊤⊎A↔⊤⊎B eq₂ ⟩
from ⊤⊎A↔⊤⊎B (inj₁ tt) ≡⟨ to-from ⊤⊎A↔⊤⊎B eq₁ ⟩∎
inj₂ b ∎)
-- If the codomain of ⊎-left-cancellative-⊤ is paired up with a value
-- in ⊤ ⊎ B, then the function can be strengthened to a bijection
-- (assuming both decidability of equality of values in B and
-- extensionality).
[⊤⊎↔⊤⊎]↔[⊤⊎×↔] :
∀ {a b} {A : Type a} {B : Type b} →
Decidable-equality B →
((⊤ ⊎ A) ↔ (⊤ ⊎ B)) ↝[ a ⊔ b ∣ a ⊔ b ] (⊤ ⊎ B) × (A ↔ B)
[⊤⊎↔⊤⊎]↔[⊤⊎×↔] {a = a} {b = b} {A = A} {B = B} _≟B_ =
generalise-ext? [⊤⊎↔⊤⊎]⇔[⊤⊎×↔] (λ ext → to∘from ext , from∘to ext)
where
_≟_ : Decidable-equality (⊤ ⊎ B)
_≟_ = ⊎.Dec._≟_ ⊤._≟_ _≟B_
if-not : ∀ {a p} {A : Type a} {P : Type p} (d : Dec P) (t e : A) →
¬ P → if d then t else e ≡ e
if-not (yes p) t e ¬p = ⊥-elim (¬p p)
if-not (no _) t e ¬p = refl _
to : (⊤ ⊎ A) ↔ (⊤ ⊎ B) → (⊤ ⊎ B) × (A ↔ B)
to ⊤⊎A↔⊤⊎B = _↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt) , ⊎-left-cancellative-⊤ ⊤⊎A↔⊤⊎B
from : (⊤ ⊎ B) × (A ↔ B) → (⊤ ⊎ A) ↔ (⊤ ⊎ B)
from (⊤⊎B , A↔B) = record
{ surjection = record
{ logical-equivalence = record
{ to = t ⊤⊎B
; from = f ⊤⊎B
}
; right-inverse-of = t∘f ⊤⊎B
}
; left-inverse-of = f∘t ⊤⊎B
}
where
t : ⊤ ⊎ B → ⊤ ⊎ A → ⊤ ⊎ B
t ⊤⊎B (inj₁ tt) = ⊤⊎B
t ⊤⊎B (inj₂ a) =
let b = inj₂ (_↔_.to A↔B a) in
if b ≟ ⊤⊎B then inj₁ tt else b
f : ⊤ ⊎ B → ⊤ ⊎ B → ⊤ ⊎ A
f ⊤⊎B (inj₁ tt) = [ const (inj₁ tt) , inj₂ ∘ _↔_.from A↔B ] ⊤⊎B
f ⊤⊎B (inj₂ b) =
if ⊤⊎B ≟ inj₂ b then inj₁ tt else inj₂ (_↔_.from A↔B b)
abstract
t∘f : ∀ ⊤⊎B x → t ⊤⊎B (f ⊤⊎B x) ≡ x
t∘f (inj₁ tt) (inj₁ tt) = refl _
t∘f (inj₁ tt) (inj₂ b′) = inj₂ (_↔_.to A↔B (_↔_.from A↔B b′)) ≡⟨ cong inj₂ $ _↔_.right-inverse-of A↔B _ ⟩∎
inj₂ b′ ∎
t∘f (inj₂ b) (inj₁ tt) with _↔_.to A↔B (_↔_.from A↔B b) ≟B b
t∘f (inj₂ b) (inj₁ tt) | yes _ = refl _
t∘f (inj₂ b) (inj₁ tt) | no b≢b = ⊥-elim $ b≢b (
_↔_.to A↔B (_↔_.from A↔B b) ≡⟨ _↔_.right-inverse-of A↔B _ ⟩∎
b ∎)
t∘f (inj₂ b) (inj₂ b′) with b ≟B b′
t∘f (inj₂ b) (inj₂ b′) | yes b≡b′ = inj₂ b ≡⟨ cong inj₂ b≡b′ ⟩∎
inj₂ b′ ∎
t∘f (inj₂ b) (inj₂ b′) | no b≢b′ =
t (inj₂ b) (inj₂ (_↔_.from A↔B b′)) ≡⟨⟩
if inj₂ (_↔_.to A↔B (_↔_.from A↔B b′)) ≟ inj₂ b then inj₁ tt
else inj₂ (_↔_.to A↔B (_↔_.from A↔B b′)) ≡⟨ cong (λ b′ → if inj₂ b′ ≟ inj₂ b then inj₁ tt else inj₂ b′) $
_↔_.right-inverse-of A↔B _ ⟩
if inj₂ b′ ≟ inj₂ b then inj₁ tt else inj₂ b′ ≡⟨ if-not (inj₂ b′ ≟ inj₂ b) (inj₁ tt) _ (b≢b′ ∘ sym ∘ ⊎.cancel-inj₂) ⟩∎
inj₂ b′ ∎
f∘t : ∀ ⊤⊎B x → f ⊤⊎B (t ⊤⊎B x) ≡ x
f∘t (inj₁ tt) (inj₁ tt) = refl _
f∘t (inj₁ tt) (inj₂ a) = inj₂ (_↔_.from A↔B (_↔_.to A↔B a)) ≡⟨ cong inj₂ $ _↔_.left-inverse-of A↔B _ ⟩∎
inj₂ a ∎
f∘t (inj₂ b) (inj₁ tt) with b ≟B b
f∘t (inj₂ b) (inj₁ tt) | yes _ = refl _
f∘t (inj₂ b) (inj₁ tt) | no b≢b = ⊥-elim $ b≢b (refl _)
f∘t (inj₂ b) (inj₂ a) with _↔_.to A↔B a ≟B b
f∘t (inj₂ b) (inj₂ a) | yes to-a≡b = inj₂ (_↔_.from A↔B b) ≡⟨ cong inj₂ $ _↔_.to-from A↔B to-a≡b ⟩∎
inj₂ a ∎
f∘t (inj₂ b) (inj₂ a) | no to-a≢b with b ≟B _↔_.to A↔B a
f∘t (inj₂ b) (inj₂ a) | no to-a≢b | yes b≡to-a = ⊥-elim $ to-a≢b
(_↔_.to A↔B a ≡⟨ sym b≡to-a ⟩∎
b ∎)
f∘t (inj₂ b) (inj₂ a) | no to-a≢b | no b≢to-a =
inj₂ (_↔_.from A↔B (_↔_.to A↔B a)) ≡⟨ cong inj₂ $ _↔_.left-inverse-of A↔B _ ⟩∎
inj₂ a ∎
[⊤⊎↔⊤⊎]⇔[⊤⊎×↔] : ((⊤ ⊎ A) ↔ (⊤ ⊎ B)) ⇔ (⊤ ⊎ B) × (A ↔ B)
[⊤⊎↔⊤⊎]⇔[⊤⊎×↔] = record
{ to = to
; from = from
}
to∘from :
Extensionality (a ⊔ b) (a ⊔ b) →
∀ x → to (from x) ≡ x
to∘from ext (⊤⊎B , A↔B) =
cong (⊤⊎B ,_) (_↔_.to (↔-to-≡↔≡ ext A-set) (lemma ⊤⊎B))
where
A-set : Is-set A
A-set = $⟨ _≟B_ ⟩
Decidable-equality B ↝⟨ decidable⇒set ⟩
Is-set B ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse A↔B) 2 ⟩□
Is-set A □
lemma :
∀ ⊤⊎B a →
_↔_.to (⊎-left-cancellative-⊤ (from (⊤⊎B , A↔B))) a ≡ _↔_.to A↔B a
lemma (inj₁ tt) a = refl _
lemma (inj₂ b) a with inspect (_↔_.to (from (inj₂ b , A↔B))
(inj₂ a))
lemma (inj₂ b) a | (inj₁ tt , eq) with _↔_.to A↔B a ≟B b
lemma (inj₂ b) a | (inj₁ tt , eq) | yes to-a≡b = sym to-a≡b
lemma (inj₂ b) a | (inj₁ tt , eq) | no _ = ⊥-elim $ ⊎.inj₁≢inj₂ $ sym eq
lemma (inj₂ b) a | (inj₂ _ , eq) with _↔_.to A↔B a ≟B b
lemma (inj₂ b) a | (inj₂ _ , eq) | yes _ = ⊥-elim $ ⊎.inj₁≢inj₂ eq
lemma (inj₂ b) a | (inj₂ _ , eq) | no _ = ⊎.cancel-inj₂ $ sym eq
from∘to :
Extensionality (a ⊔ b) (a ⊔ b) →
∀ x → from (to x) ≡ x
from∘to ext ⊤⊎A↔⊤⊎B = _↔_.to (↔-to-≡↔≡ ext ⊤⊎A-set) lemma₁
where
open ⊎-left-cancellative
⊤⊎A-set : Is-set (⊤ ⊎ A)
⊤⊎A-set = $⟨ _≟B_ ⟩
Decidable-equality B ↝⟨ decidable⇒set ⟩
Is-set B ↝⟨ ⊎-closure 0 (mono (zero≤ 2) ⊤-contractible) ⟩
Is-set (⊤ ⊎ B) ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse ⊤⊎A↔⊤⊎B) 2 ⟩□
Is-set (⊤ ⊎ A) □
mutual
lemma₁ : ∀ ⊤⊎A →
_↔_.to (from (to ⊤⊎A↔⊤⊎B)) ⊤⊎A ≡ _↔_.to ⊤⊎A↔⊤⊎B ⊤⊎A
lemma₁ (inj₁ tt) = refl _
lemma₁ (inj₂ a) = lemma₂ (inspect _) (inspect _)
lemma₂ :
∀ {a} {wb : Well-behaved (_↔_.to ⊤⊎A↔⊤⊎B)}
(x : Other-singleton (_↔_.to ⊤⊎A↔⊤⊎B (inj₂ a)))
(y : Other-singleton (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt))) →
let b = g′ (_↔_.to ⊤⊎A↔⊤⊎B) wb x in
if inj₂ b ≟ proj₁ y then inj₁ tt else inj₂ b ≡ proj₁ x
lemma₂ {a} (inj₁ tt , eq₁) (inj₁ tt , eq₂) = ⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ tt ≡⟨ sym $ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt)) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) eq₂ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (inj₁ tt) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) $ sym eq₁ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₂ a)) ≡⟨ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩∎
inj₂ a ∎)
lemma₂ (inj₁ tt , eq₁) (inj₂ b′ , eq₂) = lemma₃ eq₁ (inspect _) eq₂ (inj₂ _ ≟ inj₂ b′)
lemma₂ (inj₂ b , eq₁) (inj₁ tt , eq₂) = refl _
lemma₂ (inj₂ b , eq₁) (inj₂ b′ , eq₂) with b ≟B b′
lemma₂ (inj₂ b , eq₁) (inj₂ b′ , eq₂) | no _ = refl _
lemma₂ {a} (inj₂ b , eq₁) (inj₂ b′ , eq₂) | yes b≡b′ =
⊥-elim $ ⊎.inj₁≢inj₂ (
inj₁ tt ≡⟨ sym $ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt)) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) eq₂ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (inj₂ b′) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B ∘ inj₂) $ sym b≡b′ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (inj₂ b) ≡⟨ cong (_↔_.from ⊤⊎A↔⊤⊎B) $ sym eq₁ ⟩
_↔_.from ⊤⊎A↔⊤⊎B (_↔_.to ⊤⊎A↔⊤⊎B (inj₂ a)) ≡⟨ _↔_.left-inverse-of ⊤⊎A↔⊤⊎B _ ⟩∎
inj₂ a ∎)
lemma₃ :
∀ {a b′} {wb : Well-behaved (_↔_.to ⊤⊎A↔⊤⊎B)}
(eq : _↔_.to ⊤⊎A↔⊤⊎B (inj₂ a) ≡ inj₁ tt)
(x : Other-singleton (_↔_.to ⊤⊎A↔⊤⊎B (inj₁ tt))) →
proj₁ x ≡ inj₂ b′ →
let b = g″ (_↔_.to ⊤⊎A↔⊤⊎B) wb eq x in
(d : Dec (inj₂ {A = ⊤} b ≡ inj₂ b′)) →
if d then inj₁ tt else inj₂ b ≡ inj₁ tt
lemma₃ eq₁ (inj₁ _ , eq₂) eq₃ _ = ⊥-elim $ ⊎.inj₁≢inj₂ eq₃
lemma₃ eq₁ (inj₂ b″ , eq₂) eq₃ (yes b″≡b′) = refl _
lemma₃ eq₁ (inj₂ b″ , eq₂) eq₃ (no b″≢b′) = ⊥-elim $ b″≢b′ eq₃
|
srcs/boot/boot_ap.asm | gamozolabs/falkervisor_beta | 69 | 89503 | [bits 16]
; boot_ap
;
; Summary:
;
; This is the real mode entry point for all APs. This function sets the A20
; line, loads the GDT, and goes into protected mode.
;
; Optimization:
;
; Readability
;
boot_ap:
cli
; Blindly set the A20 line
in al, 0x92
or al, 2
out 0x92, al
; Load the gdt (for 32-bit proteted mode)
lgdt [gdt]
; Set the protection bit
mov eax, cr0
or al, (1 << 0)
mov cr0, eax
; We go to protected land now!
jmp 0x0008:ap_pmland
[bits 32]
; ap_pmland
;
; Summary:
;
; This is the protected mode entry point for all APs. This function sets up
; paging, enables long mode, and loads the 64-bit gdt.
;
; Optimization:
;
; Readability
;
ap_pmland:
; Set up all data selectors
mov ax, 0x10
mov es, ax
mov ds, ax
mov fs, ax
mov ss, ax
mov gs, ax
; Enable SSE
mov eax, cr0
btr eax, 2 ; Disable CR0.EM
bts eax, 1 ; Enable CR0.MP
mov cr0, eax
; Enable OSFXSR and OSXSAVE and OSXMMEXCPT
mov eax, cr4
bts eax, 9
bts eax, 18
bts eax, 10
mov cr4, eax
; Disable paging
mov eax, cr0
and eax, 0x7FFFFFFF
mov cr0, eax
; Set up CR3
mov edi, 0x00100000
mov cr3, edi
; Enable PAE
mov eax, cr4
or eax, (1 << 5)
mov cr4, eax
; Enable long mode
mov ecx, 0xC0000080
rdmsr
or eax, (1 << 8)
wrmsr
; Enable paging
mov eax, cr0
or eax, (1 << 31)
mov cr0, eax
; Load the 64-bit GDT and jump to the long mode code
lgdt [gdt64]
jmp 0x08:lmland
align 8
gdt64_base:
dq 0x0000000000000000
dq 0x0020980000000000
dq 0x0000900000000000
gdt64:
.len: dw (gdt64 - gdt64_base) - 1
.base: dq gdt64_base
[bits 64]
init_pic:
push rax
; Start PIC init
mov al, (PIC_INIT | PIC_ICW4)
out MPIC_CTRL, al
out SPIC_CTRL, al
; IRQ 0-7 now based at int IRQ07_MAP (32)
; IRQ 8-F now based at int IRQ8F_MAP (40)
mov al, IRQ07_MAP
out MPIC_DATA, al
mov al, IRQ8F_MAP
out SPIC_DATA, al
; Inform the MPIC about the SPIC and inform the SPIC about the cascade
mov al, 0x04
out MPIC_DATA, al
mov al, 0x02
out SPIC_DATA, al
; Set 8086 mode
mov al, PIC_8086
out MPIC_DATA, al
out SPIC_DATA, al
; Zero out the masks
xor al, al
out MPIC_DATA, al
out SPIC_DATA, al
pop rax
ret
; copy_kern_to_pnm
;
; Summary:
;
; This function relocates the entire kernel to PNM address space
;
; Parameters:
;
; None
;
; Alignment:
;
; None
;
; Returns:
;
; None
;
; Smashes:
;
; None
;
; Optimization
;
; Readability
;
copy_kern_to_pnm:
push rcx
push rsi
push rdi
mov rdi, kern_size
bamp_alloc rdi
push rdi
mov rcx, kern_size
mov rsi, boot_bsp
rep movsb
pop rbx
pop rdi
pop rsi
pop rcx
ret
; init_pnm
;
; Summary:
;
; This function initializes the PDPTEs for the PNM
;
; Parameters:
;
; None
;
; Alignment:
;
; None
;
; Returns:
;
; None
;
; Smashes:
;
; None
;
; Optimization
;
; Readability
;
init_pnm:
push rax
push rbx
push rcx
push rdx
push rdi
push rbp
push r8
mov rbx, MEMORY_MAP_LOC + 0x20
movzx rcx, word [MEMORY_MAP_LOC]
.for_each_map:
; If the mapping is not type 1, fail!
mov eax, dword [rbx + 0x10]
cmp rax, 1
jne .go_next_map
; get the base and 1GB align it
mov rax, qword [rbx + 0x00]
add rax, (1 * 1024 * 1024 * 1024 - 1)
and rax, ~(1 * 1024 * 1024 * 1024 - 1)
; get the length of the ALIGNED remainder. This could be negative. Since
; we do signed compares, this is fine!
mov rdx, qword [rbx + 0x00] ; base
add rdx, qword [rbx + 0x08] ; length
sub rdx, rax
.while_1G_left:
; If we don't have 1GB left, go to the next mapping
cmp rdx, (1 * 1024 * 1024 * 1024)
jl short .go_next_map
; If we're below 5GB physical, loop without alloc
mov rbp, (5 * 1024 * 1024 * 1024)
cmp rax, rbp
jl short .go_next_1gb
mov rbp, rax
add rbp, (1 * 1024 * 1024 * 1024 - 1)
; rax now points to the base physical address of a 1GB aligned page
; rbp points to the last byte available in this 1GB page
lea rdi, [rel dram_routing_table]
lea r8, [rdi + 0x20 * MAX_NODES]
.find_dram:
; Check if end_of_this_map > end_of_dram_for_node
cmp rbp, [rdi + 0x08]
ja short .next_dram
; Check if base_of_this_map < base_of_dram_for_node
cmp rax, [rdi + 0x00]
jb short .next_dram
jmp short .found_dram
.next_dram:
add rdi, 0x20
cmp rdi, r8
jl short .find_dram
jmp short .go_next_1gb
.found_dram:
; Get the next PDPTE location for this node and populate it
mov rbp, qword [rdi + 0x18]
mov qword [rbp], rax
or qword [rbp], 0x83 ; Present, writable, page size
; Increment the PDPTE pointer
add qword [rdi + 0x18], 8
.go_next_1gb:
add rax, (1 * 1024 * 1024 * 1024)
sub rdx, (1 * 1024 * 1024 * 1024)
jmp short .while_1G_left
.go_next_map:
add rbx, 0x20
dec rcx
jnz .for_each_map
pop r8
pop rbp
pop rdi
pop rdx
pop rcx
pop rbx
pop rax
ret
; fetch_dram_info
;
; Summary:
;
; This function populates the global table which contains DRAM routing rules.
; We use this information to set up the PNMs
;
fetch_dram_info:
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
push rbp
push r15
; Get the MMIO address for the processor PCIE config space
mov ecx, 0xc0010058
rdmsr
shl rdx, 32
or rdx, rax
and rdx, ~0x3F
mov r15, rdx
lea rsi, [rel dram_routing_table]
xor ebp, ebp
.per_node:
; Bus 0, Device 18, Function 1
mov eax, [r15 + rbp*8 + 0x040 + ((0 << 20) | (0x18 << 15) | (0x1 << 12))]
mov ebx, [r15 + rbp*8 + 0x044 + ((0 << 20) | (0x18 << 15) | (0x1 << 12))]
mov ecx, [r15 + rbp*8 + 0x140 + ((0 << 20) | (0x18 << 15) | (0x1 << 12))]
mov edx, [r15 + rbp*8 + 0x144 + ((0 << 20) | (0x18 << 15) | (0x1 << 12))]
; eax - DRAM base low
; ebx - DRAM limit low
; ecx - DRAM base high
; edx - DRAM limit high
; Check for readable
bt eax, 0
jnc short .next_node
; Check for writable
bt eax, 1
jnc short .next_node
; Check for node interleave
test eax, (3 << 8)
jnz short .interleave_warning
; Get the node route
mov edi, ebx
and edi, 7
mov qword [rsi + 0x10], rdi
; Get the low part from DRAM base low
and eax, 0xffff0000
shl rax, (24 - 16)
; Combine the high and low base parts
mov edi, ecx
and edi, 0xff
shl rdi, 40
or rdi, rax
mov qword [rsi + 0x00], rdi ; DRAM base
; Get the low part from DRAM limit low
and ebx, 0xffff0000
shl rbx, (24 - 16)
; Combine the high and low limit parts
mov edi, edx
and edi, 0xff
shl rdi, 40
or rdi, rbx
or rdi, 0xFFFFFF
mov qword [rsi + 0x08], rdi ; DRAM limit
.next_node:
add rsi, 0x20
inc ebp
cmp ebp, MAX_NODES
jb .per_node
pop r15
pop rbp
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
ret
.interleave_warning:
mov rdi, 0xb8000
lea rbx, [rel .ilw]
mov rcx, 58
call outstr
cli
hlt
.ilw: db "Node interleaving is enabled, please disable from the BIOS"
align 16
dram_routing_table:
; base, limit, node to route to, next PDPTE
; If the limit is zero the entry is invalid
dq 0, 0, 0, 0x100103000
dq 0, 0, 0, 0x100104000
dq 0, 0, 0, 0x100105000
dq 0, 0, 0, 0x100106000
dq 0, 0, 0, 0x100107000
dq 0, 0, 0, 0x100108000
dq 0, 0, 0, 0x100109000
dq 0, 0, 0, 0x10010a000
; fetch_mmio_info
fetch_mmio_info:
push rax
push rbx
push rcx
push rdx
push rsi
push rbp
push r10
push r15
; Get the MMIO address for the processor PCIE config space
mov ecx, 0xc0010058
rdmsr
shl rdx, 32
or rdx, rax
and rdx, ~0x3F
mov r15, rdx
lea rsi, [rel mmio_routing_table]
xor ebp, ebp
.per_node:
; Bus 0, Device 18, Function 1
mov eax, [r15 + rbp*8 + 0x080 + ((0 << 20) | (0x18 << 15) | (0x1 << 12))]
mov ebx, [r15 + rbp*8 + 0x084 + ((0 << 20) | (0x18 << 15) | (0x1 << 12))]
mov ecx, [r15 + rbp*8 + 0x180 + ((0 << 20) | (0x18 << 15) | (0x1 << 12))]
; eax - MMIO base low
; ebx - MMIO limit low
; ecx - MMIO base/limit high
; Skip blank mappings
test eax, 0x3
jz short .next_node
; Get the low part from MMIO base low
and eax, 0xffffff00
shl rax, (16 - 8)
; Combine the high and low base parts
mov r10d, ecx
and r10d, 0xff
shl r10, 40
or r10, rax
; Save the base
mov qword [rsi + 0], r10
; Get the low part from MMIO limit low
and ebx, 0xffffff00
shl rbx, (16 - 8)
; Combine the high and low limit parts
bextr r10d, ecx, 0x0810
shl r10, 40
or r10, rbx
or r10, 0xFFFF
; Save the limit
mov qword [rsi + 8], r10
.next_node:
add rsi, 0x10
inc ebp
cmp ebp, 12
jb .per_node
pop r15
pop r10
pop rbp
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
ret
align 16
mmio_routing_table:
times (12 * 2) dq 0
; Initialize the fs segment.
init_globals:
push rax
push rbx
push rcx
push rdx
; This is a fixed allocation. We compensate for this by properly
; initializing bamp_addrs to not start here
mov rbx, 0x0000010000000000
mov eax, ebx
bextr rdx, rbx, 0x2020
mov ecx, 0xC0000100 ; FS.base MSR
wrmsr
pop rdx
pop rcx
pop rbx
pop rax
ret
; Initialize the global values
populate_globals:
push rbx
push rcx
push rdx
push rsi
mov rbx, 0x0000010000000000
; Zero out the global table
push rax
push rcx
push rdi
mov rdi, rbx
mov rcx, GLOBAL_STORAGE
xor eax, eax
rep stosb
pop rdi
pop rcx
pop rax
mov qword [fs:globals.fs_base], rbx
mov rbx, 0x50000000000
mov qword [fs:globals.next_free_vaddr], rbx
mov rbx, 0x0000010000000000 + GLOBAL_STORAGE ; Node 0 base (less globals)
mov qword [fs:globals.bamp_addr + 0x00], rbx
mov rbx, 0x0000018000000000 ; Node 1 base
mov qword [fs:globals.bamp_addr + 0x08], rbx
mov rbx, 0x0000020000000000 ; Node 2 base
mov qword [fs:globals.bamp_addr + 0x10], rbx
mov rbx, 0x0000028000000000 ; Node 3 base
mov qword [fs:globals.bamp_addr + 0x18], rbx
mov rbx, 0x0000030000000000 ; Node 4 base
mov qword [fs:globals.bamp_addr + 0x20], rbx
mov rbx, 0x0000038000000000 ; Node 5 base
mov qword [fs:globals.bamp_addr + 0x28], rbx
mov rbx, 0x0000040000000000 ; Node 6 base
mov qword [fs:globals.bamp_addr + 0x30], rbx
mov rbx, 0x0000048000000000 ; Node 7 base
mov qword [fs:globals.bamp_addr + 0x38], rbx
lea rsi, [rel dram_routing_table]
mov ecx, 0
.for_each_node:
mov rbx, qword [rsi + 0x18]
and rbx, 0xfff
shl rbx, 27 ; Multiply by (1GB / 8). This gives us the number of bytes in
; this nodes pool
mov rdx, qword [fs:globals.bamp_addr + rcx*8]
add rdx, rbx
and rdx, ~((1024 * 1024 * 1024) - 1)
mov qword [fs:globals.bamp_ends + rcx*8], rdx
add rsi, 0x20
inc ecx
cmp ecx, MAX_NODES
jb short .for_each_node
pop rsi
pop rdx
pop rcx
pop rbx
ret
; qwait
;
; Summary:
;
; This is a shitty spinloop used for delaying execution for INIT-SIPI-SIPIs
;
qwait:
push rcx
mov rcx, 1000000
.lewp:
dec rcx
jnz short .lewp
pop rcx
ret
boot_aps:
push rax
push rbx
; Send INIT
mov eax, 0x000C4500
mov ebx, 0xFEE00300
mov dword [rbx], eax
call qwait
; Send SIPI #1
mov eax, 0x000C4609
mov dword [rbx], eax
call qwait
; Send SIPI #2
mov dword [rbx], eax
call qwait
pop rbx
pop rax
ret
create_cephys:
push rax
push rcx
push rdi
mov rdi, 0x100102000
; Set up the 1GB PDPTEs for the cephys map
; Present, writable, page size
mov rax, 0x83 ; Low 32-bits
mov ecx, 512
.set1Gentry_cephys:
mov qword [rdi + 0], rax ; Low bits
add rax, (1 * 1024 * 1024 * 1024)
add rdi, 8
dec ecx
jnz short .set1Gentry_cephys
pop rdi
pop rcx
pop rax
ret
switch_cr3:
push rdi
mov rdi, 0x100100000
mov dword [rdi + 0x00], 0x00102003 ; cephys
mov dword [rdi + 0x04], 0x00000001 ; cephys high
mov dword [rdi + 0x08], 0x00102003 ; cephys
mov dword [rdi + 0x0c], 0x00000001 ; cephys high
mov dword [rdi + 0x10], 0x00103003 ; PNM node 0
mov dword [rdi + 0x14], 0x00000001 ; PNM node 0 high
mov dword [rdi + 0x18], 0x00104003 ; PNM node 1
mov dword [rdi + 0x1c], 0x00000001 ; PNM node 1 high
mov dword [rdi + 0x20], 0x00105003 ; PNM node 2
mov dword [rdi + 0x24], 0x00000001 ; PNM node 2 high
mov dword [rdi + 0x28], 0x00106003 ; PNM node 3
mov dword [rdi + 0x2c], 0x00000001 ; PNM node 3 high
mov dword [rdi + 0x30], 0x00107003 ; PNM node 4
mov dword [rdi + 0x34], 0x00000001 ; PNM node 4 high
mov dword [rdi + 0x38], 0x00108003 ; PNM node 5
mov dword [rdi + 0x3c], 0x00000001 ; PNM node 5 high
mov dword [rdi + 0x40], 0x00109003 ; PNM node 6
mov dword [rdi + 0x44], 0x00000001 ; PNM node 6 high
mov dword [rdi + 0x48], 0x0010a003 ; PNM node 7
mov dword [rdi + 0x4c], 0x00000001 ; PNM node 7 high
mov cr3, rdi
wbinvd
pop rdi
ret
create_relocated_idt:
push rax
push rbx
push rcx
push rdx
push rsi
push rbp
; Allocate room for the IDT and the entries
mov rbx, (256 * 16) + 8 + 2
bamp_alloc rbx
mov rsi, rbx
; Skip ahead past the actual IDT
add rbx, (8 + 2)
; Create the IDT structure
mov word [rbx - 0x0a], 4095 ; Limit
mov qword [rbx - 0x08], rbx ; Base
; Allocate room for the dispatchers
; 50 push rax
; 53 push rbx
; 48 b8 <imm64> mov rax, <vector number>
; 48 bb <imm64> mov rbx, <rel relocated_handler>
; ff e3 jmp rbx
mov rdx, ((1 + 1 + 10 + 10 + 2) * 256)
bamp_alloc rdx
; Install exception handlers, [0, 32)
lea rax, [rel relocated_handler]
xor ecx, ecx
.install_exception_handlers:
; Create the dispatcher
mov word [rdx + 0x00 + 0], 0x5350
mov word [rdx + 0x00 + 2], 0xb848
mov qword [rdx + 0x02 + 2], rcx
mov word [rdx + 0x0a + 2], 0xbb48
mov qword [rdx + 0x0c + 2], rax
mov word [rdx + 0x14 + 2], 0xe3ff
mov word [rbx + 0], dx ; offset 15..0
mov word [rbx + 2], 0x0008 ; Segment selector
mov byte [rbx + 4], 0x00 ; ist
mov byte [rbx + 5], 0x8E ; type
bextr rbp, rdx, 0x1010
mov word [rbx + 6], bp ; offset 31..16
bextr rbp, rdx, 0x2020
mov dword [rbx + 0x8], ebp ; offset 63..32
mov dword [rbx + 0xc], 0 ; reserved
add rdx, (1 + 1 + 10 + 10 + 2)
add rbx, 16
inc ecx
cmp ecx, 32
jl short .install_exception_handlers
; Install interrupt handlers, [32, 256)
mov rcx, 32
.install_interrupt_handlers:
imul rbx, rcx, 16
lea rdx, [rel user_handler]
mov word [rsi + (8 + 2) + rbx + 0x0], dx
mov word [rsi + (8 + 2) + rbx + 0x2], 0x0008
mov byte [rsi + (8 + 2) + rbx + 0x4], 0x00
mov byte [rsi + (8 + 2) + rbx + 0x5], 0x8E
bextr rbp, rdx, 0x1010
mov word [rsi + (8 + 2) + rbx + 0x6], bp
bextr rbp, rdx, 0x2020
mov dword [rsi + (8 + 2) + rbx + 0x8], ebp
mov dword [rsi + (8 + 2) + rbx + 0xc], 0
inc ecx
cmp ecx, 256
jl short .install_interrupt_handlers
; Install the node local IBS handler
lea rdx, [rel ibs_handler]
mov word [rsi + (8 + 2) + (16 * 0x2) + 0x0], dx
mov word [rsi + (8 + 2) + (16 * 0x2) + 0x2], 0x0008
mov byte [rsi + (8 + 2) + (16 * 0x2) + 0x4], 0x00
mov byte [rsi + (8 + 2) + (16 * 0x2) + 0x5], 0x8E
bextr rbp, rdx, 0x1010
mov word [rsi + (8 + 2) + (16 * 0x2) + 0x6], bp
bextr rbp, rdx, 0x2020
mov dword [rsi + (8 + 2) + (16 * 0x2) + 0x8], ebp
mov dword [rsi + (8 + 2) + (16 * 0x2) + 0xc], 0
; Program the IBS APIC vector to deliver NMIs
mov eax, 0xFEE00500
mov dword [eax], (4 << 8)
lidt [rsi]
pop rbp
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
ret
; rdx <- MMIO address for processor PCIE config space
amd_fam15h_fetch_pcie_mmio:
push rax
push rcx
; Get the MMIO address for the processor PCIE config space
mov ecx, 0xc0010058
rdmsr
shl rdx, 32
or rdx, rax
and rdx, ~0x3F
pop rcx
pop rax
ret
falkrand:
movdqu xmm15, [gs:thread_local.xs_seed]
aesenc xmm15, xmm15
movdqu [gs:thread_local.xs_seed], xmm15
ret
; rcx -> Lower bound
; rdx -> Upper bound
; rax <- Random number in range [lower, upper]
randexp:
push rdx
call randuni
mov rdx, rax
call randuni
pop rdx
ret
; rcx -> Lower bound
; rdx -> Upper bound
; rax <- Random number in range [lower, upper]
randuni:
push rdx
push rbp
push rsi
push r15
; Default to returning the lower bound
mov rax, rcx
; If the lower bound is greater than or equal to the upper bound, either
; there is no range, or the range is invalid, return the lower bound.
cmp rcx, rdx
jae short .done
; rbp <- Range
mov rbp, rdx
sub rbp, rcx
inc rbp
; Get the number of set bits in range. If only one bit is set, use a mask,
; otherwise, use a div.
popcnt rsi, rbp
cmp rsi, 1
jne short .use_div
.use_mask:
dec rbp ; Create mask
call xorshift64
and r15, rbp
lea rax, [rcx + r15]
jmp short .done
.use_div:
call xorshift64
xor rdx, rdx
mov rax, r15
div rbp
lea rax, [rcx + rdx]
.done:
pop r15
pop rsi
pop rbp
pop rdx
ret
xorshift64:
XMMPUSH xmm15
call falkrand
movq r15, xmm15
XMMPOP xmm15
ret
falkseed:
push rax
push rdx
XMMPUSH xmm15
pinsrq xmm15, rsp, 0
rdtsc
shl rdx, 32
or rdx, rax
bts rdx, 63
btr rdx, 62
pinsrq xmm15, rdx, 1
aesenc xmm15, xmm15
aesenc xmm15, xmm15
aesenc xmm15, xmm15
aesenc xmm15, xmm15
movdqu [gs:thread_local.xs_seed], xmm15
XMMPOP xmm15
pop rdx
pop rax
ret
init_lwp:
push rax
push rcx
push rdx
; Set up xcr0 to save all state (FPU, MMX, SSE, AVX, and LWP)
mov edx, 0x40000000
mov eax, 0x00000007
xor ecx, ecx
xsetbv
; Get the LWP features
mov eax, 0x8000001c
cpuid
; Write the LWP features to the LWP_CFG MSR
mov rax, rdx
xor rdx, rdx
mov ecx, 0xc0000105
wrmsr
pop rdx
pop rcx
pop rax
ret
lmland:
cli
xor ax, ax
mov es, ax
mov ds, ax
mov gs, ax
mov ss, ax
mov fs, ax
lidt [idt]
; Enable the IO APIC
mov ebx, 0xFEE000F0 ; Spurious Interrupt Vector Register
mov eax, dword [rbx]
or eax, 0x100
mov dword [rbx], eax
; Get a unique core ID
mov rax, 1
lock xadd qword [proc_id], rax
; Each core gets it's own quarter-line on the screen, obviously this would
; cause problems if there are more than 100 cores
imul rdi, rax, (40)
add rdi, 0xb8000
; Each core gets a unique 64kB stack
imul rsp, rax, 0x10000 ; 64kB stack per core
add rsp, 0x00504000
test rax, rax
jnz short .not_bsp
; We've entered LM as the BSP, we need to set up the PNM and start the
; APs
call create_cephys
call fetch_dram_info
call fetch_mmio_info
call init_pnm
call init_globals
call populate_globals
; Get the rdtsc increment frequency in MHz and store it
push rax
call amd_fam15h_sw_p0_freq
mov qword [fs:globals.rdtsc_freq], rax
pop rax
call i825xx_init
call x540_init
; Initialize the per_node_kern_code struct
mov qword [fs:globals.per_node_kern_code + node_struct.orig_data], boot_bsp
mov qword [fs:globals.per_node_kern_code + node_struct.data_len], kern_size
call boot_aps
.not_bsp:
; Set up the FS segment for this core
call init_globals
call init_per_core_storage
call init_lwp
push rax
; Get a copy of the kernel on this node
mov rbx, [fs:globals.fs_base]
lea rbx, [rbx + globals.per_node_kern_code]
mov rbx, [rbx + node_struct.orig_data]
pop rax
; Jump to the kernel code
add rbx, (.cores_init_bamp - boot_bsp)
jmp rbx
.cores_init_bamp:
; At this point we are relocated
; Allocate a 32MB stack from the BAMP
mov rbx, (1024 * 1024 * 32)
bamp_alloc rbx
add rbx, (1024 * 1024 * 32)
mov rsp, rbx
mov rbx, cr0
btr rbx, 30 ; Enable cache
btr rbx, 29 ; Enable write through
bts rbx, 5 ; Enable numeric error
mov cr0, rbx
; Increment the counter of number of cores up and relocated
mov rbx, 1
lock xadd qword [cores_reloc], rbx
; Wait for all cores to relocate
mov rbx, qword [num_cores]
.wait_for_reloc:
pause
cmp rbx, qword [cores_reloc]
jne short .wait_for_reloc
call switch_cr3
; Relocate the GDT
lea rbx, [rel gdt64]
lea rcx, [rel gdt64_base]
mov [rbx + 2], rcx
lgdt [rbx]
.next:
call falkseed
call x540_init_local_rx
call x540_init_local_tx
call i825xx_init_thread_local
call create_relocated_idt
; Jump to the actual program to run!
jmp program
|
Time and Date/Get Current Date.applescript | rogues-gallery/applescript | 360 | 4646 | <gh_stars>100-1000
set crrtdate to current date
set crrtdate to (current date) as Unicode text
|
libsrc/_DEVELOPMENT/stdio/c/sdcc_ix/putchar_fastcall.asm | meesokim/z88dk | 0 | 88403 |
; int putchar_fastcall(int c)
INCLUDE "clib_cfg.asm"
SECTION code_stdio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _putchar_fastcall
EXTERN asm_putchar
_putchar_fastcall:
push ix
call asm_putchar
pop ix
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC _putchar_fastcall
EXTERN _putchar_unlocked_fastcall
defc _putchar_fastcall = _putchar_unlocked_fastcall
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
complexity-drafts/Proofs.agda | benhuds/Agda | 2 | 3013 | <filename>complexity-drafts/Proofs.agda
{- Name: Bowornmet (<NAME>
-- define the source language from the paper
-}
open import Preliminaries
open import Preorder-withmax
module Proofs where
-- define the source language from the paper
-- we want to focus on arrow, cross, and nat types
data Tp : Set where
unit : Tp
nat : Tp
susp : Tp → Tp
_->s_ : Tp → Tp → Tp
_×s_ : Tp → Tp → Tp
data Cost : Set where
0c : Cost
1c : Cost
_+c_ : Cost → Cost → Cost
data Equals0c : Cost → Set where
Eq0-0c : Equals0c 0c
Eq0-+c : ∀ {c c'} → Equals0c c → Equals0c c' → Equals0c (c +c c')
-- represent a context as a list of types
Ctx = List Tp
-- de Bruijn indices (for free variables)
data _∈_ : Tp → Ctx → Set where
i0 : ∀ {Γ τ}
→ τ ∈ (τ :: Γ)
iS : ∀ {Γ τ τ1}
→ τ ∈ Γ
→ τ ∈ (τ1 :: Γ)
data _|-_ : Ctx → Tp → Set where
unit : ∀ {Γ}
→ Γ |- unit
var : ∀ {Γ τ}
→ τ ∈ Γ
→ Γ |- τ
z : ∀ {Γ}
→ Γ |- nat
suc : ∀ {Γ}
→ (e : Γ |- nat)
→ Γ |- nat
rec : ∀ {Γ τ}
→ Γ |- nat
→ Γ |- τ
→ (nat :: (susp τ :: Γ)) |- τ
→ Γ |- τ
lam : ∀ {Γ τ ρ}
→ (ρ :: Γ) |- τ
→ Γ |- (ρ ->s τ)
app : ∀ {Γ τ1 τ2}
→ Γ |- (τ2 ->s τ1)
→ Γ |- τ2
→ Γ |- τ1
prod : ∀ {Γ τ1 τ2}
→ Γ |- τ1
→ Γ |- τ2
→ Γ |- (τ1 ×s τ2)
l-proj : ∀ {Γ τ1 τ2}
→ Γ |- (τ1 ×s τ2)
→ Γ |- τ1
r-proj : ∀ {Γ τ1 τ2}
→ Γ |- (τ1 ×s τ2)
→ Γ |- τ2
-- include split, delay/susp/force instead of usual elim rules for products
delay : ∀ {Γ τ}
→ Γ |- τ
→ Γ |- susp τ
force : ∀ {Γ τ}
→ Γ |- susp τ
→ Γ |- τ
split : ∀ {Γ τ τ1 τ2}
→ Γ |- (τ1 ×s τ2)
→ (τ1 :: (τ2 :: Γ)) |- τ
→ Γ |- τ
------weakening and substitution lemmas
-- renaming function
rctx : Ctx → Ctx → Set
rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ
-- re: transferring variables in contexts
lem1 : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ')
lem1 d i0 = i0
lem1 d (iS x) = iS (d x)
-- renaming lemma
ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ
ren unit d = unit
ren (var x) d = var (d x)
ren z d = z
ren (suc e) d = suc (ren e d)
ren (rec e e0 e1) d = rec (ren e d) (ren e0 d) (ren e1 (lem1 (lem1 d)))
ren (lam e) d = lam (ren e (lem1 d))
ren (app e1 e2) d = app (ren e1 d) (ren e2 d)
ren (prod e1 e2) d = prod (ren e1 d) (ren e2 d)
ren (l-proj e) d = l-proj (ren e d)
ren (r-proj e) d = r-proj (ren e d)
ren (delay e) d = delay (ren e d)
ren (force e) d = force (ren e d)
ren (split e e1) d = split (ren e d) (ren e1 (lem1 (lem1 d)))
-- substitution
sctx : Ctx → Ctx → Set
sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ
-- weakening a context
wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2
wkn e = ren e iS
-- weakening also works with substitution
wkn-s : ∀ {Γ τ1 Γ'} → sctx Γ Γ' → sctx (τ1 :: Γ) Γ'
wkn-s d = λ f → wkn (d f)
wkn-r : ∀ {Γ τ1 Γ'} → rctx Γ Γ' → rctx (τ1 :: Γ) Γ'
wkn-r d = λ x → iS (d x)
-- lem2 (need a lemma for subst like we did for renaming)
lem2 : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ')
lem2 d i0 = var i0
lem2 d (iS i) = wkn (d i)
-- another substitution lemma
lem3 : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ)
lem3 e i0 = e
lem3 e (iS i) = var i
lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ')
lem3' Θ e i0 = e
lem3' Θ e (iS i) = Θ i
-- one final lemma needed for the last stepping rule. Thank you Professor Licata!
lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ))
lem4 e1 e2 i0 = e1
lem4 e1 e2 (iS i0) = e2
lem4 e1 e2 (iS (iS i)) = var i
lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ'))
lem4' Θ a b i0 = a
lem4' Θ a b (iS i0) = b
lem4' Θ a b (iS (iS i)) = Θ i
lem5 : ∀ {Γ τ1 τ2} → Γ |- (τ1 ×s τ2) → sctx Γ ((τ1 ×s τ2) :: (τ1 :: (τ2 :: Γ)))
lem5 e i0 = e
lem5 e (iS i0) = l-proj e
lem5 e (iS (iS i0)) = r-proj e
lem5 e (iS (iS (iS i))) = var i
-- the 'real' substitution lemma (if (x : τ') :: Γ |- (e : τ) and Γ |- (e : τ') , then Γ |- e[x -> e'] : τ)
subst : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ' |- τ → Γ |- τ
subst d unit = unit
subst d (var x) = d x
subst d z = z
subst d (suc x) = suc (subst d x)
subst d (rec e e0 e1) = rec (subst d e) (subst d e0) (subst (lem2 (lem2 d)) e1)
subst d (lam e) = lam (subst (lem2 d) e)
subst d (app e1 e2) = app (subst d e1) (subst d e2)
subst d (prod e1 e2) = prod (subst d e1) (subst d e2)
subst d (l-proj e) = l-proj (subst d e)
subst d (r-proj e) = r-proj (subst d e)
subst d (delay e) = delay (subst d e)
subst d (force e) = force (subst d e)
subst d (split e e1) = split (subst d e) (subst (lem2 (lem2 d)) e1)
subst-compose : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) )
→ subst (lem3 v) (subst (lem2 Θ) e) == subst (lem3' Θ v) e
subst-compose Θ unit e = {!!}
subst-compose Θ (var x) e = {!!}
subst-compose Θ z e = {!!}
subst-compose Θ (suc v) e = {!!}
subst-compose Θ (rec v v₁ v₂) e = {!!}
subst-compose Θ (lam v) e = {!!}
subst-compose Θ (app v v₁) e = {!!}
subst-compose Θ (prod v v₁) e = {!!}
subst-compose Θ (l-proj v) e = {!!}
subst-compose Θ (r-proj v) e = {!!}
subst-compose Θ (delay v) e = {!!}
subst-compose Θ (force v) e = {!!}
subst-compose Θ (split v v₁) e = {!!}
|
Cubical/Foundations/CartesianKanOps.agda | cj-xu/cubical | 0 | 9322 | -- This file derives some of the Cartesian Kan operations using transp
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.CartesianKanOps where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
coe0→1 : ∀ {ℓ} (A : I → Type ℓ) → A i0 → A i1
coe0→1 A a = transp A i0 a
-- "coe filler"
coe0→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i0 → A i
coe0→i A i a = transp (λ j → A (i ∧ j)) (~ i) a
-- Check the equations for the coe filler
coe0→i1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coe0→i A i1 a ≡ coe0→1 A a
coe0→i1 A a = refl
coe0→i0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coe0→i A i0 a ≡ a
coe0→i0 A a = refl
-- coe backwards
coe1→0 : ∀ {ℓ} (A : I → Type ℓ) → A i1 → A i0
coe1→0 A a = transp (λ i → A (~ i)) i0 a
-- coe backwards filler
coe1→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i1 → A i
coe1→i A i a = transp (λ j → A (i ∨ ~ j)) i a
-- Check the equations for the coe backwards filler
coe1→i0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coe1→i A i0 a ≡ coe1→0 A a
coe1→i0 A a = refl
coe1→i1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coe1→i A i1 a ≡ a
coe1→i1 A a = refl
-- "squeezeNeg"
coei→0 : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i → A i0
coei→0 A i a = transp (λ j → A (i ∧ ~ j)) (~ i) a
coei0→0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coei→0 A i0 a ≡ a
coei0→0 A a = refl
coei1→0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coei→0 A i1 a ≡ coe1→0 A a
coei1→0 A a = refl
-- "master coe"
-- defined as the filler of coei→0, coe0→i, and coe1→i
-- unlike in cartesian cubes, we don't get coei→i = id definitionally
coei→j : ∀ {ℓ} (A : I → Type ℓ) (i j : I) → A i → A j
coei→j A i j a =
fill A
(λ j → λ { (i = i0) → coe0→i A j a
; (i = i1) → coe1→i A j a
})
(inS (coei→0 A i a))
j
-- "squeeze"
-- this is just defined as the composite face of the master coe
coei→1 : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i → A i1
coei→1 A i a = coei→j A i i1 a
coei0→1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coei→1 A i0 a ≡ coe0→1 A a
coei0→1 A a = refl
coei1→1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coei→1 A i1 a ≡ a
coei1→1 A a = refl
-- equations for "master coe"
coei→i0 : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i) → coei→j A i i0 a ≡ coei→0 A i a
coei→i0 A i a = refl
coei0→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i0) → coei→j A i0 i a ≡ coe0→i A i a
coei0→i A i a = refl
coei→i1 : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i) → coei→j A i i1 a ≡ coei→1 A i a
coei→i1 A i a = refl
coei1→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i1) → coei→j A i1 i a ≡ coe1→i A i a
coei1→i A i a = refl
-- only non-definitional equation
coei→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i) → coei→j A i i a ≡ a
coei→i A i = coe0→i (λ i → (a : A i) → coei→j A i i a ≡ a) i (λ _ → refl)
-- do the same for fill
fill1→i : ∀ {ℓ} (A : ∀ i → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(u1 : A i1 [ φ ↦ u i1 ])
---------------------------
(i : I) → A i
fill1→i A {φ = φ} u u1 i =
comp (λ j → A (i ∨ ~ j))
(λ j → λ { (φ = i1) → u (i ∨ ~ j) 1=1
; (i = i1) → outS u1 })
(outS u1)
filli→0 : ∀ {ℓ} (A : ∀ i → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(i : I)
(ui : A i [ φ ↦ u i ])
---------------------------
→ A i0
filli→0 A {φ = φ} u i ui =
comp (λ j → A (i ∧ ~ j))
(λ j → λ { (φ = i1) → u (i ∧ ~ j) 1=1
; (i = i0) → outS ui })
(outS ui)
filli→j : ∀ {ℓ} (A : ∀ i → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(i : I)
(ui : A i [ φ ↦ u i ])
---------------------------
(j : I) → A j
filli→j A {φ = φ} u i ui j =
fill A
(λ j → λ { (φ = i1) → u j 1=1
; (i = i0) → fill A u ui j
; (i = i1) → fill1→i A u ui j
})
(inS (filli→0 A u i ui))
j
-- We can reconstruct fill from hfill, coei→j, and the path coei→i ≡ id.
-- The definition does not rely on the computational content of the coei→i path.
fill' : ∀ {ℓ} (A : I → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(u0 : A i0 [ φ ↦ u i0 ])
---------------------------
(i : I) → A i [ φ ↦ u i ]
fill' A {φ = φ} u u0 i =
inS (hcomp (λ j → λ {(φ = i1) → coei→i A i (u i 1=1) j; (i = i0) → coei→i A i (outS u0) j}) t)
where
t : A i
t = hfill {φ = φ} (λ j v → coei→j A j i (u j v)) (inS (coe0→i A i (outS u0))) i
fill'-cap : ∀ {ℓ} (A : I → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(u0 : A i0 [ φ ↦ u i0 ])
---------------------------
→ outS (fill' A u u0 i0) ≡ outS (u0)
fill'-cap A u u0 = refl
|
thirdparty/adasdl/thin/adasdl/AdaGL/GL_x11/adagl.adb | Lucretia/old_nehe_ada95 | 0 | 30013 | <filename>thirdparty/adasdl/thin/adasdl/AdaGL/GL_x11/adagl.adb
-- ---------------------------------------------------------------- --
-- This file contains some improvements to the gl Ada binding --
-- in order to allow a better programming style. --
-- The prototypes below follow the Implementation advice from --
-- ARM Annex B (B.3). --
-- ---------------------------------------------------------------- --
-- ----------------------------------------------------------------- --
-- Copyright (C) 2001 A.M.F.Vargas --
-- <NAME> --
-- <NAME> - Azores - Portugal --
-- http://www.adapower.net/~avargas --
-- E-mail: <EMAIL> --
-- ----------------------------------------------------------------- --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public --
-- License as published by the Free Software Foundation; either --
-- version 2 of the License, or (at your option) any later version. --
-- --
-- This library is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public --
-- License along with this library; if not, write to the --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330, --
-- Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
-- ----------------------------------------------------------------- --
with Interfaces.C.Strings;
use Interfaces.C.Strings;
with Ada.Unchecked_Conversion;
package body AdaGL is
package CS renames Interfaces.C.Strings;
function To_chars_ptr is new Ada.Unchecked_Conversion (
GLubyte_Ptr, CS.chars_ptr);
-- ======================================
function Get_chars_ptr (Chars_Ref : GLenum) return CS.chars_ptr is
begin
return To_chars_ptr (glGetString (Chars_Ref));
end Get_chars_ptr;
-- ======================================
function glGetString (Chars_Ref : GLenum) return String is
temp_chars_ptr : CS.chars_ptr;
begin
temp_chars_ptr := Get_chars_ptr (Chars_ref);
if temp_chars_ptr /= Cs.Null_Ptr then
return CS.Value (Get_chars_ptr (Chars_Ref));
else
return "";
end if;
end glGetString;
-- ======================================
end AdaGL;
|
src/pw.ads | ventaquil/PW-Ada | 0 | 1456 | <filename>src/pw.ads
package PW is
task type Semaphore is
entry Initialize(N : in Natural);
entry Wait;
entry Signal;
entry Try(Success : out Boolean);
end Semaphore;
type SemaphoreAccess is access Semaphore;
task PlaceSemaphore is
entry Wait;
entry Signal;
end PlaceSemaphore;
task PrinterSemaphore is
entry Wait;
entry Signal;
end PrinterSemaphore;
type Car is
record
Number : Integer;
ToDistributor : Integer;
InDistributor : Integer;
GoToExit : Boolean;
end record;
task type CarAction is
entry Construct(Cr : Car);
end CarAction;
type CarActionAccess is access CarAction;
function CarConstructor(Number : Integer; ca : CarActionAccess) return Car;
type Distributor is tagged
record
S : SemaphoreAccess;
end record;
procedure Initialize(D : in out Distributor);
type DistributorCollectionArray is array(1..3) of Distributor;
type DistributorCollection is tagged
record
DC : DistributorCollectionArray;
end record;
procedure Initialize(DC : in out DistributorCollection);
function FindEmptyDistributor(DC : in DistributorCollection) return Integer;
type QueueArray is array(1..3) of Car;
type EntryQueue is
record
Queue : QueueArray;
FirstIndex, LastIndex : Integer := 0;
end record;
procedure Put(q : in out EntryQueue; c : in Car);
procedure Pop(q : in out EntryQueue; c : out Car);
procedure GetFirst(q : in out EntryQueue; c : out Car);
function Size(q : EntryQueue) return Integer;
task SpawnCar;
task Data is
entry SendDC(DC : in DistributorCollection);
entry GetDC(DC : out DistributorCollection);
entry SendQueue(Q : in EntryQueue);
entry GetQueue(Q : out EntryQueue);
end Data;
end PW;
|
Transynther/x86/_processed/AVXALIGN/_zr_/i9-9900K_12_0xa0_notsx.log_21829_1048.asm | ljhsiun2/medusa | 9 | 243513 | <filename>Transynther/x86/_processed/AVXALIGN/_zr_/i9-9900K_12_0xa0_notsx.log_21829_1048.asm
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0xb102, %rsi
lea addresses_A_ht+0x1d552, %rdi
xor %r9, %r9
mov $63, %rcx
rep movsb
nop
nop
nop
nop
and $23788, %rax
lea addresses_normal_ht+0x9efa, %rsi
lea addresses_WT_ht+0x2, %rdi
nop
nop
nop
nop
cmp %r12, %r12
mov $121, %rcx
rep movsb
nop
nop
sub %rdi, %rdi
lea addresses_WC_ht+0x1bb82, %rsi
lea addresses_UC_ht+0x11882, %rdi
nop
nop
sub $52756, %r12
mov $42, %rcx
rep movsl
nop
nop
nop
nop
nop
add %rcx, %rcx
lea addresses_UC_ht+0x3502, %rsi
lea addresses_A_ht+0xdb02, %rdi
clflush (%rsi)
and $33110, %r11
mov $71, %rcx
rep movsb
nop
nop
xor %r11, %r11
lea addresses_WT_ht+0x3d82, %r11
and %r12, %r12
mov $0x6162636465666768, %rdi
movq %rdi, %xmm6
vmovups %ymm6, (%r11)
nop
nop
nop
nop
sub $64304, %rsi
lea addresses_WT_ht+0x19302, %r12
nop
nop
nop
nop
nop
cmp $30127, %r9
mov (%r12), %rdi
nop
nop
nop
nop
cmp $7656, %rdi
lea addresses_normal_ht+0x17e02, %rsi
lea addresses_normal_ht+0x5b02, %rdi
nop
nop
nop
nop
nop
sub $22052, %r13
mov $124, %rcx
rep movsq
cmp $1447, %r9
lea addresses_UC_ht+0x1d25a, %r11
dec %rcx
and $0xffffffffffffffc0, %r11
vmovntdqa (%r11), %ymm2
vextracti128 $1, %ymm2, %xmm2
vpextrq $1, %xmm2, %rdi
nop
nop
nop
nop
nop
xor $55312, %rax
lea addresses_A_ht+0x9772, %rsi
lea addresses_UC_ht+0x4dc0, %rdi
cmp $14203, %rax
mov $31, %rcx
rep movsb
nop
nop
nop
cmp %rcx, %rcx
lea addresses_D_ht+0x1d202, %rsi
nop
xor %r13, %r13
movb (%rsi), %r12b
inc %r12
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r9
push %rax
push %rcx
push %rdx
push %rsi
// Store
lea addresses_UC+0xb8b2, %rax
nop
inc %rdx
mov $0x5152535455565758, %rcx
movq %rcx, %xmm1
movups %xmm1, (%rax)
nop
nop
nop
dec %rsi
// Store
mov $0x34e, %rax
cmp %r9, %r9
movb $0x51, (%rax)
nop
sub $14846, %r11
// Faulty Load
lea addresses_A+0x6b02, %r9
nop
nop
nop
nop
nop
and %rax, %rax
movntdqa (%r9), %xmm6
vpextrq $0, %xmm6, %rcx
lea oracles, %r12
and $0xff, %rcx
shlq $12, %rcx
mov (%r12,%rcx,1), %rcx
pop %rsi
pop %rdx
pop %rcx
pop %rax
pop %r9
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_A', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'AVXalign': False, 'size': 16, 'NT': False, 'same': False, 'congruent': 3}}
{'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 1}}
[Faulty Load]
{'src': {'type': 'addresses_A', 'AVXalign': False, 'size': 16, 'NT': True, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}}
{'src': {'type': 'addresses_normal_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}}
{'src': {'type': 'addresses_WC_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}}
{'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 7}}
{'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 8}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 8, 'same': True}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}}
{'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 32, 'NT': True, 'same': False, 'congruent': 2}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}}
{'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 6}, 'OP': 'LOAD'}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
MASM_Practice/44_Jump_xorEncrypt.asm | TuringGu/RELearning | 0 | 86639 | .586
.MODEL flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include msvcrt.inc
includelib user32.lib
includelib kernel32.lib
includelib msvcrt.lib
.data
key db 10
source byte "who am i?",0
sourcesize = ($ - source) - 1
.code
;XOR Encrypt & Decrypt
;esi: array address
;ecx: array length
xor_encrypt proc uses esi ecx
mov eax,0 ;Initial
jnz01:
mov al,[esi]
xor al,key
mov [esi],al
inc esi ;next element
dec ecx
cmp ecx,0
jnz jnz01
ret
xor_encrypt endp
; a xor b xor b == a
main PROC
;Encrypt
mov esi,offset source
mov ecx,sourcesize
push esi
push ecx
call xor_encrypt
;Decrypt
mov esi,offset source
mov ecx,sourcesize
push esi
push ecx
call xor_encrypt
;Exit
push 0
call ExitProcess
add esp,4
main ENDP
END main
|
generated/natools-static_maps-web-comments.ads | faelys/natools-web | 1 | 24892 | -- Generated at 2017-04-30 21:14:26 +0000 by Natools.Static_Hash_Maps
-- from src/natools-web-comments-maps.sx
package Natools.Static_Maps.Web.Comments is
pragma Pure;
package Item is
package Command is
type Enum is (Unknown, Date, Id, Parent, Rank);
end Command;
package Condition is
type Enum is
(Unknown,
Field_List_Is, Field_List_Contains, Field_List_Among, Fields_Equal,
Has_Extra_Fields, Has_Unknown_Field, Action_Is);
end Condition;
package Element is
type Enum is (Unknown, Date, Flags);
end Element;
package Form is
type Enum is (Unknown, Cookie_Save, Date, Filter, Atom);
end Form;
package Post_Action is
type Enum is
(Unknown, Save, Force_Preview, Force_Redirect, Reject, Dump,
Reason, Append_Reason, Set_Reason, Ignore, Unignore, Anchor);
end Post_Action;
end Item;
package List is
package Command is
type Enum is
(Unknown, List, Preview, Size, Parent, If_Closed, If_Not_Closed);
end Command;
package Element is
type Enum is
(Unknown, Backend, Post_Filter, Tags,
Default_Text_Filter, Text_Filters, Flags);
end Element;
end List;
function To_Item_Command (Key : String) return Item.Command.Enum;
function To_Item_Condition (Key : String) return Item.Condition.Enum;
function To_Item_Element (Key : String) return Item.Element.Enum;
function To_Item_Form (Key : String) return Item.Form.Enum;
function To_Item_Action (Key : String) return Item.Post_Action.Enum;
function To_List_Command (Key : String) return List.Command.Enum;
function To_List_Element (Key : String) return List.Element.Enum;
private
Map_1_Key_0 : aliased constant String := "date";
Map_1_Key_1 : aliased constant String := "id";
Map_1_Key_2 : aliased constant String := "parent";
Map_1_Key_3 : aliased constant String := "rank";
Map_1_Keys : constant array (0 .. 3) of access constant String
:= (Map_1_Key_0'Access,
Map_1_Key_1'Access,
Map_1_Key_2'Access,
Map_1_Key_3'Access);
Map_1_Elements : constant array (0 .. 3) of Item.Command.Enum
:= (Item.Command.Date,
Item.Command.Id,
Item.Command.Parent,
Item.Command.Rank);
Map_2_Key_0 : aliased constant String := "action-is";
Map_2_Key_1 : aliased constant String := "action-is-any-of";
Map_2_Key_2 : aliased constant String := "field-list-is";
Map_2_Key_3 : aliased constant String := "field-list-contains";
Map_2_Key_4 : aliased constant String := "field-list-among";
Map_2_Key_5 : aliased constant String := "fields-equal";
Map_2_Key_6 : aliased constant String := "has-extra-field";
Map_2_Key_7 : aliased constant String := "has-extra-fields";
Map_2_Key_8 : aliased constant String := "has-unknown-field";
Map_2_Key_9 : aliased constant String := "has-unknown-fields";
Map_2_Keys : constant array (0 .. 9) of access constant String
:= (Map_2_Key_0'Access,
Map_2_Key_1'Access,
Map_2_Key_2'Access,
Map_2_Key_3'Access,
Map_2_Key_4'Access,
Map_2_Key_5'Access,
Map_2_Key_6'Access,
Map_2_Key_7'Access,
Map_2_Key_8'Access,
Map_2_Key_9'Access);
Map_2_Elements : constant array (0 .. 9) of Item.Condition.Enum
:= (Item.Condition.Action_Is,
Item.Condition.Action_Is,
Item.Condition.Field_List_Is,
Item.Condition.Field_List_Contains,
Item.Condition.Field_List_Among,
Item.Condition.Fields_Equal,
Item.Condition.Has_Extra_Fields,
Item.Condition.Has_Extra_Fields,
Item.Condition.Has_Unknown_Field,
Item.Condition.Has_Unknown_Field);
Map_3_Key_0 : aliased constant String := "date";
Map_3_Key_1 : aliased constant String := "flags";
Map_3_Keys : constant array (0 .. 1) of access constant String
:= (Map_3_Key_0'Access,
Map_3_Key_1'Access);
Map_3_Elements : constant array (0 .. 1) of Item.Element.Enum
:= (Item.Element.Date,
Item.Element.Flags);
Map_4_Key_0 : aliased constant String := "c_cookie";
Map_4_Key_1 : aliased constant String := "c_date";
Map_4_Key_2 : aliased constant String := "c_filter";
Map_4_Key_3 : aliased constant String := "c_name";
Map_4_Key_4 : aliased constant String := "c_note";
Map_4_Key_5 : aliased constant String := "c_mail";
Map_4_Key_6 : aliased constant String := "c_link";
Map_4_Key_7 : aliased constant String := "c_text";
Map_4_Key_8 : aliased constant String := "c_title";
Map_4_Keys : constant array (0 .. 8) of access constant String
:= (Map_4_Key_0'Access,
Map_4_Key_1'Access,
Map_4_Key_2'Access,
Map_4_Key_3'Access,
Map_4_Key_4'Access,
Map_4_Key_5'Access,
Map_4_Key_6'Access,
Map_4_Key_7'Access,
Map_4_Key_8'Access);
Map_4_Elements : constant array (0 .. 8) of Item.Form.Enum
:= (Item.Form.Cookie_Save,
Item.Form.Date,
Item.Form.Filter,
Item.Form.Atom,
Item.Form.Atom,
Item.Form.Atom,
Item.Form.Atom,
Item.Form.Atom,
Item.Form.Atom);
Map_5_Key_0 : aliased constant String := "anchor";
Map_5_Key_1 : aliased constant String := "no-anchor";
Map_5_Key_2 : aliased constant String := "append-reason";
Map_5_Key_3 : aliased constant String := "add-reason";
Map_5_Key_4 : aliased constant String := "dump";
Map_5_Key_5 : aliased constant String := "log";
Map_5_Key_6 : aliased constant String := "write";
Map_5_Key_7 : aliased constant String := "preview";
Map_5_Key_8 : aliased constant String := "force-preview";
Map_5_Key_9 : aliased constant String := "redirect";
Map_5_Key_10 : aliased constant String := "force-redirect";
Map_5_Key_11 : aliased constant String := "ignore";
Map_5_Key_12 : aliased constant String := "reason";
Map_5_Key_13 : aliased constant String := "reject";
Map_5_Key_14 : aliased constant String := "accept";
Map_5_Key_15 : aliased constant String := "save";
Map_5_Key_16 : aliased constant String := "set-reason";
Map_5_Key_17 : aliased constant String := "reset-reason";
Map_5_Key_18 : aliased constant String := "unignore";
Map_5_Keys : constant array (0 .. 18) of access constant String
:= (Map_5_Key_0'Access,
Map_5_Key_1'Access,
Map_5_Key_2'Access,
Map_5_Key_3'Access,
Map_5_Key_4'Access,
Map_5_Key_5'Access,
Map_5_Key_6'Access,
Map_5_Key_7'Access,
Map_5_Key_8'Access,
Map_5_Key_9'Access,
Map_5_Key_10'Access,
Map_5_Key_11'Access,
Map_5_Key_12'Access,
Map_5_Key_13'Access,
Map_5_Key_14'Access,
Map_5_Key_15'Access,
Map_5_Key_16'Access,
Map_5_Key_17'Access,
Map_5_Key_18'Access);
Map_5_Elements : constant array (0 .. 18) of Item.Post_Action.Enum
:= (Item.Post_Action.Anchor,
Item.Post_Action.Anchor,
Item.Post_Action.Append_Reason,
Item.Post_Action.Append_Reason,
Item.Post_Action.Dump,
Item.Post_Action.Dump,
Item.Post_Action.Dump,
Item.Post_Action.Force_Preview,
Item.Post_Action.Force_Preview,
Item.Post_Action.Force_Redirect,
Item.Post_Action.Force_Redirect,
Item.Post_Action.Ignore,
Item.Post_Action.Reason,
Item.Post_Action.Reject,
Item.Post_Action.Save,
Item.Post_Action.Save,
Item.Post_Action.Set_Reason,
Item.Post_Action.Set_Reason,
Item.Post_Action.Unignore);
Map_6_Key_0 : aliased constant String := "if-closed";
Map_6_Key_1 : aliased constant String := "if-not-closed";
Map_6_Key_2 : aliased constant String := "list";
Map_6_Key_3 : aliased constant String := "parent";
Map_6_Key_4 : aliased constant String := "preview";
Map_6_Key_5 : aliased constant String := "size";
Map_6_Key_6 : aliased constant String := "length";
Map_6_Keys : constant array (0 .. 6) of access constant String
:= (Map_6_Key_0'Access,
Map_6_Key_1'Access,
Map_6_Key_2'Access,
Map_6_Key_3'Access,
Map_6_Key_4'Access,
Map_6_Key_5'Access,
Map_6_Key_6'Access);
Map_6_Elements : constant array (0 .. 6) of List.Command.Enum
:= (List.Command.If_Closed,
List.Command.If_Not_Closed,
List.Command.List,
List.Command.Parent,
List.Command.Preview,
List.Command.Size,
List.Command.Size);
Map_7_Key_0 : aliased constant String := "backend";
Map_7_Key_1 : aliased constant String := "default-text-filter";
Map_7_Key_2 : aliased constant String := "flags";
Map_7_Key_3 : aliased constant String := "post-filter";
Map_7_Key_4 : aliased constant String := "filter";
Map_7_Key_5 : aliased constant String := "tags";
Map_7_Key_6 : aliased constant String := "allowed-filters";
Map_7_Key_7 : aliased constant String := "text-filters";
Map_7_Keys : constant array (0 .. 7) of access constant String
:= (Map_7_Key_0'Access,
Map_7_Key_1'Access,
Map_7_Key_2'Access,
Map_7_Key_3'Access,
Map_7_Key_4'Access,
Map_7_Key_5'Access,
Map_7_Key_6'Access,
Map_7_Key_7'Access);
Map_7_Elements : constant array (0 .. 7) of List.Element.Enum
:= (List.Element.Backend,
List.Element.Default_Text_Filter,
List.Element.Flags,
List.Element.Post_Filter,
List.Element.Post_Filter,
List.Element.Tags,
List.Element.Text_Filters,
List.Element.Text_Filters);
end Natools.Static_Maps.Web.Comments;
|
libsrc/stdio/c128/getk.asm | dex4er/deb-z88dk | 1 | 26389 | <filename>libsrc/stdio/c128/getk.asm
;
; Keyboard routines for the Commodore 128 (Z80 mode)
; By <NAME> - 27/08/2001
;
; getk() Read key status
;
; $Id: getk.asm,v 1.2 2002/04/17 21:30:26 dom Exp $
;
XLIB getk
.getk
ld hl,keytab
ld de,8
ld a,@01111111
ld bc,$dc00
.kloop1
out (c),a
ld e,a
inc bc
in a,(c)
dec bc
cp 255
jr nz,scanline
ld a,e
scf
rra
jr nc,nokey
ld e,8
add hl,de
jr kloop1
.scanline
rla
jr nc,readtab
inc hl
jr scanline
.readtab
ld a,(hl)
jr done
.nokey
xor a
.done
ld h,0
ld l,a
ret
.keytab
defb 3,'Q','c',' ','2','c','a','1'
defb '/','^','=','r','h',';','*','_'
defb ',','@',':','.','-','L','P','+'
defb 'N','O','K','M','0','J','I','9'
defb 'V','U','H','B','8','G','Y','7'
defb 'X','T','F','C','6','D','R','5'
defb 'l','E','S','Z','4','A','W','3'
defb '_','5','3','1','7','_', 13, 12
|
run/programs/const.asm | thecodewarrior/KotlinToyCPU | 0 | 97291 | NOP
CONST_Z R0 true
CONST_B R1 -0x10
CONST_BU R2 0xF0
CONST_S R3 -0xF0F
CONST_SU R4 0xF00F
CONST_I R5 -0x100FF00F
CONST_IU R6 0xF00FF00F
CONST_L R7 -0x100FF00FF00FF00F
CONST_LU R8 0xF00FF00FF00FF00F
CONST_F R9 3.141592
CONST_D R10 3.141592
HALT
|
Transynther/x86/_processed/AVXALIGN/_st_sm_/i7-7700_9_0x48_notsx.log_21829_1650.asm | ljhsiun2/medusa | 9 | 240880 | .global s_prepare_buffers
s_prepare_buffers:
push %r13
push %rbp
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WT_ht+0xfc5b, %rsi
lea addresses_normal_ht+0xe05b, %rdi
nop
nop
dec %rbp
mov $11, %rcx
rep movsb
nop
nop
nop
nop
and $29358, %r13
lea addresses_UC_ht+0x1545b, %rbx
clflush (%rbx)
nop
nop
add $27738, %rdx
movups (%rbx), %xmm2
vpextrq $0, %xmm2, %rbp
add $3151, %rbx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r14
push %r8
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
// Store
lea addresses_D+0x1d65b, %rsi
nop
nop
cmp %r14, %r14
movw $0x5152, (%rsi)
nop
sub $62115, %rbx
// Store
lea addresses_A+0xe15b, %rcx
nop
nop
and $458, %rbp
mov $0x5152535455565758, %r14
movq %r14, (%rcx)
nop
nop
nop
nop
nop
sub %rbx, %rbx
// Store
lea addresses_UC+0x1dd1b, %r8
nop
nop
nop
nop
nop
add $34108, %rsi
movw $0x5152, (%r8)
add $28051, %rbp
// Store
lea addresses_WC+0xb323, %r8
nop
inc %rbp
mov $0x5152535455565758, %rcx
movq %rcx, %xmm2
movups %xmm2, (%r8)
nop
sub %rbp, %rbp
// REPMOV
lea addresses_D+0x1d65b, %rsi
lea addresses_PSE+0xb55b, %rdi
nop
nop
nop
nop
sub $21034, %r9
mov $77, %rcx
rep movsl
nop
dec %r14
// Faulty Load
lea addresses_D+0x1d65b, %rdi
nop
nop
cmp $29423, %rbp
mov (%rdi), %r14w
lea oracles, %rdi
and $0xff, %r14
shlq $12, %r14
mov (%rdi,%r14,1), %r14
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r8
pop %r14
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_D', 'congruent': 0}}
{'dst': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_D', 'congruent': 0}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_A', 'congruent': 8}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_UC', 'congruent': 6}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WC', 'congruent': 2}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 8, 'type': 'addresses_PSE'}, 'OP': 'REPM', 'src': {'same': True, 'congruent': 0, 'type': 'addresses_D'}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': True, 'size': 2, 'type': 'addresses_D', 'congruent': 0}}
<gen_prepare_buffer>
{'dst': {'same': False, 'congruent': 9, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 9, 'type': 'addresses_WT_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC_ht', 'congruent': 8}}
{'52': 21829}
52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52
*/
|
tools/scitools/conf/understand/ada/ada12/s-secsta.ads | brucegua/moocos | 1 | 13585 | <filename>tools/scitools/conf/understand/ada/ada12/s-secsta.ads
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . S E C O N D A R Y _ S T A C K --
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
pragma Compiler_Unit;
with System.Storage_Elements;
package System.Secondary_Stack is
package SSE renames System.Storage_Elements;
Default_Secondary_Stack_Size : Natural := 10 * 1024;
-- Default size of a secondary stack. May be modified by binder -D switch
-- which causes the binder to generate an appropriate assignment in the
-- binder generated file.
procedure SS_Init
(Stk : in out Address;
Size : Natural := Default_Secondary_Stack_Size);
-- Initialize the secondary stack with a main stack of the given Size.
--
-- If System.Parameters.Sec_Stack_Percentage equals Dynamic, Stk is really
-- an OUT parameter that will be allocated on the heap. Then all further
-- allocations which do not overflow the main stack will not generate
-- dynamic (de)allocation calls. If the main Stack overflows, a new
-- chuck of at least the same size will be allocated and linked to the
-- previous chunk.
--
-- Otherwise (Sec_Stack_Percentage between 0 and 100), Stk is an IN
-- parameter that is already pointing to a Stack_Id. The secondary stack
-- in this case is fixed, and any attempt to allocate more than the initial
-- size will result in a Storage_Error being raised.
--
-- Note: the reason that Stk is passed is that SS_Init is called before
-- the proper interface is established to obtain the address of the
-- stack using System.Soft_Links.Get_Sec_Stack_Addr.
procedure SS_Allocate
(Addr : out Address;
Storage_Size : SSE.Storage_Count);
-- Allocate enough space for a 'Storage_Size' bytes object with Maximum
-- alignment. The address of the allocated space is returned in Addr.
procedure SS_Free (Stk : in out Address);
-- Release the memory allocated for the Secondary Stack. That is
-- to say, all the allocated chunks. Upon return, Stk will be set
-- to System.Null_Address.
type Mark_Id is private;
-- Type used to mark the stack for mark/release processing
function SS_Mark return Mark_Id;
-- Return the Mark corresponding to the current state of the stack
procedure SS_Release (M : Mark_Id);
-- Restore the state of the stack corresponding to the mark M. If an
-- additional chunk have been allocated, it will never be freed during a
-- ??? missing comment here
function SS_Get_Max return Long_Long_Integer;
-- Return maximum used space in storage units for the current secondary
-- stack. For a dynamically allocated secondary stack, the returned
-- result is always -1. For a statically allocated secondary stack,
-- the returned value shows the largest amount of space allocated so
-- far during execution of the program to the current secondary stack,
-- i.e. the secondary stack for the current task.
generic
with procedure Put_Line (S : String);
procedure SS_Info;
-- Debugging procedure used to print out secondary Stack allocation
-- information. This procedure is generic in order to avoid a direct
-- dependance on a particular IO package.
private
SS_Pool : Integer;
-- Unused entity that is just present to ease the sharing of the pool
-- mechanism for specific allocation/deallocation in the compiler
type SS_Ptr is new SSE.Integer_Address;
-- Stack pointer value for secondary stack
type Mark_Id is record
Sstk : System.Address;
Sptr : SS_Ptr;
end record;
-- A mark value contains the address of the secondary stack structure,
-- as returned by System.Soft_Links.Get_Sec_Stack_Addr, and a stack
-- pointer value corresponding to the point of the mark call.
end System.Secondary_Stack;
|
oeis/229/A229031.asm | neoneye/loda-programs | 11 | 6121 | ; A229031: Number of 5-colorings of the strong product of the complete graph K2 and the cycle graph Cn.
; Submitted by <NAME>
; 120,0,2400,3840,63360,215040,1943040,9031680,64665600,346030080,2243911680,12792299520,79437987840,465890181120,2838290104320,16857940623360,101834835886080,608260231004160,3660556491816960,21919358464819200,131692072607416320,789448748118835200,4739507238312345600,28425784430470103040,170599742578423234560,1023418311484102410240,6141230444842309386240,36844500365286970490880,221078531406757153996800,1326425071580337175265280,7958734896922717197434880,47751671511773268903198720
add $0,2
mov $1,$0
mov $0,2
pow $0,$1
seq $1,91000 ; Number of closed walks of length n on the Petersen graph.
mul $1,$0
mov $0,$1
mul $0,10
|
agda/book/Programming_Language_Foundations_in_Agda/x05-842Isomorphism.agda | haroldcarr/learn-haskell-coq-ml-etc | 36 | 6968 | <reponame>haroldcarr/learn-haskell-coq-ml-etc
module 842Isomorphism where
-- Library
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; cong-app; sym) -- added last
open Eq.≡-Reasoning
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat.Properties using (+-comm; +-suc; +-identityʳ) -- added last
-- Function composition.
_∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(g ∘ f) x = g (f x)
_∘′_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
g ∘′ f = λ x → g (f x)
postulate
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
-- Another definition of addition.
_+′_ : ℕ → ℕ → ℕ -- split on n instead, get different code
m +′ zero = m
m +′ suc n = suc (m +′ n)
same-app : ∀ (m n : ℕ) → m +′ n ≡ m + n
same-app m zero = sym (+-identityʳ m)
same-app m (suc n) rewrite +-suc m n | same-app m n = refl
same : _+′_ ≡ _+_ -- this requires extensionality
same = extensionality λ x → extensionality λ x₁ → same-app x x₁
-- Isomorphism.
infix 0 _≃_
record _≃_ (A B : Set) : Set where
constructor mk-≃ -- This has been added, not in PLFA
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
-- Equivalent to the following:
data _≃′_ (A B : Set): Set where
mk-≃′ : ∀ (to : A → B) →
∀ (from : B → A) →
∀ (from∘to : (∀ (x : A) → from (to x) ≡ x)) →
∀ (to∘from : (∀ (y : B) → to (from y) ≡ y)) →
A ≃′ B
to′ : ∀ {A B : Set} → (A ≃′ B) → (A → B)
to′ (mk-≃′ f g g∘f f∘g) = f
from′ : ∀ {A B : Set} → (A ≃′ B) → (B → A)
from′ (mk-≃′ f g g∘f f∘g) = g
from∘to′ : ∀ {A B : Set} → (A≃B : A ≃′ B)
→ (∀ (x : A)
→ from′ A≃B (to′ A≃B x) ≡ x)
from∘to′ (mk-≃′ f g g∘f f∘g) = g∘f
to∘from′ : ∀ {A B : Set} → (A≃B : A ≃′ B)
→ (∀ (y : B)
→ to′ A≃B (from′ A≃B y) ≡ y)
to∘from′ (mk-≃′ f g g∘f f∘g) = f∘g
-- End of equivalent formulation (records are faster!)
-- Properties of isomorphism.
-- Reflexivity.
≃-refl : ∀ {A : Set}
-----
→ A ≃ A
-- in empty hole, split on result, get copatterns (not in PLFA)
to ≃-refl x = x
from ≃-refl x = x
from∘to ≃-refl x = refl
to∘from ≃-refl x = refl
-- Symmetry.
≃-sym : ∀ {A B : Set}
→ A ≃ B
-----
→ B ≃ A
to (≃-sym A≃B) = from A≃B
from (≃-sym A≃B) = to A≃B
from∘to (≃-sym A≃B) = to∘from A≃B
to∘from (≃-sym A≃B) = from∘to A≃B
-- Transitivity.
≃-trans : ∀ {A B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
to (≃-trans A≃B B≃C) = to B≃C ∘ to A≃B
from (≃-trans A≃B B≃C) = from A≃B ∘ from B≃C
from∘to (≃-trans A≃B B≃C) x rewrite from∘to B≃C (to A≃B x) = from∘to A≃B x
to∘from (≃-trans A≃B B≃C) x rewrite to∘from A≃B (from B≃C x) = to∘from B≃C x
-- Isomorphism is an equivalence relation.
-- We can create syntax for equational reasoning.
module ≃-Reasoning where
infix 1 ≃-begin_
infixr 2 _≃⟨_⟩_
infix 3 _≃-∎
≃-begin_ : ∀ {A B : Set}
→ A ≃ B
-----
→ A ≃ B
≃-begin A≃B = A≃B
_≃⟨_⟩_ : ∀ (A : Set) {B C : Set}
→ A ≃ B
→ B ≃ C
-----
→ A ≃ C
A ≃⟨ A≃B ⟩ B≃C = ≃-trans A≃B B≃C
_≃-∎ : ∀ (A : Set)
-----
→ A ≃ A
A ≃-∎ = ≃-refl
open ≃-Reasoning
-- Embedding (weaker than isomorphism)
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
≲-refl : ∀ {A : Set} → A ≲ A
to ≲-refl x = x
from ≲-refl x = x
from∘to ≲-refl x = refl
≲-trans : ∀ {A B C : Set} → A ≲ B → B ≲ C → A ≲ C
to (≲-trans A≲B B≲C) = to B≲C ∘ to A≲B
from (≲-trans A≲B B≲C) = from A≲B ∘ from B≲C
from∘to (≲-trans A≲B B≲C) x rewrite from∘to B≲C (to A≲B x) = from∘to A≲B x
≲-antisym : ∀ {A B : Set}
→ (A≲B : A ≲ B)
→ (B≲A : B ≲ A)
→ (to A≲B ≡ from B≲A)
→ (from A≲B ≡ to B≲A)
-------------------
→ A ≃ B
to (≲-antisym A≲B B≲A to≡from from≡to) = to A≲B
from (≲-antisym A≲B B≲A to≡from from≡to) = from A≲B
from∘to (≲-antisym A≲B B≲A to≡from from≡to) x = from∘to A≲B x
to∘from (≲-antisym A≲B B≲A to≡from from≡to) y
rewrite from≡to | to≡from = from∘to B≲A y
-- Tabular reasoning for embedding.
module ≲-Reasoning where
infix 1 ≲-begin_
infixr 2 _≲⟨_⟩_
infix 3 _≲-∎
≲-begin_ : ∀ {A B : Set}
→ A ≲ B
-----
→ A ≲ B
≲-begin A≲B = A≲B
_≲⟨_⟩_ : ∀ (A : Set) {B C : Set}
→ A ≲ B
→ B ≲ C
-----
→ A ≲ C
A ≲⟨ A≲B ⟩ B≲C = ≲-trans A≲B B≲C
_≲-∎ : ∀ (A : Set)
-----
→ A ≲ A
A ≲-∎ = ≲-refl
open ≲-Reasoning
-- PLFA exercise: Isomorphism implies embedding.
≃-implies-≲ : ∀ {A B : Set}
→ A ≃ B
-----
→ A ≲ B
to (≃-implies-≲ a≃b) = to a≃b
from (≃-implies-≲ a≃b) = from a≃b
from∘to (≃-implies-≲ a≃b) = from∘to a≃b
-- PLFA exercise: propositional equivalence (weaker than embedding).
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
open _⇔_ -- added
-- This is also an equivalence relation.
⇔-refl : ∀ {A : Set}
-----
→ A ⇔ A
_⇔_.to ⇔-refl x = x
_⇔_.from ⇔-refl x = x
⇔-sym : ∀ {A B : Set}
→ A ⇔ B
-----
→ B ⇔ A
_⇔_.to (⇔-sym A⇔B) = from A⇔B
_⇔_.from (⇔-sym A⇔B) = to A⇔B
⇔-trans : ∀ {A B C : Set}
→ A ⇔ B
→ B ⇔ C
-----
→ A ⇔ C
to (⇔-trans A⇔B B⇔C) = to B⇔C ∘ to A⇔B
from (⇔-trans A⇔B B⇔C) = from A⇔B ∘ from B⇔C
-- 842 extended exercise: Canonical bitstrings.
-- Modified and extended from Bin-predicates exercise in PLFA Relations.
-- Copied from 842Naturals.
data Bin-ℕ : Set where
bits : Bin-ℕ
_x0 : Bin-ℕ → Bin-ℕ
_x1 : Bin-ℕ → Bin-ℕ
dbl : ℕ → ℕ
dbl zero = zero
dbl (suc n) = suc (suc (dbl n))
-- Copy your versions of 'inc', 'tob', and 'fromb' over from earlier files.
-- You may choose to change the definitions here to make proofs easier.
-- But make sure to test them if you do!
-- You may also copy over any theorems that prove useful.
inc : Bin-ℕ → Bin-ℕ
inc n = {!!}
tob : ℕ → Bin-ℕ
tob n = {!!}
dblb : Bin-ℕ → Bin-ℕ
dblb n = {!!}
fromb : Bin-ℕ → ℕ
fromb n = {!!}
-- The reason that we couldn't prove ∀ {n : Bin-ℕ} → tob (fromb n) ≡ n
-- is because of the possibility of leading zeroes in a Bin-ℕ value.
-- 'bits x0 x0 x1' is such a value that gives a counterexample.
-- However, the theorem is true is true for n without leading zeroes.
-- We define a predicate to be able to state this in a theorem.
-- A value of type One n is evidence that n has a leading one.
data One : Bin-ℕ → Set where
[bitsx1] : One (bits x1)
_[x0] : ∀ {n : Bin-ℕ} → One n → One (n x0)
_[x1] : ∀ {n : Bin-ℕ} → One n → One (n x1)
-- Here's a proof that 'bits x1 x0 x0' has a leading one.
_ : One (bits x1 x0 x0)
_ = [bitsx1] [x0] [x0]
-- There is no value of type One (bits x0 x0 x1).
-- But we can't state and prove this yet, because we don't know
-- how to express negation. That comes in the Connectives chapter.
-- A canonical binary representation is either zero or has a leading one.
data Can : Bin-ℕ → Set where
[zero] : Can bits
[pos] : ∀ {n : Bin-ℕ} → One n → Can n
-- Some obvious examples:
_ : Can bits
_ = [zero]
_ : Can (bits x1 x0)
_ = [pos] ([bitsx1] [x0])
-- The Bin-predicates exercise in PLFA Relations gives three properties of canonicity.
-- The first is that the increment of a canonical number is canonical.
-- Most of the work is done in the following lemma.
-- 842 exercise: IncCanOne (2 points)
-- The increment of a canonical number has a leading one.
one-inc : ∀ {n : Bin-ℕ} → Can n → One (inc n)
one-inc cn = {!!}
-- The first canonicity property is now an easy corollary.
-- 842 exercise: OneInc (1 point)
can-inc : ∀ {n : Bin-ℕ} → Can n → Can (inc n)
can-inc cn = {!!}
-- The second canonicity property is that converting a unary number
-- to binary produces a canonical number.
-- 842 exercise: CanToB (1 point)
to-can : ∀ (n : ℕ) → Can (tob n)
to-can n = {!!}
-- The third canonicity property is that converting a canonical number
-- from binary and back to unary produces the same number.
-- This takes more work, and some helper lemmas from 842Induction.
-- You will need to discover which ones.
-- 842 exercise: OneDblbX0 (1 point)
-- This helper function relates binary double to the x0 constructor,
-- for numbers with a leading one.
dblb-x0 : ∀ {n : Bin-ℕ} → One n → dblb n ≡ n x0
dblb-x0 on = {!!}
-- We can now prove the third property for numbers with a leading one.
-- 842 exercise: OneToFrom (3 points)
one-to∘from : ∀ {n : Bin-ℕ} → One n → tob (fromb n) ≡ n
one-to∘from on = {!!}
-- The third property is now an easy corollary.
-- 842 exercise: CanToFrom (1 point)
can-to∘from : ∀ {n : Bin-ℕ} → Can n → tob (fromb n) ≡ n
can-to∘from cn = {!!}
-- 842 exercise: OneUnique (2 points)
-- Proofs of positivity are unique.
one-unique : ∀ {n : Bin-ℕ} → (x y : One n) → x ≡ y
one-unique x y = {!!}
-- 842 exercise: CanUnique (1 point)
-- Proofs of canonicity are unique.
can-unique : ∀ {n : Bin-ℕ} → (x y : Can n) → x ≡ y
can-unique x y = {!!}
-- Do we have an isomorphism between ℕ (unary) and canonical binary representations?
-- Can is not a set, but a family of sets, so it doesn't quite fit
-- into our framework for isomorphism.
-- But we can roll all the values into one set which is isomorphic to ℕ.
-- A CanR value wraps up a Bin-ℕ and proof it has a canonical representation.
data CanR : Set where
wrap : ∀ (n : Bin-ℕ) → Can n → CanR
-- We can show that there is an isomorphism between ℕ and CanR.
-- 842 exercise: IsoNCanR (3 points)
iso-ℕ-CanR : ℕ ≃ CanR
iso-ℕ-CanR = {!!}
-- Can we get an isomorphism between ℕ and some binary encoding,
-- without the awkwardness of non-canonical values?
-- Yes: we use digits 1 and 2, instead of 0 and 1 (multiplier/base is still 2).
-- This is known as bijective binary numbering.
-- The counting sequence goes <empty>, 1, 2, 11, 12, 21, 22, 111...
data Bij-ℕ : Set where
bits : Bij-ℕ
_x1 : Bij-ℕ → Bij-ℕ
_x2 : Bij-ℕ → Bij-ℕ
-- There is an isomorphism between ℕ and Bij-ℕ.
-- The proof largely follows the outline of what we did above,
-- and is left as an optional exercise.
-- See PLFA for remarks on standard library definitions similar to those here.
-- Unicode introduced in this chapter:
{-
∘ U+2218 RING OPERATOR (\o, \circ, \comp)
λ U+03BB GREEK SMALL LETTER LAMBDA (\lambda, \Gl)
≃ U+2243 ASYMPTOTICALLY EQUAL TO (\~-)
≲ U+2272 LESS-THAN OR EQUIVALENT TO (\<~)
⇔ U+21D4 LEFT RIGHT DOUBLE ARROW (\<=>)
-}
|
programs/oeis/047/A047474.asm | neoneye/loda | 22 | 100043 | ; A047474: Numbers that are congruent to {0, 2, 3} mod 8.
; 0,2,3,8,10,11,16,18,19,24,26,27,32,34,35,40,42,43,48,50,51,56,58,59,64,66,67,72,74,75,80,82,83,88,90,91,96,98,99,104,106,107,112,114,115,120,122,123,128,130,131,136,138,139,144,146,147,152,154,155,160,162,163,168,170,171,176,178,179,184,186,187,192,194,195,200,202,203,208,210,211,216,218,219,224,226,227,232,234,235,240,242,243,248,250,251,256,258,259,264
mul $0,8
sub $0,3
div $0,3
mov $2,-1
pow $2,$0
sub $0,$2
|
Cubical/Categories/Category.agda | ayberkt/cubical | 0 | 6486 | <filename>Cubical/Categories/Category.agda
{-
Definition of various kinds of categories.
This library follows the UniMath terminology, that is:
Concept Ob C Hom C Univalence
Precategory Type Type No
Category Type Set No
Univalent Category Type Set Yes
This file also contains
- pathToIso : Turns a path between two objects into an isomorphism between them
- opposite categories
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.Category where
open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
-- Precategories
record Precategory ℓ ℓ' : Type (ℓ-suc (ℓ-max ℓ ℓ')) where
no-eta-equality
field
ob : Type ℓ
hom : ob → ob → Type ℓ'
idn : ∀ x → hom x x
seq : ∀ {x y z} (f : hom x y) (g : hom y z) → hom x z
seq-λ : ∀ {x y : ob} (f : hom x y) → seq (idn x) f ≡ f
seq-ρ : ∀ {x y} (f : hom x y) → seq f (idn y) ≡ f
seq-α : ∀ {u v w x} (f : hom u v) (g : hom v w) (h : hom w x) → seq (seq f g) h ≡ seq f (seq g h)
open Precategory public
-- Categories
record isCategory {ℓ ℓ'} (𝒞 : Precategory ℓ ℓ') : Type (ℓ-max ℓ ℓ') where
field
homIsSet : ∀ {x y} → isSet (𝒞 .hom x y)
open isCategory public
-- Isomorphisms and paths in precategories
record CatIso {ℓ ℓ' : Level} {𝒞 : Precategory ℓ ℓ'} (x y : 𝒞 .ob) : Type ℓ' where
constructor catiso
field
h : 𝒞 .hom x y
h⁻¹ : 𝒞 .hom y x
sec : 𝒞 .seq h⁻¹ h ≡ 𝒞 .idn y
ret : 𝒞 .seq h h⁻¹ ≡ 𝒞 .idn x
pathToIso : {ℓ ℓ' : Level} {𝒞 : Precategory ℓ ℓ'} (x y : 𝒞 .ob) (p : x ≡ y) → CatIso {𝒞 = 𝒞} x y
pathToIso {𝒞 = 𝒞} x y p = J (λ z _ → CatIso x z) (catiso (𝒞 .idn x) idx (𝒞 .seq-λ idx) (𝒞 .seq-λ idx)) p
where
idx = 𝒞 .idn x
-- Univalent Categories
record isUnivalent {ℓ ℓ'} (𝒞 : Precategory ℓ ℓ') : Type (ℓ-max ℓ ℓ') where
field
univ : (x y : 𝒞 .ob) → isEquiv (pathToIso {𝒞 = 𝒞} x y)
open isUnivalent public
-- Opposite Categories
_^op : ∀ {ℓ ℓ'} → Precategory ℓ ℓ' → Precategory ℓ ℓ'
(𝒞 ^op) .ob = 𝒞 .ob
(𝒞 ^op) .hom x y = 𝒞 .hom y x
(𝒞 ^op) .idn = 𝒞 .idn
(𝒞 ^op) .seq f g = 𝒞 .seq g f
(𝒞 ^op) .seq-λ = 𝒞 .seq-ρ
(𝒞 ^op) .seq-ρ = 𝒞 .seq-λ
(𝒞 ^op) .seq-α f g h = sym (𝒞 .seq-α _ _ _)
|
Aurora/Aurora/x64/Debug/pe.asm | manaskamal/aurora-xeneva | 8 | 88543 | ; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1
include listing.inc
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
PUBLIC ?ent@@3P6AXPEAX@ZEA ; ent
PUBLIC ?image_base@@3_KA ; image_base
_BSS SEGMENT
?ent@@3P6AXPEAX@ZEA DQ 01H DUP (?) ; ent
?image_base@@3_KA DQ 01H DUP (?) ; image_base
_BSS ENDS
PUBLIC ?load_pe_file@@YAXPEAEH@Z ; load_pe_file
PUBLIC ?get_entry_point@@YAP6AXPEAX@ZXZ ; get_entry_point
PUBLIC ?get_image_base@@YA_KXZ ; get_image_base
PUBLIC ?GetProcAddress@@YAPEAXPEAXPEBD@Z ; GetProcAddress
PUBLIC ??$raw_offset@PEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@@@YAPEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@H@Z ; raw_offset<_IMAGE_NT_HEADERS_PE32PLUS * __ptr64,_IMAGE_DOS_HEADER_ * __ptr64>
PUBLIC ??$raw_offset@PEAU_IMAGE_EXPORT_DIRECTORY@@PEAX@@YAPEAU_IMAGE_EXPORT_DIRECTORY@@PEAXH@Z ; raw_offset<_IMAGE_EXPORT_DIRECTORY * __ptr64,void * __ptr64>
PUBLIC ??$raw_offset@PEAIPEAX@@YAPEAIPEAXH@Z ; raw_offset<unsigned int * __ptr64,void * __ptr64>
PUBLIC ??$raw_offset@PEAGPEAX@@YAPEAGPEAXH@Z ; raw_offset<unsigned short * __ptr64,void * __ptr64>
PUBLIC ??$raw_offset@PEADPEAX@@YAPEADPEAXH@Z ; raw_offset<char * __ptr64,void * __ptr64>
PUBLIC ??$raw_offset@PEAXPEAX@@YAPEAXPEAXH@Z ; raw_offset<void * __ptr64,void * __ptr64>
EXTRN ?strcmp@@YAHPEBD0@Z:PROC ; strcmp
pdata SEGMENT
$pdata$?load_pe_file@@YAXPEAEH@Z DD imagerel $LN3
DD imagerel $LN3+94
DD imagerel $unwind$?load_pe_file@@YAXPEAEH@Z
$pdata$?GetProcAddress@@YAPEAXPEAXPEBD@Z DD imagerel $LN10
DD imagerel $LN10+386
DD imagerel $unwind$?GetProcAddress@@YAPEAXPEAXPEBD@Z
pdata ENDS
xdata SEGMENT
$unwind$?load_pe_file@@YAXPEAEH@Z DD 010d01H
DD 0620dH
$unwind$?GetProcAddress@@YAPEAXPEAXPEBD@Z DD 010e01H
DD 0e20eH
xdata ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\include\stdint.h
; COMDAT ??$raw_offset@PEAXPEAX@@YAPEAXPEAXH@Z
_TEXT SEGMENT
p1$ = 8
offset$ = 16
??$raw_offset@PEAXPEAX@@YAPEAXPEAXH@Z PROC ; raw_offset<void * __ptr64,void * __ptr64>, COMDAT
; 183 : {
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
; 184 : return (T) ((size_t)p1 + offset);
movsxd rax, DWORD PTR offset$[rsp]
mov rcx, QWORD PTR p1$[rsp]
add rcx, rax
mov rax, rcx
; 185 : };
ret 0
??$raw_offset@PEAXPEAX@@YAPEAXPEAXH@Z ENDP ; raw_offset<void * __ptr64,void * __ptr64>
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\include\stdint.h
; COMDAT ??$raw_offset@PEADPEAX@@YAPEADPEAXH@Z
_TEXT SEGMENT
p1$ = 8
offset$ = 16
??$raw_offset@PEADPEAX@@YAPEADPEAXH@Z PROC ; raw_offset<char * __ptr64,void * __ptr64>, COMDAT
; 183 : {
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
; 184 : return (T) ((size_t)p1 + offset);
movsxd rax, DWORD PTR offset$[rsp]
mov rcx, QWORD PTR p1$[rsp]
add rcx, rax
mov rax, rcx
; 185 : };
ret 0
??$raw_offset@PEADPEAX@@YAPEADPEAXH@Z ENDP ; raw_offset<char * __ptr64,void * __ptr64>
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\include\stdint.h
; COMDAT ??$raw_offset@PEAGPEAX@@YAPEAGPEAXH@Z
_TEXT SEGMENT
p1$ = 8
offset$ = 16
??$raw_offset@PEAGPEAX@@YAPEAGPEAXH@Z PROC ; raw_offset<unsigned short * __ptr64,void * __ptr64>, COMDAT
; 183 : {
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
; 184 : return (T) ((size_t)p1 + offset);
movsxd rax, DWORD PTR offset$[rsp]
mov rcx, QWORD PTR p1$[rsp]
add rcx, rax
mov rax, rcx
; 185 : };
ret 0
??$raw_offset@PEAGPEAX@@YAPEAGPEAXH@Z ENDP ; raw_offset<unsigned short * __ptr64,void * __ptr64>
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\include\stdint.h
; COMDAT ??$raw_offset@PEAIPEAX@@YAPEAIPEAXH@Z
_TEXT SEGMENT
p1$ = 8
offset$ = 16
??$raw_offset@PEAIPEAX@@YAPEAIPEAXH@Z PROC ; raw_offset<unsigned int * __ptr64,void * __ptr64>, COMDAT
; 183 : {
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
; 184 : return (T) ((size_t)p1 + offset);
movsxd rax, DWORD PTR offset$[rsp]
mov rcx, QWORD PTR p1$[rsp]
add rcx, rax
mov rax, rcx
; 185 : };
ret 0
??$raw_offset@PEAIPEAX@@YAPEAIPEAXH@Z ENDP ; raw_offset<unsigned int * __ptr64,void * __ptr64>
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\include\stdint.h
; COMDAT ??$raw_offset@PEAU_IMAGE_EXPORT_DIRECTORY@@PEAX@@YAPEAU_IMAGE_EXPORT_DIRECTORY@@PEAXH@Z
_TEXT SEGMENT
p1$ = 8
offset$ = 16
??$raw_offset@PEAU_IMAGE_EXPORT_DIRECTORY@@PEAX@@YAPEAU_IMAGE_EXPORT_DIRECTORY@@PEAXH@Z PROC ; raw_offset<_IMAGE_EXPORT_DIRECTORY * __ptr64,void * __ptr64>, COMDAT
; 183 : {
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
; 184 : return (T) ((size_t)p1 + offset);
movsxd rax, DWORD PTR offset$[rsp]
mov rcx, QWORD PTR p1$[rsp]
add rcx, rax
mov rax, rcx
; 185 : };
ret 0
??$raw_offset@PEAU_IMAGE_EXPORT_DIRECTORY@@PEAX@@YAPEAU_IMAGE_EXPORT_DIRECTORY@@PEAXH@Z ENDP ; raw_offset<_IMAGE_EXPORT_DIRECTORY * __ptr64,void * __ptr64>
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\include\stdint.h
; COMDAT ??$raw_offset@PEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@@@YAPEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@H@Z
_TEXT SEGMENT
p1$ = 8
offset$ = 16
??$raw_offset@PEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@@@YAPEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@H@Z PROC ; raw_offset<_IMAGE_NT_HEADERS_PE32PLUS * __ptr64,_IMAGE_DOS_HEADER_ * __ptr64>, COMDAT
; 183 : {
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
; 184 : return (T) ((size_t)p1 + offset);
movsxd rax, DWORD PTR offset$[rsp]
mov rcx, QWORD PTR p1$[rsp]
add rcx, rax
mov rax, rcx
; 185 : };
ret 0
??$raw_offset@PEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@@@YAPEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@H@Z ENDP ; raw_offset<_IMAGE_NT_HEADERS_PE32PLUS * __ptr64,_IMAGE_DOS_HEADER_ * __ptr64>
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\pe.cpp
_TEXT SEGMENT
i$1 = 32
ordinal$2 = 36
exportdir$ = 40
FunctionAddress$3 = 48
datadir$ = 56
dos_header$ = 64
ntHeaders$ = 72
function_name$4 = 80
FunctionOrdinalAddressArray$ = 88
FuntionNameAddressArray$ = 96
FunctionAddressArray$ = 104
image$ = 128
procname$ = 136
?GetProcAddress@@YAPEAXPEAXPEBD@Z PROC ; GetProcAddress
; 50 : void* GetProcAddress(void *image, const char* procname){
$LN10:
mov QWORD PTR [rsp+16], rdx
mov QWORD PTR [rsp+8], rcx
sub rsp, 120 ; 00000078H
; 51 :
; 52 : PIMAGE_DOS_HEADER dos_header = (PIMAGE_DOS_HEADER)image;
mov rax, QWORD PTR image$[rsp]
mov QWORD PTR dos_header$[rsp], rax
; 53 : PIMAGE_NT_HEADERS ntHeaders = raw_offset<PIMAGE_NT_HEADERS>(dos_header, dos_header->e_lfanew);
mov rax, QWORD PTR dos_header$[rsp]
movzx eax, WORD PTR [rax+60]
mov edx, eax
mov rcx, QWORD PTR dos_header$[rsp]
call ??$raw_offset@PEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@@@YAPEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@H@Z ; raw_offset<_IMAGE_NT_HEADERS_PE32PLUS * __ptr64,_IMAGE_DOS_HEADER_ * __ptr64>
mov QWORD PTR ntHeaders$[rsp], rax
; 54 : if (IMAGE_DATA_DIRECTORY_EXPORT + 1 > ntHeaders->OptionalHeader.NumberOfRvaAndSizes)
mov rax, QWORD PTR ntHeaders$[rsp]
cmp DWORD PTR [rax+132], 1
jae SHORT $LN7@GetProcAdd
; 55 : return NULL;
xor eax, eax
jmp $LN8@GetProcAdd
$LN7@GetProcAdd:
; 56 : IMAGE_DATA_DIRECTORY& datadir = ntHeaders->OptionalHeader.DataDirectory[IMAGE_DATA_DIRECTORY_EXPORT];
mov eax, 8
imul rax, 0
mov rcx, QWORD PTR ntHeaders$[rsp]
lea rax, QWORD PTR [rcx+rax+136]
mov QWORD PTR datadir$[rsp], rax
; 57 : if (datadir.VirtualAddress == 0 || datadir.Size == 0)
mov rax, QWORD PTR datadir$[rsp]
cmp DWORD PTR [rax], 0
je SHORT $LN5@GetProcAdd
mov rax, QWORD PTR datadir$[rsp]
cmp DWORD PTR [rax+4], 0
jne SHORT $LN6@GetProcAdd
$LN5@GetProcAdd:
; 58 : return NULL;
xor eax, eax
jmp $LN8@GetProcAdd
$LN6@GetProcAdd:
; 59 : PIMAGE_EXPORT_DIRECTORY exportdir = raw_offset<PIMAGE_EXPORT_DIRECTORY>(image, datadir.VirtualAddress);
mov rax, QWORD PTR datadir$[rsp]
mov edx, DWORD PTR [rax]
mov rcx, QWORD PTR image$[rsp]
call ??$raw_offset@PEAU_IMAGE_EXPORT_DIRECTORY@@PEAX@@YAPEAU_IMAGE_EXPORT_DIRECTORY@@PEAXH@Z ; raw_offset<_IMAGE_EXPORT_DIRECTORY * __ptr64,void * __ptr64>
mov QWORD PTR exportdir$[rsp], rax
; 60 : uint32_t* FuntionNameAddressArray = raw_offset<uint32_t*>(image,exportdir->AddressOfNames);
mov rax, QWORD PTR exportdir$[rsp]
mov edx, DWORD PTR [rax+32]
mov rcx, QWORD PTR image$[rsp]
call ??$raw_offset@PEAIPEAX@@YAPEAIPEAXH@Z ; raw_offset<unsigned int * __ptr64,void * __ptr64>
mov QWORD PTR FuntionNameAddressArray$[rsp], rax
; 61 : uint16_t* FunctionOrdinalAddressArray = raw_offset<uint16_t*>(image,exportdir->AddressOfNameOrdinal);
mov rax, QWORD PTR exportdir$[rsp]
mov edx, DWORD PTR [rax+36]
mov rcx, QWORD PTR image$[rsp]
call ??$raw_offset@PEAGPEAX@@YAPEAGPEAXH@Z ; raw_offset<unsigned short * __ptr64,void * __ptr64>
mov QWORD PTR FunctionOrdinalAddressArray$[rsp], rax
; 62 : uint32_t* FunctionAddressArray = raw_offset<uint32_t*>(image,exportdir->AddressOfFunctions);
mov rax, QWORD PTR exportdir$[rsp]
mov edx, DWORD PTR [rax+28]
mov rcx, QWORD PTR image$[rsp]
call ??$raw_offset@PEAIPEAX@@YAPEAIPEAXH@Z ; raw_offset<unsigned int * __ptr64,void * __ptr64>
mov QWORD PTR FunctionAddressArray$[rsp], rax
; 63 :
; 64 : for (int i = 0; i < exportdir->NumberOfNames; i++ ) {
mov DWORD PTR i$1[rsp], 0
jmp SHORT $LN4@GetProcAdd
$LN3@GetProcAdd:
mov eax, DWORD PTR i$1[rsp]
inc eax
mov DWORD PTR i$1[rsp], eax
$LN4@GetProcAdd:
mov rax, QWORD PTR exportdir$[rsp]
mov eax, DWORD PTR [rax+24]
cmp DWORD PTR i$1[rsp], eax
jae SHORT $LN2@GetProcAdd
; 65 :
; 66 : char* function_name = raw_offset<char*>(image,FuntionNameAddressArray [i]);
movsxd rax, DWORD PTR i$1[rsp]
mov rcx, QWORD PTR FuntionNameAddressArray$[rsp]
mov edx, DWORD PTR [rcx+rax*4]
mov rcx, QWORD PTR image$[rsp]
call ??$raw_offset@PEADPEAX@@YAPEADPEAXH@Z ; raw_offset<char * __ptr64,void * __ptr64>
mov QWORD PTR function_name$4[rsp], rax
; 67 : if (strcmp (function_name, procname) == 0) {
mov rdx, QWORD PTR procname$[rsp]
mov rcx, QWORD PTR function_name$4[rsp]
call ?strcmp@@YAHPEBD0@Z ; strcmp
test eax, eax
jne SHORT $LN1@GetProcAdd
; 68 : uint16_t ordinal = FunctionOrdinalAddressArray[i];
movsxd rax, DWORD PTR i$1[rsp]
mov rcx, QWORD PTR FunctionOrdinalAddressArray$[rsp]
movzx eax, WORD PTR [rcx+rax*2]
mov WORD PTR ordinal$2[rsp], ax
; 69 : uint32_t FunctionAddress = FunctionAddressArray [ordinal];
movzx eax, WORD PTR ordinal$2[rsp]
mov rcx, QWORD PTR FunctionAddressArray$[rsp]
mov eax, DWORD PTR [rcx+rax*4]
mov DWORD PTR FunctionAddress$3[rsp], eax
; 70 : return raw_offset<void*>(image,FunctionAddress);
mov edx, DWORD PTR FunctionAddress$3[rsp]
mov rcx, QWORD PTR image$[rsp]
call ??$raw_offset@PEAXPEAX@@YAPEAXPEAXH@Z ; raw_offset<void * __ptr64,void * __ptr64>
jmp SHORT $LN8@GetProcAdd
$LN1@GetProcAdd:
; 71 : }
; 72 : }
jmp $LN3@GetProcAdd
$LN2@GetProcAdd:
; 73 :
; 74 : return nullptr;
xor eax, eax
$LN8@GetProcAdd:
; 75 : }
add rsp, 120 ; 00000078H
ret 0
?GetProcAddress@@YAPEAXPEAXPEBD@Z ENDP ; GetProcAddress
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\pe.cpp
_TEXT SEGMENT
?get_image_base@@YA_KXZ PROC ; get_image_base
; 46 : return image_base;
mov rax, QWORD PTR ?image_base@@3_KA ; image_base
; 47 : }
ret 0
?get_image_base@@YA_KXZ ENDP ; get_image_base
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\pe.cpp
_TEXT SEGMENT
?get_entry_point@@YAP6AXPEAX@ZXZ PROC ; get_entry_point
; 41 : return ent;
mov rax, QWORD PTR ?ent@@3P6AXPEAX@ZEA ; ent
; 42 : }
ret 0
?get_entry_point@@YAP6AXPEAX@ZXZ ENDP ; get_entry_point
_TEXT ENDS
; Function compile flags: /Odtpy
; File e:\xeneva project\xeneva\aurora\aurora\pe.cpp
_TEXT SEGMENT
nt$ = 32
dos$ = 40
buffer$ = 64
size$ = 72
?load_pe_file@@YAXPEAEH@Z PROC ; load_pe_file
; 22 : void load_pe_file (unsigned char* buffer, int size) {
$LN3:
mov DWORD PTR [rsp+16], edx
mov QWORD PTR [rsp+8], rcx
sub rsp, 56 ; 00000038H
; 23 :
; 24 : IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER*)buffer;
mov rax, QWORD PTR buffer$[rsp]
mov QWORD PTR dos$[rsp], rax
; 25 : PIMAGE_NT_HEADERS nt = raw_offset<PIMAGE_NT_HEADERS>(dos, dos->e_lfanew);
mov rax, QWORD PTR dos$[rsp]
movzx eax, WORD PTR [rax+60]
mov edx, eax
mov rcx, QWORD PTR dos$[rsp]
call ??$raw_offset@PEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@@@YAPEAU_IMAGE_NT_HEADERS_PE32PLUS@@PEAU_IMAGE_DOS_HEADER_@@H@Z ; raw_offset<_IMAGE_NT_HEADERS_PE32PLUS * __ptr64,_IMAGE_DOS_HEADER_ * __ptr64>
mov QWORD PTR nt$[rsp], rax
; 26 :
; 27 : image_base = nt->OptionalHeader.ImageBase;
mov rax, QWORD PTR nt$[rsp]
mov rax, QWORD PTR [rax+48]
mov QWORD PTR ?image_base@@3_KA, rax ; image_base
; 28 : ent = (ientry)(nt->OptionalHeader.AddressOfEntryPoint + nt->OptionalHeader.ImageBase); //buffer
mov rax, QWORD PTR nt$[rsp]
mov eax, DWORD PTR [rax+40]
mov rcx, QWORD PTR nt$[rsp]
add rax, QWORD PTR [rcx+48]
mov QWORD PTR ?ent@@3P6AXPEAX@ZEA, rax ; ent
; 29 : //! For now Xeneva only loads binary that are aligned in 512, 1024 & 4096 byte
; 30 : //! aligned. Simply we call its entry address that are expected to be aligned in
; 31 : //! 512, 1024 and 4096 bytes
; 32 :
; 33 : //! copy the image to its desired virtual address
; 34 : //memcpy ((void*)nt->OptionalHeader.ImageBase,buffer, size);
; 35 :
; 36 : //! set the entry point
; 37 : //set_entry_point (nt);
; 38 : }
add rsp, 56 ; 00000038H
ret 0
?load_pe_file@@YAXPEAEH@Z ENDP ; load_pe_file
_TEXT ENDS
END
|
agda-stdlib-0.9/src/Data/Conat.agda | qwe2/try-agda | 1 | 6599 | ------------------------------------------------------------------------
-- The Agda standard library
--
-- Coinductive "natural" numbers
------------------------------------------------------------------------
module Data.Conat where
open import Coinduction
open import Data.Nat using (ℕ; zero; suc)
open import Relation.Binary
------------------------------------------------------------------------
-- The type
data Coℕ : Set where
zero : Coℕ
suc : (n : ∞ Coℕ) → Coℕ
------------------------------------------------------------------------
-- Some operations
fromℕ : ℕ → Coℕ
fromℕ zero = zero
fromℕ (suc n) = suc (♯ fromℕ n)
∞ℕ : Coℕ
∞ℕ = suc (♯ ∞ℕ)
infixl 6 _+_
_+_ : Coℕ → Coℕ → Coℕ
zero + n = n
suc m + n = suc (♯ (♭ m + n))
------------------------------------------------------------------------
-- Equality
data _≈_ : Coℕ → Coℕ → Set where
zero : zero ≈ zero
suc : ∀ {m n} (m≈n : ∞ (♭ m ≈ ♭ n)) → suc m ≈ suc n
setoid : Setoid _ _
setoid = record
{ Carrier = Coℕ
; _≈_ = _≈_
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {zero} = zero
refl {suc n} = suc (♯ refl)
sym : Symmetric _≈_
sym zero = zero
sym (suc m≈n) = suc (♯ sym (♭ m≈n))
trans : Transitive _≈_
trans zero zero = zero
trans (suc m≈n) (suc n≈k) = suc (♯ trans (♭ m≈n) (♭ n≈k))
|
programs/oeis/210/A210645.asm | neoneye/loda | 22 | 163446 | <reponame>neoneye/loda<gh_stars>10-100
; A210645: Area A of the triangles such that A, the sides and one of the altitudes are four consecutive integers of an arithmetic progression d.
; 84,336,756,1344,2100,3024,4116,5376,6804,8400,10164,12096,14196,16464,18900,21504,24276,27216,30324,33600,37044,40656,44436,48384,52500,56784,61236,65856,70644,75600,80724,86016,91476,97104,102900,108864,114996,121296
add $0,1
pow $0,2
mul $0,84
|
test/asset/agda-stdlib-1.0/Relation/Nullary/Decidable.agda | omega12345/agda-mode | 0 | 7990 | <filename>test/asset/agda-stdlib-1.0/Relation/Nullary/Decidable.agda
------------------------------------------------------------------------
-- The Agda standard library
--
-- Operations on and properties of decidable relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Decidable where
open import Data.Bool.Base using (Bool; false; true; not; T)
open import Data.Empty
open import Data.Product hiding (map)
open import Data.Unit
open import Function
open import Function.Equality using (_⟨$⟩_; module Π)
open import Function.Equivalence
using (_⇔_; equivalence; module Equivalence)
open import Function.Injection using (Injection; module Injection)
open import Level using (Lift)
open import Relation.Binary using (Setoid; module Setoid; Decidable)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
⌊_⌋ : ∀ {p} {P : Set p} → Dec P → Bool
⌊ yes _ ⌋ = true
⌊ no _ ⌋ = false
True : ∀ {p} {P : Set p} → Dec P → Set
True Q = T ⌊ Q ⌋
False : ∀ {p} {P : Set p} → Dec P → Set
False Q = T (not ⌊ Q ⌋)
-- Gives a witness to the "truth".
toWitness : ∀ {p} {P : Set p} {Q : Dec P} → True Q → P
toWitness {Q = yes p} _ = p
toWitness {Q = no _} ()
-- Establishes a "truth", given a witness.
fromWitness : ∀ {p} {P : Set p} {Q : Dec P} → P → True Q
fromWitness {Q = yes p} = const _
fromWitness {Q = no ¬p} = ¬p
-- Variants for False.
toWitnessFalse : ∀ {p} {P : Set p} {Q : Dec P} → False Q → ¬ P
toWitnessFalse {Q = yes _} ()
toWitnessFalse {Q = no ¬p} _ = ¬p
fromWitnessFalse : ∀ {p} {P : Set p} {Q : Dec P} → ¬ P → False Q
fromWitnessFalse {Q = yes p} = flip _$_ p
fromWitnessFalse {Q = no ¬p} = const _
map : ∀ {p q} {P : Set p} {Q : Set q} → P ⇔ Q → Dec P → Dec Q
map P⇔Q (yes p) = yes (Equivalence.to P⇔Q ⟨$⟩ p)
map P⇔Q (no ¬p) = no (¬p ∘ _⟨$⟩_ (Equivalence.from P⇔Q))
map′ : ∀ {p q} {P : Set p} {Q : Set q} →
(P → Q) → (Q → P) → Dec P → Dec Q
map′ P→Q Q→P = map (equivalence P→Q Q→P)
module _ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂} where
open Injection
open Setoid A using () renaming (_≈_ to _≈A_)
open Setoid B using () renaming (_≈_ to _≈B_)
-- If there is an injection from one setoid to another, and the
-- latter's equivalence relation is decidable, then the former's
-- equivalence relation is also decidable.
via-injection : Injection A B → Decidable _≈B_ → Decidable _≈A_
via-injection inj dec x y with dec (to inj ⟨$⟩ x) (to inj ⟨$⟩ y)
... | yes injx≈injy = yes (Injection.injective inj injx≈injy)
... | no injx≉injy = no (λ x≈y → injx≉injy (Π.cong (to inj) x≈y))
-- If a decision procedure returns "yes", then we can extract the
-- proof using from-yes.
module _ {p} {P : Set p} where
From-yes : Dec P → Set p
From-yes (yes _) = P
From-yes (no _) = Lift p ⊤
from-yes : (p : Dec P) → From-yes p
from-yes (yes p) = p
from-yes (no _) = _
-- If a decision procedure returns "no", then we can extract the proof
-- using from-no.
From-no : Dec P → Set p
From-no (no _) = ¬ P
From-no (yes _) = Lift p ⊤
from-no : (p : Dec P) → From-no p
from-no (no ¬p) = ¬p
from-no (yes _) = _
|
src/epoll.ads | JeremyGrosser/epoll-ada | 0 | 18854 | --
-- Copyright (C) 2022 <NAME> <<EMAIL>>
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with Interfaces.C; use Interfaces.C;
with Interfaces; use Interfaces;
with GNAT.Sockets; use GNAT.Sockets;
package Epoll is
Epoll_Error : exception;
type Epoll_Descriptor is private;
type Epoll_Flags is record
Readable : Boolean; -- EPOLLIN
Writable : Boolean; -- EPOLLOUT
Peer_Shutdown : Boolean; -- EPOLLRDHUP
Out_Of_Band : Boolean; -- EPOLLPRI
Error : Boolean; -- EPOLLERR
Hang_Up : Boolean; -- EPOLLHUP
Edge_Triggered : Boolean; -- EPOLLET
One_Shot : Boolean; -- EPOLLONESHOT
Wake_Up : Boolean; -- EPOLLWAKEUP
Exclusive : Boolean; -- EPOLLEXCLUSIVE
end record
with Size => 32;
for Epoll_Flags use record
Readable at 0 range 0 .. 0;
Out_Of_Band at 0 range 1 .. 1;
Writable at 0 range 2 .. 2;
Error at 0 range 3 .. 3;
Hang_Up at 0 range 4 .. 4;
Peer_Shutdown at 0 range 13 .. 13;
Exclusive at 0 range 28 .. 28;
Wake_Up at 0 range 29 .. 29;
One_Shot at 0 range 30 .. 30;
Edge_Triggered at 0 range 31 .. 31;
end record;
type Epoll_Event is record
Flags : Epoll_Flags := (others => False);
Data : Unsigned_64 := -1;
end record
with Pack,
Convention => C_Pass_By_Copy;
type Epoll_Events is array (Integer range <>) of Epoll_Event
with Convention => C;
type Epoll_Operation is (Add, Delete, Modify)
with Size => 32;
for Epoll_Operation use (1, 2, 3);
function Create
return Epoll_Descriptor;
procedure Control
(This : Epoll_Descriptor;
Socket : Socket_Type;
Op : Epoll_Operation;
Event : access Epoll_Event);
function Wait
(This : Epoll_Descriptor;
Max_Events : Positive := 1;
Timeout : Integer := -1)
return Epoll_Events;
private
type Epoll_Descriptor is new int;
end Epoll;
|
Transynther/x86/_processed/NONE/_xt_/i7-7700_9_0xca_notsx.log_21829_551.asm | ljhsiun2/medusa | 9 | 83907 | .global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %r8
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0x69eb, %rsi
lea addresses_WC_ht+0x1076b, %rdi
clflush (%rsi)
sub $63621, %r12
mov $114, %rcx
rep movsl
nop
nop
nop
inc %r12
lea addresses_D_ht+0x173eb, %rcx
nop
nop
xor $3270, %r14
movw $0x6162, (%rcx)
nop
nop
cmp %r12, %r12
lea addresses_WT_ht+0x1da15, %rsi
lea addresses_normal_ht+0x47eb, %rdi
nop
nop
dec %r8
mov $54, %rcx
rep movsq
nop
nop
nop
nop
and %rcx, %rcx
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r8
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r9
push %rbp
push %rbx
push %rcx
push %rdx
// Store
lea addresses_UC+0x19ceb, %rbx
inc %r11
movb $0x51, (%rbx)
nop
nop
nop
nop
xor %rdx, %rdx
// Faulty Load
lea addresses_WC+0x117eb, %rbp
nop
nop
nop
xor %r10, %r10
movb (%rbp), %r9b
lea oracles, %r10
and $0xff, %r9
shlq $12, %r9
mov (%r10,%r9,1), %r9
pop %rdx
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': False, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 7, 'same': False, 'type': 'addresses_UC'}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_WC'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 9, 'same': False, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 0, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 10, 'same': True, 'type': 'addresses_D_ht'}, 'OP': 'STOR'}
{'src': {'congruent': 1, 'same': False, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 11, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'REPM'}
{'38': 21829}
38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38
*/
|
src/third_party/nasm/test/br3392418.asm | Mr-Sheep/naiveproxy | 2,219 | 244643 | <gh_stars>1000+
section __LD,__compact_unwind data debug
dd 0
|
src/winnt_50_forwarders.asm | enlyze/EnlyzeWinCompatLib | 5 | 162394 | <reponame>enlyze/EnlyzeWinCompatLib
;
; EnlyzeWinCompatLib - Let Clang-compiled applications run on older Windows versions
; Copyright (c) 2021 <NAME>, ENLYZE GmbH <<EMAIL>>
; SPDX-License-Identifier: MIT
;
.model flat
EXTERN _LibGetModuleHandleExW@12 : PROC
EXTERN _LibHeapQueryInformation@20 : PROC
EXTERN _LibInitializeSListHead@4 : PROC
EXTERN _LibInterlockedFlushSList@4 : PROC
EXTERN _LibInterlockedPushEntrySList@8 : PROC
.data
PUBLIC __imp__GetModuleHandleExW@12
__imp__GetModuleHandleExW@12 dd _LibGetModuleHandleExW@12
PUBLIC __imp__HeapQueryInformation@20
__imp__HeapQueryInformation@20 dd _LibHeapQueryInformation@20
PUBLIC __imp__InitializeSListHead@4
__imp__InitializeSListHead@4 dd _LibInitializeSListHead@4
PUBLIC __imp__InterlockedFlushSList@4
__imp__InterlockedFlushSList@4 dd _LibInterlockedFlushSList@4
PUBLIC __imp__InterlockedPushEntrySList@8
__imp__InterlockedPushEntrySList@8 dd _LibInterlockedPushEntrySList@8
END
|
ada-dispatching-non_preemptive.ads | mgrojo/adalib | 15 | 19772 | <filename>ada-dispatching-non_preemptive.ads
-- Standard Ada library specification
-- Copyright (c) 2004-2016 AXE Consultants
-- Copyright (c) 2004, 2005, 2006 Ada-Europe
-- Copyright (c) 2000 The MITRE Corporation, Inc.
-- Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
-- SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
---------------------------------------------------------------------------
package Ada.Dispatching.Non_Preemptive is
pragma Preelaborate(Non_Preemptive);
procedure Yield_To_Higher;
procedure Yield_To_Same_Or_Higher renames Yield;
end Ada.Dispatching.Non_Preemptive;
|
BasicIPC/Metatheory/ClosedHilbert-BasicTarski.agda | mietek/hilbert-gentzen | 29 | 13031 | <filename>BasicIPC/Metatheory/ClosedHilbert-BasicTarski.agda
module BasicIPC.Metatheory.ClosedHilbert-BasicTarski where
open import BasicIPC.Syntax.ClosedHilbert public
open import BasicIPC.Semantics.BasicTarski public
-- Soundness with respect to all models, or evaluation, for closed terms only.
eval₀ : ∀ {A} → ⊢ A → ⊨ A
eval₀ (app t u) = eval₀ t $ eval₀ u
eval₀ ci = I
eval₀ ck = K
eval₀ cs = S
eval₀ cpair = _,_
eval₀ cfst = π₁
eval₀ csnd = π₂
eval₀ unit = ∙
-- Correctness of evaluation with respect to conversion.
eval₀✓ : ∀ {{_ : Model}} {A} {t t′ : ⊢ A} → t ⋙ t′ → eval₀ t ≡ eval₀ t′
eval₀✓ refl⋙ = refl
eval₀✓ (trans⋙ p q) = trans (eval₀✓ p) (eval₀✓ q)
eval₀✓ (sym⋙ p) = sym (eval₀✓ p)
eval₀✓ (congapp⋙ p q) = cong² _$_ (eval₀✓ p) (eval₀✓ q)
eval₀✓ (congi⋙ p) = cong I (eval₀✓ p)
eval₀✓ (congk⋙ p q) = cong² K (eval₀✓ p) (eval₀✓ q)
eval₀✓ (congs⋙ p q r) = cong³ S (eval₀✓ p) (eval₀✓ q) (eval₀✓ r)
eval₀✓ (congpair⋙ p q) = cong² _,_ (eval₀✓ p) (eval₀✓ q)
eval₀✓ (congfst⋙ p) = cong π₁ (eval₀✓ p)
eval₀✓ (congsnd⋙ p) = cong π₂ (eval₀✓ p)
eval₀✓ beta▻ₖ⋙ = refl
eval₀✓ beta▻ₛ⋙ = refl
eval₀✓ beta∧₁⋙ = refl
eval₀✓ beta∧₂⋙ = refl
eval₀✓ eta∧⋙ = refl
eval₀✓ eta⊤⋙ = refl
|
Bubblesort.asm | PeinZero/PsuedoCode_To_Assembly-Language | 0 | 24703 | TITLE My First Program (Bubblesort.asm)
INCLUDE Irvine32.inc
.data
array DWORD 18, 12, 123, 33, 12, 156, 1, 5, 0, 9, 99, 7
var1 DWORD ?
.code
main PROC
mov eax, 0
mov ebx, 0
mov edx, 0
mov ecx, 12
mov esi, 0
L1:
mov ebx, ecx
mov edi, 1
mov esi, 0
L2:
mov edx, array[esi*TYPE array]
cmp edx, array[edi*TYPE array]
ja swap
elsepart:
inc edi
inc esi
LOOP L2
mov ecx, ebx
LOOP L1
jmp ending
swap:
mov var1, edx
mov edx, array[edi*TYPE array]
mov array[esi*TYPE array], edx
mov edx, var1
mov array[edi*TYPE array], edx
jmp elsepart
ending:
mov ecx, 12
mov esi, 0
L3:
mov eax, array[esi*TYPE array]
inc esi
call writedec
call crlf
LOOP L3
exit
main ENDP
END main |
prototyping/Luau/RuntimeType.agda | TheGreatSageEqualToHeaven/luau | 1 | 15051 | <filename>prototyping/Luau/RuntimeType.agda
module Luau.RuntimeType where
open import Luau.Syntax using (Value; nil; addr; number; bool; string)
data RuntimeType : Set where
function : RuntimeType
number : RuntimeType
nil : RuntimeType
boolean : RuntimeType
string : RuntimeType
valueType : Value → RuntimeType
valueType nil = nil
valueType (addr a) = function
valueType (number n) = number
valueType (bool b) = boolean
valueType (string x) = string
|
utils/csv_logs.adb | jorge-real/Ball-On-Beam | 4 | 10594 | <reponame>jorge-real/Ball-On-Beam
--------------------------------------------------------------------------------
-- --
-- C S V _ L O G S --
-- --
-- Body --
-- --
-- Author: <NAME> --
-- February, 2021 --
-- --
--------------------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Float_Text_IO;
with Ada.Strings.Unbounded;
with Ada.Directories;
package body CSV_Logs is
A_Session_Is_Open : Boolean := False;
Writing_To_File : Boolean := False;
Output_File_Name : Ada.Strings.Unbounded.Unbounded_String;
-- The log file, if it is used
Log_File : aliased Ada.Text_IO.File_Type;
-- The output file access. May access Log_File or Standard_Output
Output_File : Ada.Text_IO.File_Access;
------------------------
-- Open_Log_Session --
------------------------
procedure Open_Log_Session (File_Name : String := "") is
use Ada.Strings.Unbounded;
begin
if A_Session_Is_Open then
return;
end if;
A_Session_Is_Open := True;
if File_Name /= "" then
-- A file name was given. Create the file and take note we are writing
-- to a file, so that we close the file when the session is closed.
Writing_To_File := True;
Ada.Text_IO.Create (File => Log_File,
Mode => Ada.Text_IO.Out_File,
Name => File_Name);
-- The output file is set to access the just created Log_File
Output_File := Log_File'Access;
-- File name saved for the closing session message
Output_File_Name := To_Unbounded_String (File_Name);
else
Writing_To_File := False;
-- The output file is set to access the standard output
Output_File := Ada.Text_IO.Standard_Output;
end if;
end Open_Log_Session;
-------------------------
-- Close_Log_Session --
-------------------------
procedure Close_Log_Session is
use Ada.Strings.Unbounded;
use Ada.Directories;
begin
if A_Session_Is_Open then
A_Session_Is_Open := False;
if Writing_To_File then
Ada.Text_IO.Close (Log_File);
-- File info message for every closed log session
Ada.Text_IO.Put_Line ("Logged data was saved to """
& Current_Directory & "/"
& To_String (Output_File_Name) & """");
end if;
end if;
end Close_Log_Session;
-----------
-- Log --
-----------
procedure Log_Data (Data_Set : Float_Array) is
begin
if not A_Session_Is_Open then
return;
end if;
for I in Data_Set'Range loop
Ada.Float_Text_IO.Put
(File => Output_File.all,
Item => Data_Set (I),
Exp => 0);
-- Put separating comma after each value or new line after last value
if I /= Data_Set'Last then
Ada.Text_IO.Put (Output_File.all, ", ");
else
Ada.Text_IO.New_Line (Output_File.all);
end if;
end loop;
end Log_Data;
----------------
-- Log_Text --
----------------
procedure Log_Text (Text_Line : String) is
begin
if not A_Session_Is_Open then
return;
end if;
Ada.Text_IO.Put_Line (Output_File.all, Text_Line);
end Log_Text;
end CSV_Logs;
|
alloy4fun_models/trainstlt/models/0/KQbLKEKGEAZZFPg8t.als | Kaixi26/org.alloytools.alloy | 0 | 4314 | open main
pred idKQbLKEKGEAZZFPg8t_prop1 {
always (all t:Entry | Green not in t.signal)
}
pred __repair { idKQbLKEKGEAZZFPg8t_prop1 }
check __repair { idKQbLKEKGEAZZFPg8t_prop1 <=> prop1o } |
tests/src/tc.ads | persan/AUnit-addons | 0 | 30683 | with AUnit.Test_Cases;
package Tc is
type Test_Case is new AUnit.Test_Cases.Test_Case with null record;
function Name (Test : Test_Case) return AUnit.Message_String;
procedure Register_Tests (Test : in out Test_Case);
end tc;
|
programs/oeis/110/A110199.asm | neoneye/loda | 22 | 99136 | <reponame>neoneye/loda<filename>programs/oeis/110/A110199.asm
; A110199: a(n) = Sum_{k=0..floor(n/2)} Catalan(k).
; 1,1,2,2,4,4,9,9,23,23,65,65,197,197,626,626,2056,2056,6918,6918,23714,23714,82500,82500,290512,290512,1033412,1033412,3707852,3707852,13402697,13402697,48760367,48760367,178405157,178405157,656043857
div $0,2
seq $0,14137 ; Partial sums of Catalan numbers (A000108).
|
Transynther/x86/_processed/NC/_zr_/i3-7100_9_0x84_notsx.log_70_1817.asm | ljhsiun2/medusa | 9 | 14338 | <reponame>ljhsiun2/medusa
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r9
push %rax
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0xe8f1, %rsi
lea addresses_A_ht+0xbe80, %rdi
nop
nop
nop
nop
cmp %rbx, %rbx
mov $50, %rcx
rep movsl
nop
nop
cmp $44764, %rbp
lea addresses_WC_ht+0x1772b, %rax
clflush (%rax)
nop
nop
nop
nop
nop
add $13230, %rbx
movb (%rax), %cl
nop
nop
nop
inc %rcx
lea addresses_D_ht+0x8b2b, %rbx
nop
nop
nop
nop
nop
add %r10, %r10
mov (%rbx), %si
nop
add %rdi, %rdi
lea addresses_WT_ht+0x1ee93, %rsi
lea addresses_WT_ht+0x1872b, %rdi
nop
nop
nop
sub %r9, %r9
mov $127, %rcx
rep movsw
nop
xor $51683, %rdi
lea addresses_WT_ht+0x9b2b, %rax
nop
nop
nop
nop
cmp %rbp, %rbp
vmovups (%rax), %ymm0
vextracti128 $0, %ymm0, %xmm0
vpextrq $0, %xmm0, %rbx
nop
nop
nop
nop
cmp %rdi, %rdi
lea addresses_UC_ht+0x4b2b, %rsi
and %rdi, %rdi
mov (%rsi), %ebp
nop
xor %rax, %rax
lea addresses_WC_ht+0xeb2b, %rbx
nop
nop
nop
sub $35357, %rsi
mov $0x6162636465666768, %rdi
movq %rdi, %xmm2
movups %xmm2, (%rbx)
nop
nop
nop
nop
inc %r9
lea addresses_normal_ht+0x188d7, %rsi
lea addresses_WT_ht+0x16cd, %rdi
clflush (%rdi)
nop
nop
nop
nop
nop
sub $64700, %r10
mov $80, %rcx
rep movsl
nop
nop
nop
sub $30780, %rbp
lea addresses_normal_ht+0x1db2b, %rsi
lea addresses_WC_ht+0x27d3, %rdi
cmp %rbx, %rbx
mov $24, %rcx
rep movsl
nop
nop
nop
nop
add $5543, %r10
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %rax
pop %r9
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r8
push %rax
push %rbx
push %rcx
push %rdx
// Store
lea addresses_WC+0xa33e, %rbx
nop
nop
sub %r13, %r13
movw $0x5152, (%rbx)
nop
nop
nop
nop
nop
lfence
// Store
lea addresses_PSE+0xe22b, %rax
nop
nop
nop
nop
xor $25301, %rdx
movb $0x51, (%rax)
nop
nop
add $63559, %rcx
// Store
lea addresses_PSE+0x189ab, %rcx
clflush (%rcx)
nop
nop
nop
lfence
mov $0x5152535455565758, %r8
movq %r8, %xmm6
movups %xmm6, (%rcx)
nop
nop
nop
cmp $23488, %r12
// Faulty Load
mov $0x7ea33b0000000b2b, %rdx
nop
add $64563, %rax
mov (%rdx), %r13
lea oracles, %r12
and $0xff, %r13
shlq $12, %r13
mov (%r12,%r13,1), %r13
pop %rdx
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_NC', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WC', 'same': False, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_PSE', 'same': False, 'size': 1, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_PSE', 'same': False, 'size': 16, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'type': 'addresses_NC', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 1, 'congruent': 9, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D_ht', 'same': True, 'size': 2, 'congruent': 11, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 32, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 4, 'congruent': 10, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 16, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'}
{'00': 70}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
libsrc/_DEVELOPMENT/stdio/z80/asm_fseek.asm | meesokim/z88dk | 0 | 172895 |
; ===============================================================
; Jan 2014
; ===============================================================
;
; int fseek(FILE *stream, long offset, int whence)
;
; Move to new position in file indicated by the signed value
; offset.
;
; If whence is:
;
; STDIO_SEEK_SET (0) : offset is relative to start of file
; STDIO_SEEK_CUR (1) : offset is relative to current position
; STDIO_SEEK_END (2) : offset is relative to end of file
;
; For STDIO_SEEK_SET, offset is treated as unsigned.
;
; ===============================================================
INCLUDE "clib_cfg.asm"
SECTION code_stdio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC asm_fseek
EXTERN asm0_fseek_unlocked, __stdio_lock_release
asm_fseek:
; enter : ix = FILE *
; dehl = offset
; c = whence
;
; exit : ix = FILE *
;
; success
;
; hl = 0
; carry reset
;
; fail
;
; hl = -1
; carry set
;
; uses : all except ix
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_STDIO & $01
EXTERN __stdio_verify_valid_lock
call __stdio_verify_valid_lock
ret c
ELSE
EXTERN __stdio_lock_acquire, error_enolck_mc
call __stdio_lock_acquire
jp c, error_enolck_mc
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call asm0_fseek_unlocked
jp __stdio_lock_release
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC asm_fseek
EXTERN asm_fseek_unlocked
defc asm_fseek = asm_fseek_unlocked
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
header/013/CPROM.asm | freem/nes_corelib | 16 | 168468 | ; CPROM: 32KB PRG-ROM + 16KB CHR-RAM
; http://bootgod.dyndns.org:7777/search.php?keywords=CPROM&kwtype=pcb
;------------------------------------------------------------------------------;
; Mapper 013 (CPROM) iNES header
.byte "NES",$1A
.byte $04 ; 4x 16K PRG banks
.byte $00 ; CHR-RAM
.byte $D1 ; flags 6
.byte $00 ; flags 7
.byte $00 ; no PRG RAM
.dsb 7, $00 ; clear the remaining bytes
|
tests/control-hazard-3.asm | skyzh/RISCV-Simulator | 106 | 173902 | <filename>tests/control-hazard-3.asm
.globl main
.text
main:
li a1, 0x10
nop
nop
nop
jalr a0, a1, 8
addi a0, a0, 8
addi a0, a0, 8
test:
li a2,255
lui a3,0x30
sb a2,4(a3)
nop
nop
nop
nop
nop
nop
nop
nop
|
org.alloytools.alloy.diff/misc/multiplicities/tests/fieldTest1v2.als | jringert/alloy-diff | 1 | 3031 | module b2
sig Branch{}
sig BranchDummy{}
sig Bankv2{
branches: one BranchDummy
}
|
_maps/obj51.asm | NatsumiFox/AMPS-Sonic-1-2005 | 2 | 17380 | ; ---------------------------------------------------------------------------
; Sprite mappings - smashable green block (MZ)
; ---------------------------------------------------------------------------
dc.w byte_FDD8-Map_obj51
dc.w byte_FDE3-Map_obj51
byte_FDD8: dc.b 2
dc.b $F0, $D, 0, 0, $F0
dc.b 0, $D, 0, 0, $F0
byte_FDE3: dc.b 4
dc.b $F0, 5, $80, 0, $F0
dc.b 0, 5, $80, 0, $F0
dc.b $F0, 5, $80, 0, 0
dc.b 0, 5, $80, 0, 0
even |
Transynther/x86/_processed/AVXALIGN/_ht_zr_un_/i9-9900K_12_0xa0.log_21829_1868.asm | ljhsiun2/medusa | 9 | 162333 | <filename>Transynther/x86/_processed/AVXALIGN/_ht_zr_un_/i9-9900K_12_0xa0.log_21829_1868.asm
.global s_prepare_buffers
s_prepare_buffers:
push %r8
push %r9
push %rax
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0xbcce, %rbx
nop
nop
nop
xor %r8, %r8
mov (%rbx), %ax
nop
and %r9, %r9
lea addresses_D_ht+0x2a1a, %rbp
nop
nop
nop
nop
and $22564, %r8
movl $0x61626364, (%rbp)
dec %rbx
lea addresses_A_ht+0x70a, %rsi
lea addresses_A_ht+0x7d9a, %rdi
clflush (%rsi)
clflush (%rdi)
nop
nop
xor $36347, %r8
mov $66, %rcx
rep movsb
nop
nop
nop
nop
nop
sub $4580, %r9
lea addresses_WC_ht+0x226a, %rax
nop
nop
cmp $36930, %r8
mov $0x6162636465666768, %rcx
movq %rcx, %xmm2
vmovups %ymm2, (%rax)
and $43406, %r8
lea addresses_A_ht+0xd6d0, %rdi
nop
nop
add $11549, %r9
movb (%rdi), %cl
cmp %r9, %r9
lea addresses_normal_ht+0x1b6ea, %rsi
lea addresses_WC_ht+0x4aaa, %rdi
dec %rbp
mov $39, %rcx
rep movsq
nop
nop
xor %rcx, %rcx
lea addresses_normal_ht+0x13a5e, %rbx
nop
nop
inc %rsi
mov (%rbx), %r8w
nop
nop
nop
nop
nop
sub $27029, %r8
lea addresses_WT_ht+0xf88a, %rbp
clflush (%rbp)
nop
nop
dec %rsi
mov (%rbp), %rbx
nop
cmp %r9, %r9
lea addresses_WT_ht+0x1126a, %r9
nop
nop
sub %r8, %r8
mov (%r9), %rax
nop
and $36377, %rdi
lea addresses_D_ht+0xc12a, %rsi
add %r8, %r8
movb $0x61, (%rsi)
nop
sub %rbp, %rbp
lea addresses_WC_ht+0x2ac2, %rsi
nop
sub $34611, %rbx
mov $0x6162636465666768, %r8
movq %r8, %xmm7
vmovups %ymm7, (%rsi)
nop
nop
inc %rax
lea addresses_WT_ht+0x1d92a, %rsi
lea addresses_UC_ht+0x107d8, %rdi
nop
nop
nop
nop
sub %rax, %rax
mov $85, %rcx
rep movsb
nop
dec %rsi
lea addresses_A_ht+0x12ede, %rsi
lea addresses_WC_ht+0x1269a, %rdi
nop
nop
nop
add %rbp, %rbp
mov $96, %rcx
rep movsb
nop
nop
nop
cmp %rsi, %rsi
lea addresses_WC_ht+0xc12a, %rsi
lea addresses_UC_ht+0xad2a, %rdi
clflush (%rdi)
nop
nop
nop
nop
add $12779, %r8
mov $93, %rcx
rep movsq
nop
nop
nop
nop
nop
sub $1014, %rcx
lea addresses_WC_ht+0x1d0a, %rbp
cmp $11559, %rbx
movl $0x61626364, (%rbp)
nop
xor $58232, %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %rax
pop %r9
pop %r8
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r13
push %r15
push %rbp
push %rdi
push %rsi
// Load
lea addresses_UC+0x15f7a, %rbp
nop
nop
nop
dec %rdi
mov (%rbp), %r11w
cmp $928, %r10
// Store
lea addresses_UC+0x812a, %rsi
clflush (%rsi)
nop
nop
nop
nop
cmp $31836, %r13
movl $0x51525354, (%rsi)
nop
nop
nop
nop
cmp $26404, %rdi
// Store
lea addresses_WC+0xff8a, %r10
nop
nop
nop
nop
nop
add %r15, %r15
movw $0x5152, (%r10)
and $2555, %r10
// Store
lea addresses_RW+0xfb8c, %r11
nop
nop
xor $28999, %r10
movw $0x5152, (%r11)
sub $21730, %rdi
// Faulty Load
lea addresses_UC+0x1e92a, %rbp
nop
nop
add %r11, %r11
vmovntdqa (%rbp), %ymm1
vextracti128 $1, %ymm1, %xmm1
vpextrq $1, %xmm1, %r10
lea oracles, %rbp
and $0xff, %r10
shlq $12, %r10
mov (%rbp,%r10,1), %r10
pop %rsi
pop %rdi
pop %rbp
pop %r15
pop %r13
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_UC', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_UC', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_UC', 'AVXalign': False, 'size': 4}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_WC', 'AVXalign': True, 'size': 2}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_RW', 'AVXalign': False, 'size': 2}}
[Faulty Load]
{'src': {'NT': True, 'same': True, 'congruent': 0, 'type': 'addresses_UC', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_WT_ht', 'AVXalign': True, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 4}}
{'src': {'same': False, 'congruent': 5, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 4, 'type': 'addresses_A_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}}
{'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_WC_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 2, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_WT_ht', 'AVXalign': True, 'size': 8}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 11, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 1}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}}
{'src': {'same': False, 'congruent': 7, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_UC_ht'}}
{'src': {'same': False, 'congruent': 2, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': True, 'congruent': 3, 'type': 'addresses_WC_ht'}}
{'src': {'same': False, 'congruent': 8, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 4}}
{'44': 4777, '45': 2, '72': 1, '00': 17049}
44 00 00 00 00 44 44 44 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 44 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 44 00 44 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 44 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
cards/bn5/ModCards/136-B048 Maddy's Custom.asm | RockmanEXEZone/MMBN-Mod-Card-Kit | 10 | 26632 | <filename>cards/bn5/ModCards/136-B048 Maddy's Custom.asm
.include "defaults_mod.asm"
table_file_jp equ "exe5-utf8.tbl"
table_file_en equ "bn5-utf8.tbl"
game_code_len equ 3
game_code equ 0x4252424A // BRBJ
game_code_2 equ 0x42524245 // BRBE
game_code_3 equ 0x42524250 // BRBP
card_type equ 1
card_id equ 98
card_no equ "098"
card_sub equ "Mod Card 098"
card_sub_x equ 64
card_desc_len equ 2
card_desc_1 equ "<NAME>"
card_desc_2 equ "5MB"
card_desc_3 equ ""
card_name_jp_full equ "まどいのカスタマイズ"
card_name_jp_game equ "まどいのカスタマイズ"
card_name_en_full equ "<NAME>"
card_name_en_game equ "Maddy's Custom"
card_address equ ""
card_address_id equ 0
card_bug equ 0
card_wrote_en equ ""
card_wrote_jp equ "" |
problems/042/a042.adb | melwyncarlo/ProjectEuler | 0 | 19262 | with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Numerics.Elementary_Functions;
-- Copyright 2021 <NAME>
procedure A042 is
use Ada.Text_IO;
use Ada.Integer_Text_IO;
use Ada.Numerics.Elementary_Functions;
-- File Reference: http://www.naturalnumbers.org/primes.html
FT : File_Type;
Ch : Character;
File_Name : constant String := "problems/042/p042_words.txt";
Count_Val : Integer := 0;
Index_Val : Integer := -1;
Word_Val : Integer := 0;
Is_Incremented : Boolean := False;
Sqrt_Term, N_Term : Float;
begin
Open (FT, In_File, File_Name);
Get (FT, Ch);
while not End_Of_File (FT) loop
Get (FT, Ch);
if Ch in 'A' .. 'Z' or Ch in 'a' .. 'z' then
Word_Val := Word_Val + Character'Pos (Ch) - 64;
Index_Val := Index_Val + 1;
Is_Incremented := False;
else
if not Is_Incremented then
Index_Val := 0;
Is_Incremented := True;
Sqrt_Term := Sqrt (1.0 + (8.0 * Float (Word_Val)));
Word_Val := 0;
if (Sqrt_Term - Float (Integer (Sqrt_Term))) = 0.0 then
N_Term := (Sqrt_Term - 1.0) / 2.0;
if (N_Term - Float (Integer (N_Term))) = 0.0 then
Count_Val := Count_Val + 1;
end if;
end if;
end if;
end if;
end loop;
Close (FT);
Put (Count_Val, Width => 0);
end A042;
|
programs/oeis/100/A100152.asm | jmorken/loda | 1 | 20651 | ; A100152: Structured truncated cubic numbers.
; 1,24,100,260,535,956,1554,2360,3405,4720,6336,8284,10595,13300,16430,20016,24089,28680,33820,39540,45871,52844,60490,68840,77925,87776,98424,109900,122235,135460,149606,164704,180785,197880,216020,235236,255559,277020,299650,323480,348541,374864,402480,431420,461715,493396,526494,561040,597065,634600,673676,714324,756575,800460,846010,893256,942229,992960,1045480,1099820,1156011,1214084,1274070,1336000,1399905,1465816,1533764,1603780,1675895,1750140,1826546,1905144,1985965,2069040,2154400,2242076,2332099,2424500,2519310,2616560,2716281,2818504,2923260,3030580,3140495,3253036,3368234,3486120,3606725,3730080,3856216,3985164,4116955,4251620,4389190,4529696,4673169,4819640,4969140,5121700,5277351,5436124,5598050,5763160,5931485,6103056,6277904,6456060,6637555,6822420,7010686,7202384,7397545,7596200,7798380,8004116,8213439,8426380,8642970,8863240,9087221,9314944,9546440,9781740,10020875,10263876,10510774,10761600,11016385,11275160,11537956,11804804,12075735,12350780,12629970,12913336,13200909,13492720,13788800,14089180,14393891,14702964,15016430,15334320,15656665,15983496,16314844,16650740,16991215,17336300,17686026,18040424,18399525,18763360,19131960,19505356,19883579,20266660,20654630,21047520,21445361,21848184,22256020,22668900,23086855,23509916,23938114,24371480,24810045,25253840,25702896,26157244,26616915,27081940,27552350,28028176,28509449,28996200,29488460,29986260,30489631,30998604,31513210,32033480,32559445,33091136,33628584,34171820,34720875,35275780,35836566,36403264,36975905,37554520,38139140,38729796,39326519,39929340,40538290,41153400,41774701,42402224,43036000,43676060,44322435,44975156,45634254,46299760,46971705,47650120,48335036,49026484,49724495,50429100,51140330,51858216,52582789,53314080,54052120,54796940,55548571,56307044,57072390,57844640,58623825,59409976,60203124,61003300,61810535,62624860,63446306,64274904,65110685,65953680,66803920,67661436,68526259,69398420,70277950,71164880,72059241,72961064,73870380,74787220,75711615,76643596,77583194,78530440,79485365,80448000
mov $1,1
mov $2,$0
mov $7,$0
add $0,2
lpb $2
add $1,3
lpb $0
add $3,$0
sub $0,1
lpe
add $3,2
sub $3,$2
add $1,$3
sub $2,1
lpe
mov $5,$7
mov $8,$7
lpb $5
sub $5,1
add $6,$8
lpe
mov $4,8
mov $8,$6
lpb $4
add $1,$8
sub $4,1
lpe
mov $5,$7
mov $6,0
lpb $5
sub $5,1
add $6,$8
lpe
mov $4,5
mov $8,$6
lpb $4
add $1,$8
sub $4,1
lpe
|
binary-diagnostic/uint_to_ascii64.asm | schuler-henry/snp-assembler | 0 | 164684 | <filename>binary-diagnostic/uint_to_ascii64.asm
;-----------------------------------------------------------------------------
; uint_to_ascii64.asm - convernts integer number to ascii number
;-----------------------------------------------------------------------------
;
; DHBW Ravensburg - <NAME>
;
; Vorlesung Systemnahe Programmierung (SNP)
;
;----------------------------------------------------------------------------
;
; Architecture: x86-64
; Language: NASM Assembly Language
;
; Author: <NAME>
; Created: 2021-12-02
;
; Editet by: <NAME>
; Edited: 2022-01-14
;
;----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Section TEXT
;-----------------------------------------------------------------------------
SECTION .text
global uint_to_ascii:function
uint_to_ascii:
; rdi: number in ascii (return value)
; rsi: number as int (input value)
; rcx: loopcounter for number positions
; rbx: divisor for division
push rbp
mov rbp,rsp
push rcx ; safe all required registers
push rbx
mov rcx,[rbp+16] ; set loop counter (row-width)
test rsi,rsi
jnz .loop_start ; only start if input > 0
mov byte [rdi+rcx-1],'0' ; if 0 -> set to ascii 0 and exit
jmp .loop_exit
.loop_start:
mov rbx,10 ; set divisor rbx to 10 (decimal)
mov rax,rsi ; copy given number into accumulator
.loop:
;-----------------------------------------------------------
; loop through every decimal position of rsi and transform to ascii
;-----------------------------------------------------------
test rax,rax ; test accu for 0 -> exit
jz .loop_exit
xor rdx,rdx ; empty rdx for division
div rbx ; divide rax by divisor rbx
add dl,'0' ; rest is safed in dl -> add ascii 0 to get ascii number
mov byte [rdi+rcx-1],dl ; safe ascii number into return string
dec rcx ; decrement loop counter for next digit
jnz .loop
.loop_exit:
pop rbx ; restore all safed registers
pop rcx
pop rbp
ret
|
libsrc/nc100/textout.asm | meesokim/z88dk | 0 | 102771 | <reponame>meesokim/z88dk<gh_stars>0
PUBLIC textout
; fastcall
.textout
jp 0xB81E
|
src/Generic/Lib/Data/String.agda | turion/Generic | 30 | 6910 | module Generic.Lib.Data.String where
open import Data.String.Base using (String) renaming (toList to toListˢ; _++_ to _++ˢ_) public
open import Generic.Lib.Decidable
import Data.String as String
instance
StringEq : Eq String
StringEq = viaBase String._≟_
|
oeis/227/A227036.asm | neoneye/loda-programs | 11 | 25936 | <filename>oeis/227/A227036.asm<gh_stars>10-100
; A227036: Expansion of 2*(1+x^2)/((1-x)*(1-x-2*x^3)).
; Submitted by <NAME>(s2)
; 2,4,8,16,28,48,84,144,244,416,708,1200,2036,3456,5860,9936,16852,28576,48452,82160,139316,236224,400548,679184,1151636,1952736,3311108,5614384,9519860,16142080,27370852,46410576,78694740,133436448,226257604,383647088,650519988,1103035200,1870329380,3171369360,5377439764,9118098528,15460837252,26215716784,44451913844,75373588352,127805021924,216708849616,367456026324,623066070176,1056483769412,1791395822064,3037527962420,5150495501248,8733287145380,14808343070224,25109334072724,42575908363488
mov $2,2
mov $3,1
mov $4,1
lpb $0
sub $0,1
mov $1,$4
add $1,$4
mov $4,$2
add $2,$3
mov $3,$1
lpe
mov $0,$2
sub $0,1
mul $0,2
|
ltl.g4 | igor-buzhinsky/nusmv_counterexample_visualizer | 4 | 494 | <filename>ltl.g4<gh_stars>1-10
grammar ltl;
options {
language = Java;
}
@header {
import nusmv_counterexample_visualizer.formula.ltl.*;
import nusmv_counterexample_visualizer.formula.arithmetic.*;
}
@parser::members {
}
WS : (' ' | '\t' | ('\r'? '\n'))+ -> channel(HIDDEN);
REAL_CONST : '-'? (('f\'' | 'F\'') ('0' | ('1'..'9' ('0'..'9')*)) '/' ('0' | ('1'..'9' ('0'..'9')*))
| ('0' | ('1'..'9' ('0'..'9')*)) '.' ('0'..'9')+
| ('0' | ('1'..'9' ('0'..'9')*)) ('.' ('0'..'9')+)? ('e' | 'E') ('-' | '+')? ('0' | ('1'..'9' ('0'..'9')*)));
INT_CONST : '-'? ('0' | ('1'..'9' ('0'..'9')*));
TRUE : 'TRUE';
FALSE : 'FALSE';
COUNT : 'count';
// note: dashes in identifiers are not supported
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'$'|'#'|'0'..'9')*;
constant
: REAL_CONST | INT_CONST | TRUE | FALSE
;
composite_id
: ID ('.' ID)* ('[' INT_CONST ']')*
;
unary_operator_sign
: '!' | 'X' | 'G' | 'F' | 'Y' | 'Z' | 'O' | 'H'
;
binary_operator_sign5
: 'U' | 'V'
;
binary_operator_sign4
: '&'
;
binary_operator_sign3
: '|' | 'xnor' | 'xor'
;
binary_operator_sign2
: '<->'
;
binary_operator_sign1
: '->'
;
comparison_operator_sign
: '=' | '!=' | '>' | '>=' | '<' | '<='
;
////////////////////
arithmetic_atomic_value returns[ArithmeticExpression f]
: constant { $f = new Constant($constant.text); }
| composite_id { $f = new Variable($composite_id.text); }
;
arithmetic_atom returns[ArithmeticExpression f]
: arithmetic_atomic_value { $f = $arithmetic_atomic_value.f; }
| '(' implies_arithmetic_expression ')' { $f = $implies_arithmetic_expression.f; }
| COUNT '(' { List<ArithmeticExpression> args = new ArrayList<>(); }
f1=implies_arithmetic_expression { args.add($f1.f); }
(',' f2=implies_arithmetic_expression { args.add($f2.f); })+ ')'
{ $f = new CountArithmeticOperator(args); }
;
arithmetic_expression3 returns[ArithmeticExpression f]
: arithmetic_atom { $f = $arithmetic_atom.f; }
| { String op; } ('-' { op = "-"; } | '+' { op = "+"; } | '!' { op = "!"; }) arithmetic_expression3
{ $f = new UnaryArithmeticOperator(op, $arithmetic_expression3.f); }
;
arithmetic_expression2 returns[ArithmeticExpression f]
: f1=arithmetic_expression3 { $f = $f1.f; String op; }
(('*' { op = "*"; } | '/' { op = "/"; } | 'mod' { op = "mod"; })
f2=arithmetic_expression3 { $f = new BinaryArithmeticOperator(op, $f, $f2.f); })*
;
arithmetic_expression1 returns[ArithmeticExpression f]
: f1=arithmetic_expression2 { $f = $f1.f; String op; } (('+' { op = "+"; } | '-' { op = "-"; })
f2=arithmetic_expression2 { $f = new BinaryArithmeticOperator(op, $f, $f2.f); })*
;
comparison_expression returns[ArithmeticExpression f]
: f1=arithmetic_expression1 { $f = $f1.f; } (comparison_operator_sign f2=arithmetic_expression1
{ $f = new ComparisonOperator($comparison_operator_sign.text, $f, $f2.f); })?
;
////////////////////
and_arithmetic_expression returns[ArithmeticExpression f]
: f1=comparison_expression { $f = $f1.f; } ('&' f2=comparison_expression
{ $f = new BinaryArithmeticOperator("&", $f, $f2.f); })?
;
or_arithmetic_expression returns[ArithmeticExpression f]
: f1=and_arithmetic_expression { $f = $f1.f; String op; }
(('|' { op = "|"; } | 'xor' { op = "xor"; } | 'xnor' { op = "xnor"; })
f2=and_arithmetic_expression { $f = new BinaryArithmeticOperator(op, $f, $f2.f); })?
;
ternary_arithmetic_expression returns[ArithmeticExpression f]
: f1=or_arithmetic_expression { $f = $f1.f; } ('?' f2=or_arithmetic_expression ':' f3=or_arithmetic_expression
{ $f = new TernaryArithmeticOperator($f1.f, $f2.f, $f3.f); })?
;
eq_arithmetic_expression returns[ArithmeticExpression f]
: f1=ternary_arithmetic_expression { $f = $f1.f; } ('<->' f2=ternary_arithmetic_expression
{ $f = new BinaryArithmeticOperator("<->", $f, $f2.f); })?
;
implies_arithmetic_expression returns[ArithmeticExpression f]
: f1=eq_arithmetic_expression { $f = $f1.f; } ('->' f2=implies_arithmetic_expression
{ $f = new BinaryArithmeticOperator("->", $f, $f2.f); })?
;
////////////////////
proposition returns[ArithmeticExpression f]
: f1=arithmetic_expression1 comparison_operator_sign f2=arithmetic_expression1
{ $f = new ComparisonOperator($comparison_operator_sign.text, $f1.f, $f2.f); }
| o1=or_arithmetic_expression '?' o2=or_arithmetic_expression ':' o3=or_arithmetic_expression
{ $f = new TernaryArithmeticOperator($o1.f, $o2.f, $o3.f); }
| arithmetic_atomic_value { $f = $arithmetic_atomic_value.f; }
;
atom returns[LTLFormula f]
: '(' formula ')' { $f = $formula.f; }
| proposition { $f = new Proposition($proposition.f); }
;
unary_operator returns[LTLFormula f]
: atom { $f = $atom.f; }
| unary_operator_sign unary_operator { $f = new UnaryOperator($unary_operator_sign.text, $unary_operator.f); }
;
binary_operator5 returns[LTLFormula f]
: f1=unary_operator { $f = $f1.f; } (binary_operator_sign5 f2=unary_operator
{ $f = new BinaryOperator($binary_operator_sign5.text, $f, $f2.f); })*
;
binary_operator4 returns[LTLFormula f]
: f1=binary_operator5 { $f = $f1.f; } (binary_operator_sign4 f2=binary_operator5
{ $f = new BinaryOperator($binary_operator_sign4.text, $f, $f2.f); })*
;
binary_operator3 returns[LTLFormula f]
: f1=binary_operator4 { $f = $f1.f; } (binary_operator_sign3 f2=binary_operator4
{ $f = new BinaryOperator($binary_operator_sign3.text, $f, $f2.f); })*
;
binary_operator2 returns[LTLFormula f]
: f1=binary_operator3 { $f = $f1.f; } (binary_operator_sign2 f2=binary_operator3
{ $f = new BinaryOperator($binary_operator_sign2.text, $f, $f2.f); })*
;
binary_operator1 returns[LTLFormula f]
: f1=binary_operator2 { $f = $f1.f; } (binary_operator_sign1 f2=binary_operator1
{ $f = new BinaryOperator($binary_operator_sign1.text, $f, $f2.f); })?
;
formula returns[LTLFormula f]
: binary_operator1 { $f = $binary_operator1.f; }
;
formula_eof returns[LTLFormula f]
: formula { $f = $formula.f; } EOF
;
|
Data/Dyck/Rose.agda | oisdk/agda-playground | 6 | 9289 | {-# OPTIONS --cubical --safe --postfix-projections #-}
-- This module defines a data type for balanced strings of parentheses,
-- which is isomorphic to binary trees.
module Data.Dyck.Rose where
open import Prelude
open import Data.Nat using (_+_)
open import Data.Vec.Iterated using (Vec; _∷_; []; foldlN; head)
open import Data.Tree.Rose
open import Data.List
private
variable
n : ℕ
--------------------------------------------------------------------------------
-- Programs: definition and associated functions
--------------------------------------------------------------------------------
data Prog (A : Type a) : ℕ → Type a where
halt : Prog A 1
pull : Prog A (1 + n) → Prog A n
push : A → Prog A (1 + n) → Prog A (2 + n)
--------------------------------------------------------------------------------
-- Conversion from a Prog to a Tree
--------------------------------------------------------------------------------
prog→tree⊙ : Prog A n → Vec (Forest A) n → Forest A
prog→tree⊙ halt (v ∷ []) = v
prog→tree⊙ (pull is) st = prog→tree⊙ is ([] ∷ st)
prog→tree⊙ (push v is) (t₁ ∷ t₂ ∷ st) = prog→tree⊙ is (((v & t₂) ∷ t₁) ∷ st)
prog→tree : Prog A zero → Forest A
prog→tree ds = prog→tree⊙ ds []
--------------------------------------------------------------------------------
-- Conversion from a Tree to a Prog
--------------------------------------------------------------------------------
tree→prog⊙ : Forest A → Prog A (suc n) → Prog A n
tree→prog⊙ [] = pull
tree→prog⊙ ((t & ts) ∷ xs) = tree→prog⊙ ts ∘ tree→prog⊙ xs ∘ push t
tree→prog : Forest A → Prog A zero
tree→prog tr = tree→prog⊙ tr halt
--------------------------------------------------------------------------------
-- Proof of isomorphism
--------------------------------------------------------------------------------
tree→prog→tree⊙ : (e : Forest A) (is : Prog A (1 + n)) (st : Vec (Forest A) n) →
prog→tree⊙ (tree→prog⊙ e is) st ≡ prog→tree⊙ is (e ∷ st)
tree→prog→tree⊙ [] is st = refl
tree→prog→tree⊙ ((t & ts) ∷ xs) is st =
tree→prog→tree⊙ ts _ st ; tree→prog→tree⊙ xs (push t is) (ts ∷ st)
tree→prog→tree : (e : Forest A) → prog→tree (tree→prog e) ≡ e
tree→prog→tree e = tree→prog→tree⊙ e halt []
prog→tree→prog⊙ : (is : Prog A n) (st : Vec (Forest A) n) →
tree→prog (prog→tree⊙ is st) ≡ foldlN (Prog A) tree→prog⊙ is st
prog→tree→prog⊙ halt st = refl
prog→tree→prog⊙ (pull is) st = prog→tree→prog⊙ is ([] ∷ st)
prog→tree→prog⊙ (push x is) (t₁ ∷ t₂ ∷ st) =
prog→tree→prog⊙ is (((x & t₂) ∷ t₁) ∷ st)
prog→tree→prog : (is : Prog A 0) → tree→prog (prog→tree is) ≡ is
prog→tree→prog is = prog→tree→prog⊙ is []
prog-iso : Prog A zero ⇔ Forest A
prog-iso .fun = prog→tree
prog-iso .inv = tree→prog
prog-iso .rightInv = tree→prog→tree
prog-iso .leftInv = prog→tree→prog
|
oeis/076/A076100.asm | neoneye/loda-programs | 11 | 170367 | ; A076100: Least common multiple of n numbers starting with n.
; Submitted by <NAME>
; 1,6,60,420,2520,27720,360360,360360,12252240,232792560,232792560,5354228880,26771144400,80313433200,2329089562800,72201776446800,144403552893600,144403552893600,5342931457063200,5342931457063200
mul $0,2
seq $0,51426 ; Least common multiple of {2, 4, 6, ..., 2n}.
div $0,2
|
pkgs/tools/yasm/src/modules/arch/x86/tests/gas64/riprel.asm | manggoguy/parsec-modified | 2,151 | 164555 | <filename>pkgs/tools/yasm/src/modules/arch/x86/tests/gas64/riprel.asm
mov %rax,foo(%rip)
|
Transynther/x86/_processed/US/_zr_/i9-9900K_12_0xa0.log_21829_146.asm | ljhsiun2/medusa | 9 | 97870 | .global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r14
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0x1136, %rsi
lea addresses_UC_ht+0x9f6, %rdi
inc %rdx
mov $26, %rcx
rep movsq
nop
nop
nop
and $56292, %r14
lea addresses_A_ht+0x79a, %rcx
clflush (%rcx)
nop
cmp $41964, %rbx
mov (%rcx), %rdi
nop
nop
nop
nop
nop
add %r14, %r14
lea addresses_UC_ht+0xd1f6, %rdi
nop
xor $51005, %rcx
movb (%rdi), %dl
nop
cmp $56043, %rbx
lea addresses_D_ht+0xa926, %rdi
nop
nop
add %r10, %r10
movups (%rdi), %xmm3
vpextrq $1, %xmm3, %rbx
nop
nop
nop
nop
nop
add $27383, %r14
lea addresses_WC_ht+0xa7f6, %rsi
lea addresses_WT_ht+0xff6, %rdi
nop
nop
nop
nop
nop
sub %r11, %r11
mov $86, %rcx
rep movsl
nop
nop
nop
nop
add $15488, %r14
lea addresses_normal_ht+0x167a6, %rbx
nop
cmp %rdi, %rdi
movl $0x61626364, (%rbx)
nop
add $11844, %rsi
lea addresses_A_ht+0x18416, %r10
nop
nop
add %rdx, %rdx
mov $0x6162636465666768, %rsi
movq %rsi, %xmm2
movups %xmm2, (%r10)
add %rsi, %rsi
lea addresses_WC_ht+0xb305, %rdi
clflush (%rdi)
nop
nop
nop
nop
nop
sub $22735, %r10
mov $0x6162636465666768, %rbx
movq %rbx, (%rdi)
nop
nop
nop
nop
cmp %rcx, %rcx
lea addresses_WT_ht+0x126, %rsi
lea addresses_normal_ht+0x13cf6, %rdi
nop
nop
cmp $30882, %r10
mov $45, %rcx
rep movsw
nop
inc %rdi
lea addresses_WC_ht+0x16b9e, %rsi
lea addresses_D_ht+0x9dce, %rdi
nop
nop
nop
inc %rdx
mov $81, %rcx
rep movsq
nop
nop
nop
cmp $52421, %rdi
lea addresses_D_ht+0x115f6, %rdi
nop
nop
nop
nop
nop
xor %r10, %r10
mov $0x6162636465666768, %r14
movq %r14, %xmm2
movups %xmm2, (%rdi)
nop
nop
inc %r14
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r14
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r13
push %rbp
push %rdi
// Faulty Load
lea addresses_US+0xebf6, %rdi
nop
inc %r12
mov (%rdi), %bp
lea oracles, %r11
and $0xff, %rbp
shlq $12, %rbp
mov (%r11,%rbp,1), %rbp
pop %rdi
pop %rbp
pop %r13
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_US', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_US', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'same': False, 'congruent': 5, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_UC_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 2, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'}
{'src': {'NT': True, 'same': False, 'congruent': 8, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 9, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_WT_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 4}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 16}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 8}}
{'src': {'same': False, 'congruent': 4, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_normal_ht'}}
{'src': {'same': False, 'congruent': 0, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_D_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 16}}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
gcc-gcc-7_3_0-release/gcc/ada/g-expect.adb | best08618/asylo | 7 | 8959 | <filename>gcc-gcc-7_3_0-release/gcc/ada/g-expect.adb<gh_stars>1-10
------------------------------------------------------------------------------
-- --
-- GNAT LIBRARY COMPONENTS --
-- --
-- G N A T . E X P E C T --
-- --
-- B o d y --
-- --
-- Copyright (C) 2000-2016, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with System; use System;
with System.OS_Constants; use System.OS_Constants;
with Ada.Calendar; use Ada.Calendar;
with GNAT.IO; use GNAT.IO;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with GNAT.Regpat; use GNAT.Regpat;
with Ada.Unchecked_Deallocation;
package body GNAT.Expect is
type Array_Of_Pd is array (Positive range <>) of Process_Descriptor_Access;
Expect_Process_Died : constant Expect_Match := -100;
Expect_Internal_Error : constant Expect_Match := -101;
-- Additional possible outputs of Expect_Internal. These are not visible in
-- the spec because the user will never see them.
procedure Expect_Internal
(Descriptors : in out Array_Of_Pd;
Result : out Expect_Match;
Timeout : Integer;
Full_Buffer : Boolean);
-- Internal function used to read from the process Descriptor.
--
-- Several outputs are possible:
-- Result=Expect_Timeout, if no output was available before the timeout
-- expired.
-- Result=Expect_Full_Buffer, if Full_Buffer is True and some characters
-- had to be discarded from the internal buffer of Descriptor.
-- Result=Express_Process_Died if one of the processes was terminated.
-- That process's Input_Fd is set to Invalid_FD
-- Result=Express_Internal_Error
-- Result=<integer>, indicates how many characters were added to the
-- internal buffer. These characters are from indexes
-- Descriptor.Buffer_Index - Result + 1 .. Descriptor.Buffer_Index
-- Process_Died is raised if the process is no longer valid.
procedure Reinitialize_Buffer
(Descriptor : in out Process_Descriptor'Class);
-- Reinitialize the internal buffer.
-- The buffer is deleted up to the end of the last match.
procedure Free is new Ada.Unchecked_Deallocation
(Pattern_Matcher, Pattern_Matcher_Access);
procedure Free is new Ada.Unchecked_Deallocation
(Filter_List_Elem, Filter_List);
procedure Call_Filters
(Pid : Process_Descriptor'Class;
Str : String;
Filter_On : Filter_Type);
-- Call all the filters that have the appropriate type.
-- This function does nothing if the filters are locked
------------------------------
-- Target dependent section --
------------------------------
function Dup (Fd : File_Descriptor) return File_Descriptor;
pragma Import (C, Dup);
procedure Dup2 (Old_Fd, New_Fd : File_Descriptor);
pragma Import (C, Dup2);
procedure Kill (Pid : Process_Id; Sig_Num : Integer; Close : Integer);
pragma Import (C, Kill, "__gnat_kill");
-- if Close is set to 1 all OS resources used by the Pid must be freed
function Create_Pipe (Pipe : not null access Pipe_Type) return Integer;
pragma Import (C, Create_Pipe, "__gnat_pipe");
function Poll
(Fds : System.Address;
Num_Fds : Integer;
Timeout : Integer;
Dead_Process : access Integer;
Is_Set : System.Address) return Integer;
pragma Import (C, Poll, "__gnat_expect_poll");
-- Check whether there is any data waiting on the file descriptors
-- Fds, and wait if there is none, at most Timeout milliseconds
-- Returns -1 in case of error, 0 if the timeout expired before
-- data became available.
--
-- Is_Set is an array of the same size as FDs and elements are set to 1 if
-- data is available for the corresponding File Descriptor, 0 otherwise.
--
-- If a process dies, then Dead_Process is set to the index of the
-- corresponding file descriptor.
function Waitpid (Pid : Process_Id) return Integer;
pragma Import (C, Waitpid, "__gnat_waitpid");
-- Wait for a specific process id, and return its exit code
---------
-- "+" --
---------
function "+" (S : String) return GNAT.OS_Lib.String_Access is
begin
return new String'(S);
end "+";
---------
-- "+" --
---------
function "+"
(P : GNAT.Regpat.Pattern_Matcher) return Pattern_Matcher_Access
is
begin
return new GNAT.Regpat.Pattern_Matcher'(P);
end "+";
----------------
-- Add_Filter --
----------------
procedure Add_Filter
(Descriptor : in out Process_Descriptor;
Filter : Filter_Function;
Filter_On : Filter_Type := Output;
User_Data : System.Address := System.Null_Address;
After : Boolean := False)
is
Current : Filter_List := Descriptor.Filters;
begin
if After then
while Current /= null and then Current.Next /= null loop
Current := Current.Next;
end loop;
if Current = null then
Descriptor.Filters :=
new Filter_List_Elem'
(Filter => Filter, Filter_On => Filter_On,
User_Data => User_Data, Next => null);
else
Current.Next :=
new Filter_List_Elem'
(Filter => Filter, Filter_On => Filter_On,
User_Data => User_Data, Next => null);
end if;
else
Descriptor.Filters :=
new Filter_List_Elem'
(Filter => Filter, Filter_On => Filter_On,
User_Data => User_Data, Next => Descriptor.Filters);
end if;
end Add_Filter;
------------------
-- Call_Filters --
------------------
procedure Call_Filters
(Pid : Process_Descriptor'Class;
Str : String;
Filter_On : Filter_Type)
is
Current_Filter : Filter_List;
begin
if Pid.Filters_Lock = 0 then
Current_Filter := Pid.Filters;
while Current_Filter /= null loop
if Current_Filter.Filter_On = Filter_On then
Current_Filter.Filter
(Pid, Str, Current_Filter.User_Data);
end if;
Current_Filter := Current_Filter.Next;
end loop;
end if;
end Call_Filters;
-----------
-- Close --
-----------
procedure Close
(Descriptor : in out Process_Descriptor;
Status : out Integer)
is
Current_Filter : Filter_List;
Next_Filter : Filter_List;
begin
if Descriptor.Input_Fd /= Invalid_FD then
Close (Descriptor.Input_Fd);
end if;
if Descriptor.Error_Fd /= Descriptor.Output_Fd then
Close (Descriptor.Error_Fd);
end if;
Close (Descriptor.Output_Fd);
-- ??? Should have timeouts for different signals
if Descriptor.Pid > 0 then -- see comment in Send_Signal
Kill (Descriptor.Pid, Sig_Num => 9, Close => 0);
end if;
GNAT.OS_Lib.Free (Descriptor.Buffer);
Descriptor.Buffer_Size := 0;
Current_Filter := Descriptor.Filters;
while Current_Filter /= null loop
Next_Filter := Current_Filter.Next;
Free (Current_Filter);
Current_Filter := Next_Filter;
end loop;
Descriptor.Filters := null;
-- Check process id (see comment in Send_Signal)
if Descriptor.Pid > 0 then
Status := Waitpid (Descriptor.Pid);
else
raise Invalid_Process;
end if;
end Close;
procedure Close (Descriptor : in out Process_Descriptor) is
Status : Integer;
pragma Unreferenced (Status);
begin
Close (Descriptor, Status);
end Close;
------------
-- Expect --
------------
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexp : String;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
begin
if Regexp = "" then
Expect (Descriptor, Result, Never_Match, Timeout, Full_Buffer);
else
Expect (Descriptor, Result, Compile (Regexp), Timeout, Full_Buffer);
end if;
end Expect;
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexp : String;
Matched : out GNAT.Regpat.Match_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
begin
pragma Assert (Matched'First = 0);
if Regexp = "" then
Expect
(Descriptor, Result, Never_Match, Matched, Timeout, Full_Buffer);
else
Expect
(Descriptor, Result, Compile (Regexp), Matched, Timeout,
Full_Buffer);
end if;
end Expect;
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexp : GNAT.Regpat.Pattern_Matcher;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
Matched : GNAT.Regpat.Match_Array (0 .. 0);
pragma Warnings (Off, Matched);
begin
Expect (Descriptor, Result, Regexp, Matched, Timeout, Full_Buffer);
end Expect;
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexp : GNAT.Regpat.Pattern_Matcher;
Matched : out GNAT.Regpat.Match_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
N : Expect_Match;
Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
Try_Until : constant Time := Clock + Duration (Timeout) / 1000.0;
Timeout_Tmp : Integer := Timeout;
begin
pragma Assert (Matched'First = 0);
Reinitialize_Buffer (Descriptor);
loop
-- First, test if what is already in the buffer matches (This is
-- required if this package is used in multi-task mode, since one of
-- the tasks might have added something in the buffer, and we don't
-- want other tasks to wait for new input to be available before
-- checking the regexps).
Match
(Regexp, Descriptor.Buffer (1 .. Descriptor.Buffer_Index), Matched);
if Descriptor.Buffer_Index >= 1 and then Matched (0).First /= 0 then
Result := 1;
Descriptor.Last_Match_Start := Matched (0).First;
Descriptor.Last_Match_End := Matched (0).Last;
return;
end if;
-- Else try to read new input
Expect_Internal (Descriptors, N, Timeout_Tmp, Full_Buffer);
case N is
when Expect_Internal_Error
| Expect_Process_Died
=>
raise Process_Died;
when Expect_Full_Buffer
| Expect_Timeout
=>
Result := N;
return;
when others =>
null; -- See below
end case;
-- Calculate the timeout for the next turn
-- Note that Timeout is, from the caller's perspective, the maximum
-- time until a match, not the maximum time until some output is
-- read, and thus cannot be reused as is for Expect_Internal.
if Timeout /= -1 then
Timeout_Tmp := Integer (Try_Until - Clock) * 1000;
if Timeout_Tmp < 0 then
Result := Expect_Timeout;
exit;
end if;
end if;
end loop;
-- Even if we had the general timeout above, we have to test that the
-- last test we read from the external process didn't match.
Match
(Regexp, Descriptor.Buffer (1 .. Descriptor.Buffer_Index), Matched);
if Matched (0).First /= 0 then
Result := 1;
Descriptor.Last_Match_Start := Matched (0).First;
Descriptor.Last_Match_End := Matched (0).Last;
return;
end if;
end Expect;
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexps : Regexp_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
Patterns : Compiled_Regexp_Array (Regexps'Range);
Matched : GNAT.Regpat.Match_Array (0 .. 0);
pragma Warnings (Off, Matched);
begin
for J in Regexps'Range loop
Patterns (J) := new Pattern_Matcher'(Compile (Regexps (J).all));
end loop;
Expect (Descriptor, Result, Patterns, Matched, Timeout, Full_Buffer);
for J in Regexps'Range loop
Free (Patterns (J));
end loop;
end Expect;
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexps : Compiled_Regexp_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
Matched : GNAT.Regpat.Match_Array (0 .. 0);
pragma Warnings (Off, Matched);
begin
Expect (Descriptor, Result, Regexps, Matched, Timeout, Full_Buffer);
end Expect;
procedure Expect
(Result : out Expect_Match;
Regexps : Multiprocess_Regexp_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
Matched : GNAT.Regpat.Match_Array (0 .. 0);
pragma Warnings (Off, Matched);
begin
Expect (Result, Regexps, Matched, Timeout, Full_Buffer);
end Expect;
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexps : Regexp_Array;
Matched : out GNAT.Regpat.Match_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
Patterns : Compiled_Regexp_Array (Regexps'Range);
begin
pragma Assert (Matched'First = 0);
for J in Regexps'Range loop
Patterns (J) := new Pattern_Matcher'(Compile (Regexps (J).all));
end loop;
Expect (Descriptor, Result, Patterns, Matched, Timeout, Full_Buffer);
for J in Regexps'Range loop
Free (Patterns (J));
end loop;
end Expect;
procedure Expect
(Descriptor : in out Process_Descriptor;
Result : out Expect_Match;
Regexps : Compiled_Regexp_Array;
Matched : out GNAT.Regpat.Match_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
N : Expect_Match;
Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
begin
pragma Assert (Matched'First = 0);
Reinitialize_Buffer (Descriptor);
loop
-- First, test if what is already in the buffer matches (This is
-- required if this package is used in multi-task mode, since one of
-- the tasks might have added something in the buffer, and we don't
-- want other tasks to wait for new input to be available before
-- checking the regexps).
if Descriptor.Buffer /= null then
for J in Regexps'Range loop
Match
(Regexps (J).all,
Descriptor.Buffer (1 .. Descriptor.Buffer_Index),
Matched);
if Matched (0) /= No_Match then
Result := Expect_Match (J);
Descriptor.Last_Match_Start := Matched (0).First;
Descriptor.Last_Match_End := Matched (0).Last;
return;
end if;
end loop;
end if;
Expect_Internal (Descriptors, N, Timeout, Full_Buffer);
case N is
when Expect_Internal_Error
| Expect_Process_Died
=>
raise Process_Died;
when Expect_Full_Buffer
| Expect_Timeout
=>
Result := N;
return;
when others =>
null; -- Continue
end case;
end loop;
end Expect;
procedure Expect
(Result : out Expect_Match;
Regexps : Multiprocess_Regexp_Array;
Matched : out GNAT.Regpat.Match_Array;
Timeout : Integer := 10_000;
Full_Buffer : Boolean := False)
is
N : Expect_Match;
Descriptors : Array_Of_Pd (Regexps'Range);
begin
pragma Assert (Matched'First = 0);
for J in Descriptors'Range loop
Descriptors (J) := Regexps (J).Descriptor;
if Descriptors (J) /= null then
Reinitialize_Buffer (Regexps (J).Descriptor.all);
end if;
end loop;
loop
-- First, test if what is already in the buffer matches (This is
-- required if this package is used in multi-task mode, since one of
-- the tasks might have added something in the buffer, and we don't
-- want other tasks to wait for new input to be available before
-- checking the regexps).
for J in Regexps'Range loop
if Regexps (J).Regexp /= null
and then Regexps (J).Descriptor /= null
then
Match (Regexps (J).Regexp.all,
Regexps (J).Descriptor.Buffer
(1 .. Regexps (J).Descriptor.Buffer_Index),
Matched);
if Matched (0) /= No_Match then
Result := Expect_Match (J);
Regexps (J).Descriptor.Last_Match_Start := Matched (0).First;
Regexps (J).Descriptor.Last_Match_End := Matched (0).Last;
return;
end if;
end if;
end loop;
Expect_Internal (Descriptors, N, Timeout, Full_Buffer);
case N is
when Expect_Internal_Error
| Expect_Process_Died
=>
raise Process_Died;
when Expect_Full_Buffer
| Expect_Timeout
=>
Result := N;
return;
when others =>
null; -- Continue
end case;
end loop;
end Expect;
---------------------
-- Expect_Internal --
---------------------
procedure Expect_Internal
(Descriptors : in out Array_Of_Pd;
Result : out Expect_Match;
Timeout : Integer;
Full_Buffer : Boolean)
is
Num_Descriptors : Integer;
Buffer_Size : Integer := 0;
N : Integer;
type File_Descriptor_Array is
array (0 .. Descriptors'Length - 1) of File_Descriptor;
Fds : aliased File_Descriptor_Array;
Fds_Count : Natural := 0;
Fds_To_Descriptor : array (Fds'Range) of Integer;
-- Maps file descriptor entries from Fds to entries in Descriptors.
-- They do not have the same index when entries in Descriptors are null.
type Integer_Array is array (Fds'Range) of Integer;
Is_Set : aliased Integer_Array;
begin
for J in Descriptors'Range loop
if Descriptors (J) /= null then
Fds (Fds'First + Fds_Count) := Descriptors (J).Output_Fd;
Fds_To_Descriptor (Fds'First + Fds_Count) := J;
Fds_Count := Fds_Count + 1;
if Descriptors (J).Buffer_Size = 0 then
Buffer_Size := Integer'Max (Buffer_Size, 4096);
else
Buffer_Size :=
Integer'Max (Buffer_Size, Descriptors (J).Buffer_Size);
end if;
end if;
end loop;
declare
Buffer : aliased String (1 .. Buffer_Size);
-- Buffer used for input. This is allocated only once, not for
-- every iteration of the loop
D : aliased Integer;
-- Index in Descriptors
begin
-- Loop until we match or we have a timeout
loop
Num_Descriptors :=
Poll (Fds'Address, Fds_Count, Timeout, D'Access, Is_Set'Address);
case Num_Descriptors is
-- Error?
when -1 =>
Result := Expect_Internal_Error;
if D /= 0 then
Close (Descriptors (D).Input_Fd);
Descriptors (D).Input_Fd := Invalid_FD;
end if;
return;
-- Timeout?
when 0 =>
Result := Expect_Timeout;
return;
-- Some input
when others =>
for F in Fds'Range loop
if Is_Set (F) = 1 then
D := Fds_To_Descriptor (F);
Buffer_Size := Descriptors (D).Buffer_Size;
if Buffer_Size = 0 then
Buffer_Size := 4096;
end if;
N := Read (Descriptors (D).Output_Fd, Buffer'Address,
Buffer_Size);
-- Error or End of file
if N <= 0 then
-- ??? Note that ddd tries again up to three times
-- in that case. See LiterateA.C:174
Close (Descriptors (D).Input_Fd);
Descriptors (D).Input_Fd := Invalid_FD;
Result := Expect_Process_Died;
return;
else
-- If there is no limit to the buffer size
if Descriptors (D).Buffer_Size = 0 then
declare
Tmp : String_Access := Descriptors (D).Buffer;
begin
if Tmp /= null then
Descriptors (D).Buffer :=
new String (1 .. Tmp'Length + N);
Descriptors (D).Buffer (1 .. Tmp'Length) :=
Tmp.all;
Descriptors (D).Buffer
(Tmp'Length + 1 .. Tmp'Length + N) :=
Buffer (1 .. N);
Free (Tmp);
Descriptors (D).Buffer_Index :=
Descriptors (D).Buffer'Last;
else
Descriptors (D).Buffer :=
new String (1 .. N);
Descriptors (D).Buffer.all :=
Buffer (1 .. N);
Descriptors (D).Buffer_Index := N;
end if;
end;
else
-- Add what we read to the buffer
if Descriptors (D).Buffer_Index + N >
Descriptors (D).Buffer_Size
then
-- If the user wants to know when we have
-- read more than the buffer can contain.
if Full_Buffer then
Result := Expect_Full_Buffer;
return;
end if;
-- Keep as much as possible from the buffer,
-- and forget old characters.
Descriptors (D).Buffer
(1 .. Descriptors (D).Buffer_Size - N) :=
Descriptors (D).Buffer
(N - Descriptors (D).Buffer_Size +
Descriptors (D).Buffer_Index + 1 ..
Descriptors (D).Buffer_Index);
Descriptors (D).Buffer_Index :=
Descriptors (D).Buffer_Size - N;
end if;
-- Keep what we read in the buffer
Descriptors (D).Buffer
(Descriptors (D).Buffer_Index + 1 ..
Descriptors (D).Buffer_Index + N) :=
Buffer (1 .. N);
Descriptors (D).Buffer_Index :=
Descriptors (D).Buffer_Index + N;
end if;
-- Call each of the output filter with what we
-- read.
Call_Filters
(Descriptors (D).all, Buffer (1 .. N), Output);
Result := Expect_Match (D);
return;
end if;
end if;
end loop;
end case;
end loop;
end;
end Expect_Internal;
----------------
-- Expect_Out --
----------------
function Expect_Out (Descriptor : Process_Descriptor) return String is
begin
return Descriptor.Buffer (1 .. Descriptor.Last_Match_End);
end Expect_Out;
----------------------
-- Expect_Out_Match --
----------------------
function Expect_Out_Match (Descriptor : Process_Descriptor) return String is
begin
return Descriptor.Buffer
(Descriptor.Last_Match_Start .. Descriptor.Last_Match_End);
end Expect_Out_Match;
------------------------
-- First_Dead_Process --
------------------------
function First_Dead_Process
(Regexp : Multiprocess_Regexp_Array) return Natural is
begin
for R in Regexp'Range loop
if Regexp (R).Descriptor /= null
and then Regexp (R).Descriptor.Input_Fd = GNAT.OS_Lib.Invalid_FD
then
return R;
end if;
end loop;
return 0;
end First_Dead_Process;
-----------
-- Flush --
-----------
procedure Flush
(Descriptor : in out Process_Descriptor;
Timeout : Integer := 0)
is
Buffer_Size : constant Integer := 8192;
Num_Descriptors : Integer;
N : aliased Integer;
Is_Set : aliased Integer;
Buffer : aliased String (1 .. Buffer_Size);
begin
-- Empty the current buffer
Descriptor.Last_Match_End := Descriptor.Buffer_Index;
Reinitialize_Buffer (Descriptor);
-- Read everything from the process to flush its output
loop
Num_Descriptors :=
Poll (Descriptor.Output_Fd'Address,
1,
Timeout,
N'Access,
Is_Set'Address);
case Num_Descriptors is
-- Error ?
when -1 =>
raise Process_Died;
-- Timeout => End of flush
when 0 =>
return;
-- Some input
when others =>
if Is_Set = 1 then
N := Read (Descriptor.Output_Fd, Buffer'Address,
Buffer_Size);
if N = -1 then
raise Process_Died;
elsif N = 0 then
return;
end if;
end if;
end case;
end loop;
end Flush;
----------
-- Free --
----------
procedure Free (Regexp : in out Multiprocess_Regexp) is
procedure Unchecked_Free is new Ada.Unchecked_Deallocation
(Process_Descriptor'Class, Process_Descriptor_Access);
begin
Unchecked_Free (Regexp.Descriptor);
Free (Regexp.Regexp);
end Free;
------------------------
-- Get_Command_Output --
------------------------
function Get_Command_Output
(Command : String;
Arguments : GNAT.OS_Lib.Argument_List;
Input : String;
Status : not null access Integer;
Err_To_Out : Boolean := False) return String
is
use GNAT.Expect;
Process : Process_Descriptor;
Output : String_Access := new String (1 .. 1024);
-- Buffer used to accumulate standard output from the launched
-- command, expanded as necessary during execution.
Last : Integer := 0;
-- Index of the last used character within Output
begin
Non_Blocking_Spawn
(Process, Command, Arguments, Err_To_Out => Err_To_Out,
Buffer_Size => 0);
if Input'Length > 0 then
Send (Process, Input);
end if;
Close (Process.Input_Fd);
Process.Input_Fd := Invalid_FD;
declare
Result : Expect_Match;
pragma Unreferenced (Result);
begin
-- This loop runs until the call to Expect raises Process_Died
loop
Expect (Process, Result, ".+", Timeout => -1);
declare
NOutput : String_Access;
S : constant String := Expect_Out (Process);
pragma Assert (S'Length > 0);
begin
-- Expand buffer if we need more space. Note here that we add
-- S'Length to ensure that S will fit in the new buffer size.
if Last + S'Length > Output'Last then
NOutput := new String (1 .. 2 * Output'Last + S'Length);
NOutput (Output'Range) := Output.all;
Free (Output);
-- Here if current buffer size is OK
else
NOutput := Output;
end if;
NOutput (Last + 1 .. Last + S'Length) := S;
Last := Last + S'Length;
Output := NOutput;
end;
end loop;
exception
when Process_Died =>
Close (Process, Status.all);
end;
if Last = 0 then
Free (Output);
return "";
end if;
declare
S : constant String := Output (1 .. Last);
begin
Free (Output);
return S;
end;
end Get_Command_Output;
------------------
-- Get_Error_Fd --
------------------
function Get_Error_Fd
(Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor
is
begin
return Descriptor.Error_Fd;
end Get_Error_Fd;
------------------
-- Get_Input_Fd --
------------------
function Get_Input_Fd
(Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor
is
begin
return Descriptor.Input_Fd;
end Get_Input_Fd;
-------------------
-- Get_Output_Fd --
-------------------
function Get_Output_Fd
(Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor
is
begin
return Descriptor.Output_Fd;
end Get_Output_Fd;
-------------
-- Get_Pid --
-------------
function Get_Pid
(Descriptor : Process_Descriptor) return Process_Id
is
begin
return Descriptor.Pid;
end Get_Pid;
-----------------
-- Has_Process --
-----------------
function Has_Process (Regexp : Multiprocess_Regexp_Array) return Boolean is
begin
return Regexp /= (Regexp'Range => (null, null));
end Has_Process;
---------------
-- Interrupt --
---------------
procedure Interrupt (Descriptor : in out Process_Descriptor) is
SIGINT : constant := 2;
begin
Send_Signal (Descriptor, SIGINT);
end Interrupt;
------------------
-- Lock_Filters --
------------------
procedure Lock_Filters (Descriptor : in out Process_Descriptor) is
begin
Descriptor.Filters_Lock := Descriptor.Filters_Lock + 1;
end Lock_Filters;
------------------------
-- Non_Blocking_Spawn --
------------------------
procedure Non_Blocking_Spawn
(Descriptor : out Process_Descriptor'Class;
Command : String;
Args : GNAT.OS_Lib.Argument_List;
Buffer_Size : Natural := 4096;
Err_To_Out : Boolean := False)
is
function Fork return Process_Id;
pragma Import (C, Fork, "__gnat_expect_fork");
-- Starts a new process if possible. See the Unix command fork for more
-- information. On systems that do not support this capability (such as
-- Windows...), this command does nothing, and Fork will return
-- Null_Pid.
Pipe1, Pipe2, Pipe3 : aliased Pipe_Type;
Arg : String_Access;
Arg_List : String_List (1 .. Args'Length + 2);
C_Arg_List : aliased array (1 .. Args'Length + 2) of System.Address;
Command_With_Path : String_Access;
begin
Command_With_Path := Locate_Exec_On_Path (Command);
if Command_With_Path = null then
raise Invalid_Process;
end if;
-- Create the rest of the pipes once we know we will be able to
-- execute the process.
Set_Up_Communications
(Descriptor, Err_To_Out, Pipe1'Access, Pipe2'Access, Pipe3'Access);
-- Fork a new process
Descriptor.Pid := Fork;
-- Are we now in the child (or, for Windows, still in the common
-- process).
if Descriptor.Pid = Null_Pid then
-- Prepare an array of arguments to pass to C
Arg := new String (1 .. Command_With_Path'Length + 1);
Arg (1 .. Command_With_Path'Length) := Command_With_Path.all;
Arg (Arg'Last) := ASCII.NUL;
Arg_List (1) := Arg;
for J in Args'Range loop
Arg := new String (1 .. Args (J)'Length + 1);
Arg (1 .. Args (J)'Length) := Args (J).all;
Arg (Arg'Last) := ASCII.NUL;
Arg_List (J + 2 - Args'First) := Arg.all'Access;
end loop;
Arg_List (Arg_List'Last) := null;
-- Make sure all arguments are compatible with OS conventions
Normalize_Arguments (Arg_List);
-- Prepare low-level argument list from the normalized arguments
for K in Arg_List'Range loop
C_Arg_List (K) :=
(if Arg_List (K) /= null
then Arg_List (K).all'Address
else System.Null_Address);
end loop;
-- This does not return on Unix systems
Set_Up_Child_Communications
(Descriptor, Pipe1, Pipe2, Pipe3, Command_With_Path.all,
C_Arg_List'Address);
end if;
Free (Command_With_Path);
-- Did we have an error when spawning the child ?
if Descriptor.Pid < Null_Pid then
raise Invalid_Process;
else
-- We are now in the parent process
Set_Up_Parent_Communications (Descriptor, Pipe1, Pipe2, Pipe3);
end if;
-- Create the buffer
Descriptor.Buffer_Size := Buffer_Size;
if Buffer_Size /= 0 then
Descriptor.Buffer := new String (1 .. Positive (Buffer_Size));
end if;
-- Initialize the filters
Descriptor.Filters := null;
end Non_Blocking_Spawn;
-------------------------
-- Reinitialize_Buffer --
-------------------------
procedure Reinitialize_Buffer
(Descriptor : in out Process_Descriptor'Class)
is
begin
if Descriptor.Buffer_Size = 0 then
declare
Tmp : String_Access := Descriptor.Buffer;
begin
Descriptor.Buffer :=
new String
(1 .. Descriptor.Buffer_Index - Descriptor.Last_Match_End);
if Tmp /= null then
Descriptor.Buffer.all := Tmp
(Descriptor.Last_Match_End + 1 .. Descriptor.Buffer_Index);
Free (Tmp);
end if;
end;
Descriptor.Buffer_Index := Descriptor.Buffer'Last;
else
Descriptor.Buffer
(1 .. Descriptor.Buffer_Index - Descriptor.Last_Match_End) :=
Descriptor.Buffer
(Descriptor.Last_Match_End + 1 .. Descriptor.Buffer_Index);
if Descriptor.Buffer_Index > Descriptor.Last_Match_End then
Descriptor.Buffer_Index :=
Descriptor.Buffer_Index - Descriptor.Last_Match_End;
else
Descriptor.Buffer_Index := 0;
end if;
end if;
Descriptor.Last_Match_Start := 0;
Descriptor.Last_Match_End := 0;
end Reinitialize_Buffer;
-------------------
-- Remove_Filter --
-------------------
procedure Remove_Filter
(Descriptor : in out Process_Descriptor;
Filter : Filter_Function)
is
Previous : Filter_List := null;
Current : Filter_List := Descriptor.Filters;
begin
while Current /= null loop
if Current.Filter = Filter then
if Previous = null then
Descriptor.Filters := Current.Next;
else
Previous.Next := Current.Next;
end if;
end if;
Previous := Current;
Current := Current.Next;
end loop;
end Remove_Filter;
----------
-- Send --
----------
procedure Send
(Descriptor : in out Process_Descriptor;
Str : String;
Add_LF : Boolean := True;
Empty_Buffer : Boolean := False)
is
Line_Feed : aliased constant String := (1 .. 1 => ASCII.LF);
Descriptors : Array_Of_Pd := (1 => Descriptor'Unrestricted_Access);
Result : Expect_Match;
Discard : Natural;
pragma Warnings (Off, Result);
pragma Warnings (Off, Discard);
begin
if Empty_Buffer then
-- Force a read on the process if there is anything waiting
Expect_Internal
(Descriptors, Result, Timeout => 0, Full_Buffer => False);
if Result = Expect_Internal_Error
or else Result = Expect_Process_Died
then
raise Process_Died;
end if;
Descriptor.Last_Match_End := Descriptor.Buffer_Index;
-- Empty the buffer
Reinitialize_Buffer (Descriptor);
end if;
Call_Filters (Descriptor, Str, Input);
Discard :=
Write (Descriptor.Input_Fd, Str'Address, Str'Last - Str'First + 1);
if Add_LF then
Call_Filters (Descriptor, Line_Feed, Input);
Discard :=
Write (Descriptor.Input_Fd, Line_Feed'Address, 1);
end if;
end Send;
-----------------
-- Send_Signal --
-----------------
procedure Send_Signal
(Descriptor : Process_Descriptor;
Signal : Integer)
is
begin
-- A nonpositive process id passed to kill has special meanings. For
-- example, -1 means kill all processes in sight, including self, in
-- POSIX and Windows (and something slightly different in Linux). See
-- man pages for details. In any case, we don't want to do that. Note
-- that Descriptor.Pid will be -1 if the process was not successfully
-- started; we don't want to kill ourself in that case.
if Descriptor.Pid > 0 then
Kill (Descriptor.Pid, Signal, Close => 1);
-- ??? Need to check process status here
else
raise Invalid_Process;
end if;
end Send_Signal;
---------------------------------
-- Set_Up_Child_Communications --
---------------------------------
procedure Set_Up_Child_Communications
(Pid : in out Process_Descriptor;
Pipe1 : in out Pipe_Type;
Pipe2 : in out Pipe_Type;
Pipe3 : in out Pipe_Type;
Cmd : String;
Args : System.Address)
is
pragma Warnings (Off, Pid);
pragma Warnings (Off, Pipe1);
pragma Warnings (Off, Pipe2);
pragma Warnings (Off, Pipe3);
Input : File_Descriptor;
Output : File_Descriptor;
Error : File_Descriptor;
No_Fork_On_Target : constant Boolean := Target_OS = Windows;
begin
if No_Fork_On_Target then
-- Since Windows does not have a separate fork/exec, we need to
-- perform the following actions:
-- - save stdin, stdout, stderr
-- - replace them by our pipes
-- - create the child with process handle inheritance
-- - revert to the previous stdin, stdout and stderr.
Input := Dup (GNAT.OS_Lib.Standin);
Output := Dup (GNAT.OS_Lib.Standout);
Error := Dup (GNAT.OS_Lib.Standerr);
end if;
-- Since we are still called from the parent process, there is no way
-- currently we can cleanly close the unneeded ends of the pipes, but
-- this doesn't really matter.
-- We could close Pipe1.Output, Pipe2.Input, Pipe3.Input
Dup2 (Pipe1.Input, GNAT.OS_Lib.Standin);
Dup2 (Pipe2.Output, GNAT.OS_Lib.Standout);
Dup2 (Pipe3.Output, GNAT.OS_Lib.Standerr);
Portable_Execvp (Pid.Pid'Access, Cmd & ASCII.NUL, Args);
-- The following lines are only required for Windows systems and will
-- not be executed on Unix systems, but we use the same condition as
-- above to avoid warnings on uninitialized variables on Unix systems.
-- We are now in the parent process.
if No_Fork_On_Target then
-- Restore the old descriptors
Dup2 (Input, GNAT.OS_Lib.Standin);
Dup2 (Output, GNAT.OS_Lib.Standout);
Dup2 (Error, GNAT.OS_Lib.Standerr);
Close (Input);
Close (Output);
Close (Error);
end if;
end Set_Up_Child_Communications;
---------------------------
-- Set_Up_Communications --
---------------------------
procedure Set_Up_Communications
(Pid : in out Process_Descriptor;
Err_To_Out : Boolean;
Pipe1 : not null access Pipe_Type;
Pipe2 : not null access Pipe_Type;
Pipe3 : not null access Pipe_Type)
is
Status : Boolean;
pragma Unreferenced (Status);
begin
-- Create the pipes
if Create_Pipe (Pipe1) /= 0 then
return;
end if;
if Create_Pipe (Pipe2) /= 0 then
Close (Pipe1.Input);
Close (Pipe1.Output);
return;
end if;
-- Record the 'parent' end of the two pipes in Pid:
-- Child stdin is connected to the 'write' end of Pipe1;
-- Child stdout is connected to the 'read' end of Pipe2.
-- We do not want these descriptors to remain open in the child
-- process, so we mark them close-on-exec/non-inheritable.
Pid.Input_Fd := Pipe1.Output;
Set_Close_On_Exec (Pipe1.Output, True, Status);
Pid.Output_Fd := Pipe2.Input;
Set_Close_On_Exec (Pipe2.Input, True, Status);
if Err_To_Out then
-- Reuse the standard output pipe for standard error
Pipe3.all := Pipe2.all;
else
-- Create a separate pipe for standard error
if Create_Pipe (Pipe3) /= 0 then
Pipe3.all := Pipe2.all;
end if;
end if;
-- As above, record the proper fd for the child's standard error stream
Pid.Error_Fd := Pipe3.Input;
Set_Close_On_Exec (Pipe3.Input, True, Status);
end Set_Up_Communications;
----------------------------------
-- Set_Up_Parent_Communications --
----------------------------------
procedure Set_Up_Parent_Communications
(Pid : in out Process_Descriptor;
Pipe1 : in out Pipe_Type;
Pipe2 : in out Pipe_Type;
Pipe3 : in out Pipe_Type)
is
pragma Warnings (Off, Pid);
pragma Warnings (Off, Pipe1);
pragma Warnings (Off, Pipe2);
pragma Warnings (Off, Pipe3);
begin
Close (Pipe1.Input);
Close (Pipe2.Output);
if Pipe3.Output /= Pipe2.Output then
Close (Pipe3.Output);
end if;
end Set_Up_Parent_Communications;
------------------
-- Trace_Filter --
------------------
procedure Trace_Filter
(Descriptor : Process_Descriptor'Class;
Str : String;
User_Data : System.Address := System.Null_Address)
is
pragma Warnings (Off, Descriptor);
pragma Warnings (Off, User_Data);
begin
GNAT.IO.Put (Str);
end Trace_Filter;
--------------------
-- Unlock_Filters --
--------------------
procedure Unlock_Filters (Descriptor : in out Process_Descriptor) is
begin
if Descriptor.Filters_Lock > 0 then
Descriptor.Filters_Lock := Descriptor.Filters_Lock - 1;
end if;
end Unlock_Filters;
end GNAT.Expect;
|
src/pycropml/transpiler/antlr_py/grammars/Comments.g4 | AgriculturalModelExchangeInitiative/PyCropML | 3 | 3616 | /*
Copyright (c) 2022 Cyrille.
License for use and distribution: Eclipse Public License
CyML comments language grammar
*/
grammar Comments;
documentation
: '!%%Cyml Comments Begin%%' documentationContent '!%%Cyml Comments End%%' EOF
;
documentationContent: comment_line +;
comment_line
: Symbol Identifier /* DESCRIPTION '('Unit')' '('Value ',' '['Value '-' Value ']' ')' '('CATEGORY ')'*/
;
Identifier
: [A-Za-z_][A-Za-z0-9_]*
;
/*
CATEGORY : 'state' | 'rate' | 'exogenous' | 'soil' |'genotypic' | 'constant';
Value : NUM+ '.' NUM*;
*/
/*
Unit
: (~[ \t\r\n()#"\\] | Escape_sequence)+
;
Escape_sequence
: Escape_identity | Escape_encoded | Escape_semicolon
;
*/
Symbol: ('!'|'#'|'//');
fragment Newline
: '\r\n' | '\r' | '\n'
;
fragment Num
: ('0' .. '9')
;
/*
fragment
Escape_identity
: '\\' ~[A-Za-z0-9;]
;
fragment
Escape_encoded
: '\\t' | '\\r' | '\\n'
;
fragment
Escape_semicolon
: '\\;'
;
*/
/*
fragment
Quoted_cont
: '\\' ('\r' '\n'? | '\n')
;
Bracket_argument
: '[' Bracket_arg_nested ']'
;
fragment
Bracket_arg_nested
: '=' Bracket_arg_nested '='
| '[' .*? ']'
;
*/
fragment Space
: (' '|'\t')+
;
Ws
: (Space+|Newline) -> skip
;
/*DESCRIPTION
: ~[()! ] + .
;*/
/*LINECONT
: (SPACE? NEWLINE SPACE* [ \t] * '! ') -> skip
;*/
|
src/test/resources/data/potests/test46.asm | cpcitor/mdlz80optimizer | 36 | 90562 | <reponame>cpcitor/mdlz80optimizer
; test to check the "bit 6,a" pattern
bit 6,a
jp nz,loop
ld (hl), 1
loop:
jr loop
|
programs/oeis/004/A004152.asm | neoneye/loda | 22 | 11319 | ; A004152: Sum of digits of n!.
; 1,1,2,6,6,3,9,9,9,27,27,36,27,27,45,45,63,63,54,45,54,63,72,99,81,72,81,108,90,126,117,135,108,144,144,144,171,153,108,189,189,144,189,180,216,207,216,225,234,225,216,198,279,279,261,279,333,270,288,324,288,315,306,333,324,351,351,369,342,351,459,423,432,315,378,432,441,432,423,441,450,486,477,486,477,414,495,495,531,549,585,594,540,513,549,585,648,648,639,648
seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters).
seq $0,7953 ; Digital sum (i.e., sum of digits) of n; also called digsum(n).
|
Source/Assembly/eeprom2.65c02.asm | neilpate/6502-Sandbox | 0 | 83987 | .target "6502"
EEPROM .equ $E000
.org $E000
reset:
lda EEPROM
lda EEPROM + 32
lda EEPROM + 33
lda EEPROM + 34
jmp reset
.org $fffc
.word reset
.word $0000
|
tools/SPARK2005/examples/erfRiemann/tutorial-steps/02-methodError/riemann.adb | michalkonecny/polypaver | 1 | 1225 | <gh_stars>1-10
with PP_F_Elementary;
package body Riemann is
function erf_Riemann(x : Float; n : Integer) return Float
is
partitionSize : Integer;
stepSize : Float;
tLeft : Float;
valueLeft : Float;
result : Float;
step : Integer;
begin
partitionSize := 2 ** n;
stepSize := x/Float(partitionSize);
result := 0.0;
step := 0;
while step < (2**n) loop
tLeft := stepSize * Float(step);
valueLeft := PP_F_Elementary.Exp(-(tLeft * tLeft));
result := result + stepSize * valueLeft;
step := step + 1;
end loop;
return result;
end erf_Riemann;
end Riemann;
|
bb-runtimes/src/s-bbsuti__riscv_clint.adb | JCGobbi/Nucleo-STM32G474RE | 0 | 15340 | ------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . B B . B O A R D _ S U P P O R T . T I M E --
-- --
-- B o d y --
-- --
-- Copyright (C) 1999-2002 Universidad Politecnica de Madrid --
-- Copyright (C) 2003-2005 The European Space Agency --
-- Copyright (C) 2003-2019, AdaCore --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
-- The port of GNARL to bare board targets was initially developed by the --
-- Real-Time Systems Group at the Technical University of Madrid. --
-- --
------------------------------------------------------------------------------
with System.BB.Board_Parameters;
with System.BB.CPU_Specific;
with Interfaces; use Interfaces;
separate (System.BB.Board_Support)
package body Time is
package BBBOPA renames System.BB.Board_Parameters;
-----------------------
-- Local Definitions --
-----------------------
Mtime_Lo : Unsigned_32
with Volatile,
Address => System'To_Address (BBBOPA.Mtime_Base_Address);
Mtime_Hi : Unsigned_32
with Volatile,
Address => System'To_Address (BBBOPA.Mtime_Base_Address + 4);
-- The mtime register has a 64-bit precision on all RV32, RV64, and RV128
-- systems.
Mtimecmp_Lo : Unsigned_32
with Volatile,
Address => System'To_Address (BBBOPA.Mtimecmp_Base_Address);
Mtimecmp_Hi : Unsigned_32
with Volatile,
Address => System'To_Address (BBBOPA.Mtimecmp_Base_Address + 4);
-- The mtimecmp register has a 64-bit precision on all RV32, RV64, and
-- RV128 systems.
----------------
-- Read_Clock --
----------------
function Read_Clock return BB.Time.Time is
Lo : Unsigned_32;
Hi : Unsigned_32;
Hi1 : Unsigned_32;
Result : Unsigned_64;
begin
-- We don't atomically read the 64-bits counter. So check that the 32
-- MSB don't change. Note that mtime could be read atomically on RV64
-- and RV128, this would require a separate implementation.
Hi := Mtime_Hi;
loop
Lo := Mtime_Lo;
Hi1 := Mtime_Hi;
exit when Hi = Hi1;
Hi := Hi1;
end loop;
Result := Unsigned_64 (Hi) * 2**32 + Unsigned_64 (Lo);
Result := Result * System.BB.Board_Parameters.Clock_Scale;
return BB.Time.Time (Result);
end Read_Clock;
---------------------------
-- Install_Alarm_Handler --
---------------------------
procedure Install_Alarm_Handler
(Handler : BB.Interrupts.Interrupt_Handler)
is
begin
CPU_Specific.Install_Trap_Handler
(Handler, CPU_Specific.Timer_Trap);
end Install_Alarm_Handler;
---------------
-- Set_Alarm --
---------------
procedure Set_Alarm (Ticks : BB.Time.Time)
is
U64_Ticks : constant Unsigned_64 :=
Unsigned_64 (Ticks) / System.BB.Board_Parameters.Clock_Scale;
Lo : constant Unsigned_32 :=
Unsigned_32 (U64_Ticks and 16#FFFF_FFFF#);
Hi : constant Unsigned_32 :=
Unsigned_32 (Shift_Right (U64_Ticks, 32) and 16#FFFF_FFFF#);
begin
-- In RV32, memory-mapped writes to mtimecmp modify only one 32-bit
-- part of the register. The following code sequence sets a 64-bit
-- mtimecmp value without spuriously generating a timer interrupt due to
-- the intermediate value of the comparand:
Mtimecmp_Lo := Unsigned_32'Last; -- No smaller than old value
Mtimecmp_Hi := Hi; -- No smaller than new value
Mtimecmp_Lo := Lo; -- New value.
end Set_Alarm;
---------------------------
-- Clear_Alarm_Interrupt --
---------------------------
procedure Clear_Alarm_Interrupt is
begin
Mtimecmp_Lo := Unsigned_32'Last;
Mtimecmp_Hi := Unsigned_32'Last;
end Clear_Alarm_Interrupt;
end Time;
|
2020/12/solution.adb | dglmoore/advent-of-code | 0 | 7526 | <filename>2020/12/solution.adb
with Ada.Containers.Vectors;
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
procedure Solution is
package Line_Vectors is new Ada.Containers.Vectors (Natural, Unbounded_String);
use Line_Vectors;
type Ship is tagged
record
X : Real_Vector := (0.0, 0.0);
end record;
function Read_Instructions(Filename : String) return Vector is
File : File_Type;
Lines : Vector;
begin
Open (File => File,
Mode => In_File,
Name => Filename);
while not End_Of_File (File) loop
Append (Lines, To_Unbounded_String (Get_Line (File)));
end loop;
Close(File);
return Lines;
end Read_Instructions;
Instructions : Vector;
begin
Instructions := Read_Instructions ("input.txt");
for Instruction of Instructions loop
Put_Line (Character'Image (Element (Instruction, 1)));
end loop;
end;
|
programs/oeis/290/A290631.asm | neoneye/loda | 22 | 5422 | <reponame>neoneye/loda
; A290631: a(n) = (n^2 + 1) * (2*n - 1).
; 2,15,50,119,234,407,650,975,1394,1919,2562,3335,4250,5319,6554,7967,9570,11375,13394,15639,18122,20855,23850,27119,30674,34527,38690,43175,47994,53159,58682,64575,70850,77519,84594,92087,100010,108375,117194,126479,136242,146495,157250,168519,180314,192647,205530,218975,232994,247599,262802,278615,295050,312119,329834,348207,367250,386975,407394,428519,450362,472935,496250,520319,545154,570767,597170,624375,652394,681239,710922,741455,772850,805119,838274,872327,907290,943175,979994,1017759,1056482,1096175,1136850,1178519,1221194,1264887,1309610,1355375,1402194,1450079,1499042,1549095,1600250,1652519,1705914,1760447,1816130,1872975,1930994,1990199
mov $1,$0
pow $0,2
add $0,3
mov $2,$1
mul $2,2
add $2,5
mul $0,$2
sub $0,13
|
oeis/229/A229554.asm | neoneye/loda-programs | 11 | 247624 | <gh_stars>10-100
; A229554: 7*n! + 1.
; 8,8,15,43,169,841,5041,35281,282241,2540161,25401601,279417601,3353011201,43589145601,610248038401,9153720576001,146459529216001,2489811996672001,44816615940096001,851515702861824001,17030314057236480001,357636595201966080001,7868005094443253760001,180964117172194836480001,4343138812132676075520001,108578470303316901888000001,2823040227886239449088000001,76222086152928465125376000001,2134218412281997023510528000001,61892333956177913681805312000001,1856770018685337410454159360000001
seq $0,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters).
mul $0,7
add $0,1
|
src/boot_sect_main.asm | thinkreed/tinyos | 0 | 244051 | [org 0x7c00]
mov bx, HELLO
call print
call print_nl
mov bx, GOODBYE
call print
call print_nl
mov dx, 0x12fe
call print_hex
jmp $
%include "src/boot_sect_print.asm"
%include "src/boot_sect_print_hex.asm"
HELLO:
db 'Hello, World', 0
GOODBYE:
db 'Goodbye', 0
times 510-($-$$) db 0
dw 0xaa55
|
Transynther/x86/_processed/AVXALIGN/_zr_/i7-8650U_0xd2.log_185_1675.asm | ljhsiun2/medusa | 9 | 84294 | .global s_prepare_buffers
s_prepare_buffers:
push %r14
push %r15
push %r8
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_normal_ht+0x1099d, %r8
nop
inc %rdx
movb $0x61, (%r8)
nop
add $2300, %r8
lea addresses_D_ht+0x1efa7, %rsi
lea addresses_WC_ht+0x12bc7, %rdi
nop
nop
nop
cmp $59719, %r15
mov $111, %rcx
rep movsw
nop
nop
nop
nop
nop
cmp $28559, %r15
lea addresses_WT_ht+0x3467, %rcx
nop
xor $25975, %rdx
mov (%rcx), %edi
nop
xor %r15, %r15
lea addresses_normal_ht+0x6507, %rcx
clflush (%rcx)
nop
inc %rdx
mov (%rcx), %r8d
nop
nop
nop
nop
nop
inc %r8
lea addresses_D_ht+0xc6c7, %rdi
nop
nop
nop
inc %rdx
mov $0x6162636465666768, %rcx
movq %rcx, %xmm4
movups %xmm4, (%rdi)
nop
nop
nop
nop
and $47069, %r14
lea addresses_WT_ht+0x48a7, %rdi
nop
and $11144, %r15
mov $0x6162636465666768, %rcx
movq %rcx, (%rdi)
sub $46577, %r15
lea addresses_WC_ht+0x42de, %rdx
nop
nop
nop
dec %rdi
mov (%rdx), %r8w
and $7303, %rsi
lea addresses_D_ht+0x8fa7, %rsi
clflush (%rsi)
nop
nop
nop
nop
xor %r14, %r14
and $0xffffffffffffffc0, %rsi
movntdqa (%rsi), %xmm6
vpextrq $0, %xmm6, %rdx
dec %r15
lea addresses_normal_ht+0x1951f, %rsi
lea addresses_WC_ht+0x2fa7, %rdi
clflush (%rsi)
nop
nop
nop
nop
nop
sub $22416, %r15
mov $25, %rcx
rep movsq
nop
nop
nop
and %rdi, %rdi
lea addresses_normal_ht+0x7f67, %rsi
lea addresses_WT_ht+0x1b705, %rdi
clflush (%rdi)
and $57248, %rax
mov $65, %rcx
rep movsl
sub %rsi, %rsi
lea addresses_A_ht+0xee3f, %rsi
lea addresses_WC_ht+0x7007, %rdi
nop
nop
xor %r14, %r14
mov $94, %rcx
rep movsw
nop
nop
and %rcx, %rcx
lea addresses_normal_ht+0xa7a7, %rsi
lea addresses_normal_ht+0x6ebf, %rdi
nop
nop
nop
nop
nop
add %r14, %r14
mov $67, %rcx
rep movsq
xor $9062, %rax
lea addresses_WC_ht+0x1bfa7, %rsi
lea addresses_D_ht+0x105, %rdi
nop
and $50580, %r14
mov $68, %rcx
rep movsq
cmp %rdx, %rdx
lea addresses_D_ht+0x1e4cc, %rsi
lea addresses_UC_ht+0x156a7, %rdi
nop
nop
inc %rdx
mov $26, %rcx
rep movsw
nop
nop
dec %r15
lea addresses_D_ht+0x162e7, %rsi
nop
nop
nop
nop
dec %rdx
movb (%rsi), %r8b
nop
nop
nop
dec %rax
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r15
pop %r14
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r14
push %r15
push %r9
push %rbx
push %rcx
// Store
lea addresses_UC+0x9335, %rcx
nop
lfence
mov $0x5152535455565758, %r13
movq %r13, %xmm2
vmovups %ymm2, (%rcx)
nop
nop
sub %r9, %r9
// Load
mov $0x629fef00000005a7, %r15
nop
nop
nop
dec %r9
movups (%r15), %xmm5
vpextrq $1, %xmm5, %rcx
nop
nop
nop
sub %rcx, %rcx
// Store
lea addresses_RW+0x1e3a7, %r15
nop
nop
nop
nop
and %r14, %r14
mov $0x5152535455565758, %r9
movq %r9, %xmm6
movups %xmm6, (%r15)
nop
nop
nop
and %r13, %r13
// Faulty Load
mov $0x6ab02200000007a7, %r11
nop
nop
nop
add $51736, %rcx
movb (%r11), %bl
lea oracles, %rcx
and $0xff, %rbx
shlq $12, %rbx
mov (%rcx,%rbx,1), %rbx
pop %rcx
pop %rbx
pop %r9
pop %r15
pop %r14
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'size': 1, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 5, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 11, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': True}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': True}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'00': 185}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.