<commit_before><!DOCTYPE html>
<html>
<head>
<title>piecewise &mdash; SageMath</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>

<script src="https://sagecell.sagemath.org/static/jquery.min.js"></script>
<script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
<script src="../setup.js"></script>

<p class="sagemath"> piecewise( [ [ ( <code>begin</code> , <code>end</code> ) , <code>function</code> ] , ... ] ) </p>

<p>A  piecewise function in SageMath defined by <code>function</code> on the interval from <code>begin</code> to <code>end</code>. Consecutive intervals must share an endpoint.</p>

<p>Attempting to specify a partial range when plotting a piecewise function leads to the opaque error message <code>local variable 'G' referenced before assignment</code>.</p>

<p>Including a numerical integral directly in <code>piecewise</code> leads to the error message <code>unable to simplify to float approximation</code>. This can be avoided by moving the numerical integral to a Python function and including the name of the function without arguments in <code>piecewise</code>.</p>

<p>Examples:</p>

<div class="sagemathcell">
<script type="text/x-sage">

show( 'f = piecewise( [ [(0,1),x],[(1,3),2-x],[(3,4),x-4] ] )' )
show( 'show( plot( f, figsize=[4.5,2], color=(0,.5,1) ) )' )

f = piecewise( [ [(0,1),x],[(1,3),2-x],[(3,4),x-4] ] )
show( plot( f, figsize=[4.5,2], color=(0,.5,1) ) )

</script>
</div>

<br/><br/>
<commit_msg>Update piecewise<commit_after><!DOCTYPE html>
<html>
<head>
<title>piecewise &mdash; SageMath</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>

<script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script>
<script src="../setup.js"></script>

<p class="sagemath"> piecewise( [ [ ( <code>begin</code> , <code>end</code> ) , <code>function</code> ] , ... ] ) </p>

<p>A  piecewise function in SageMath defined by <code>function</code> on the interval from <code>begin</code> to <code>end</code>. Consecutive intervals must share an endpoint.</p>

<p>Attempting to specify a partial range when plotting a piecewise function leads to the opaque error message <code>local variable 'G' referenced before assignment</code>.</p>

<p>Including a numerical integral directly in <code>piecewise</code> leads to the error message <code>unable to simplify to float approximation</code>. This can be avoided by moving the numerical integral to a Python function and including the name of the function without arguments in <code>piecewise</code>.</p>

<p><b>NOTE: <code>piecewise</code> appears to have broken severely in Sage 7.2, which is currently running on the public server.</b></p>

<p>Examples:</p>

<div class="sagemathcell">
<script type="text/x-sage">

show( 'f = piecewise( [ [(0,1),x],[(1,3),2-x],[(3,4),x-4] ] )' )
show( 'show( plot( f, figsize=[4.5,2], color=(0,.5,1) ) )' )

f = piecewise( [ [(0,1),x],[(1,3),2-x],[(3,4),x-4] ] )
show( plot( f, figsize=[4.5,2], color=(0,.5,1) ) )

</script>
</div>

<br/><br/>

{'fraction_non_alphanumeric': 0.1981747066492829, 'fraction_numerical': 0.018904823989569754, 'mean_word_length': 5.150300601202405, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 107, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2816215', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1073, 'n_words': 293}