| Alternative 1 | |
|---|---|
| Error | 2.4 |
| Cost | 1100 |
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* x (/ (* (/ y z) t) t))) (t_2 (/ (* y x) z)))
(if (<= t_1 -3e+287)
t_2
(if (<= t_1 -1e-196)
(/ x (/ z y))
(if (<= t_1 1e-56) t_2 (/ y (/ z x)))))))double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
double code(double x, double y, double z, double t) {
double t_1 = x * (((y / z) * t) / t);
double t_2 = (y * x) / z;
double tmp;
if (t_1 <= -3e+287) {
tmp = t_2;
} else if (t_1 <= -1e-196) {
tmp = x / (z / y);
} else if (t_1 <= 1e-56) {
tmp = t_2;
} else {
tmp = y / (z / x);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x * (((y / z) * t) / t)
end function
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = x * (((y / z) * t) / t)
t_2 = (y * x) / z
if (t_1 <= (-3d+287)) then
tmp = t_2
else if (t_1 <= (-1d-196)) then
tmp = x / (z / y)
else if (t_1 <= 1d-56) then
tmp = t_2
else
tmp = y / (z / x)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
public static double code(double x, double y, double z, double t) {
double t_1 = x * (((y / z) * t) / t);
double t_2 = (y * x) / z;
double tmp;
if (t_1 <= -3e+287) {
tmp = t_2;
} else if (t_1 <= -1e-196) {
tmp = x / (z / y);
} else if (t_1 <= 1e-56) {
tmp = t_2;
} else {
tmp = y / (z / x);
}
return tmp;
}
def code(x, y, z, t): return x * (((y / z) * t) / t)
def code(x, y, z, t): t_1 = x * (((y / z) * t) / t) t_2 = (y * x) / z tmp = 0 if t_1 <= -3e+287: tmp = t_2 elif t_1 <= -1e-196: tmp = x / (z / y) elif t_1 <= 1e-56: tmp = t_2 else: tmp = y / (z / x) return tmp
function code(x, y, z, t) return Float64(x * Float64(Float64(Float64(y / z) * t) / t)) end
function code(x, y, z, t) t_1 = Float64(x * Float64(Float64(Float64(y / z) * t) / t)) t_2 = Float64(Float64(y * x) / z) tmp = 0.0 if (t_1 <= -3e+287) tmp = t_2; elseif (t_1 <= -1e-196) tmp = Float64(x / Float64(z / y)); elseif (t_1 <= 1e-56) tmp = t_2; else tmp = Float64(y / Float64(z / x)); end return tmp end
function tmp = code(x, y, z, t) tmp = x * (((y / z) * t) / t); end
function tmp_2 = code(x, y, z, t) t_1 = x * (((y / z) * t) / t); t_2 = (y * x) / z; tmp = 0.0; if (t_1 <= -3e+287) tmp = t_2; elseif (t_1 <= -1e-196) tmp = x / (z / y); elseif (t_1 <= 1e-56) tmp = t_2; else tmp = y / (z / x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$1, -3e+287], t$95$2, If[LessEqual[t$95$1, -1e-196], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-56], t$95$2, N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]]]]]]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\begin{array}{l}
t_1 := x \cdot \frac{\frac{y}{z} \cdot t}{t}\\
t_2 := \frac{y \cdot x}{z}\\
\mathbf{if}\;t_1 \leq -3 \cdot 10^{+287}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-196}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\mathbf{elif}\;t_1 \leq 10^{-56}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\end{array}
Results
| Original | 15.0 |
|---|---|
| Target | 1.5 |
| Herbie | 4.3 |
if (*.f64 x (/.f64 (*.f64 (/.f64 y z) t) t)) < -2.9999999999999999e287 or -1e-196 < (*.f64 x (/.f64 (*.f64 (/.f64 y z) t) t)) < 1e-56Initial program 19.9
Simplified8.1
[Start]19.9 | \[ x \cdot \frac{\frac{y}{z} \cdot t}{t}
\] |
|---|---|
rational.json-simplify-2 [=>]19.9 | \[ x \cdot \frac{\color{blue}{t \cdot \frac{y}{z}}}{t}
\] |
rational.json-simplify-49 [=>]8.1 | \[ x \cdot \color{blue}{\left(\frac{y}{z} \cdot \frac{t}{t}\right)}
\] |
rational.json-simplify-2 [=>]8.1 | \[ x \cdot \color{blue}{\left(\frac{t}{t} \cdot \frac{y}{z}\right)}
\] |
rational.json-simplify-54 [=>]19.5 | \[ x \cdot \color{blue}{\frac{\frac{y}{t}}{\frac{z}{t}}}
\] |
rational.json-simplify-61 [=>]16.3 | \[ x \cdot \color{blue}{\frac{t}{\frac{z}{\frac{y}{t}}}}
\] |
rational.json-simplify-61 [=>]12.2 | \[ x \cdot \frac{t}{\color{blue}{\frac{t}{\frac{y}{z}}}}
\] |
rational.json-simplify-61 [=>]8.1 | \[ x \cdot \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}}
\] |
rational.json-simplify-60 [=>]8.1 | \[ x \cdot \color{blue}{\frac{y}{z}}
\] |
Taylor expanded in x around 0 4.8
if -2.9999999999999999e287 < (*.f64 x (/.f64 (*.f64 (/.f64 y z) t) t)) < -1e-196Initial program 0.8
Simplified0.4
[Start]0.8 | \[ x \cdot \frac{\frac{y}{z} \cdot t}{t}
\] |
|---|---|
rational.json-simplify-2 [=>]0.8 | \[ x \cdot \frac{\color{blue}{t \cdot \frac{y}{z}}}{t}
\] |
rational.json-simplify-49 [=>]0.4 | \[ x \cdot \color{blue}{\left(\frac{y}{z} \cdot \frac{t}{t}\right)}
\] |
rational.json-simplify-2 [=>]0.4 | \[ x \cdot \color{blue}{\left(\frac{t}{t} \cdot \frac{y}{z}\right)}
\] |
rational.json-simplify-54 [=>]17.7 | \[ x \cdot \color{blue}{\frac{\frac{y}{t}}{\frac{z}{t}}}
\] |
rational.json-simplify-61 [=>]22.6 | \[ x \cdot \color{blue}{\frac{t}{\frac{z}{\frac{y}{t}}}}
\] |
rational.json-simplify-61 [=>]15.9 | \[ x \cdot \frac{t}{\color{blue}{\frac{t}{\frac{y}{z}}}}
\] |
rational.json-simplify-61 [=>]0.4 | \[ x \cdot \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}}
\] |
rational.json-simplify-60 [=>]0.4 | \[ x \cdot \color{blue}{\frac{y}{z}}
\] |
Applied egg-rr0.6
if 1e-56 < (*.f64 x (/.f64 (*.f64 (/.f64 y z) t) t)) Initial program 17.9
Simplified7.7
[Start]17.9 | \[ x \cdot \frac{\frac{y}{z} \cdot t}{t}
\] |
|---|---|
rational.json-simplify-2 [=>]17.9 | \[ x \cdot \frac{\color{blue}{t \cdot \frac{y}{z}}}{t}
\] |
rational.json-simplify-49 [=>]7.7 | \[ x \cdot \color{blue}{\left(\frac{y}{z} \cdot \frac{t}{t}\right)}
\] |
rational.json-simplify-2 [=>]7.7 | \[ x \cdot \color{blue}{\left(\frac{t}{t} \cdot \frac{y}{z}\right)}
\] |
rational.json-simplify-54 [=>]24.9 | \[ x \cdot \color{blue}{\frac{\frac{y}{t}}{\frac{z}{t}}}
\] |
rational.json-simplify-61 [=>]25.0 | \[ x \cdot \color{blue}{\frac{t}{\frac{z}{\frac{y}{t}}}}
\] |
rational.json-simplify-61 [=>]18.7 | \[ x \cdot \frac{t}{\color{blue}{\frac{t}{\frac{y}{z}}}}
\] |
rational.json-simplify-61 [=>]7.7 | \[ x \cdot \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}}
\] |
rational.json-simplify-60 [=>]7.7 | \[ x \cdot \color{blue}{\frac{y}{z}}
\] |
Applied egg-rr6.6
Final simplification4.3
| Alternative 1 | |
|---|---|
| Error | 2.4 |
| Cost | 1100 |
| Alternative 2 | |
|---|---|
| Error | 2.2 |
| Cost | 1100 |
| Alternative 3 | |
|---|---|
| Error | 2.3 |
| Cost | 1100 |
| Alternative 4 | |
|---|---|
| Error | 6.2 |
| Cost | 320 |
herbie shell --seed 2023075
(FPCore (x y z t)
:name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B"
:precision binary64
:herbie-target
(if (< (/ (* (/ y z) t) t) -1.20672205123045e+245) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) -5.907522236933906e-275) (* x (/ y z)) (if (< (/ (* (/ y z) t) t) 5.658954423153415e-65) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) 2.0087180502407133e+217) (* x (/ y z)) (/ (* y x) z)))))
(* x (/ (* (/ y z) t) t)))