
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (+ x (* y (- z x))) z))
double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + (y * (z - x))) / z
end function
public static double code(double x, double y, double z) {
return (x + (y * (z - x))) / z;
}
def code(x, y, z): return (x + (y * (z - x))) / z
function code(x, y, z) return Float64(Float64(x + Float64(y * Float64(z - x))) / z) end
function tmp = code(x, y, z) tmp = (x + (y * (z - x))) / z; end
code[x_, y_, z_] := N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y \cdot \left(z - x\right)}{z}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (/ (- z x) z))))
(if (<= y -1.25e+19)
t_0
(if (<= y 60000000.0) (/ (+ x (* y (- z x))) z) t_0))))
double code(double x, double y, double z) {
double t_0 = y * ((z - x) / z);
double tmp;
if (y <= -1.25e+19) {
tmp = t_0;
} else if (y <= 60000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * ((z - x) / z)
if (y <= (-1.25d+19)) then
tmp = t_0
else if (y <= 60000000.0d0) then
tmp = (x + (y * (z - x))) / z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * ((z - x) / z);
double tmp;
if (y <= -1.25e+19) {
tmp = t_0;
} else if (y <= 60000000.0) {
tmp = (x + (y * (z - x))) / z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * ((z - x) / z) tmp = 0 if y <= -1.25e+19: tmp = t_0 elif y <= 60000000.0: tmp = (x + (y * (z - x))) / z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(Float64(z - x) / z)) tmp = 0.0 if (y <= -1.25e+19) tmp = t_0; elseif (y <= 60000000.0) tmp = Float64(Float64(x + Float64(y * Float64(z - x))) / z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * ((z - x) / z); tmp = 0.0; if (y <= -1.25e+19) tmp = t_0; elseif (y <= 60000000.0) tmp = (x + (y * (z - x))) / z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.25e+19], t$95$0, If[LessEqual[y, 60000000.0], N[(N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \frac{z - x}{z}\\
\mathbf{if}\;y \leq -1.25 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 60000000:\\
\;\;\;\;\frac{x + y \cdot \left(z - x\right)}{z}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.25e19 or 6e7 < y Initial program 71.3%
Taylor expanded in x around 0
Applied rewrites9.6%
Taylor expanded in x around 0
Applied rewrites9.6%
Taylor expanded in x around inf
Applied rewrites99.9%
if -1.25e19 < y < 6e7Initial program 99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (- z x)))) (if (<= z -1.15e-298) (* y t_0) (+ x t_0))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (z <= -1.15e-298) {
tmp = y * t_0;
} else {
tmp = x + t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * (z - x)
if (z <= (-1.15d-298)) then
tmp = y * t_0
else
tmp = x + t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (z <= -1.15e-298) {
tmp = y * t_0;
} else {
tmp = x + t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if z <= -1.15e-298: tmp = y * t_0 else: tmp = x + t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (z <= -1.15e-298) tmp = Float64(y * t_0); else tmp = Float64(x + t_0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (z <= -1.15e-298) tmp = y * t_0; else tmp = x + t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.15e-298], N[(y * t$95$0), $MachinePrecision], N[(x + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;z \leq -1.15 \cdot 10^{-298}:\\
\;\;\;\;y \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;x + t\_0\\
\end{array}
\end{array}
if z < -1.15e-298Initial program 88.3%
Taylor expanded in x around 0
Applied rewrites1.0%
Taylor expanded in x around 0
Applied rewrites2.0%
Taylor expanded in x around inf
Applied rewrites6.8%
if -1.15e-298 < z Initial program 89.0%
Taylor expanded in x around 0
Applied rewrites10.6%
(FPCore (x y z) :precision binary64 (* y (/ (- z x) z)))
double code(double x, double y, double z) {
return y * ((z - x) / z);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * ((z - x) / z)
end function
public static double code(double x, double y, double z) {
return y * ((z - x) / z);
}
def code(x, y, z): return y * ((z - x) / z)
function code(x, y, z) return Float64(y * Float64(Float64(z - x) / z)) end
function tmp = code(x, y, z) tmp = y * ((z - x) / z); end
code[x_, y_, z_] := N[(y * N[(N[(z - x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \frac{z - x}{z}
\end{array}
Initial program 88.7%
Taylor expanded in x around 0
Applied rewrites5.8%
Taylor expanded in x around 0
Applied rewrites6.0%
Taylor expanded in x around inf
Applied rewrites64.0%
(FPCore (x y z) :precision binary64 (* y (- z x)))
double code(double x, double y, double z) {
return y * (z - x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * (z - x)
end function
public static double code(double x, double y, double z) {
return y * (z - x);
}
def code(x, y, z): return y * (z - x)
function code(x, y, z) return Float64(y * Float64(z - x)) end
function tmp = code(x, y, z) tmp = y * (z - x); end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(z - x\right)
\end{array}
Initial program 88.7%
Taylor expanded in x around 0
Applied rewrites5.8%
Taylor expanded in x around 0
Applied rewrites6.0%
(FPCore (x y z) :precision binary64 (- z x))
double code(double x, double y, double z) {
return z - x;
}
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
end function
public static double code(double x, double y, double z) {
return z - x;
}
def code(x, y, z): return z - x
function code(x, y, z) return Float64(z - x) end
function tmp = code(x, y, z) tmp = z - x; end
code[x_, y_, z_] := N[(z - x), $MachinePrecision]
\begin{array}{l}
\\
z - x
\end{array}
Initial program 88.7%
Taylor expanded in x around 0
Applied rewrites5.8%
Taylor expanded in x around 0
Applied rewrites3.1%
(FPCore (x y z) :precision binary64 (- (+ y (/ x z)) (/ y (/ z x))))
double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y + (x / z)) - (y / (z / x))
end function
public static double code(double x, double y, double z) {
return (y + (x / z)) - (y / (z / x));
}
def code(x, y, z): return (y + (x / z)) - (y / (z / x))
function code(x, y, z) return Float64(Float64(y + Float64(x / z)) - Float64(y / Float64(z / x))) end
function tmp = code(x, y, z) tmp = (y + (x / z)) - (y / (z / x)); end
code[x_, y_, z_] := N[(N[(y + N[(x / z), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + \frac{x}{z}\right) - \frac{y}{\frac{z}{x}}
\end{array}
herbie shell --seed 2024321
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:rasterificRadialGradient from diagrams-rasterific-1.3.1.3"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (- (+ y (/ x z)) (/ y (/ z x))))
(/ (+ x (* y (- z x))) z))