
(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) (/ t z))))
double code(double x, double y, double z, double t) {
return ((x / y) * (x / y)) + ((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 / y) * (x / y)) + ((z / t) / (t / z))
end function
public static double code(double x, double y, double z, double t) {
return ((x / y) * (x / y)) + ((z / t) / (t / z));
}
def code(x, y, z, t): return ((x / y) * (x / y)) + ((z / t) / (t / z))
function code(x, y, z, t) return Float64(Float64(Float64(x / y) * Float64(x / y)) + Float64(Float64(z / t) / Float64(t / z))) end
function tmp = code(x, y, z, t) tmp = ((x / y) * (x / y)) + ((z / t) / (t / z)); end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision] + N[(N[(z / t), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} \cdot \frac{x}{y} + \frac{\frac{z}{t}}{\frac{t}{z}}
\end{array}
Initial program 74.1%
times-frac86.5%
times-frac99.7%
Simplified99.7%
clear-num99.7%
div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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 74.1%
times-frac86.5%
times-frac99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y z t) :precision binary64 (if (<= z -6.5e+200) (* (/ (* x x) y) (/ t (* y t))) (* (/ x y) (/ x y))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6.5e+200) {
tmp = ((x * x) / y) * (t / (y * t));
} else {
tmp = (x / y) * (x / y);
}
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.5d+200)) then
tmp = ((x * x) / y) * (t / (y * t))
else
tmp = (x / y) * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6.5e+200) {
tmp = ((x * x) / y) * (t / (y * t));
} else {
tmp = (x / y) * (x / y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -6.5e+200: tmp = ((x * x) / y) * (t / (y * t)) else: tmp = (x / y) * (x / y) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -6.5e+200) tmp = Float64(Float64(Float64(x * x) / y) * Float64(t / Float64(y * t))); else tmp = Float64(Float64(x / y) * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -6.5e+200) tmp = ((x * x) / y) * (t / (y * t)); else tmp = (x / y) * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -6.5e+200], N[(N[(N[(x * x), $MachinePrecision] / y), $MachinePrecision] * N[(t / N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{+200}:\\
\;\;\;\;\frac{x \cdot x}{y} \cdot \frac{t}{y \cdot t}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -6.49999999999999963e200Initial program 70.0%
associate-*r/77.6%
fma-def77.6%
associate-/l*85.5%
associate-*r/92.9%
Simplified92.9%
fma-udef92.9%
associate-*r/85.5%
associate-/l*77.6%
frac-times96.5%
associate-*r/88.8%
associate-*l/85.3%
frac-add58.0%
Applied egg-rr58.0%
fma-def58.0%
associate-*l*66.2%
associate-*r*66.2%
associate-*l*73.9%
Simplified73.9%
Taylor expanded in x around inf 40.0%
unpow240.0%
Simplified40.0%
*-commutative40.0%
times-frac40.1%
*-commutative40.1%
Applied egg-rr40.1%
if -6.49999999999999963e200 < z Initial program 74.5%
associate-*r/78.4%
fma-def78.4%
associate-/l*83.7%
associate-*r/87.0%
Simplified87.0%
fma-udef87.0%
associate-*r/83.7%
associate-/l*78.4%
frac-times89.4%
associate-*r/85.5%
associate-*l/84.8%
frac-add56.1%
Applied egg-rr56.1%
fma-def56.1%
associate-*l*68.3%
associate-*r*68.3%
associate-*l*73.5%
Simplified73.5%
Taylor expanded in x around inf 50.8%
unpow250.8%
Simplified50.8%
Taylor expanded in t around 0 56.1%
unpow256.1%
unpow256.1%
times-frac66.2%
Simplified66.2%
Final simplification63.5%
(FPCore (x y z t) :precision binary64 (if (<= z -3.3e+212) (/ (* t (* x x)) (* y (* y t))) (* (/ x y) (/ x y))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.3e+212) {
tmp = (t * (x * x)) / (y * (y * t));
} else {
tmp = (x / y) * (x / y);
}
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 <= (-3.3d+212)) then
tmp = (t * (x * x)) / (y * (y * t))
else
tmp = (x / y) * (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.3e+212) {
tmp = (t * (x * x)) / (y * (y * t));
} else {
tmp = (x / y) * (x / y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -3.3e+212: tmp = (t * (x * x)) / (y * (y * t)) else: tmp = (x / y) * (x / y) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -3.3e+212) tmp = Float64(Float64(t * Float64(x * x)) / Float64(y * Float64(y * t))); else tmp = Float64(Float64(x / y) * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -3.3e+212) tmp = (t * (x * x)) / (y * (y * t)); else tmp = (x / y) * (x / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.3e+212], N[(N[(t * N[(x * x), $MachinePrecision]), $MachinePrecision] / N[(y * N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{+212}:\\
\;\;\;\;\frac{t \cdot \left(x \cdot x\right)}{y \cdot \left(y \cdot t\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{x}{y}\\
\end{array}
\end{array}
if z < -3.3e212Initial program 70.4%
associate-*r/79.1%
fma-def79.1%
associate-/l*87.8%
associate-*r/96.2%
Simplified96.2%
fma-udef96.2%
associate-*r/87.8%
associate-/l*79.1%
frac-times96.1%
associate-*r/87.4%
associate-*l/83.4%
frac-add56.9%
Applied egg-rr56.9%
fma-def56.9%
associate-*l*66.2%
associate-*r*66.2%
associate-*l*74.9%
Simplified74.9%
Taylor expanded in x around inf 45.0%
unpow245.0%
Simplified45.0%
if -3.3e212 < z Initial program 74.4%
associate-*r/78.2%
fma-def78.2%
associate-/l*83.5%
associate-*r/86.8%
Simplified86.8%
fma-udef86.8%
associate-*r/83.5%
associate-/l*78.2%
frac-times89.5%
associate-*r/85.6%
associate-*l/85.0%
frac-add56.2%
Applied egg-rr56.2%
fma-def56.2%
associate-*l*68.3%
associate-*r*68.3%
associate-*l*73.4%
Simplified73.4%
Taylor expanded in x around inf 50.1%
unpow250.1%
Simplified50.1%
Taylor expanded in t around 0 55.4%
unpow255.4%
unpow255.4%
times-frac65.4%
Simplified65.4%
Final simplification63.5%
(FPCore (x y z t) :precision binary64 (* (/ x y) (/ x y)))
double code(double x, double y, double z, double t) {
return (x / y) * (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 = (x / y) * (x / y)
end function
public static double code(double x, double y, double z, double t) {
return (x / y) * (x / y);
}
def code(x, y, z, t): return (x / y) * (x / y)
function code(x, y, z, t) return Float64(Float64(x / y) * Float64(x / y)) end
function tmp = code(x, y, z, t) tmp = (x / y) * (x / y); end
code[x_, y_, z_, t_] := N[(N[(x / y), $MachinePrecision] * N[(x / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{y} \cdot \frac{x}{y}
\end{array}
Initial program 74.1%
associate-*r/78.3%
fma-def78.3%
associate-/l*83.8%
associate-*r/87.6%
Simplified87.6%
fma-udef87.6%
associate-*r/83.8%
associate-/l*78.3%
frac-times90.1%
associate-*r/85.8%
associate-*l/84.8%
frac-add56.3%
Applied egg-rr56.3%
fma-def56.3%
associate-*l*68.1%
associate-*r*68.1%
associate-*l*73.6%
Simplified73.6%
Taylor expanded in x around inf 49.7%
unpow249.7%
Simplified49.7%
Taylor expanded in t around 0 53.3%
unpow253.3%
unpow253.3%
times-frac61.7%
Simplified61.7%
Final simplification61.7%
(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 2023195
(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))))