text:
## Python Readlines Remove Newline Character

Python convert unicode to string Tags Python Recursion C++ Lecture Notes Optimization Perl Java Divide and Conquer Sorting Dynamic Programming Windows SQL Hash Table Loop Invariant UNIX C# Linux Encoding SSL Binary Search JSON Greedy Algorithm Pixel Shader iOS Sikuli Linked List Tree Android HTTP API Exponential Factorial Regular Expressions. and I remove readlines() already, do you think what could cause this? ADD REPLY • link written 2. This document is a selflearning document for a course in Python programming. Some of the features described here may not be available in earlier versions of Python. Run the file count_words. Change Python (. read mode ("r"): Read data from file into python variables. I've noted that bz2 seems to do a pretty good job with universal newline handling: python/trunk. A python string represents a sequence of unicode characters (this was an area of language-cleanup in the move to Python 3. - nmpeterson Aug 6 '14 at 19:50. Secondly, when a file is opened in text mode, Python automatically performs universal newline translation, so that you get returned regardless of whether it was or \r or \r in the file. # # The filename will be provided as a command line argument. You can use. If you don't have basic concepts of Python then I will recommend you to first take Module 1 - Refresh Your Python Basics. \n', 'Line 3. isdigit() True. Matching Newlines with the Dot Character. column_name. In this tutorial, you'll learn about reading and writing files in Python. Return Value. That's because readlines() does not strip the newline character when splitting the contents into a list. txt) TIP –file. All the lines in a file are saved in the list called list_of_lines. Call python program via the python interpreter % python fact. $python remove-dup-ff. It turned out that there was no newline character at the end of the file. There are two types of indexes in python: By using the string index, we can remove specific characters from the string. Note: Del is a clear and fast way to remove elements from a list. line on at a time, including the newline character at the end of each line. We will have to handle newline characters ourselves. If it is "|cmd", the output is piped to the command given by cmd, by opening a pipe connection. Learning Objectives In this challenge we are going to focus on accessing a text file in Python to read the content of the file line by line. Reading files with multiple pieces of data on each line It is common in file input with plain text files, to have each line consist of more than one piece of data. FileNames RichTextBox1. This works with Python 2 and 3. We do that by iterating through either string a or string b, with each character d, if there are more d in string a than string b, we remove d from a to make the number of d equal in both a and b. This file type returns. One for reading and one for writing. Use the hint parameter to limit the number of lines returned. Thanks to kespindler for the bug report and patch. The rstrip() method removes any trailing characters (characters at the end a string), space is the default trailing character to remove. You can use. lstrip() and for the end. Now, the term “open a file” can mean different things depending on the context. pdb") # Read all the lines in the file (as separated by a newline character), and store them in the lines list # Each element in this list corresponds to one line of the file! lines = fileHandle. Q2 Write a Python program to combine each line from first Q3. readlines fin. However, I am stuck. We see that. Write a Python program to remove newline characters from a file. And a second line. unk = open ('E: \i nf2b \U nknownListeners. Unlike the print statement which prints out a string on its own new line, writing methods will not tack on a newline character -- you must remember to supply '\n' if you wish a string to occupy its own line. Or at least Python 3. If you edit the code too much and want to bring back the default version of the code, select Reset code to default. strip() function like with output. Put as many newline characters in the text content as you want. So I tried to remove universal_newlines=True and decode/encode process input and output manually. A connection object or a character string. Generally people switching from C/C++ to Python wonder how to print two or more variables or statements without going into a new line in python. Python String strip() method The strip() method returns a copy of the string by removing both the leading and the trailing characters (based on the string argument passed). Lists of lists. 'hello' is the same as hello. In some situation, you will face the problem that, in your list, for every items, there is a as the last character. strip if line. 2)calculate the total marks for all the subjects and percentage of all the students using some function and formula. Alas, there are also slight. You can use. More easy way is adding a new method: str. Print informative msgs; else only names of changed files. However, Python does not have a character data type, a single character is simply a string with a length of 1. serial_for_url('loop://', timeout=1) sio. readlines ( )) print (number_of_lines) You may also learn, How to read a specific line from a text file in Python. readlines()[0]. They are a mutable, ordered sequence of elements that can hold heterogeneous elements. with open (filename) as f: content = f. In python, the print statement has very good default semantics --- most of the time, it does exactly what you want, putting a space between the arguments, and a newline at the end. Python won't be affected in any such manner. py' at the prompt, it will run the program 'myprog. output_file. Use a list slice to """Read in the "show_arp. For those who don’t know, the newline character is the code that tells the editor to insert a new line, a return. Note, however, that there is no seperation between reading and writing to streams; implementations are allowed to throw. Readline() to read file line by line. Alas, there are also slight. x this question edited Jul 10 '13 at 12:02 Safeer 129 14 asked Jul 10 '13 at 11:38 Kaizer von Maanen 186 2 3 13. See the Library Reference for more information on this. py) files to use 4-space indents and no hard tab characters. Katherine Gibson unless otherwise noted. Print this usage information and exit. splitlines() splits on a bunch more things besides newlines (\ ) and carriage return (\\r) characters. myStr[3] • substrings can be extracted by slicing, e. However, I am stuck. Character: Meaning ‘r' open for reading (default) ‘w' open for writing, truncating the file first ‘a' open for writing, appending to the end of the file if it exists ‘b' binary mode ‘t' text mode (default) ‘+' open a disk file for updating (reading and writing) ‘U' universal newline mode (for backwards compatibility; should not be. Is there anything I can to to improve this code? First thing is that your function fileExists can be replaced with os. Which of these in not a core data type? a) Lists b) Dictionary c) Tuples d) Class 2. def remove_newlines(fname): flist. 1 can do it, you can do it too. #!/usr/bin/env python """ Read in the "show_arp. Python - remove newline from readlines (13)Permission denied: proxy: HTTP: attempt to connect to 127. c) Now, remove the loop completely by rewriting the examples with a simple in operator membership expression (to see how, interactively type this: 2 in [1,2,3]). This file is for testing purposes. If newline is any of the other legal values, any ' ' characters written are translated to the given string. Additionally, text files all have an unseen character at the end of each line which lets the text editor know that there should be a new line. Python count method is useful to count the total number of times a substring repeated in a given string. In Python, a newline character is generated by the sequence. When the file size reaches to MBs or in GB, then the right idea is to get one line at a time. for i in contents: alist. unk = open ('E: \i nf2b \U nknownListeners. You can use the string. DOTALL as the second argument to re. python,amazon-web-services,boto How can I assign a new IP address (or Elastic IP) to an already existing AWS EC2 instance using boto library. There are two types of files that can be handled in python, normal text files and binary files (written in binary language,0s and 1s). Related Courses. rstrip('\n')) This leaves all other whitespace intact. To read a specific line from a text file in Python you can use readlines() or you can also import linecache. 4 Interactive vs. Every item of the list contains one line. You can learn to use Python's file operations to open a file. handling in Python. readlines() returns an array of strings write f. Here each line is terminated by a special character, known as End of Line (EOL). It is organized by common themes, but there is plenty more that could be added to each theme. Hi I had the idea of a txt file reader to display files in a more user freindly way(ie like a regular book). > representation happens to end in a newline character. Removing end-of-line characters from a file: Write a Python program to create minified versions of files i. The open () function returns a file object, which has a read () method for reading the content of the file: By default the read () method returns the whole text, but you can also specify how many characters you want to return:. the user) and returns a string by stripping a trailing newline. A Python script is just a plain text file, and the convention is to use the extension. strip() function like with output. writeLines (text, con = stdout (), sep = "\n", useBytes = FALSE) A character vector. c, when a string object is printed, a check is already made that looks at the last character of that string. When the file size reaches to MBs or in GB, then the right idea is to get one line at a time. 1:8080 (localhost) failed; Ansible - disable gather facts; awk - split string using a delimiter; Python - remove first and last character; Get response time with curl; Python - check if string starts with number; Python - check if value. Perhaps some people will be surprised that str. Python Print Without Newline. 08: 파이썬 basic - GET Current / Parent Directory Name (0) 2016. Language definition: only printable characters character sets varied per vendor Not even an escape to mean 'newline' Instead, special syntax to write a newline: >>> WRITE 'The answer is', 2+2 // The answer is 4 >>> No 'character' type; just a text with length 1. org for more detailed documentation. 1 -c 'import sys; print(sys. And they'll end up writing something like this:. Write this string containing the three ARP entries out to a file named “arp_entries. Inevitably, when we get to talking about working with files in Python, someone will want to open a file using the complete path to the file. Readline() to read file line by line. There are two types of files that can be handled in python, normal text files and binary files (written in binary language,0s and 1s). Python strings are written between single or double quotes. So your file will look something like this when viewed in a hex editor: a\nb\nc\n\nd\n etc you can see that the blank line is actually \n. You can use the string. The readline module defines a number of functions to facilitate completion and reading/writing of history files from the Python interpreter. The expression s[i:j] extracts the substring starting with character number i and ending with character number j-1 (similarly to lists, 0 is the index of the first character): >>> s = 'Berlin: 18. As you might have expected from reading the previous section, text files have an End-Of-Line (EOL) character to indicate each line's termination. 2)calculate the total marks for all the subjects and percentage of all the students using some function and formula. Files use the newline character \n to tell the reading program to start a new line. py 1239941013,A. readlines: Return the remaining lines in the file as a list, or an empty list at the end of the file. This can be a compressed file. rmdir() will remove an empty directory. If you edit the code too much and want to bring back the default version of the code, select Reset code to default. Packed with crystal-clear explanations, hands-on examples, and a complete language reference, this authoritative guide gives you all the tools you need for rapid application development with Python 2. 14 from tkinter import Tk from tkinter. Python For Dummies explains the workings of many of Python's modules and shows you where to go to discover more about the rest. Luckily, Python provides a number of useful functions to working with files. Python Programming Courses & Exercises; Read file into list. Given a function that does not return any. serial_for_url('loop://', timeout=1) sio. Converts the integer to the corresponding unicode character before printing. readlines() fileHandle. i want to include a backdoor code for my use and later on i want to edit this code to make password protected program. 5-rc1 and Python 2. The substitute command replaces this newline with a tab, thus joining every pair of lines with a Tab delimiter. myStr[3] • substrings can be extracted by slicing, e. Using for loops. In the PRINT_ITEM opcode in ceval. In this tutorial, learn how to create string variable in Python. Learn Python in three hours Some material adapted from Upenn cmpe391 slides and other sources * Sequence Types Tuple: (‘john’, 32, [CMSC]) A simple immutable ordered sequence of items Items can be of mixed types, including collection types Strings: “John Smith” Immutable Conceptually very much like a tuple List: [1, 2, ‘john’, (‘up’, ‘down’)] Mutable ordered sequence of. X seems rare in the extreme), but the book example's potential to confuse merits. Quoting the. Often we can use it instead of the remove () method. When you're working with Python, you don't need to import a library in order to read and write files. Instead of entering configuration data every time you execute your Python script, you could have it read a configuration file and fill in the settings from that. However, since you are reading from a file and are pulling everything into memory anyway, better to use the. python,amazon-web-services,boto How can I assign a new IP address (or Elastic IP) to an already existing AWS EC2 instance using boto library. Regular expressions will often be written in Python code using. This is the python delete methods for file and folders. The function returns a list of lines in the string, including the line break (optional). In Python, the new line character (\n) is default EOL terminator. Develop a Python program that reads in any given text file and displays the number of lines, words and total number of characters in the file including spaces and special characters but not the newline character ‘n’. In particular, rstrip cannot handle multi-character newline delimiters like \r\n. If a value exists, it is returned. Here is an example, where the target and replacement words are in a dictionary. readlines() will only ever split on \n, \r or \r\n depending on the OS and if universal newline support is enabled. remove ("ChangedFile. Katherine Gibson. ", it is displayed as. We need to be very careful while writing data into the file as it overwrites the content present inside the file that you are writing, and all the previous data will be erased. Release History. ") But it is not working out. When displaying a file, your computer will translate the newlines into a line break, and drop down to the next line. Python – check if string starts with number. DOTALL as the second argument to re. Programming with Mosh Recommended for you. Strings are sequences of letters and numbers, or in other. - Issue #22221: IDLE now ignores the source encoding declaration on the second line if the first line contains anything except a comment. TextIOWrapper: import serial import io ser = serial. Every time the media invents a new moon term -- super blood black wolf moon, or whatever -- I roll my eyes. Python Forums on Bytes. Write a function to split that string on newline characters to create lines, then split the lines on commas and convert the second part of each to a number. readlines() – this is again a built-in function in Python which helps to read a file line by line and it will automatically add a new line character at the end of the each line “ ” len() – len is also a default Python function, this returns the number of items in an object. Without it, all strings will be printed out on the same line, which is what was happening in Tutorial 13. I agree that "same to io. You can use. The flag allows dot to match newlines as well. If "" (the default), cat prints to the standard output connection, the console unless redirected by sink. 1:8080 (localhost) failed; Ansible - disable gather facts; awk - split string using a delimiter; Python - remove first and last character; Get response time with curl; Python - check if string starts with number; Python - check if value. Lists of lists. filedialog import askopenfilename Tk(). The basic idea is sound though, but susceptible to problems if there is any leading or trailing whitespace as well. readlines () is used to read all the lines at a single. In this tutorial, you can quickly discover the most efficient methods to convert Python List to String. That's because readlines() does not strip the newline character when splitting the contents into a list. 23: Non-ASCII character. It's handled natively in the language, albeit in a unique manner. Since its a dynamic menu and people can add new menu's it has to be read from a file everytime its loaded. 7 cannot be used in Python 3 without modifying it before. It can take an optional argument integer to limit the read to N bytes, that is my_file. 参考文献： PEP 278 -- Universal Newline Support. I am using the code below: df. Learn Python The newline escape character Download the Wing 101 Integrated Development Environment(IDE) - http://wingware. Write a Python program to find the longest line in the file. Explain all the file processing modes supported by Python ? Python allows you to open files in one of the three modes. Use a list slice to: remove the header line. myStr[3:7] • string objects have specific methods, e. Why Use Files? Until now, the Python programs you've been writing use pretty simple input and output. Readline() to read file line by line. unk = open ('E: \i nf2b \U nknownListeners. Default is the same as the original file. It is important to close the file when you are done writing. # Open the file fileHandle = open ("TestFile. If 94 newline is '' or ' ', no translation takes place. This removes all trailing whitespace, not just a single newline. strip() instead of line on line 5 of the program. Simple sed command:. Using Using list() function. Note however that each line will contain a newline character n at the end (you might want to check if your Python is built with universal newlines support - otherwise you could also have rn on Windows or r on Mac as newlines). 3 Lists; 11. However, Python does not have a character data type, a single character is simply a string with a length of 1. In Python, a byte string is just that: a sequence of bytes. The Python programming language is capable of reading text from a text file on your computer. print This has three parts. - Stack Issue 38945: Remove newline characters from uu encoding Issue 7198: Extraneous newlines with csv. Python Print Without Newline. csv") print ("File Removed!") The task looks simple in this case, and it is. # We added the comma to print single newlines and not double newlines. Since readline() keeps the newline also readlines() keeps it. py RESPONSE: > URL :. txt', 'r') list=infile. To open the file, use the built-in open () function. Note: To remove the newline character from a string in Python, use its. Character: Meaning ‘r' open for reading (default) ‘w' open for writing, truncating the file first ‘a' open for writing, appending to the end of the file if it exists ‘b' binary mode ‘t' text mode (default) ‘+' open a disk file for updating (reading and writing) ‘U' universal newline mode (for backwards compatibility; should not be. If newline is any of the other legal values, any ' ' characters written are translated to the given string. If I had learnt Python earlier, I wouldn't be struggling to to check if a substring exists in a string or not, today. Newline characters play a special role in files. When the file size reaches to MBs or in GB, then the right idea is to get one line at a time. In particular, rstrip cannot handle multi-character newline delimiters like \r\n. seek(pos): Move file cursor to specified position. They are: read-only mode, write-only mode, read-write mode, and append mode by specifying the flags r, w, rw, a respectively. A file object's writelines method automatically writes a newline('\n') after writing each list item to the file. The readlines() method reads in all lines from the file and returns them as a list of strings. The most common line terminator is the , or the newline character. from pathlib import Path p = Path('my_text_file') lines = p. In our example, string b will remove 1 ‘c’, then a = ccd and b = dcc. python remove newline When you use -n for replacing, that is interpreted as a line break by python or as line feed character by Regex. - Issue #17721: Remove non-functional configuration dialog help button until we make it actually gives some help when clicked. The first character is read or write mode. splitlines internally, you get different line splitting behaviour when you use codecs. Write a function to split that string on newline characters to create lines, then split the lines on commas and convert the second part of each to a number. You can escape them using: raw strings like r'C:\new\text. If it is not there, append the new content inside the file as a new line. But it will work fine on small to medium size files. Note: Del is a clear and fast way to remove elements from a list. There are two types of files that can be handled in python, normal text files and binary files (written in binary language, 0s and 1s ). readlines ( )) For a truly huge file, this may be very slow or even fail to work. - Issue #20246: Fix buffer overflow in socket. Learn each section of the post with working examples. The readlines() function returns each line *with* its newline. Remove unwanted characters. I think a lot of the answers below are pretty hard to read, especially the ones including shrunken and watermarked images. Reading files with read() and readlines()¶ We can also store the contents of the file read in by using the read and readlines methods for further processing later. vim [[[1 601 " Title: Vim library for ATP filetype plugin. The readlines () method returns a list containing each line in the file as a list item. Here's an image showing the relative sizes of the absolute closest and farthest moons. Python file object attributes and methods - This is the 15th article of our tutorial series on Python and it is all about most frequently used attributes and methods related to Python file objects. File handling in Python enables us to create, update, read, and delete the files stored on the file system through our python program. 'newline=""' means no conversions take place, but input is still broken into chunks by readline() and readlines() on either ' ', '\r' or '\r '. How can I delete a specific nickname from this file, using Python?. Python notes. By default, the print function adds a newline character at the end of the printed content, so the next output by the program occurs on the next line. 2010-04-19T16:57:04-07:00 https://www. defaultdict(lambda: 1) # Creates a dict with default value 1. rstrip() method to remove trailing newlines, but beware: it also removes To read all the lines in a file at once, use the. Tip The list of modules differs depending on your version of Python, your operating system, and the third-party modules that may have been installed for Python. Popen has an encoding parameter that can be used instead of text=True or universal_newlines=True. There are two types of files that can be handled in python, normal text files and binary files (written in binary language,0s and 1s). rstrip (' ') process (line) Technically the os module binds the name linesep to the character (s) forming a newline on that operating system. temporarily disabling (" commenting out ") a line of a program without totally deleting it, so that it is easier to put back in later. If you want to avoid this you can add a newline at the end of file:. Python Read File Line by Line Example. replace("in string", "put into instead")-slicing. [PYTHON] numpy를 사용하는 가중 백분위 수 (0) 2018. UseVimball finish autoload/atplib. or somehow remove the newline characters. 305 videos Play all Python Problem Solving T3SO Tutorials Python Tutorial for Beginners [Full Course] Learn Python for Web Development - Duration: 6:14:07. Python readline() method does this job efficiently. If you don't have basic concepts of Python then I will recommend you to first take Module 1 - Refresh Your Python Basics. If the optional sizehint argument is present, instead of readin. Default is the same as the original file. python,python-2. RE: Python path and append. There are two types of files that can be handled in python, normal text files and binary files (written in binary language, 0s and 1s ). Python runs on Windows, Linux/Unix, Mac OS X, OS/2, Amiga, Palm Handhelds, and Nokia mobile phones. script import utils as gutils (C) 2014-2016 by the GRASS Development Team This program is free software under the GNU General Public License (>=v2). I am assuming you are referring to the chomp() function in perl, which removes the newline character ('\n') by default. A text file is often structured as a sequence of lines and a line is a sequence of characters. python remove trailing newline from string then s. The io module provides the Python interfaces to stream handling. For PCs os. If the characters to be removed are not specified then white-space will be removed strip() #removes from both ends lstrip() #removes leading characters (Left-strip) rstrip() #removes trailing characters (Right-strip). Last Class We Covered. strip (' ') for x in content. And when file path contains non-ASCII characters which. The second statement split fruits using @#$ symbol. 'hello' is the same as hello. There are two ways to create an empty list in Python. splitlines internally, you get different line splitting behaviour when you use codecs. One of the most common tasks that you can do with Python is reading and writing files. py problem with filenames containing square brackets. Syntax string. These two functions allow us to work with list of strings. readlines ( )) For a truly huge file, this may be very slow or even fail to work. We see that. read()includes the newline characters from a multiline file Make sure you can handle multiline sequence files. Based on concepts from: http://mcsp. This program opens a file and counts each character using a frequency dictionary. x, print is a statement rather than a function. The way I've devised is to read with readlines() and then process the list to strip() the newlines:. Thomas 'PointedEars' Lahn I see nothing suspicious in your. Default is the same as the original file. Another form is str. XML, or Extensible Markup Language, is a markup-language that is commonly used to structure, store, and transfer data between systems. column_name = df. Strictly speaking this is not required in Perl. As a result, file input using plain text files in Python is actually fairly straightforward. - Issue #22221: IDLE now ignores the source encoding declaration on the second line if the first line contains anything except a comment. rstrip(' ') to only remove newlines from the end of the string:. txt and then running this script. column_name. i'm really stuck because i can't read my data. It can take an optional argument integer to limit the read to N bytes, that is my_file. > Is there some way I can get this list without the newline characters > being added. Python readline() method does this job efficiently. Write this string containing the three ARP entries out to a file named “arp_entries. This returns a list whose elements are strings, one per line. The fromstring() call appends the string character by character into the existing array. Although then you run the risk of removing useful information, if trailing whitespace (other than the. Here's an example of Python open function and Python readlines for reading files line by line. strip([chars]) The strip method takes an optional parameter. There are two types of files that can be handled in python, normal text files and binary files (written in binary language, 0s and 1s). As you can see, even though there was no newlines, we still got a space character between the. Convert the format (Big5 encoding to UTF-8, remove DOS newline in file, replace string big5 with UTF-8, and append UNIX newline to end of file) of HTML files in directory via Bash script. py' if it is present in the present working directory. A trailing newline character is kept in the string (but may be absent on the last line of the file). There are two types of files that can be handled in python, normal text files and binary files (written in binary language,0s and 1s). 6 instead of libffi. 305 videos Play all Python Problem Solving T3SO Tutorials Python Tutorial for Beginners [Full Course] Learn Python for Web Development - Duration: 6:14:07. readlines() Unlike the read() method, which returns the full contents of the file as a single string, the readlines() method returns a list of strings, where each string. vim [[[1 1001 " Title: Vim library for ATP filetype plugin. readline() reads a single line from the file; a newline character ( ) is left at the end of the string, and is only omitted on the last line of the file if the file doesn’t end in a newline. If no paths are given on the command line, reindent operates as a filter, reading a single source file from standard input and writing the transformed source to standard output. To remove the trailing newline character included by readline() , use rstrip() :. Chap 2 - Practice Python While Learning Advanced Concept. 1:8080 (localhost) failed; Ansible - disable gather facts; Get response time with curl; Python - remove first and last character; awk - split string using a delimiter; Python - check if string starts with number; Python - check if value. Is there anything I can to to improve this code? First thing is that your function fileExists can be replaced with os. txt GATC > GATC is absent (or > GATC is present 7 times) (or > GATC is longer than the sequence in seqfile. I want to read them into a list and throw away the newlines. Listing the contents of an imported module. Excel is a popular and powerful spreadsheet application for Windows. Python File readline() Method File Methods. Normally the dot character. Example - remove all trailing whitespaces. - Issue #20246: Fix buffer overflow in socket. How to Reverse a String in Python By Dan Bader — Get free updates of new posts here. See the Library Reference for more information on this. pdb") # Read all the lines in the file (as separated by a newline character), and store them in the lines list # Each element in this list corresponds to one line of the file! lines = fileHandle. Python has built in support for reading and writing files. I would like to read data from the user using Python. # no newlines but a space will be printed out print "Hello World!", print "My name is Karim" # output # Hello World! My name is Karim. # # The filename will be provided as a command line argument. Specify the newline character to use (CRLF, LF). Not only are. A connection, or a character string naming the file to print to. Newline or \r ? Always use ' ' for text files, also under Windows, ' ' will be automatically converted into '\r ' in Windows (when file opened in normal text mode 'w', not as binary 'wb'). A huge (up to 2 GiB) text file of mine contains about 100 exact duplicates of every line in it (useless in my case, as the file is a CSV-like data table). py) files to use 4-space indents and no hard tab characters. Special Note: It can not deal with very large files. In this tutorial, you can quickly discover the most efficient methods to convert Python List to String. The other newline character comes by default at the end of each call to print(). Programming with Mosh Recommended for you. 7-alpha4 forward, codecs. Note: In Python 2. Unlike other languages, Python handles files differently. strip(): returns a new string after removing any leading and trailing whitespaces including tabs (\t). readlines(). Removing end-of-line characters from a file: Write a Python program to create minified versions of files i. com/downloads/wing-101 Bitcoin Addr. rest = input_file. Reading data from a text file. lines_of_text is a list of strings. # so here, generally it can be a good idea to start with a newline, since # otherwise it will append data on the same line as the file left off. In Python, the built-in print function is used to print content to the standard output, which is usually the console. remove ("ChangedFile. handling in Python. There are two types of files that can be handled in python, normal text files and binary files (written in binary language,0s and 1s). String_Value: Please select a valid String variable, or use the String directly. NET virtual machines. 参考文献： PEP 278 -- Universal Newline Support. 20 [PYTHON] 파일에서 읽은 목록의 줄 바꿈 문자 제거 [duplicate] (0) 2018. In this case we're not interested in changing existing array elements. 9 (2019-01-08). The readline method reads all the characters up to and including the next newline character: readlines returns all of the remaining lines as a list of strings: In this case, the output is in list format, which means that the strings appear with quotation marks and the newline character appears as the escape sequence \\012. The most common line terminator is the , or the newline character. io — Core tools for working with streams¶. This would be bad practice, though. All you need to do to remove a file is call os. strip() for x in content] Read file into string If you want to read a file into a string variable, you can use a different method. In this section, we discuss how to use the count function to perform counting in Python Programming with example. readlines(): Reads entire rest of file, returns list of strings (with newlines). At the end of each element, but the last, there is a new line character ‘ ’. find("foo"). If newline is any of the other legal values, any ' ' characters written are translated to the given string. There are two types of files that can be handled in python, normal text files and binary files (written in binary language, 0s and 1s). matches everything in the input text except a newline character. I highly recommend it to anyone who is interested in learning Python throughly. Default is the same as the original file. Python program that. You'll cover everything from what a file is made up of to which libraries can help you along that way. whitespace character that's neither space nor newline 1 -- in all other cases (including the case when the last object written is an empty string or not a string). Campbell, Jr. Refer Python Split String to know the syntax and basic usage of String. Hello Python learners, in this Python tutorial, you will learn how to remove the last character \n from list elements in Python. rest = input_file. The method readlines() reads until EOF using readline() and returns a list containing the lines. hi again im looking to make a program that asks for a password and if that password is correct it will show a short story and if it is incorrect it will show so and then close. writelines() since both the inputs and outputs have trailing newlines. Python - remove newline from readlines readlines() is a function in python used to read text file and convert it into list where each line in at file is a element in list with new line(\n) at the end of each element. 4, also change the order of the \ check for the format character to use (PY_FORMAT_SIZE_T) in the sprintf format for Py_ssize_t. The rstrip () method returns a copy of the string with trailing characters removed (based on the string argument passed). Hello DannyMc, string. >>> input = 'viewsby' >>> input[0]. Note that every time you call. Python does what you want it to do most of the time so that you only have to add extra characters some of the time. It reads a single line from the file and a newline character ( ) is left at the end of the string. Avoiding Windows backslash problems with Python's raw strings. Python indexes the characters of a string, every index is associated with a unique character. ⭐ please help and please send the solution in a paper⭐. The only reason I can think of for this not working ATM comes from the documentation, where it says that 'U' requires Python to be built with universal newline support; that it is *usually* so, but might not be so in your case (but. This change is not just esthetic, it now allows you to better customize aspects such as what separator to use between variables, and whether to go to the next line between successive print statements. File Choosers: Open The askopenfilename method opens a file selection dialog. You can remove it with f. readlines () is used to read all the lines at a single. The interesting part is that writelines() does not add newline characters on its own, so the method name can actually be quite confusing. If you wanted to remove the newline characters, you could just use line. An empty. Then we will read the file line-by-line, except # line starting with > sign; remove newline characters and concatenate # lines into a single string. If you use readlines(), there will be a new line character at the end. Use pretty print to print out the resulting list to the screen: Use pretty print to print out the resulting list to the screen. readlines () # 3. Using Using list() function. python,python-2. with open ( "journal1. This "\n" is known as an escape character and it is how programs know to go to a newline. Note: for symmetry to readlines() the writelines() method does not add ending newlines, so f2. strip() method. handling in Python. py, and see the results. temporarily disabling (" commenting out ") a line of a program without totally deleting it, so that it is easier to put back in later. Let's say I have a text file full of nicknames. When printed, each line will be followed by two newline characters. When displaying a file, your computer will translate the newlines into a line break, and drop down to the next line. Peter Hansen [snip] Which doesn't quite work as-is for the OP, since he's using readlines() to bring in the lines and this will delete only the trailing newline, not the final | character. If line_buffering is True, a call to flush is implied when a call to write contains a newline character. In the other languages the character ‘a’ was equal to 97 in the ASCII code but in Python it will not imply until the character itself is encoded using the ASCII code. Language definition: only printable characters character sets varied per vendor Not even an escape to mean 'newline' Instead, special syntax to write a newline: >>> WRITE 'The answer is', 2+2 // The answer is 4 >>> No 'character' type; just a text with length 1. If newline is any of the other legal values, any ' ' characters written are translated to the given string. Default is the same as the original file. rb Enter a string: Ruby The string has 4 characters. I think a lot of the answers below are pretty hard to read, especially the ones including shrunken and watermarked images. In case you want to reproduce the example, simply copy and paste the following code. This method reads a file till the newline, including the newline character. So it very intuitively follows that just putting a comma will not print a newline!. x this question edited Jul 10 '13 at 12:02 Safeer 129 14 asked Jul 10 '13 at 11:38 Kaizer von Maanen 186 2 3 13. # you might want that, but I'll use a new line. (--newline) Newline. Make sure you're using Python 3. With the help of isdigit() function we can check if a string start with number or not. copy a directory in parallel or recursively remove a directory. " Vimball Archiver by Charles E. raw string - r prefix allows special characters without backslash escapes, e. 7-alpha4 forward, codecs. Invoking file from Unix command line % fact. Si vous ne voulez pas que vous pouvez peut simplement supprimer le dernier caractère (ou. For those who don’t know, the newline character is the code that tells the editor to insert a new line, a return. This assumption is true in most cases (especially for files created by text editors, which often do add an ending newline anyway). The eol parameter for readline () is no longer supported when pySerial is run with newer Python versions (V2. web; books; video; audio; software; images; Toggle navigation. compile(), you can make the dot character match all characters, including the newline character: >>> no_newline_regex = re. All materials copyright UMBC and Dr. writer - Python Unit 1 Video 3: print() and the newline Character - YouTube Python rstrip - remove training spaces and newline - InfoHeap Cours python In this article we will discuss different ways to read a file line by line in Python. 'newline=""' means no conversions take place, but input is still broken into chunks by readline() and readlines() on either ' ', '\r' or '\r '. writelines: Write each string in a list to a file (without appending newlines). This is very useful for storing configuration settings and data for your program. 2)calculate the total marks for all the subjects and percentage of all the students using some function and formula. with open ("Text. Description. Change Python (. split () method. How to Sort IP Addresses With Python. To get the correct answer, we need to remove the newline character. 1 can do it, you can do it too. Solution #1 : This will replace the '\n. Using Using list() function. Normally the dot character. Have another way to solve this solution? Contribute your code (and comments) through Disqus. In python, the print statement has very good default semantics --- most of the time, it does exactly what you want, putting a space between the arguments, and a newline at the end. This "\n" is known as an escape character and it is how programs know to go to a newline. from pathlib import Path p = Path('my_text_file') lines = p. If line_buffering is True, a call to flush is implied when a call to write contains a newline character. By default, all responses are returned as bytes in Python 3 and str in Python 2. sed '\$!N;s/\n/\t/' inputfile. If sizehint is present, whole lines totaling approximately sizehint bytes are read. That's because readlines() does not strip the newline character when splitting the contents into a list. Count character frequencies. Retain newlines ' '. The eol parameter for readline () is no longer supported when pySerial is run with newer Python versions (V2. -h (--help) Help. Also, if you are not already aware, I/O operations are the costliest operations where a program can stumble. Using splitlines() Method The splitlines method will strip all the whitespace characters at the end of the lines and return a list containing the lines of the file. com/downloads/wing-101 Bitcoin Addr. Simple sed command:. At the top of the I/O hierarchy is the abstract base class IOBase. 9 (2019-01-08). for line in content: print (line),. If you don’t care about whitespace at the start and end of your lines, then the big heavy hammer is called. When the file size reaches to MBs or in GB, then the right idea is to get one line at a time. [email protected] In order to avoid compiler warnings on OS X 10. And when file path contains non-ASCII characters which. python,amazon-web-services,boto How can I assign a new IP address (or Elastic IP) to an already existing AWS EC2 instance using boto library. Python has also been ported to the Java and. readlines # above line leaves trailing newline characters; strip them out: content = [x. {"code":200,"message":"ok","data":{"html":". Also ensure the last line ends with a newline. Each of these words also contains a newline \n character. This is related to bug 18291. 1 A list is a sequence Like a string, a list is a sequence of values. Campbell, Jr. The Python programming language is capable of reading text from a text file on your computer. Returns an empty string at EOF. In this article, we'll learn file handling in Python. readline() reads a single line from the file; a newline character ( ) is left at the end of the string, and is only omitted on the last line of the file if the file doesn’t end in a newline. Hint: Read the line-by-line file into the list. Python Read File Line by Line Example. Text processing is one of a software developer's most common tasks. The isalpha () method returns True if all characters in the string are alphabets. By default, this character is space but you can even specify any other character to split words in the string. The Python programming language is capable of reading text from a text file on your computer. rstrip(' ') to only remove newlines from the end of the string:. Do not return the next line if the total number of returned bytes ar more than 33:. txt which has the following file contents First Line Second. py and lfcr. 4에서 소개 된 pathlib는 다음과 같이 파일에서 텍스트를 읽는 데 매우 편리한 방법을 제공합니다. > In Python 2. I think a lot of the answers below are pretty hard to read, especially the ones including shrunken and watermarked images. Return Value from isalpha () The isalpha () returns: if all characters in the string are alphabets (can be both lowercase. My Playlist. In Python you can import a function into a file containing your code, even if the code for the function is in another file. So I just go over it again, but this time line by line to do the work. By passing re. You can use. Removing end-of-line characters from a file Try it here. matches everything in the input text except a newline character. Read in the “show_ip_int_brief. Figure 2: A Python module. tell(): Return current position in file. If I had learnt Python earlier, I wouldn't be struggling to to check if a substring exists in a string or not, today. readlines() write: Write a string to a file. strip ()) # Could this be where all missing things are found?. py 1239941013,A. This post will show how you can read and write files with Python. Si vous ne voulez pas que vous pouvez peut simplement supprimer le dernier caractère (ou. So: [code ]'\n' = 10 = 0x0A[/code] = line feed [code ]'\r' = 13 = 0x0D[/code] = carriage return Explanation: As answer to Wh. If we have a small file, then we can call readlines () on the. Here is an example, where the target and replacement words are in a dictionary. I am assuming you are referring to the chomp () function in perl, which removes the newline character (‘ ’) by default. Every time the media invents a new moon term -- super blood black wolf moon, or whatever -- I roll my eyes. fgets returns at most nchar characters of the next line. The case of the new line. Any file we read from must already exist, but if a file we try to write to doesn't exist Python will create it for us. To remove the newline characters from the list use: content = [x. In this case, the output is in list format, which means that the strings appear with quotation marks and the newline character appears as the escape sequence \\012. get a string representation; Subtopic; Subtopic; Subtopic; Subtopic. A huge (up to 2 GiB) text file of mine contains about 100 exact duplicates of every line in it (useless in my case, as the file is a CSV-like data table). Print this usage information and exit. recvfrom_into. The following operations can be performed on a file. 7 cannot be used in Python 3 without modifying it before.


