
(FPCore (x y z t) :precision binary64 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
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
public static double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t): return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t) return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t))) end
function tmp = code(x, y, z, t) tmp = ((x * x) / (y * y)) + ((z * z) / (t * t)); 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]
\begin{array}{l}
\\
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ (/ (* x x) (* y y)) (/ (* z z) (* t t))))
double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
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
public static double code(double x, double y, double z, double t) {
return ((x * x) / (y * y)) + ((z * z) / (t * t));
}
def code(x, y, z, t): return ((x * x) / (y * y)) + ((z * z) / (t * t))
function code(x, y, z, t) return Float64(Float64(Float64(x * x) / Float64(y * y)) + Float64(Float64(z * z) / Float64(t * t))) end
function tmp = code(x, y, z, t) tmp = ((x * x) / (y * y)) + ((z * z) / (t * t)); 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]
\begin{array}{l}
\\
\frac{x \cdot x}{y \cdot y} + \frac{z \cdot z}{t \cdot t}
\end{array}
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (/ x y)) (* (/ z t) (/ z t))))
double code(double x, double y, double z, double t) {
return ((x / y) * (x / y)) + ((z / t) * (z / t));
}
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) * (x / y)) + ((z / t) * (z / t))
end function
public static double code(double x, double y, double z, double t) {
return ((x / y) * (x / y)) + ((z / t) * (z / t));
}
def code(x, y, z, t): return ((x / y) * (x / y)) + ((z / t) * (z / t))
function code(x, y, z, t) return Float64(Float64(Float64(x / y) * Float64(x / y)) + Float64(Float64(z / t) * Float64(z / t))) end
function tmp = code(x, y, z, t) tmp = ((x / y) * (x / y)) + ((z / t) * (z / t)); end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + N[(N[(z / t), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} \cdot \frac{x}{y} + \frac{z}{t} \cdot \frac{z}{t}
\end{array}
Initial program 65.0%
times-frac82.4%
Simplified82.4%
frac-times99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x y z t) :precision binary64 (if (<= z 6.4e+192) (/ x (* y (/ y x))) (* t (* x (/ 1.0 (/ (* t (* y y)) x))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 6.4e+192) {
tmp = x / (y * (y / x));
} else {
tmp = t * (x * (1.0 / ((t * (y * y)) / 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
real(8) :: tmp
if (z <= 6.4d+192) then
tmp = x / (y * (y / x))
else
tmp = t * (x * (1.0d0 / ((t * (y * y)) / x)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 6.4e+192) {
tmp = x / (y * (y / x));
} else {
tmp = t * (x * (1.0 / ((t * (y * y)) / x)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 6.4e+192: tmp = x / (y * (y / x)) else: tmp = t * (x * (1.0 / ((t * (y * y)) / x))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 6.4e+192) tmp = Float64(x / Float64(y * Float64(y / x))); else tmp = Float64(t * Float64(x * Float64(1.0 / Float64(Float64(t * Float64(y * y)) / x)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 6.4e+192) tmp = x / (y * (y / x)); else tmp = t * (x * (1.0 / ((t * (y * y)) / x))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 6.4e+192], N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(x * N[(1.0 / N[(N[(t * N[(y * y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6.4 \cdot 10^{+192}:\\
\;\;\;\;\frac{x}{y \cdot \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(x \cdot \frac{1}{\frac{t \cdot \left(y \cdot y\right)}{x}}\right)\\
\end{array}
\end{array}
if z < 6.40000000000000046e192Initial program 66.2%
+-commutative66.2%
times-frac82.6%
fma-def82.6%
associate-*l/88.6%
*-commutative88.6%
Simplified88.6%
fma-udef88.6%
frac-times70.9%
associate-/r*79.3%
associate-*r/73.7%
associate-/l*79.3%
frac-add46.6%
fma-def46.6%
associate-*r/50.4%
associate-/l*51.7%
associate-/l*57.3%
Applied egg-rr57.3%
associate-*r/53.5%
associate-/l*49.3%
associate-*r/53.5%
*-commutative53.5%
associate-/l*47.9%
associate-*r/53.5%
Simplified53.5%
Taylor expanded in z around 0 58.4%
*-commutative58.4%
Simplified58.4%
associate-*r/54.5%
Applied egg-rr54.5%
*-commutative54.5%
times-frac56.8%
associate-/l*65.1%
div-inv65.1%
clear-num65.1%
*-inverses65.1%
Applied egg-rr65.1%
if 6.40000000000000046e192 < z Initial program 51.0%
+-commutative51.0%
times-frac79.7%
fma-def79.7%
associate-*l/99.7%
*-commutative99.7%
Simplified99.7%
fma-udef99.7%
frac-times71.0%
associate-/r*71.6%
associate-*r/51.6%
associate-/l*71.6%
frac-add26.0%
fma-def26.0%
associate-*r/26.0%
associate-/l*41.0%
associate-/l*46.0%
Applied egg-rr46.0%
associate-*r/46.0%
associate-/l*31.0%
associate-*r/46.0%
*-commutative46.0%
associate-/l*41.0%
associate-*r/46.0%
Simplified46.0%
Taylor expanded in z around 0 26.5%
*-commutative26.5%
Simplified26.5%
div-inv26.5%
*-commutative26.5%
associate-*l*41.5%
associate-*r/41.4%
associate-*r/51.2%
Applied egg-rr51.2%
Final simplification64.0%
(FPCore (x y z t) :precision binary64 (if (<= t 1e-9) (* (/ x (* y t)) (/ t (/ y x))) (/ x (* y (/ y x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1e-9) {
tmp = (x / (y * t)) * (t / (y / x));
} else {
tmp = x / (y * (y / 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
real(8) :: tmp
if (t <= 1d-9) then
tmp = (x / (y * t)) * (t / (y / x))
else
tmp = x / (y * (y / x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1e-9) {
tmp = (x / (y * t)) * (t / (y / x));
} else {
tmp = x / (y * (y / x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 1e-9: tmp = (x / (y * t)) * (t / (y / x)) else: tmp = x / (y * (y / x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 1e-9) tmp = Float64(Float64(x / Float64(y * t)) * Float64(t / Float64(y / x))); else tmp = Float64(x / Float64(y * Float64(y / x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 1e-9) tmp = (x / (y * t)) * (t / (y / x)); else tmp = x / (y * (y / x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 1e-9], N[(N[(x / N[(y * t), $MachinePrecision]), $MachinePrecision] * N[(t / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 10^{-9}:\\
\;\;\;\;\frac{x}{y \cdot t} \cdot \frac{t}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot \frac{y}{x}}\\
\end{array}
\end{array}
if t < 1.00000000000000006e-9Initial program 65.7%
+-commutative65.7%
times-frac82.6%
fma-def82.6%
associate-*l/90.6%
*-commutative90.6%
Simplified90.6%
fma-udef90.6%
frac-times72.1%
associate-/r*80.9%
associate-*r/73.5%
associate-/l*80.9%
frac-add48.0%
fma-def48.0%
associate-*r/52.3%
associate-/l*55.5%
associate-/l*61.3%
Applied egg-rr61.3%
associate-*r/57.0%
associate-/l*51.2%
associate-*r/57.0%
*-commutative57.0%
associate-/l*51.2%
associate-*r/57.0%
Simplified57.0%
Taylor expanded in z around 0 55.5%
*-commutative55.5%
Simplified55.5%
associate-*r*55.4%
times-frac60.3%
Applied egg-rr60.3%
if 1.00000000000000006e-9 < t Initial program 63.0%
+-commutative63.0%
times-frac81.7%
fma-def81.7%
associate-*l/86.4%
*-commutative86.4%
Simplified86.4%
fma-udef86.4%
frac-times67.7%
associate-/r*72.4%
associate-*r/67.7%
associate-/l*72.4%
frac-add36.7%
fma-def36.7%
associate-*r/38.2%
associate-/l*38.2%
associate-/l*43.2%
Applied egg-rr43.2%
associate-*r/41.7%
associate-/l*38.8%
associate-*r/41.7%
*-commutative41.7%
associate-/l*36.7%
associate-*r/41.7%
Simplified41.7%
Taylor expanded in z around 0 57.2%
*-commutative57.2%
Simplified57.2%
associate-*r/56.4%
Applied egg-rr56.4%
*-commutative56.4%
times-frac58.2%
associate-/l*68.8%
div-inv68.7%
clear-num68.7%
*-inverses68.7%
Applied egg-rr68.7%
Final simplification62.5%
(FPCore (x y z t) :precision binary64 (* (/ 1.0 y) (* x (/ x y))))
double code(double x, double y, double z, double t) {
return (1.0 / y) * (x * (x / y));
}
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 = (1.0d0 / y) * (x * (x / y))
end function
public static double code(double x, double y, double z, double t) {
return (1.0 / y) * (x * (x / y));
}
def code(x, y, z, t): return (1.0 / y) * (x * (x / y))
function code(x, y, z, t) return Float64(Float64(1.0 / y) * Float64(x * Float64(x / y))) end
function tmp = code(x, y, z, t) tmp = (1.0 / y) * (x * (x / y)); end
code[x_, y_, z_, t_] := N[(N[(1.0 / y), $MachinePrecision] * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{y} \cdot \left(x \cdot \frac{x}{y}\right)
\end{array}
Initial program 65.0%
+-commutative65.0%
times-frac82.4%
fma-def82.4%
associate-*l/89.5%
*-commutative89.5%
Simplified89.5%
fma-udef89.5%
frac-times70.9%
associate-/r*78.7%
associate-*r/72.0%
associate-/l*78.7%
frac-add45.0%
fma-def45.0%
associate-*r/48.5%
associate-/l*50.9%
associate-/l*56.5%
Applied egg-rr56.5%
associate-*r/52.9%
associate-/l*47.9%
associate-*r/52.9%
*-commutative52.9%
associate-/l*47.4%
associate-*r/52.9%
Simplified52.9%
Taylor expanded in z around 0 55.9%
*-commutative55.9%
Simplified55.9%
*-commutative55.9%
associate-*r*55.9%
times-frac57.1%
un-div-inv57.1%
clear-num57.1%
Applied egg-rr57.1%
Taylor expanded in t around 0 57.5%
Final simplification57.5%
(FPCore (x y z t) :precision binary64 (/ x (* y (/ y x))))
double code(double x, double y, double z, double t) {
return x / (y * (y / x));
}
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))
end function
public static double code(double x, double y, double z, double t) {
return x / (y * (y / x));
}
def code(x, y, z, t): return x / (y * (y / x))
function code(x, y, z, t) return Float64(x / Float64(y * Float64(y / x))) end
function tmp = code(x, y, z, t) tmp = x / (y * (y / x)); end
code[x_, y_, z_, t_] := N[(x / N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y \cdot \frac{y}{x}}
\end{array}
Initial program 65.0%
+-commutative65.0%
times-frac82.4%
fma-def82.4%
associate-*l/89.5%
*-commutative89.5%
Simplified89.5%
fma-udef89.5%
frac-times70.9%
associate-/r*78.7%
associate-*r/72.0%
associate-/l*78.7%
frac-add45.0%
fma-def45.0%
associate-*r/48.5%
associate-/l*50.9%
associate-/l*56.5%
Applied egg-rr56.5%
associate-*r/52.9%
associate-/l*47.9%
associate-*r/52.9%
*-commutative52.9%
associate-/l*47.4%
associate-*r/52.9%
Simplified52.9%
Taylor expanded in z around 0 55.9%
*-commutative55.9%
Simplified55.9%
associate-*r/52.3%
Applied egg-rr52.3%
*-commutative52.3%
times-frac55.6%
associate-/l*62.2%
div-inv62.1%
clear-num62.2%
*-inverses62.2%
Applied egg-rr62.2%
Final simplification62.2%
(FPCore (x y z t) :precision binary64 (+ (pow (/ x y) 2.0) (pow (/ z t) 2.0)))
double code(double x, double y, double z, double t) {
return pow((x / y), 2.0) + pow((z / t), 2.0);
}
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) ** 2.0d0) + ((z / t) ** 2.0d0)
end function
public static double code(double x, double y, double z, double t) {
return Math.pow((x / y), 2.0) + Math.pow((z / t), 2.0);
}
def code(x, y, z, t): return math.pow((x / y), 2.0) + math.pow((z / t), 2.0)
function code(x, y, z, t) return Float64((Float64(x / y) ^ 2.0) + (Float64(z / t) ^ 2.0)) end
function tmp = code(x, y, z, t) tmp = ((x / y) ^ 2.0) + ((z / t) ^ 2.0); end
code[x_, y_, z_, t_] := N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(z / t), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{x}{y}\right)}^{2} + {\left(\frac{z}{t}\right)}^{2}
\end{array}
herbie shell --seed 2023293
(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))))