| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
\[\left(\left(z - x\right) \cdot \frac{z + x}{y} - 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 (* (- (* (- z x) (/ (+ z x) y)) 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 (((z - x) * ((z + x) / y)) - 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 = (((z - x) * ((z + x) / y)) - 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 (((z - x) * ((z + x) / y)) - y) * -0.5;
}
def code(x, y, z): return (((x * x) + (y * y)) - (z * z)) / (y * 2.0)
def code(x, y, z): return (((z - x) * ((z + x) / y)) - 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(z - x) * Float64(Float64(z + x) / y)) - 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 = (((z - x) * ((z + x) / y)) - 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[(z - x), $MachinePrecision] * N[(N[(z + x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] * -0.5), $MachinePrecision]
\frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\left(\left(z - x\right) \cdot \frac{z + x}{y} - y\right) \cdot -0.5
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 69.0% |
|---|---|
| Target | 99.9% |
| Herbie | 99.9% |
Initial program 75.7%
Simplified99.9%
[Start]75.7% | \[ \frac{\left(x \cdot x + y \cdot y\right) - z \cdot z}{y \cdot 2}
\] |
|---|---|
sub-neg [=>]75.7% | \[ \frac{\color{blue}{\left(x \cdot x + y \cdot y\right) + \left(-z \cdot z\right)}}{y \cdot 2}
\] |
+-commutative [=>]75.7% | \[ \frac{\color{blue}{\left(-z \cdot z\right) + \left(x \cdot x + y \cdot y\right)}}{y \cdot 2}
\] |
neg-sub0 [=>]75.7% | \[ \frac{\color{blue}{\left(0 - z \cdot z\right)} + \left(x \cdot x + y \cdot y\right)}{y \cdot 2}
\] |
associate-+l- [=>]75.7% | \[ \frac{\color{blue}{0 - \left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2}
\] |
sub0-neg [=>]75.7% | \[ \frac{\color{blue}{-\left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2}
\] |
neg-mul-1 [=>]75.7% | \[ \frac{\color{blue}{-1 \cdot \left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right)}}{y \cdot 2}
\] |
*-commutative [=>]75.7% | \[ \frac{\color{blue}{\left(z \cdot z - \left(x \cdot x + y \cdot y\right)\right) \cdot -1}}{y \cdot 2}
\] |
times-frac [=>]75.8% | \[ \color{blue}{\frac{z \cdot z - \left(x \cdot x + y \cdot y\right)}{y} \cdot \frac{-1}{2}}
\] |
associate--r+ [=>]75.8% | \[ \frac{\color{blue}{\left(z \cdot z - x \cdot x\right) - y \cdot y}}{y} \cdot \frac{-1}{2}
\] |
div-sub [=>]75.8% | \[ \color{blue}{\left(\frac{z \cdot z - x \cdot x}{y} - \frac{y \cdot y}{y}\right)} \cdot \frac{-1}{2}
\] |
difference-of-squares [=>]78.6% | \[ \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 [<=]78.6% | \[ \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-*l/ [<=]80.1% | \[ \left(\color{blue}{\frac{x + z}{y} \cdot \left(z - x\right)} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2}
\] |
*-commutative [=>]80.1% | \[ \left(\color{blue}{\left(z - x\right) \cdot \frac{x + z}{y}} - \frac{y \cdot y}{y}\right) \cdot \frac{-1}{2}
\] |
associate-/l* [=>]99.9% | \[ \left(\left(z - x\right) \cdot \frac{x + z}{y} - \color{blue}{\frac{y}{\frac{y}{y}}}\right) \cdot \frac{-1}{2}
\] |
*-inverses [=>]99.9% | \[ \left(\left(z - x\right) \cdot \frac{x + z}{y} - \frac{y}{\color{blue}{1}}\right) \cdot \frac{-1}{2}
\] |
/-rgt-identity [=>]99.9% | \[ \left(\left(z - x\right) \cdot \frac{x + z}{y} - \color{blue}{y}\right) \cdot \frac{-1}{2}
\] |
metadata-eval [=>]99.9% | \[ \left(\left(z - x\right) \cdot \frac{x + z}{y} - y\right) \cdot \color{blue}{-0.5}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 832 |
| Alternative 2 | |
|---|---|
| Accuracy | 52.8% |
| Cost | 1228 |
| Alternative 3 | |
|---|---|
| Accuracy | 88.3% |
| Cost | 964 |
| Alternative 4 | |
|---|---|
| Accuracy | 88.3% |
| Cost | 964 |
| Alternative 5 | |
|---|---|
| Accuracy | 85.5% |
| Cost | 900 |
| Alternative 6 | |
|---|---|
| Accuracy | 80.2% |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Accuracy | 53.5% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 34.5% |
| Cost | 192 |
herbie shell --seed 2023263
(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)))