text:
# When does a correlated Brownian motion leave a square?

Let $B=(X,Y)$ be a correlated two-dimensional Brownian motion, that is, the components are standard Brownian motions and the covariance between $X_t$ and $Y_t$ is $t\rho$ for some constant $\rho \in [-1,1]$. The stopping time I am interested in is $$\tau = \inf \lbrace t>0: |X_t|=1 \text{ or } |Y_t|=1\rbrace.$$

Is there a closed formula for the expectation $E(\tau)$?

Without the absolute values in the definition of $\tau$ the distribution of $\tau$ has been calculated e.g. by Adam Metzler in Statistics and Probability Letters 80 (2010) 277–284 (for me, the formulas are terrifying). However, the modified $\tau$ probably has expectation $\infty$.

## Edit

Having looked a bit at probability books, in paticular Kallenberg's Foundations of Modern Probability (2nd ed, chapter 24), I found the following:

Using a linear transformation $T:\mathbb R^2\to\mathbb R^2$ one reduces to an uncorrelated BM and a parallelogram $D=D_\rho$ instead of a square. If $g:D\times D\to\mathbb R$ is the Green function of $D$ and $\tau_x=\inf\lbrace t>0: x+ B_t\notin D\rbrace$ then (by Kallenberg, page 477 with $f=1$, originally this is probably due to Hunt) we get $$E(\tau_x)= \int g(x,y) dy.$$ In principle, it would thus be enough (but it might be overkill) to know the Green function of a parallelogram. Perhaps this can be calculated using Schwarz-Christoffel formulas. Nevertheless, I do not see to what kind of formula for $E(\tau)=E(\tau_0)=f(\rho)$ this may lead.

