| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
\[\left(\frac{x + z}{\frac{y}{z - x}} - y\right) \cdot -0.5
\]

(FPCore (x y z) :precision binary64 (/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))
(FPCore (x y z) :precision binary64 (* (- (/ (+ x z) (/ y (- z x))) y) -0.5))
double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
double code(double x, double y, double z) {
return (((x + z) / (y / (z - x))) - y) * -0.5;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x * x) + (y * y)) - (z * z)) / (y * 2.0d0)
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (((x + z) / (y / (z - x))) - y) * (-0.5d0)
end function
public static double code(double x, double y, double z) {
return (((x * x) + (y * y)) - (z * z)) / (y * 2.0);
}
public static double code(double x, double y, double z) {
return (((x + z) / (y / (z - x))) - y) * -0.5;
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
def code(x, y, z): return (((x + z) / (y / (z - x))) - y) * -0.5
function code(x, y, z) return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) - Float64(z * z)) / Float64(y * 2.0)) end
function code(x, y, z) return Float64(Float64(Float64(Float64(x + z) / Float64(y / Float64(z - x))) - y) * -0.5) end
function tmp = code(x, y, z) tmp = (((x * x) + (y * y)) - (z * z)) / (y * 2.0); end
function tmp = code(x, y, z) tmp = (((x + z) / (y / (z - x))) - y) * -0.5; end
code[x_, y_, z_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] - N[(z * z), $MachinePrecision]), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := N[(N[(N[(N[(x + z), $MachinePrecision] / N[(y / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] * -0.5), $MachinePrecision]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\left(\frac{x + z}{\frac{y}{z - x}} - y\right) \cdot -0.5
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 69.4% |
|---|---|
| Target | 99.9% |
| Herbie | 99.9% |
Initial program 64.4%
Simplified99.9%
[Start]64.4% | \[ \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\] |
|---|---|
sub-neg [=>]64.4% | \[ \frac{\color{blue}{\left(x \cdot x + y \cdot y\right) + \left(-z \cdot z\right)}}{y \cdot 2}
\] |
+-commutative [=>]64.4% | \[ \frac{\color{blue}{\left(-z \cdot z\right) + \left(x \cdot x + y \cdot y\right)}}{y \cdot 2}
\] |
neg-sub0 [=>]64.4% | \[ \frac{\color{blue}{\left(0 - z \cdot z\right)} + \left(x \cdot x + y \cdot y\right)}{y \cdot 2}
\] |
associate-+l- [=>]64.4% | \[ \frac{\color{blue}{0 - \left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2}
\] |
sub0-neg [=>]64.4% | \[ \frac{\color{blue}{-\left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2}
\] |
neg-mul-1 [=>]64.4% | \[ \frac{\color{blue}{-1 \cdot \left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2}
\] |
*-commutative [=>]64.4% | \[ \frac{\color{blue}{\left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right) \cdot -1}}{y \cdot 2}
\] |
times-frac [=>]64.4% | \[ \color{blue}{\frac{z \cdot z - \left(x \cdot x + y \cdot y\right)}{y} \cdot \frac{-1}{2}}
\] |
associate--r+ [=>]64.4% | \[ \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2}
\] |
div-sub [=>]64.4% | \[ \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2}
\] |
difference-of-squares [=>]71.5% | \[ \left(\frac{\color{blue}{\left(z + x\right) \cdot \left(z - x\right)}}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2}
\] |
+-commutative [<=]71.5% | \[ \left(\frac{\color{blue}{\left(x + z\right)} \cdot \left(z - x\right)}{y} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2}
\] |
associate-*r/ [<=]74.0% | \[ \left(\color{blue}{\left(x + z\right) \cdot \frac{z - x}{y}} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2}
\] |
associate-/l* [=>]99.9% | \[ \left(\left(x + z\right) \cdot \frac{z - x}{y} - \color{blue}{\frac{y}{\frac{y}{y}}}\right) \cdot \frac{-1}{2}
\] |
*-inverses [=>]99.9% | \[ \left(\left(x + z\right) \cdot \frac{z - x}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2}
\] |
/-rgt-identity [=>]99.9% | \[ \left(\left(x + z\right) \cdot \frac{z - x}{y} - \color{blue}{y}\right) \cdot \frac{-1}{2}
\] |
metadata-eval [=>]99.9% | \[ \left(\left(x + z\right) \cdot \frac{z - x}{y} - y\right) \cdot \color{blue}{-0.5}
\] |
Applied egg-rr99.9%
[Start]99.9% | \[ \left(\left(x + z\right) \cdot \frac{z - x}{y} - y\right) \cdot -0.5
\] |
|---|---|
clear-num [=>]99.9% | \[ \left(\left(x + z\right) \cdot \color{blue}{\frac{1}{\frac{y}{z - x}}} - y\right) \cdot -0.5
\] |
un-div-inv [=>]99.9% | \[ \left(\color{blue}{\frac{x + z}{\frac{y}{z - x}}} - y\right) \cdot -0.5
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Accuracy | 49.1% |
| Cost | 1373 |
| Alternative 3 | |
|---|---|
| Accuracy | 52.4% |
| Cost | 1228 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.3% |
| Cost | 968 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.3% |
| Cost | 968 |
| Alternative 6 | |
|---|---|
| Accuracy | 87.1% |
| Cost | 964 |
| Alternative 7 | |
|---|---|
| Accuracy | 88.7% |
| Cost | 964 |
| Alternative 8 | |
|---|---|
| Accuracy | 85.7% |
| Cost | 900 |
| Alternative 9 | |
|---|---|
| Accuracy | 78.3% |
| Cost | 841 |
| Alternative 10 | |
|---|---|
| Accuracy | 78.4% |
| Cost | 841 |
| Alternative 11 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
| Alternative 12 | |
|---|---|
| Accuracy | 52.7% |
| Cost | 713 |
| Alternative 13 | |
|---|---|
| Accuracy | 34.4% |
| Cost | 192 |
herbie shell --seed 2023171
(FPCore (x y z)
:name "Diagrams.TwoD.Apollonian:initialConfig from diagrams-contrib-1.3.0.5, A"
:precision binary64
:herbie-target
(- (* y 0.5) (* (* (/ 0.5 y) (+ z x)) (- z x)))
(/ (- (+ (* x x) (* y y)) (* z z)) (* y 2.0)))