Alternative 1 | |
---|---|
Error | 3.5 |
Cost | 841 |
(FPCore (x y) :precision binary64 (/ (- (* (* 2.0 x) y)) (- x y)))
(FPCore (x y) :precision binary64 (if (or (<= y -1.75e+41) (not (<= y 1e-61))) (* x (* 2.0 (/ y (- y x)))) (* y (/ (* x -2.0) (- x y)))))
double code(double x, double y) { return -((2.0 * x) * y) / (x - y); }
double code(double x, double y) { double tmp; if ((y <= -1.75e+41) || !(y <= 1e-61)) { tmp = x * (2.0 * (y / (y - x))); } else { tmp = y * ((x * -2.0) / (x - y)); } return tmp; }
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y code = -((2.0d0 * x) * y) / (x - y) end function
real(8) function code(x, y) real(8), intent (in) :: x real(8), intent (in) :: y real(8) :: tmp if ((y <= (-1.75d+41)) .or. (.not. (y <= 1d-61))) then tmp = x * (2.0d0 * (y / (y - x))) else tmp = y * ((x * (-2.0d0)) / (x - y)) end if code = tmp end function
public static double code(double x, double y) { return -((2.0 * x) * y) / (x - y); }
public static double code(double x, double y) { double tmp; if ((y <= -1.75e+41) || !(y <= 1e-61)) { tmp = x * (2.0 * (y / (y - x))); } else { tmp = y * ((x * -2.0) / (x - y)); } return tmp; }
def code(x, y): return -((2.0 * x) * y) / (x - y)
def code(x, y): tmp = 0 if (y <= -1.75e+41) or not (y <= 1e-61): tmp = x * (2.0 * (y / (y - x))) else: tmp = y * ((x * -2.0) / (x - y)) return tmp
function code(x, y) return Float64(Float64(-Float64(Float64(2.0 * x) * y)) / Float64(x - y)) end
function code(x, y) tmp = 0.0 if ((y <= -1.75e+41) || !(y <= 1e-61)) tmp = Float64(x * Float64(2.0 * Float64(y / Float64(y - x)))); else tmp = Float64(y * Float64(Float64(x * -2.0) / Float64(x - y))); end return tmp end
function tmp = code(x, y) tmp = -((2.0 * x) * y) / (x - y); end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.75e+41) || ~((y <= 1e-61))) tmp = x * (2.0 * (y / (y - x))); else tmp = y * ((x * -2.0) / (x - y)); end tmp_2 = tmp; end
code[x_, y_] := N[((-N[(N[(2.0 * x), $MachinePrecision] * y), $MachinePrecision]) / N[(x - y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[Or[LessEqual[y, -1.75e+41], N[Not[LessEqual[y, 1e-61]], $MachinePrecision]], N[(x * N[(2.0 * N[(y / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(x * -2.0), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{-\left(2 \cdot x\right) \cdot y}{x - y}
\begin{array}{l} \mathbf{if}\;y \leq -1.75 \cdot 10^{+41} \lor \neg \left(y \leq 10^{-61}\right):\\ \;\;\;\;x \cdot \left(2 \cdot \frac{y}{y - x}\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x \cdot -2}{x - y}\\ \end{array}
Results
if y < -1.75e41 or 1e-61 < y
Initial program 15.6
Simplified0.2
[Start]15.6 | \[ \frac{-\left(2 \cdot x\right) \cdot y}{x - y}
\] |
---|---|
distribute-rgt-neg-in [=>]15.6 | \[ \frac{\color{blue}{\left(2 \cdot x\right) \cdot \left(-y\right)}}{x - y}
\] |
associate-*r/ [<=]0.2 | \[ \color{blue}{\left(2 \cdot x\right) \cdot \frac{-y}{x - y}}
\] |
*-commutative [=>]0.2 | \[ \color{blue}{\left(x \cdot 2\right)} \cdot \frac{-y}{x - y}
\] |
neg-mul-1 [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \frac{\color{blue}{-1 \cdot y}}{x - y}
\] |
sub-neg [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \frac{-1 \cdot y}{\color{blue}{x + \left(-y\right)}}
\] |
+-commutative [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \frac{-1 \cdot y}{\color{blue}{\left(-y\right) + x}}
\] |
neg-sub0 [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \frac{-1 \cdot y}{\color{blue}{\left(0 - y\right)} + x}
\] |
associate-+l- [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \frac{-1 \cdot y}{\color{blue}{0 - \left(y - x\right)}}
\] |
sub0-neg [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \frac{-1 \cdot y}{\color{blue}{-\left(y - x\right)}}
\] |
neg-mul-1 [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \frac{-1 \cdot y}{\color{blue}{-1 \cdot \left(y - x\right)}}
\] |
times-frac [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \color{blue}{\left(\frac{-1}{-1} \cdot \frac{y}{y - x}\right)}
\] |
metadata-eval [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \left(\color{blue}{1} \cdot \frac{y}{y - x}\right)
\] |
*-lft-identity [=>]0.2 | \[ \left(x \cdot 2\right) \cdot \color{blue}{\frac{y}{y - x}}
\] |
associate-*r* [<=]0.2 | \[ \color{blue}{x \cdot \left(2 \cdot \frac{y}{y - x}\right)}
\] |
if -1.75e41 < y < 1e-61
Initial program 14.0
Simplified0.2
[Start]14.0 | \[ \frac{-\left(2 \cdot x\right) \cdot y}{x - y}
\] |
---|---|
distribute-lft-neg-in [=>]14.0 | \[ \frac{\color{blue}{\left(-2 \cdot x\right) \cdot y}}{x - y}
\] |
associate-*l/ [<=]0.2 | \[ \color{blue}{\frac{-2 \cdot x}{x - y} \cdot y}
\] |
*-commutative [=>]0.2 | \[ \color{blue}{y \cdot \frac{-2 \cdot x}{x - y}}
\] |
*-commutative [=>]0.2 | \[ y \cdot \frac{-\color{blue}{x \cdot 2}}{x - y}
\] |
distribute-lft-neg-in [=>]0.2 | \[ y \cdot \frac{\color{blue}{\left(-x\right) \cdot 2}}{x - y}
\] |
sub-neg [=>]0.2 | \[ y \cdot \frac{\left(-x\right) \cdot 2}{\color{blue}{x + \left(-y\right)}}
\] |
+-commutative [=>]0.2 | \[ y \cdot \frac{\left(-x\right) \cdot 2}{\color{blue}{\left(-y\right) + x}}
\] |
neg-sub0 [=>]0.2 | \[ y \cdot \frac{\left(-x\right) \cdot 2}{\color{blue}{\left(0 - y\right)} + x}
\] |
associate-+l- [=>]0.2 | \[ y \cdot \frac{\left(-x\right) \cdot 2}{\color{blue}{0 - \left(y - x\right)}}
\] |
sub0-neg [=>]0.2 | \[ y \cdot \frac{\left(-x\right) \cdot 2}{\color{blue}{-\left(y - x\right)}}
\] |
neg-mul-1 [=>]0.2 | \[ y \cdot \frac{\left(-x\right) \cdot 2}{\color{blue}{-1 \cdot \left(y - x\right)}}
\] |
times-frac [=>]0.3 | \[ y \cdot \color{blue}{\left(\frac{-x}{-1} \cdot \frac{2}{y - x}\right)}
\] |
metadata-eval [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{\color{blue}{\frac{-2}{-1}}}{y - x}\right)
\] |
metadata-eval [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{\frac{\color{blue}{-1 \cdot 2}}{-1}}{y - x}\right)
\] |
associate-/r* [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \color{blue}{\frac{-1 \cdot 2}{-1 \cdot \left(y - x\right)}}\right)
\] |
neg-mul-1 [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{-1 \cdot 2}{\color{blue}{-\left(y - x\right)}}\right)
\] |
sub0-neg [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{-1 \cdot 2}{\color{blue}{0 - \left(y - x\right)}}\right)
\] |
associate-+l- [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{-1 \cdot 2}{\color{blue}{\left(0 - y\right) + x}}\right)
\] |
neg-sub0 [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{-1 \cdot 2}{\color{blue}{\left(-y\right)} + x}\right)
\] |
+-commutative [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{-1 \cdot 2}{\color{blue}{x + \left(-y\right)}}\right)
\] |
sub-neg [<=]0.3 | \[ y \cdot \left(\frac{-x}{-1} \cdot \frac{-1 \cdot 2}{\color{blue}{x - y}}\right)
\] |
associate-*r/ [=>]0.2 | \[ y \cdot \color{blue}{\frac{\frac{-x}{-1} \cdot \left(-1 \cdot 2\right)}{x - y}}
\] |
Final simplification0.2
Alternative 1 | |
---|---|
Error | 3.5 |
Cost | 841 |
Alternative 2 | |
---|---|
Error | 16.8 |
Cost | 721 |
Alternative 3 | |
---|---|
Error | 31.5 |
Cost | 192 |
herbie shell --seed 1
(FPCore (x y)
:name "-(2 * x* y) / (x- y)"
:precision binary64
:pre (and (and (<= -1.79e+308 x) (<= x 1.79e+308)) (and (<= -1.79e+308 y) (<= y 1.79e+308)))
(/ (- (* (* 2.0 x) y)) (- x y)))