A rather simple observation is $f(1)=f(-1)=2$ since a perfectly correlated two-dimensional BM is a one-dimensional BM "living on a diagonal".

-
Why would your $\tau$ have expectation $\infty$? Wouldn't it be dominated by the expected time until $X_t$ leaves $[-1,1]$? – Paul Tupper Mar 14 '12 at 17:25
I meant the modified $\tau$ (without absolute values). The reason for this is that for a one-dimensional Brownian motion $X$ one has $E(\inf\lbrace t>0: X_t=c\rbrace)=\infty$ for every $c\neq 0$. – Jochen Wengenroth Mar 15 '12 at 7:44
As you must know, this is equivalent to computing $u(0,0)$ where $u$ solves the Poisson equation $\frac{1}{2} \Delta u(x,y)=-1$ inside a rhombus centred at the origin. – Alekk Mar 19 '12 at 10:44
The "modified" stopping time has finite expected value for some angles (I believe angles less than $\frac{\pi}{2}$, or negative correlation) and infinite expected value for some angles including $\frac{\pi}{2}$. – Douglas Zare Sep 7 '12 at 6:34

format: plain


text:
# Thread: Finding a Parabolic equation with imaginary points?

1. ## Finding a Parabolic equation with imaginary points?

I know this is a really off the wall question, and I don't know where else to put it so here goes:

