| Alternative 1 | |
|---|---|
| Error | 20.9 |
| Cost | 720 |
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (+ x (* y (- z x))) z)))
(if (<= t_0 (- INFINITY))
(* (- 1.0 (/ x z)) y)
(if (<= t_0 2e+307)
(+ y (/ (* x (- 1.0 y)) z))
(+ y (* (- (/ y z)) x))))))double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
double code(double x, double y, double z) {
double t_0 = (x + (y * (z - x))) / z;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = (1.0 - (x / z)) * y;
} else if (t_0 <= 2e+307) {
tmp = y + ((x * (1.0 - y)) / z);
} else {
tmp = y + (-(y / z) * x);
}
return tmp;
}
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
public static double code(double x, double y, double z) {
double t_0 = (x + (y * (z - x))) / z;
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = (1.0 - (x / z)) * y;
} else if (t_0 <= 2e+307) {
tmp = y + ((x * (1.0 - y)) / z);
} else {
tmp = y + (-(y / z) * x);
}
return tmp;
}
def code(x, y, z): return (x + (y * (z - x))) / z
def code(x, y, z): t_0 = (x + (y * (z - x))) / z tmp = 0 if t_0 <= -math.inf: tmp = (1.0 - (x / z)) * y elif t_0 <= 2e+307: tmp = y + ((x * (1.0 - y)) / z) else: tmp = y + (-(y / z) * x) return tmp
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function code(x, y, z) t_0 = Float64(Float64(x + Float64(y * Float64(z - x))) / z) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(1.0 - Float64(x / z)) * y); elseif (t_0 <= 2e+307) tmp = Float64(y + Float64(Float64(x * Float64(1.0 - y)) / z)); else tmp = Float64(y + Float64(Float64(-Float64(y / z)) * x)); end return tmp end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
function tmp_2 = code(x, y, z) t_0 = (x + (y * (z - x))) / z; tmp = 0.0; if (t_0 <= -Inf) tmp = (1.0 - (x / z)) * y; elseif (t_0 <= 2e+307) tmp = y + ((x * (1.0 - y)) / z); else tmp = y + (-(y / z) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(1.0 - N[(x / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 2e+307], N[(y + N[(N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(y + N[((-N[(y / z), $MachinePrecision]) * x), $MachinePrecision]), $MachinePrecision]]]]
\frac{x + y \cdot \left(z - x\right)}{z}
\begin{array}{l}
t_0 := \frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\left(1 - \frac{x}{z}\right) \cdot y\\
\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+307}:\\
\;\;\;\;y + \frac{x \cdot \left(1 - y\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;y + \left(-\frac{y}{z}\right) \cdot x\\
\end{array}
Results
| Original | 10.2 |
|---|---|
| Target | 0.0 |
| Herbie | 0.1 |
if (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < -inf.0Initial program 64.0
Taylor expanded in y around inf 64.0
Taylor expanded in z around 0 21.2
Simplified21.2
[Start]21.2 | \[ -1 \cdot \frac{y \cdot x}{z} + y
\] |
|---|---|
rational.json-simplify-1 [=>]21.2 | \[ \color{blue}{y + -1 \cdot \frac{y \cdot x}{z}}
\] |
rational.json-simplify-2 [=>]21.2 | \[ y + \color{blue}{\frac{y \cdot x}{z} \cdot -1}
\] |
rational.json-simplify-9 [=>]21.2 | \[ y + \color{blue}{\left(-\frac{y \cdot x}{z}\right)}
\] |
Taylor expanded in y around 0 0.1
if -inf.0 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) < 1.99999999999999997e307Initial program 0.1
Taylor expanded in x around inf 0.0
Simplified0.0
[Start]0.0 | \[ y + \frac{\left(1 + -1 \cdot y\right) \cdot x}{z}
\] |
|---|---|
rational.json-simplify-2 [=>]0.0 | \[ y + \frac{\color{blue}{x \cdot \left(1 + -1 \cdot y\right)}}{z}
\] |
rational.json-simplify-17 [=>]0.0 | \[ y + \frac{x \cdot \color{blue}{\left(-1 \cdot y - -1\right)}}{z}
\] |
rational.json-simplify-2 [=>]0.0 | \[ y + \frac{x \cdot \left(\color{blue}{y \cdot -1} - -1\right)}{z}
\] |
rational.json-simplify-9 [=>]0.0 | \[ y + \frac{x \cdot \left(\color{blue}{\left(-y\right)} - -1\right)}{z}
\] |
rational.json-simplify-12 [=>]0.0 | \[ y + \frac{x \cdot \left(\color{blue}{\left(0 - y\right)} - -1\right)}{z}
\] |
rational.json-simplify-42 [=>]0.0 | \[ y + \frac{x \cdot \color{blue}{\left(\left(0 - -1\right) - y\right)}}{z}
\] |
metadata-eval [=>]0.0 | \[ y + \frac{x \cdot \left(\color{blue}{1} - y\right)}{z}
\] |
if 1.99999999999999997e307 < (/.f64 (+.f64 x (*.f64 y (-.f64 z x))) z) Initial program 63.7
Taylor expanded in x around inf 21.5
Simplified21.5
[Start]21.5 | \[ y + \frac{\left(1 + -1 \cdot y\right) \cdot x}{z}
\] |
|---|---|
rational.json-simplify-2 [=>]21.5 | \[ y + \frac{\color{blue}{x \cdot \left(1 + -1 \cdot y\right)}}{z}
\] |
rational.json-simplify-17 [=>]21.5 | \[ y + \frac{x \cdot \color{blue}{\left(-1 \cdot y - -1\right)}}{z}
\] |
rational.json-simplify-2 [=>]21.5 | \[ y + \frac{x \cdot \left(\color{blue}{y \cdot -1} - -1\right)}{z}
\] |
rational.json-simplify-9 [=>]21.5 | \[ y + \frac{x \cdot \left(\color{blue}{\left(-y\right)} - -1\right)}{z}
\] |
rational.json-simplify-12 [=>]21.5 | \[ y + \frac{x \cdot \left(\color{blue}{\left(0 - y\right)} - -1\right)}{z}
\] |
rational.json-simplify-42 [=>]21.5 | \[ y + \frac{x \cdot \color{blue}{\left(\left(0 - -1\right) - y\right)}}{z}
\] |
metadata-eval [=>]21.5 | \[ y + \frac{x \cdot \left(\color{blue}{1} - y\right)}{z}
\] |
Taylor expanded in x around 0 0.2
Taylor expanded in y around inf 0.5
Simplified0.5
[Start]0.5 | \[ y + \left(-1 \cdot \frac{y}{z}\right) \cdot x
\] |
|---|---|
rational.json-simplify-2 [=>]0.5 | \[ y + \color{blue}{\left(\frac{y}{z} \cdot -1\right)} \cdot x
\] |
rational.json-simplify-9 [=>]0.5 | \[ y + \color{blue}{\left(-\frac{y}{z}\right)} \cdot x
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 20.9 |
| Cost | 720 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Error | 0.0 |
| Cost | 704 |
| Alternative 4 | |
|---|---|
| Error | 9.6 |
| Cost | 648 |
| Alternative 5 | |
|---|---|
| Error | 9.0 |
| Cost | 320 |
| Alternative 6 | |
|---|---|
| Error | 31.6 |
| Cost | 64 |
herbie shell --seed 2023077
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:herbie-target
(- (+ y (/ x z)) (/ y (/ z x)))
(/ (+ x (* y (- z x))) z))