| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 960 |
\[\frac{\frac{x}{y}}{\frac{y}{x}} + \frac{\frac{z}{t}}{\frac{t}{z}}
\]

(FPCore (x y z t) :precision binary64 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
(FPCore (x y z t) :precision binary64 (+ (/ (/ x y) (/ y x)) (/ (/ z t) (/ t z))))
double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
double code(double x, double y, double z, double t) {
return ((x / y) / (y / x)) + ((z / t) / (t / z));
}
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 * x) / (y * y)) + ((z * 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
code = ((x / y) / (y / x)) + ((z / t) / (t / z))
end function
public static double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
public static double code(double x, double y, double z, double t) {
return ((x / y) / (y / x)) + ((z / t) / (t / z));
}
def code(x, y, z, t): return ((x * x) / (y * y)) + ((z * z) / (t * t))
def code(x, y, z, t): return ((x / y) / (y / x)) + ((z / t) / (t / z))
function code(x, y, z, t) return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t))) end
function code(x, y, z, t) return Float64(Float64(Float64(x / y) / Float64(y / x)) + Float64(Float64(z / t) / Float64(t / z))) end
function tmp = code(x, y, z, t) tmp = ((x * x) / (y * y)) + ((z * z) / (t * t)); end
function tmp = code(x, y, z, t) tmp = ((x / y) / (y / x)) + ((z / t) / (t / z)); end
code[x_, y_, z_, t_] := N[(N[(N[(x * x), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] / N[(t * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] + N[(N[(z / t), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\frac{\frac{x}{y}}{\frac{y}{x}} + \frac{\frac{z}{t}}{\frac{t}{z}}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 66.8% |
|---|---|
| Target | 99.7% |
| Herbie | 99.8% |
Initial program 67.4%
Simplified99.6%
[Start]67.4% | \[ \frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\] |
|---|---|
times-frac [=>]83.5% | \[ \color{blue}{\frac{x}{y} \cdot \frac{x}{y}} + \frac{z \cdot z}{t \cdot t}
\] |
times-frac [=>]99.6% | \[ \frac{x}{y} \cdot \frac{x}{y} + \color{blue}{\frac{z}{t} \cdot \frac{z}{t}}
\] |
Applied egg-rr99.7%
[Start]99.6% | \[ \frac{x}{y} \cdot \frac{x}{y} + \frac{z}{t} \cdot \frac{z}{t}
\] |
|---|---|
clear-num [=>]99.7% | \[ \frac{x}{y} \cdot \frac{x}{y} + \frac{z}{t} \cdot \color{blue}{\frac{1}{\frac{t}{z}}}
\] |
div-inv [<=]99.7% | \[ \frac{x}{y} \cdot \frac{x}{y} + \color{blue}{\frac{\frac{z}{t}}{\frac{t}{z}}}
\] |
Applied egg-rr99.7%
[Start]99.7% | \[ \frac{x}{y} \cdot \frac{x}{y} + \frac{\frac{z}{t}}{\frac{t}{z}}
\] |
|---|---|
clear-num [=>]99.7% | \[ \frac{x}{y} \cdot \color{blue}{\frac{1}{\frac{y}{x}}} + \frac{\frac{z}{t}}{\frac{t}{z}}
\] |
un-div-inv [=>]99.7% | \[ \color{blue}{\frac{\frac{x}{y}}{\frac{y}{x}}} + \frac{\frac{z}{t}}{\frac{t}{z}}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 960 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 960 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 960 |
| Alternative 4 | |
|---|---|
| Accuracy | 48.7% |
| Cost | 448 |
herbie shell --seed 2023272
(FPCore (x y z t)
:name "Graphics.Rasterific.Svg.PathConverter:arcToSegments from rasterific-svg-0.2.3.1"
:precision binary64
:herbie-target
(+ (pow (/ x y) 2.0) (pow (/ z t) 2.0))
(+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))