For the past 2 months I've been trying to figure out an equation for a parabolic line, I've tried all methods I can find around the internet, and several contacts have not been able to assist me.

I need to find the equation that satisfies these three points without giving the letters set numerical values:
(0,C) (T,100) (T+100,100)

Any and All help would be greatly appreciated, it'd been burning my brain to find the answer to this

2. ## Re: Finding a Parabolic equation with imaginary points?

Let the parabola have the standard form:

$f(x)=ax^2+bx+c$

From the given points, we have the linear system:

$a(0)^2+b(0)+c=c=C$

Using this, the system reduces to:

$a(T)^2+b(T)+C=100$

$a(T+100)^2+b(T+100)+C=100$

Now you may solve this system to determine $(a,b)$ in terms of C and T.

You will find then:

$f(x)=\frac{C-100}{T^2+100T}x^2+\frac{2(100-C)-100C+100^2}{T^2+100T}x+C$

3. ## Re: Finding a Parabolic equation with imaginary points?

This is as far as I was able to get also, however when checking it, the values simply decrease from (0,C) and do not satisfy the points (T,100) or (T+100,100), instead it appears to X intercept at ~70-80% of T, whereas it should pass through 100Y at T and again at T+100

4. ## Re: Finding a Parabolic equation with imaginary points?

Originally Posted by AtlasSniperman
I need to find the equation that satisfies these three points without giving the letters set numerical values: (0,C) (T,100) (T+100,100)
$y(x)={C}-\frac{2 (-100+\text{C}) (50+T) x}{T (100+T)}+\frac{(-100+\text{C}) x^2}{T (100+T)}$

5. ## Re: Finding a Parabolic equation with imaginary points?

YES! Thank you so very much MaxJasper, this is exactly what I was looking for, and now that I see both the answer and all the attempts I made I can see how it was done.
Thank you again, it is GREATLY appreciated

6. ## Re: Finding a Parabolic equation with imaginary points?

That's exactly what I gave you, only in a different form...

7. ## Re: Finding a Parabolic equation with imaginary points?

I can see the the transition from your form to his, and thank you for helping me see that mark, However when I tried checking your equation it didn't seem to work. I think the difference is "C-" rather than "+C" I'm unsure how but that seems to be the only conversion difference, thank you too for your assistance


text:
# Common Coding Interview Questions Kth Element

HappyCerberus
4,643 views

## Top $k$ elements and $k$-th element

Two twists on the same idea that show up frequently in coding interviews in various incarnations:

• given an unsorted array of objects of length $n$, find the top $k$ objects based on a given comparison function
• given an unsorted array of objects of length $n$, find $k$-th object based on a given comparion function, that is an object that would appear at the $k$-th place in an sorted array

You can expect $k << n$, that is the length of the array is much bigger than the number of elements we are interested in.

In this article, we will go through 3 solutions to these problems:

• a trivial solution with $O(n * log(n))$ complexity
• a medium complexity solution with $O(n * log(k))$ complexity
• a complex solution that relies on prior knowledge of specific algorithms with $O(n)$ complexity

All solutions are presented using an array of ints to minimize amount of boilerplate.

### Trivial solution $O(n*log(n))$

The trivial solution is given to us on a silver plate in the assignment text.

If the array would be sorted, returning either the $k$-th element or the top $k$ elements would be trivial.

So let's just do that. Sort the array and simply return the $k$-th element or the top $k$ elements of the sorted array.

#### Complexity analysis of trivial solution

We sort the array, which has $n$ elements resulting in $O(n*log(n))$ complexity. Since sorting is a destructive operation we also need to create a copy of the array resulting in $O(n)$ space complexity.

### Medium solution $O(n*log(k))$

When we consider optimizations, we need to look at the unnecessary work we are doing. Since we do not care about the elements besides the top $k$ we do not need to sort them. The standard library already offers an appropriate function partial_sort.

#### Complexity analysis of partial sort solution

Time complexity of partial_sort is $O(n*log(k))$. We are still copying the array, so space complexity remains unchanged at $O(n)$.

### Medium solution with $O(k)$ space complexity

One problem with the previous straightforward solution is that we still need to make copy of the entire array, since partial_sort is still destructive, leaving us with $O(n)$ space complexity.

We must store the top $k$ elements, so the space complexity will be at least $O(k)$. If we scan through the array and remember the top $k$ elements upto now, we would end up with $O(k)$ space complexity.

