Given the

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write the value_equality method.
Given the two expressions ? and ?, first compute the set of variables ? that appear in either ? or ?. Then, the idea consists in performing num_sample times the following test for equality:

  • First, produce a variable assignment (a dictionary) mapping each variable in ? to a random value. Choose these random values from the gaussian distribution centered around 0 and with standard deviation 10 (for instance; any continuous distribution with infinite domain would work). You can obtain such numbers using random.gauss(0, 10).
  • Then, compute the values of ? and ? with respect to that variable evaluation. If the values are closer than a specified tolerance tolerance, you consider ? and ? equal (for that variable valuation). Otherwise, you can stop and return that ? and ? are different.

If you can repeat the process num_sample times, and ? and ? are considered equal every time, then you declare them equal.

WRITE CODE IN PYTHON

### Exercise: implementation of value equality
import random
def value_equality(e, f, num_samples=1000, tolerance=le-6) :
"""Return True if the two expressions self and other are numerically
equivalent.
Equivalence is tested by generating
num_samples assignments, and checking that equality holds
for all of them.
the values of the two expressions have to be closer than tolerance.
Equality is checked up to tolerance, that is,
It can be done in less than 10 lines of code."""
# YOUR CODE HERE
Transcribed Image Text:### Exercise: implementation of value equality import random def value_equality(e, f, num_samples=1000, tolerance=le-6) : """Return True if the two expressions self and other are numerically equivalent. Equivalence is tested by generating num_samples assignments, and checking that equality holds for all of them. the values of the two expressions have to be closer than tolerance. Equality is checked up to tolerance, that is, It can be done in less than 10 lines of code.""" # YOUR CODE HERE
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Growing Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education