| Alternative 1 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 2148 |
(FPCore (x y z t a b c) :precision binary64 (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))
(FPCore (x y z t a b c)
:precision binary64
(let* ((t_1 (/ (+ (* a (* t -4.0)) (/ (+ (* x (* 9.0 y)) b) z)) c))
(t_2 (* (* x 9.0) y)))
(if (<= t_2 -5e+243)
(* 9.0 (/ x (/ z (/ y c))))
(if (<= t_2 -0.001)
t_1
(if (<= t_2 -4e-38)
(+ (* -4.0 (/ a (/ c t))) (/ b (* z c)))
(if (<= t_2 1e+209) t_1 (* 9.0 (/ y (* z (/ c x))))))))))double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
double code(double x, double y, double z, double t, double a, double b, double c) {
double t_1 = ((a * (t * -4.0)) + (((x * (9.0 * y)) + b) / z)) / c;
double t_2 = (x * 9.0) * y;
double tmp;
if (t_2 <= -5e+243) {
tmp = 9.0 * (x / (z / (y / c)));
} else if (t_2 <= -0.001) {
tmp = t_1;
} else if (t_2 <= -4e-38) {
tmp = (-4.0 * (a / (c / t))) + (b / (z * c));
} else if (t_2 <= 1e+209) {
tmp = t_1;
} else {
tmp = 9.0 * (y / (z * (c / x)));
}
return tmp;
}
real(8) function code(x, y, z, t, a, b, c)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = ((((x * 9.0d0) * y) - (((z * 4.0d0) * t) * a)) + b) / (z * c)
end function
real(8) function code(x, y, z, t, a, b, c)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = ((a * (t * (-4.0d0))) + (((x * (9.0d0 * y)) + b) / z)) / c
t_2 = (x * 9.0d0) * y
if (t_2 <= (-5d+243)) then
tmp = 9.0d0 * (x / (z / (y / c)))
else if (t_2 <= (-0.001d0)) then
tmp = t_1
else if (t_2 <= (-4d-38)) then
tmp = ((-4.0d0) * (a / (c / t))) + (b / (z * c))
else if (t_2 <= 1d+209) then
tmp = t_1
else
tmp = 9.0d0 * (y / (z * (c / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b, double c) {
return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c);
}
public static double code(double x, double y, double z, double t, double a, double b, double c) {
double t_1 = ((a * (t * -4.0)) + (((x * (9.0 * y)) + b) / z)) / c;
double t_2 = (x * 9.0) * y;
double tmp;
if (t_2 <= -5e+243) {
tmp = 9.0 * (x / (z / (y / c)));
} else if (t_2 <= -0.001) {
tmp = t_1;
} else if (t_2 <= -4e-38) {
tmp = (-4.0 * (a / (c / t))) + (b / (z * c));
} else if (t_2 <= 1e+209) {
tmp = t_1;
} else {
tmp = 9.0 * (y / (z * (c / x)));
}
return tmp;
}
def code(x, y, z, t, a, b, c): return ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c)
def code(x, y, z, t, a, b, c): t_1 = ((a * (t * -4.0)) + (((x * (9.0 * y)) + b) / z)) / c t_2 = (x * 9.0) * y tmp = 0 if t_2 <= -5e+243: tmp = 9.0 * (x / (z / (y / c))) elif t_2 <= -0.001: tmp = t_1 elif t_2 <= -4e-38: tmp = (-4.0 * (a / (c / t))) + (b / (z * c)) elif t_2 <= 1e+209: tmp = t_1 else: tmp = 9.0 * (y / (z * (c / x))) return tmp
function code(x, y, z, t, a, b, c) return Float64(Float64(Float64(Float64(Float64(x * 9.0) * y) - Float64(Float64(Float64(z * 4.0) * t) * a)) + b) / Float64(z * c)) end
function code(x, y, z, t, a, b, c) t_1 = Float64(Float64(Float64(a * Float64(t * -4.0)) + Float64(Float64(Float64(x * Float64(9.0 * y)) + b) / z)) / c) t_2 = Float64(Float64(x * 9.0) * y) tmp = 0.0 if (t_2 <= -5e+243) tmp = Float64(9.0 * Float64(x / Float64(z / Float64(y / c)))); elseif (t_2 <= -0.001) tmp = t_1; elseif (t_2 <= -4e-38) tmp = Float64(Float64(-4.0 * Float64(a / Float64(c / t))) + Float64(b / Float64(z * c))); elseif (t_2 <= 1e+209) tmp = t_1; else tmp = Float64(9.0 * Float64(y / Float64(z * Float64(c / x)))); end return tmp end
function tmp = code(x, y, z, t, a, b, c) tmp = ((((x * 9.0) * y) - (((z * 4.0) * t) * a)) + b) / (z * c); end
function tmp_2 = code(x, y, z, t, a, b, c) t_1 = ((a * (t * -4.0)) + (((x * (9.0 * y)) + b) / z)) / c; t_2 = (x * 9.0) * y; tmp = 0.0; if (t_2 <= -5e+243) tmp = 9.0 * (x / (z / (y / c))); elseif (t_2 <= -0.001) tmp = t_1; elseif (t_2 <= -4e-38) tmp = (-4.0 * (a / (c / t))) + (b / (z * c)); elseif (t_2 <= 1e+209) tmp = t_1; else tmp = 9.0 * (y / (z * (c / x))); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_, b_, c_] := N[(N[(N[(N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision] - N[(N[(N[(z * 4.0), $MachinePrecision] * t), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / N[(z * c), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_] := Block[{t$95$1 = N[(N[(N[(a * N[(t * -4.0), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x * N[(9.0 * y), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * 9.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+243], N[(9.0 * N[(x / N[(z / N[(y / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.001], t$95$1, If[LessEqual[t$95$2, -4e-38], N[(N[(-4.0 * N[(a / N[(c / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b / N[(z * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+209], t$95$1, N[(9.0 * N[(y / N[(z * N[(c / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\begin{array}{l}
t_1 := \frac{a \cdot \left(t \cdot -4\right) + \frac{x \cdot \left(9 \cdot y\right) + b}{z}}{c}\\
t_2 := \left(x \cdot 9\right) \cdot y\\
\mathbf{if}\;t_2 \leq -5 \cdot 10^{+243}:\\
\;\;\;\;9 \cdot \frac{x}{\frac{z}{\frac{y}{c}}}\\
\mathbf{elif}\;t_2 \leq -0.001:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq -4 \cdot 10^{-38}:\\
\;\;\;\;-4 \cdot \frac{a}{\frac{c}{t}} + \frac{b}{z \cdot c}\\
\mathbf{elif}\;t_2 \leq 10^{+209}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;9 \cdot \frac{y}{z \cdot \frac{c}{x}}\\
\end{array}
Results
| Original | 68.2% |
|---|---|
| Target | 77.5% |
| Herbie | 83.6% |
if (*.f64 (*.f64 x 9) y) < -5.00000000000000037e243Initial program 28.9%
Simplified27.8%
[Start]28.9 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
associate-/r* [=>]22.0 | \[ \color{blue}{\frac{\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z}}{c}}
\] |
Taylor expanded in x around inf 28.6%
Simplified73.0%
[Start]28.6 | \[ 9 \cdot \frac{y \cdot x}{c \cdot z}
\] |
|---|---|
*-commutative [=>]28.6 | \[ 9 \cdot \frac{\color{blue}{x \cdot y}}{c \cdot z}
\] |
associate-/l* [=>]60.8 | \[ 9 \cdot \color{blue}{\frac{x}{\frac{c \cdot z}{y}}}
\] |
*-commutative [=>]60.8 | \[ 9 \cdot \frac{x}{\frac{\color{blue}{z \cdot c}}{y}}
\] |
associate-/l* [=>]73.0 | \[ 9 \cdot \frac{x}{\color{blue}{\frac{z}{\frac{y}{c}}}}
\] |
if -5.00000000000000037e243 < (*.f64 (*.f64 x 9) y) < -1e-3 or -3.9999999999999998e-38 < (*.f64 (*.f64 x 9) y) < 1.0000000000000001e209Initial program 73.5%
Simplified86.0%
[Start]73.5 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
associate-/r* [=>]71.6 | \[ \color{blue}{\frac{\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z}}{c}}
\] |
Applied egg-rr86.0%
[Start]86.0 | \[ \frac{a \cdot \left(t \cdot -4\right) + \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}}{c}
\] |
|---|---|
fma-udef [=>]86.0 | \[ \frac{a \cdot \left(t \cdot -4\right) + \frac{\color{blue}{x \cdot \left(9 \cdot y\right) + b}}{z}}{c}
\] |
if -1e-3 < (*.f64 (*.f64 x 9) y) < -3.9999999999999998e-38Initial program 80.2%
Simplified85.6%
[Start]80.2 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
associate-/r* [=>]74.4 | \[ \color{blue}{\frac{\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z}}{c}}
\] |
Taylor expanded in x around 0 61.5%
Taylor expanded in b around 0 66.5%
Simplified70.1%
[Start]66.5 | \[ \frac{b}{c \cdot z} + -4 \cdot \frac{a \cdot t}{c}
\] |
|---|---|
+-commutative [=>]66.5 | \[ \color{blue}{-4 \cdot \frac{a \cdot t}{c} + \frac{b}{c \cdot z}}
\] |
associate-/l* [=>]70.1 | \[ -4 \cdot \color{blue}{\frac{a}{\frac{c}{t}}} + \frac{b}{c \cdot z}
\] |
if 1.0000000000000001e209 < (*.f64 (*.f64 x 9) y) Initial program 32.0%
Simplified39.9%
[Start]32.0 | \[ \frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z \cdot c}
\] |
|---|---|
associate-/r* [=>]29.6 | \[ \color{blue}{\frac{\frac{\left(\left(x \cdot 9\right) \cdot y - \left(\left(z \cdot 4\right) \cdot t\right) \cdot a\right) + b}{z}}{c}}
\] |
Applied egg-rr39.9%
[Start]39.9 | \[ \frac{a \cdot \left(t \cdot -4\right) + \frac{\mathsf{fma}\left(x, 9 \cdot y, b\right)}{z}}{c}
\] |
|---|---|
fma-udef [=>]39.9 | \[ \frac{a \cdot \left(t \cdot -4\right) + \frac{\color{blue}{x \cdot \left(9 \cdot y\right) + b}}{z}}{c}
\] |
Taylor expanded in x around inf 31.8%
Simplified69.2%
[Start]31.8 | \[ 9 \cdot \frac{y \cdot x}{c \cdot z}
\] |
|---|---|
associate-/l* [=>]57.2 | \[ 9 \cdot \color{blue}{\frac{y}{\frac{c \cdot z}{x}}}
\] |
associate-/l* [=>]67.4 | \[ 9 \cdot \frac{y}{\color{blue}{\frac{c}{\frac{x}{z}}}}
\] |
associate-/r/ [=>]69.2 | \[ 9 \cdot \frac{y}{\color{blue}{\frac{c}{x} \cdot z}}
\] |
Final simplification83.6%
| Alternative 1 | |
|---|---|
| Accuracy | 64.4% |
| Cost | 2148 |
| Alternative 2 | |
|---|---|
| Accuracy | 56.3% |
| Cost | 1900 |
| Alternative 3 | |
|---|---|
| Accuracy | 67.5% |
| Cost | 1625 |
| Alternative 4 | |
|---|---|
| Accuracy | 67.5% |
| Cost | 1625 |
| Alternative 5 | |
|---|---|
| Accuracy | 44.6% |
| Cost | 1500 |
| Alternative 6 | |
|---|---|
| Accuracy | 44.5% |
| Cost | 1500 |
| Alternative 7 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 1500 |
| Alternative 8 | |
|---|---|
| Accuracy | 43.8% |
| Cost | 1500 |
| Alternative 9 | |
|---|---|
| Accuracy | 64.6% |
| Cost | 1364 |
| Alternative 10 | |
|---|---|
| Accuracy | 45.3% |
| Cost | 977 |
| Alternative 11 | |
|---|---|
| Accuracy | 45.5% |
| Cost | 977 |
| Alternative 12 | |
|---|---|
| Accuracy | 45.5% |
| Cost | 976 |
| Alternative 13 | |
|---|---|
| Accuracy | 45.4% |
| Cost | 713 |
| Alternative 14 | |
|---|---|
| Accuracy | 32.9% |
| Cost | 452 |
| Alternative 15 | |
|---|---|
| Accuracy | 32.8% |
| Cost | 452 |
| Alternative 16 | |
|---|---|
| Accuracy | 32.1% |
| Cost | 320 |
herbie shell --seed 2023135
(FPCore (x y z t a b c)
:name "Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, J"
:precision binary64
:herbie-target
(if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) -1.100156740804105e-171) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 0.0) (/ (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) z) c) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.1708877911747488e-53) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 2.876823679546137e+130) (- (+ (* (* 9.0 (/ y c)) (/ x z)) (/ b (* c z))) (* 4.0 (/ (* a t) c))) (if (< (/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)) 1.3838515042456319e+158) (/ (+ (- (* (* x 9.0) y) (* (* z 4.0) (* t a))) b) (* z c)) (- (+ (* 9.0 (* (/ y (* c z)) x)) (/ b (* c z))) (* 4.0 (/ (* a t) c))))))))
(/ (+ (- (* (* x 9.0) y) (* (* (* z 4.0) t) a)) b) (* z c)))