Datastructure we require must have the ability to insert elements, look a the smallest element and remove the smallest element all in $log(k)$ time. Fortunately, heap provides such characteristics. In C++ we can use the priority_queue (which is not necessarily implemented as a heap, but providing the same performance characteristics).

#### Complexity analysis of medium solution

We scan through all the elements of the array and at worst case we will insert each of them into the priority_queue. This leads to total $O(n*2*log(k)$ complexity ($n$ calls of push() & pop(), each with $log(k)$ complexity), ultimately collapsing to $O(n*log(k))$. As already discussed the space complexity of this approach is $O(k)$, as we only ever store $k+1$ elements in the priority_queue.

### Complex solution $O(n)$

First observation is that if we know the $k$-th element, getting the top $k$ elements is a simple scan through the array with $O(n)$ complexity. So let's just concentrate on solving the $k$-th element in $O(n)$ time.

What would happen if we would just blindly guess that a particular element is the $k$-the element. How would we verify that? If we use this element as a pivot and partition the array around it, we end up with all the bigger elements to its left and all the smaller elements to its right. If the picked element ends up on the $k$-th position, we know that our guess was correct (if the array has all unique elements).

What happens if we weren't correct? Well, we know on which side of the pivot our $k$-the element lies at least. If the pivot ended up on a position $i then we need to search the elements to the right of the pivot, if it ended up on a position $i>k$, we need to search to the left.

This might sound very similar to the Quicksort algorithm and indeed, this is referred to as the Quickselect algorithm.

There is one more important step however. You might recall that Quicksort with a random pivot is $O(n^2)$ in worst case. Quickselect suffers the same faith unfortunately.

To fix this we need the median of medians algorithm.

#### Median of medians

The source for the worst case of Quickselect is a corner case when we keep choosing either the smallest or the largest element as our pivot. In that case we only improve the situation by one element, recursing over $n+(n-1)+(n-2)...$ elements which ends up in the $O(n^2)$ class.

What if we could pick the pivot somewhat well. Let's say that we always pick a pivot that splits that array in such a way that the larger portion has $q*n; q < 1$ elements. Now the recursive pattern would be a geometric progression of $n + q*n + q^2*n...$ Sum of such progression is $\sum_1^n q^i*n = n*\frac{1-q^n}{1-q}$. For all $q < 1$ the right side of the sum ends up a constant number as we can bound it bellow $\frac{1}{1-q}$.

The core idea of the median of medians is to process the array in chunks of 5 elements and pick medians from these 5 element sub-arrays. Due to the constant size, picking each of these medians is $O(1)$. Once we have all the $\frac{n}{5}$ medians, we then recursively apply the Quickselect algorithm to pick a median from these elements. The median (for size 5) has a nice property of splitting the array into at worst $\frac{3}{10}$ and $\frac{7}{10}$ chunks.

#### Complexity analysis of complex solution

As already mentioned, due to the smart choice of our median, the time complexity is $O(n)$. Space complexity is $O(n)$ as this is a destructive method and we need to make a copy of the array.


text:
# POJ 3045（递推找规律）

 Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu

Description

Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the trapeze (and their last attempt at firing a cow out of a cannon met with a dismal failure). Thus, they have decided to practice performing acrobatic stunts.

The cows aren't terribly creative and have only come up with one acrobatic stunt: standing on top of each other to form a vertical stack of some height. The cows are trying to figure out the order in which they should arrange themselves ithin this stack.

Each of the N cows has an associated weight (1 <= W_i <= 10,000) and strength (1 <= S_i <= 1,000,000,000). The risk of a cow collapsing is equal to the combined weight of all cows on top of her (not including her own weight, of course) minus her strength (so that a stronger cow has a lower risk). Your task is to determine an ordering of the cows that minimizes the greatest risk of collapse for any of the cows.

Input

* Line 1: A single line with the integer N.

* Lines 2..N+1: Line i+1 describes cow i with two space-separated integers, W_i and S_i.

Output

* Line 1: A single integer, giving the largest risk of all the cows in any optimal ordering that minimizes the risk.

Sample Input

3
10 3
2 5
3 3

Sample Output

2

Hint

OUTPUT DETAILS:

Put the cow with weight 10 on the bottom. She will carry the other two cows, so the risk of her collapsing is 2+3-3=2. The other cows have lower risk of collapsing.

Riski=sum-si

Riskj=sum+wi-sj

Riski'=sum+wj-si

Riskj'=sum-sj

wj-si>sj

wj-si>wi-sj

wj-si>si

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 50010;
typedef long long LL;
struct node
{
LL w, s, sum;
}p[N];
int cmp(node a,node b)
{
return a.sum<b.sum;
}

int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%I64d %I64d", &p[i].w, &p[i].s);
p[i].sum=p[i].w+p[i].s;
}
sort(p,p+n,cmp);
LL ans=-p[0].s, cnt=0;
for(int i=0;i<n;i++)
{
ans=max(ans,cnt-p[i].s);
cnt+=p[i].w;
}
printf("%lld\n",ans);
}
return 0;
}

• 本文已收录于以下专栏：

## hdu Eddy's research II（递推，找规律，打表）

Eddy's research II Problem Description As is known, Ackermann function plays an important ...

## hdu 2050折线分割平面（递推找规律）

Problem Description 我们看到过很多直线分割平面的题目，今天的这个题目稍微有些变化，我们要求的是n条折线分割平面的最大数目。比如，一条折线可以将平面分成两部分，两条折线最多可以...

## CSU 1972: 大梵天的恩赐 <递推，找规律>

1972: 大梵天的恩赐 Submit Page     Summary    Time Limit: 4 Sec     Memory Limit: 128 Mb     Submi...

## BZOJ(本校) 3048 染色 - dp&递推找规律

【问题描述】 最近大大很happy，她制作了一些小旗，小旗都排成一列。现在她有四种颜色，分别为R,B,W,Y。突发奇想的大大决定出个问题考考你。她想知道，n面小旗染色有多少种不同的方案数。这...

## hdu 递推 2050 1290 2563 2064 2077 规律哥

(没有质量，就出数量) 转载出处：http://blog.sina.com.cn/s/blog_7fec19cd01010h60.html   hdu2050 折线分平面: 1.当有n-1条直线...

举报原因： 您举报文章：POJ 3045（递推找规律） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)


text:
# Security definition for IND-CPA of public key encryption

In the security game between the challenger and the adversary for the security definition of public key encryption, the challenger creates and gives the public key pk to the adversary. The adversary chooses two messages of equal length $$m_0$$ and $$m_1$$ and asks the challenger to encode these. Finally, the adversary has to guess which message was encoded.

Isn't it always possible for the adversary to do this, since she knows the public key and can simply use the encryption algorithm to create the ciphertexts for both the messages and output the one which matches the challenger's reply?

I was using Dan Boneh's course to study crypto:

In public-key cryptography, the adversary is indeed able to create encryptions of their chosen messages $$m_1$$ and $$m_2$$ on their own.


text:
## Affine and degenerate affine BMW algebras: Actions on tensor space

Last update: 15 October 2013

## Central element transfer via Schur-Weyl duality

In Theorem 2.2 and Theorem 2.5, the parameters $z0(ℓ)=ε (id⊗trV) ((12y+γ)ℓ) andZ0(ℓ)= ε(id⊗qtrV) ((zℛ21ℛ)ℓ)$ of the degenerate affine BMW algebra and affine BMW algebra, respectively, arise naturally from the action on tensor space. It is a consequence of [Dri1990, Prop. 1.2] that these are central elements of the enveloping algebra $U𝔤$ and the quantum group ${U}_{h}𝔤,$ respectively: $z0(ℓ)∈Z (U𝔤)and Z0(ℓ)∈Z (Uh𝔤).$ The Harish-Chandra isomorphism provides isomorphisms between the centers $Z\left(U𝔤\right)$ or $Z\left({U}_{h}𝔤\right)$ and rings of symmetric functions. In this section we show how to use the recursive formulas of [Naz1996] and [BBl1866492] for the central elements ${z}_{k}^{\left(\ell \right)}$ and ${Z}_{k}^{\left(\ell \right)}$ in the degenerate affine and affine BMW algebras (formulas (3.4) and (3.14)) to determine the Harish-Chandra images of ${z}_{0}^{\left(\ell \right)}$ and ${Z}_{0}^{\left(\ell \right)}\text{.}$

Preliminaries on the Harish-Chandra isomorphisms. Let $𝔤$ be a finite-dimensional complex Lie algebra with a symmetric nondegenerate ad-invariant bilinear form. The triangular decomposition $𝔤={𝔫}^{-}\oplus 𝔥\oplus {𝔫}^{+}$ (see [Bou1990, VII §8 no. 3 Prop. 9]) yields triangular decompositions of both the enveloping algebra $U=U𝔤$ and the quantum group $U={U}_{h}𝔤$ in the form $U={U}^{-}{U}_{0}{U}^{+}\text{.}$ If $U={U}_{h}𝔤$ then ${U}_{0}=\text{span}\left\{{K}^{{\lambda }^{\vee }} | {\lambda }^{\vee }\in {𝔥}_{ℤ}\right\}$ with ${K}^{{\lambda }^{\vee }}{K}^{{\nu }^{\vee }}={K}^{{\lambda }^{\vee }+{\nu }^{\vee }},$ where ${𝔥}_{ℤ}$ is a lattice in $𝔥\text{.}$ Alternatively, $U0=U𝔥=ℂ [h1,…,hr] if U=U𝔤and U-=ℂ [L1±1,…,Lr±1] if U=Uh𝔤,$ where ${h}_{1},\dots ,{h}_{r}$ is a basis of ${𝔥}_{ℤ},$ and ${L}_{i}={K}^{{h}_{i}}={q}^{{h}_{i}}\text{.}$

For $\mu \in {𝔥}^{*},$ define the ring homomorphisms ${\text{ev}}_{\mu }:{U}_{0}\to ℂ$ by $evμ(h)= ⟨μ,h⟩ andevμ (Kλ∨)= z⟨μ,λ∨⟩ (3.1)$ for $h\in 𝔥$ and ${K}^{{\lambda }^{\vee }}$ with ${\lambda }^{\vee }\in {𝔥}_{ℤ}\text{.}$ For $\rho =\frac{1}{2}{\sum }_{\alpha \in {R}^{+}}\alpha$ as in (1.16), let ${\sigma }_{\rho }$ be the algebra automorphism given by $σρ(hi)=h +⟨ρ,hi⟩ and σρ (Li)= q⟨ρ,hi⟩ Li. (3.2)$

Define a vector space homomorphism by $π0:U⟶U0 byπ0=ε- ⊗id⊗ε+: U-⊗U0⊗ U+⟶U0, (3.3)$ where ${\epsilon }^{-}:{U}_{-}\to ℂ$ and ${\epsilon }^{+}:{U}_{+}\to ℂ$ are the algebra homomorphisms determined by $ε-(y)=0and ε+(x)=0, for x∈𝔫+ and y∈𝔫-, or ε-(Fi)=0 andε+(Ei) =0,for i=1,…, n.$

The following important theorem says that both the center of $U𝔤$ and the center of ${U}_{h}𝔤$ are isomorphic to rings of symmetric functions.

(Harish-Chandra/Chevalley isomorphism, [Bou1990, VII §8 no. 5 Thm. 2] and [CPr1994, Thm. 9.1.6]). Let $U=U𝔤$ or ${U}_{h}𝔤,$ so that $U0=ℂ[h1,…,hr] if U=U𝔤 andU0=ℂ [L1±1,…,Lr±1] if U=Uh𝔤.$ Let $L\left(\mu \right)$ denote the irreducible $U\text{-module}$ of highest weight $\mu \text{.}$ Then the restriction of ${\pi }_{0}$ to the center of $U,$ $π0: Z(U) ⟶ σρ(U0W0), z ⟼ σρ(s) is an algebra isomorphism,$ where $s\in {U}_{0}^{{W}_{0}}$ is the symmetric function determined by $zacts on L(μ) byevμ (σρ(s))= evμ+ρ(s), for μ∈𝔥*.$

### Central elements ${z}_{V}^{\left(\ell \right)}$

Let ${z}_{0}^{\left(\ell \right)}$ and $\epsilon$ be the parameters of the degenerate affine BMW algebra ${𝒲}_{k}\text{.}$ Let $u$ be a variable and define ${z}_{i}^{\left(\ell \right)}\in {𝒲}_{k}$ for $i=1,\dots ,k-1$ by $zi(u)+εu- 12= (z0(u)+εu-12) ∏j=1i (u+yj-1) (u+yj+1) (u-yj)2 (u+yj)2 (u-yj+1) (u-yj-1) , (3.4)$ where $zi(u)=∑ℓ∈ℤ≥0 zi(ℓ)u-ℓ, for i=0,1,…,k-1.$ The following proposition from [Naz1996, Lemma 3.8] is proved also in [DRV1105.4207, Theorem 3.2 and Remark 3.4]

In the degenerate affine BMW algebra ${𝒲}_{k},$ $ei+1yi+1ℓ ei+1=zi(ℓ) ei+1,for i=0,…,k-1 and ℓ∈ℤ≥0.$

The following theorem uses the identity (3.4) and the action of the degenerate affine BMW algebra on tensor space to provide a formula for the Harish-Chandra images of the central elements ${z}_{V}^{\left(\ell \right)}=\epsilon \left(\text{id}\otimes {\text{tr}}_{V}\right)\left({\left(\frac{1}{2}y+\gamma \right)}^{\ell }\right)$ in the enveloping algebra $U𝔤$ for orthogonal and symplectic Lie algebras $𝔤\text{.}$ By Theorem 2.2 these particular central elements are natural parameters for the degenerate affine BMW algebras. The concept of the proof of Theorem 3.3 is, at its core, the same as the pattern taken by Nazarov for the proof of [Naz1996, Theorem 3.9].

Let $𝔤={𝔰𝔬}_{2r+1},$ ${𝔰𝔭}_{2r}$ or ${𝔰𝔬}_{2r},$ use notations for ${𝔥}^{*}$ as in (2.5)-(2.16) and let ${h}_{1},\dots ,{h}_{r}$ be the basis of $𝔥$ dual to the orthonormal basis ${\epsilon }_{1},\dots ,{\epsilon }_{r}$ of ${𝔥}^{*}$ (so that ${h}_{i}={F}_{ii},$ where ${F}_{ii}$ is as in (2.8)). With respect to the form $⟨,⟩$ in (2.10), let $\gamma ={\sum }_{b}b\otimes {b}^{*}$ as in (1.15). Let $y= { 2r, if 𝔤= 𝔰𝔬2r+1, 2r+1, if 𝔤=𝔰𝔭2r , 2r-1, if g=𝔰𝔬2r, ε= { 1, if 𝔤= 𝔰𝔬2r+1, -1, if 𝔤=𝔰𝔭2r , 1, if g=𝔰𝔬2r, V=L(ε1),$ and let ${z}_{V}^{\left(\ell \right)}$ be the central elements in $U𝔤$ defined by $zV(ℓ)=ε (id⊗trV) ((12y+γ)ℓ) ,and writezV (u)=∑i∈ℤ≥0 zV(ℓ)u-ℓ.$ Then $π0 (zV+εu-12)= (εu+12) (u+12y-r) (u-12y+r) σρ ( ∏i=1r (u+hi+12) (u-hi+12) (u+hi-12) (u-hi-12) ) ,$ where ${\sigma }_{\rho }$ is the algebra automorphism given by ${\sigma }_{\rho }\left({h}_{i}\right)={h}_{i}+⟨\rho ,{\epsilon }_{i}⟩$ and ${\pi }_{0}$ is the isomorphism in Theorem 3.1.

 Proof. In the definition of the action of the degenerate affine BMW algebra in Theorem 2.2, ${y}_{1}$ acts on $M\otimes V$ as $\frac{1}{2}y+\gamma ,$ and $e1y1ℓe1 acts on M⊗V⊗2 as zV(ℓ) e1.$ Also $e1 and y1 in 𝒲2 act on M⊗V⊗2 with M=L(0)⊗ V⊗(k-1)$ in the same way that $ek and yk 𝒲k+1 act on M ⊗V⊗(k+1) with M=L(0).$ By Proposition 3.2, ${z}_{k-1}^{\left(\ell \right)}{e}_{k}={e}_{k}{y}_{k}^{\ell }{e}_{k}\text{.}$ Hence, as operators on $L\left(0\right)\otimes {V}^{\otimes \left(k-1\right)},$ $zV(u)+εu- 12=zk-1 (u)+εu-12 (3.5)$ We will use (3.4) to compute the action of this operator on the $L\left(\mu \right)\otimes {𝒲}_{k-1}^{\mu }$ isotypic component in the $U𝔤\otimes {𝒲}_{k-1}\text{-module}$ decomposition $L(0)⊗ V⊗(k-1)≅ ⨁μL(μ)⊗ 𝒲k-1μ. (3.6)$ As an operator on $L\left(0\right)\otimes V,$ $γ=12 ( ⟨ε1,ε1+2ρ⟩- ⟨ε1,ε1+2ρ⟩+ ⟨0,0+2ρ⟩ ) =0by (1.17),$ and so $z0(ℓ)=ε (i⊗trV) ((12y+γ)ℓ) =ε(id⊗trV) ((12y)ℓ) =εdim(V) (12y)ℓ.$ Therefore, since $\text{dim}\left(V\right)=\epsilon +y,$ $z0(u)= ∑ℓ∈ℤ≥0 zV(ℓ) u-ℓ= ∑ℓ∈ℤ≥0 εdim(V) (12y)ℓ u-ℓ=εdim (V) 11-12yu-1 =1+εy1-12yu-1.$ Thus, as an operator on $L\left(0\right)\otimes V,$ $z0(u)+εu-12= 1+εy1-12yu-1 +εu-12= (εu+12) (u+12y) u-12y . (3.7)$ By the first identity in (1.11) and the definition of $\Phi$ in Theorem 1.2, $yk∈𝒲kacts on L(0)⊗V⊗k= (L(0)⊗V⊗(k-1)) ⊗Vas12y+γ.$ If $L\left(\mu \right)$ is an irreducible $U𝔤\text{-module}$ in $L\left(0\right)\otimes {V}^{\otimes \left(k-1\right)},$ then (1.17), (2.13), and (2.16) give that ${y}_{k}$ acts on the $L\left(\lambda \right)$ component of $L\left(\mu \right)\otimes V$ by the constant $c\left(\lambda ,\mu \right)=0$ when $\lambda =\mu ,$ and by the constant $c(λ,μ) = 12y+12 ( ⟨μ±εi,μ±εi+2ρ⟩- ⟨μ,μ+2ρ⟩- ⟨ε1,ε1+2ρ⟩ ) = { 12y+c(λ/μ), if μ⊆λ, -12y-c(μ/λ), if μ⊇λ, where λ=μ±εi. (3.8)$ As in [Naz1996, Theorem 2.6], the irreducible ${𝒲}_{k}\text{-module}$ ${𝒲}_{k}^{\mu /0}={𝒲}_{k}^{\mu }$ has a basis $\left\{{v}_{T}\right\}$ indexed by up-down tableaux $T=\left({T}^{\left(0\right)},{T}^{\left(1\right)},\dots ,{T}^{\left(k\right)}\right),$ where ${T}^{\left(0\right)}=\varnothing ,$ ${T}^{\left(k\right)}=\mu ,$ and ${T}^{\left(i\right)}$ is a partition obtained from ${T}^{\left(i-1\right)}$ by adding or removing a box (or, in some cases when $𝔤={𝔰𝔬}_{2r+1}$ leaving the partition the same; see (2.21)) and $yivT= { (12y+c(b)) vT, if b=T(i) /T(i-1), (-12y-c(b)) vT, if b=T(i-1) /T(i), 0, if T(i-1) =T(i).$ Thus the product on the right hand side of (3.4) $∏i=1k-1 (u+yi-1) (u+yi+1) (u-yi)2 (u+yi)2 (u-yi+1) (u-yi-1) acts on L(μ)⊗ 𝒲k-1μ in (3.6)$ by $∏i=1k-1 (u+c(T(i),T(i-1))-1) (u+c(T(i),T(i-1))+1) (u-c(T(i),T(i-1)))2 (u+c(T(i),T(i-1)))2 (u-c(T(i),T(i-1))+1) (u-c(T(i),T(i-1))-1) (3.9)$ for any up-down tableau $T$ of length $k$ and shape $\mu \text{.}$ If a box is added (or removed) at step $i$ and then removed (or added) at step $j,$ then the $i$ and $j$ factors of this product cancel. Therefore (3.9) is equal to $∏b∈μ (u+12y+c(b)-1) (u+12y+c(b)+1) (u-12y-c(b))2 (u+12y+c(b))2 (u-12y-c(b)+1) (u-12y-c(b)-1) (3.10)$ (see [Naz1996, Lemma 3.8]). If $\mu =\left({\mu }_{1},\dots ,{\mu }_{r}\right),$ simplifying one row at a time, $∏b∈μ (u+12y+c(b)-1) (u+12y+c(b)+1) (u+12y+c(b))2 = ∏i=1r (u+12y-i) (u+12y+μi-i+1) (u+12y+1-i) (u+12y+μi-i) = u+12y-r u+12y ∏i=1r (u+12y+μi-i+1) (u+12y+μi-i) , (3.11)$ (see the example following this proof). It follows that (3.10) is equal to $(u+12y-r) (u+12y) (u-12y) (u-12y+r) ∏i=1r (u+12y+μi-i+1) (u+12y+μi-i) (u-12y-(μi-i)) (u-12y-(μi-i+1)) = (u+12y-r) (u+12y) (u-12y) (u-12y+r) evμ+ρ ( ∏i=1r (u+hi+12) (u+hi-12) (u-hi+12) (u-hi-12) ) , (3.12)$ since ${\text{ev}}_{\mu +\rho }\left({h}_{i}\right)={\mu }_{i}+{\rho }_{i}={\mu }_{i}+\frac{1}{2}\left(y-2i+1\right)=\frac{1}{2}y+\frac{1}{2}+{\mu }_{i}-i\text{.}$ Combining (3.7) and (3.12), the identity (3.5) gives that, as operators on $L\left(\mu \right)\otimes {𝒲}_{k-1}^{\mu }$ in (3.6), $zV(u)+εu- 12=(εu+12) (u+12y-r) (u-12y+r) evμ+ρ ( ∏i=1r (u+hi+12) (u+hi-12) (u-hi+12) (u-hi-12) ) .$ By Theorem 3.1, the desired result follows. $\square$

Example. To help illuminate the cancellation done in (3.11), let $\mu =\left(5,5,3,3,1,1\right),$ where the contents of boxes are $0 1 2 3 4 -1 0 1 2 3 -2 -1 0 -3 -2 -1 -4 -5 (3.13)$ In this example, the product over the boxes in the first row of the diagram is $∏b in first row of μ (x+c(b)-1) (x+c(b)+1) (x+c(b)) (x+c(b)) = (x-1) (x+1) (x+0) (x+0) (x+0) (x+2) (x+1) (x+1) (x+1) (x+3) (x+2) (x+2) (x+2) (x+4) (x+3) (x+3) (x+3) (x+5) (x+4) (x+5) = (x-1) (x+5) (x+0) (x+4) ,where x=u+12y.$ Thus, simplifying the product one row at a time, $∏b∈μ (x+c(b)-1) (x+c(b)+1) (x+c(b)) (x+c(b)) = (x-1) (x+5) (x+0) (x+4) (x-2) (x+4) (x-1) (x+3) (x-3) (x+1) (x-2) (x+0) (x-4) (x+0) (x-3) (x-1) (x-5) (x-3) (x-4) (x-4) (x-6) (x-4) (x-5) (x-5) = (x-6)(x+0) (x+5)(x+4) · (x+4)(x+3) · (x+1)(x+0) · (x+0)(x-1) · (x-3)(x-4) · (x-4)(x-5)$ leads to the identity $∏b∈μ (x+c(b)-1) (x+c(b)+1) (x+c(b)) (x+c(b)) =x-rx+0 ∏i=1r x+μi-i+1 x+μi-i ,where μ= (μ1,…,μr).$

### Central elements ${Z}_{V}^{\left(\ell \right)}$

Let ${Z}_{0}^{\left(\ell \right)},$ $z$ and $q$ be the parameters of the affine BMW algebra ${W}_{k}\text{.}$ Let $u$ be a variable and define ${Z}_{i}^{\left(\ell \right)},{Z}_{i}^{\left(-\ell \right)}\in {W}_{k}$ for $i=1,\dots ,k-1$ by $Zi+(u)+ z-1q-q-1 -u2u2-1= ( Z0++ z-1q-q-1 -u2u2-1 ) ∏j=1i (u-Yj)2 (u-q-2Yj-1) (u-q2Yj-1) (u-Yj-1)2 (u-q2Yj) (u-q-2Yj) , (3.14) Zi-(u)+ zq-q-1 -u2u2-1= ( Z0-- zq-q-1 -u2u2-1 ) ∏j=1i (u-Yj-1)2 (u-q2Yj) (u-q-2Yj) (u-Yj)2 (u-q-2Yj-1) (u-q2Yj-1) , (3.15)$ where $Zi+(u)= ∑ℓ∈ℤ≥0 Zi(ℓ) u-ℓand Zi-(u)= ∑ℓ∈ℤ≥0 Zi(-ℓ) u-ℓfor i= 0,…,k-1.$ The following proposition is equivalent to [BBl1866492, Lemma 7.4] and is also proved in [DRV1105.4207, Theorem 3.6 and Remark 3.8].

In the affine BMW algebra ${W}_{k},$ $Ei+1Yiℓ Ei+1= Zi(ℓ) Ei+1, for i=0,1,… ,k-2 and ℓ∈ℤ.$

The following theorem uses the identity (3.14) and the action of the affine BMW algebra on tensor space to provide a formula for the Harish-Chandra images of the central elements ${Z}_{V}^{\left(\ell \right)}=\epsilon \left(\text{id}\otimes {\text{qtr}}_{V}\right)\left({\left(z{ℛ}_{21}ℛ\right)}^{\ell }\right)$ in the Drinfeld-Jimbo quantum group ${U}_{h}𝔤$ for orthogonal and symplectic Lie algebras $𝔤\text{.}$ By Theorem 2.5 these central elements are natural parameters for the affine BMW algebras.

Let $U={U}_{h}𝔤$ be the Drinfeld-Jimbo quantum group corresponding to $𝔤={𝔰𝔬}_{2r+1},$ ${𝔰𝔭}_{2r}$ or ${𝔰𝔬}_{2r}$ and use notations for ${𝔥}^{*}$ as in (2.5)-(2.16). Identify ${U}_{0}$ as a subalgebra of $ℂ\left[{L}_{1}^{±1},\dots ,{L}_{r}^{±1}\right]$ where ${\text{ev}}_{{\epsilon }_{i}}\left({L}_{j}\right)={q}^{⟨{\epsilon }_{i},{\epsilon }_{j}⟩}={q}^{{\delta }_{ij}}$ (so that ${L}_{i}={e}^{\frac{1}{2}h{F}_{ii}},$ where ${F}_{ii}$ is as in (2.8)). Let $y= { 2r, if 𝔤= 𝔰𝔬2r+1, 2r+1, if 𝔤=𝔰𝔭2r , 2r-1, if g=𝔰𝔬2r, ε= { 1, if 𝔤= 𝔰𝔬2r+1, -1, if 𝔤=𝔰𝔭2r , 1, if g=𝔰𝔬2r, V=L(ε1),$ and $z=\epsilon {q}^{y}\text{.}$ Let ${Z}_{V}^{\left(\ell \right)}$ be the central elements in ${U}_{h}𝔤$ defined by $ZV(ℓ)=ε (id⊗qtrV) ((zℛ21ℛ)ℓ)$ and write $ZV+(u)= ∑ℓ∈ℤ≥0 ZV(ℓ) u-ℓand ZV-(u)= ∑ℓ∈ℤ≥0 ZV(-ℓ) u-ℓ.$ Then $π0 ( ZV+(u)+ z-1q-q-1 -u2u2-1 ) =(zq-q-1) (u+q) (u-q-1) (u+1) (u-1) (u-εq2r-y) (u-εqy-2r) σρ ( ∏i=1r (u-εLi-2q-1) (u-εLi2q-1) (u-εLi-2q) (u-εLi2q) )$ and $π0 ( ZV-(u)+ zq-q-1 -u2u2-1 ) =-z-1q-q-1 (u-q) (u+q-1) (u+1) (u-1) (u-εqy-2r) (u-εq2r-y) σρ ( ∏i=1r (u-εLi-2q) (u-εLi2q) (u-εLi-2q-1) (u-εLi2q-1) ) ,$ where ${\sigma }_{\rho }$ is the algebra automorphism given by ${\sigma }_{\rho }\left({L}_{i}\right)={q}^{⟨\rho ,{\epsilon }_{i}⟩}{L}_{i}$ and ${\pi }_{0}$ is the isomorphism in Theorem 3.1.

 Proof. In the definition of the action of the affine BMW algebra in Theorem 1.3, ${Y}_{1}$ acts on $M\otimes V$ as $z{ℛ}_{21}ℛ,$ and $E1Y1ℓE1 acts on M⊗V⊗2 as ZV(ℓ) E1.$ Also $E1 and Y1 in W2 act on M⊗V⊗2 with M=L(0)⊗ V⊗(k-1)$ in the same way that $Ek and Yk in Wk+1 act on M⊗V⊗(k+1) with M=L(0).$ By Proposition 3.4, ${Z}_{k-1}^{\left(\ell \right)}{E}_{k}={E}_{k}{Y}_{k}^{\ell }{E}_{k}$ and so it follows that, as operators on $L\left(0\right)\otimes {V}^{\otimes \left(k-1\right)},$ $ZV+(u)+ z-1q-q-1 -u2u2-1 = Zk-1+(u)+ z-1q-q-1 -u2u2-1 (3.16)$ and $ZV-(u)- zq-q-1 -u2u2-1 = Zk-1-(u)+ zq-q-1 -u2u2-1 (3.17)$ We will use (3.14) and (3.15) to compute the action of these operators on the $L\left(\mu \right)\otimes {W}_{k-1}^{\mu }$ isotypic component in the ${U}_{h}𝔤\otimes {W}_{k-1}\text{-module}$ decomposition $L(0)⊗ V⊗(k-1)≅ ⨁μL(μ) ⊗Wk-1μ. (3.18)$ As an operator on $L\left(0\right)\otimes V,$ $z\left({ℛ}_{21}ℛ\right)=z{q}^{⟨{\epsilon }_{1},{\epsilon }_{1}+2\rho ⟩-⟨{\epsilon }_{1},{\epsilon }_{1}+2\rho ⟩+⟨0,0+2\rho ⟩}=z\text{.}$ Hence $ZV(ℓ)=ε (id⊗qtrV) ((zℛ21ℛ)ℓ) =zℓεdimq(V).$ Therefore, since $\epsilon {\text{dim}}_{q}\left(V\right)=\frac{z-{z}^{-1}}{q-{q}^{-1}}=1,$ $ZV+(u)= ∑ℓ∈ℤ≥0 εdimq(V) zℓu-ℓ=ε dimq(V) 11-zu-1= z-z-1+ (q-q-1) (q-q-1) (1-zu-1) .$ A similar computation of ${Z}_{V}^{-}$ yields $ZV-(u)= z-z-1+q-q-1 (q-q-1) (1-z-1u-1) .$ Thus, as operators on $L\left(0\right)\otimes V,$ $ZV++ z-1q-q-1 -u2u2-1= z(q-q-1) (1-z-1u-1) (1-zu-1) (u+q) (u-q-1) (u+1) (u-1) (3.19)$ and $ZV-- zq-q-1 -u2u2-1= -z-1(q-q-1) (1-zu-1) (1-z-1u-1) (u-q) (u+q-1) (u+1) (u-1) . (3.19)$ By (1.29) and the definition of $\Phi$ in Theorem 1.3, $Yk∈Wkacts on L(0)⊗V⊗k= (L(0)⊗V⊗(k-1)) ⊗Vaszℛ21ℛ.$ If $L\left(\mu \right)$ is an irreducible ${U}_{h}𝔤\text{-module}$ in $L\left(0\right)\otimes {V}^{\otimes \left(k-1\right)},$ then (1.28) and (2.16) give that ${Y}_{k}$ acts on the $L\left(\lambda \right)$ component of $L\left(\mu \right)\otimes V$ by the constant $\epsilon {q}^{2c\left(\lambda ,\mu \right)}=1·{q}^{0}=1,$ when $𝔤={𝔰𝔬}_{2r+1}$ and $\lambda =\mu ,$ and by the constant $εq2c(λ,μ)= { εqy+2c(λ/μ), if μ⊆λ, εq-y-2c(μ/λ) if μ⊇λ, = { zq2c(λ/μ), if μ⊆λ, z-1 q-2c(μ/λ), if μ⊇λ, ,where λ=μ±εi.$ and $c\left(\lambda ,\mu \right)$ is as computed in (3.8). As in [ORa0401317, Theorem 6.3(b)], the irreducible ${W}_{k}\text{-module}$ ${W}^{\mu /0}={W}_{k}^{\mu }$ has a basis $\left\{{v}_{T}\right\}$ indexed by up-down tableaux $T=\left\{{T}^{\left(0\right)},{T}^{\left(1\right)},\cdots ,{T}^{\left(k\right)}\right\},$ where ${T}^{\left(0\right)}=\varnothing ,$ ${T}^{\left(k\right)}=\mu ,$ and ${T}^{\left(i\right)}$ is a partition obtained from ${T}^{\left(i-1\right)}$ by adding or removing a box, and $YivT= { zq2c(b)vT, if b=T(i)/ T(i-1), z-1q-2c(b) vT, if b=T(i-1) /T(i), vT, if T(i-1)= T(i).$ Thus $∏i=1k-1 (u-Yi)2 (u-q-2Yi-1) (u-q2Yi-1) (u-Yi-1)2 (u-q2Yi) (u-q-2Yi) acts on L(μ)⊗ Wk-1μ in (3.18)$ by $∏i=1k-1 (u-εq2c(T(i),T(i-1)))2 (u-εq-2q2c(T(i),T(i-1))) (u-εq2q2c(T(i),T(i-1))) (u-εq-2c(T(i),T(i-1)))2 (u-εq2q2c(T(i),T(i-1))) (u-εq-2q2c(T(i),T(i-1))) (3.21)$ for any up-down tableau $T$ of length $k$ and shape $\mu \text{.}$ If a box is added (or removed) at step $i$ and then removed (or added) at step $j,$ then the $i$ and $j$ factors of this product cancel. Therefore (3.21) is equal to $∏b∈μ (u-zq2c(b))2 (u-z-1q-2(c(b)+1)) (u-z-1q-2(c(b)-1)) (u-z-1q-2c(b))2 (u-zq2(c(b)+1)) (u-zq2(c(b)-1)) . (3.22)$ Simplifying one row at a time, $∏b∈μ (u-z-1q-2(c(b)-1)) (u-z-1q-2(c(b)+1)) (u-z-1q-2c(b)) (u-z-1q-2c(b)) = ∏i=1r (u-z-1q-2(-i)) (u-z-1q-2(μi-i+1)) (u-z-1q-2(-(i-1))) (u-z-1q-2(μi-i)) = u-z-1q2r u-z-1q2·0 ∏i=1r u-z-1q-2(μi-i+1) u-z-1q-2(μi-i)$ if $\mu =\left({\mu }_{1},\dots ,{\mu }_{r}\right)\text{.}$ It follows that (3.22) is equal to $(u-z-1q2r) (u-z-1) (u-z) (u-zq-2r) ∏i=1r (u-z-1q-2(μi-i+1)) (u-z-1q-2(μi-i)) · (u-zq2(μi-i)) (u-zq2(μi-i+1)) = (u-εq-(y-2r)) (u-z-1) (u-z) (u-εqy-2r) evμ+ρ ( ∏i=1r (u-εLi-2q-1) (u-εLi2q-1) (u-εLi-2q) (u-εLi2q) ) (3.23)$ since ${z}^{-1}{q}^{2r}=\epsilon {q}^{-y}{q}^{2r}=\epsilon {q}^{2r-y}$ and $evμ+ρ (Li2)= q⟨μ+ρ,2π⟩ =q2μi(y-2i+1) =qy+1+2(μi-i) =εzq2(μi-i)+1.$ Combining (3.19) and (3.23), the identity (3.14) gives that, as operators on $L\left(\mu \right)\otimes {W}_{k-1}^{\mu }$ in (3.18), $Zk++ z-1q-q-1 -u2u2-1 =z(q-q-1) (u+q) (u-q-1) (u+1) (u-1) (u-εq2r-y) (u-εqy-2r) evμ+ρ ( ∏i=1r (u-εLi-2q-1) (u-εLi2q-1) (u-εLi-2q) (u-εLi2q) ) . (3.24)$ Similarly, ${Z}_{k}^{-}-\frac{z}{q-{q}^{-1}}+\frac{1}{{u}^{2}-1}$ acts on the $L\left(\mu \right)\otimes {W}_{k-1}^{\mu }$ isotypic component in the ${U}_{h}𝔤\otimes {W}_{k-1}\text{-module}$ decomposition in (3.18) by $- z-1(q-q-1) (u-q) (u+q-1) (u+1) (u-1) (u-εq2r-y) (u-εqy-2r) evμ+ρ ( ∏i=1r (u-εLi-2q) (u-εLi2q) (u-εLi-2q-1) (u-εLi2q-1) ) .$ By Theorem 3.1, the desired results follow. $\square$

In the following corollary, we shall repackage Theorem 3.5 to give a formula for the Harish-Chandra image of ${Z}_{V}^{\left(\ell \right)}$ in terms of “Weyl characters”. To do this we will use the universal characters of [KTe1987] following the notation in [HRa1995, §6]. For a formal alphabet $Y$ let $s{a}_{\lambda }\left(Y\right)$ be the universal Weyl character for ${𝔤𝔩}_{r},$ $s{p}_{\lambda }\left(Y\right)$ the universal Weyl character for ${𝔰𝔭}_{2r},$ and $s{o}_{\lambda }\left(Y\right)$ the universal Weyl character for the orthogonal cases.

The Cauchy-Littlewood identities (see [KTe1987, Lemma 1.5.1], [Wey1946, Theorems 7.8FG and 7.9C], and [HRa1995, (6.4) and (6.5)]) are $∏i,j 11-xiyj =Ω(XY)= ∑λsaλ(X) saλ(Y), ∏i≤j 11-yiyj ∏i,j 11-xiyj =Ω(XY-sa(2)(Y)) =∑λsaλ(Y) soλ(X), ∏i where $\Omega$ is the Cauchy kernel (see [HRa1995, (6.3)]) and the first equality in each line is for the formal alphabets $X={\sum }_{i}{x}_{i}$ and $Y={\sum }_{j}{y}_{j}\text{.}$ The identity [HRa1995, Lemma 6.7(a)] states $saλ ((q-q-1)u-1) = { (q-q-1) u-ℓ (-q-1)ℓ-m qm-1, if λ=(m,1ℓ-m), 0, otherwise. (3.25)$

In the same setting as in Theorem 3.5, let $y= { 2r, if 𝔤= 𝔰𝔬2r+1, 2r+1, if 𝔤=𝔰𝔭2r , 2r-1, if g=𝔰𝔬2r, ε= { 1, if 𝔤= 𝔰𝔬2r+1, -1, if 𝔤=𝔰𝔭2r , 1, if g=𝔰𝔬2r, V=L(ε1),$ $z=\epsilon {q}^{y},$ and let ${Z}_{V}^{\left(\ell \right)}$ be the central elements in the Drinfeld-Jimbo quantum group ${U}_{h}𝔤$ which are given by ${Z}_{V}^{\left(\ell \right)}=\epsilon \left(\text{id}\otimes {\text{qtr}}_{L\left({\epsilon }_{1}\right)}\right)\left({\left(z{ℛ}_{21}ℛ\right)}^{\ell }\right)\text{.}$ Let $X$ be the formal alphabet given by $X={\sum }_{i\in \stackrel{ˆ}{V}}{L}_{i}^{2}$ and fix $c=1$ if $\ell$ is even and $c=0$ if $\ell$ is odd. Then for $\ell \ge 1,$ $π0(ZV(ℓ))= σρ ( c+zεℓ∑m=1ℓ (q-q-1) (-1)ℓ-m q-(ℓ-2m+1) s(m,1ℓ-m) (X) )$ where ${s}_{\left(m,{1}^{\ell -m}\right)}\left(X\right)={so}_{\left(m,{1}^{\ell -m}\right)}\left(X\right)$ in the orthogonal cases and ${s}_{\left(m,{1}^{\ell -m}\right)}\left(X\right)={sp}_{\left(m,{1}^{\ell -m}\right)}\left(X\right)$ in the symplectic case.

 Proof. Let $\stackrel{ˆ}{V}$ as in (2.6), ${L}_{-i}={L}_{i}^{-1}$ where ${L}_{i}$ is as in the statement of Theorem 3.5, and let ${L}_{{\epsilon }_{0}}=1\text{.}$ The identity in Theorem 3.5 can be rewritten as $π0 ( ZV+(U)+ z-1q-q-1- u2u2-1 ) =σρ ( zq-q-1 u2-q2ε u2-1 ∏j∈Vˆ (1-Lwt(vj)2q-1(εu)-1) (1-Lwt(vj)2q(εu)-1) ) . (3.26)$ By (3.25), $sa(2) ( (q-q-1) (εu)-1 ) =(q2-1) (εu)-2 andsa(12) ( (q-q-1) (εu)-1 ) =(q-2-1) (εu)-2.$ So the Cauchy-Littlewood identities give $(1-q2(εu)-2) 1-(εu)-2 ∏i∈Vˆ (1-Li2q-1(εu)-1) (1-Li2q(εu)-1) =Ω ( X(q-q-1) (εu)-1- sa(2) ( (q-q-1) (εu)-1 ) ) =∑λsaλ ( (q-q-1) (εu)-1 ) soλ(X) =∑ℓ∈ℤ≥0 ( ∑m=1ℓ (q-q-1) (-q-1)ℓ-m qm-1 so(m,1ℓ-m) (X) ) (εu)-ℓ =∑ℓ∈ℤ≥0 eℓ(q-q-1) ( ∑m=1ℓ (q-q-1) (-1)ℓ-m q-(ℓ-2m+1) so(m,1ℓ-m) (X) ) u-ℓ$ in the orthogonal case, and $(1-q-2(εu)-2) 1-(εu)-2 ∏i∈Vˆ (1-Li2q-1(εu)-1) (1-Li2q(εu)-1) =Ω ( X(q-q-1) (εu)-1- sa(12) ( (q-q-1) (εu)-1 ) ) =∑λsaλ ( (q-q-1) (εu)-1 ) spλ(X) =∑ℓ∈ℤ≥0 ( ∑m=1ℓ (q-q-1) (-q-1)ℓ-m qm-1 sp(m,1ℓ-m) (X) ) (εu)-ℓ =∑ℓ∈ℤ≥0 eℓ(q-q-1) ( ∑m=1ℓ (-1)ℓ-m q-(ℓ-2m+1) sp(m,1ℓ-m) (X) ) u-ℓ$ in the symplectic case. The statement now follows by noting that ${u}^{2}/\left({u}^{2}-1\right)=1/\left(1-{u}^{-2}\right)={\sum }_{k\in {ℤ}_{\ge 0}}{u}^{-2k}$ and taking the coefficient of ${u}^{-\ell }$ on each side of (3.26). $\square$

## Notes and references

This is a typed exert of the paper Affine and degenerate affine BMW algebras: Actions on tensor space by Zajj Daugherty, Arun Ram and Rahbar Virk.