
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
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 - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
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 - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
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 - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Initial program 100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (- x y) z)))
(if (<= y -3.2e+44)
(/ y (- y z))
(if (<= y -2.2e-125)
t_0
(if (<= y 1.05e-67)
(/ x (- z y))
(if (<= y 3.4e+51) t_0 (- 1.0 (/ x y))))))))
double code(double x, double y, double z) {
double t_0 = (x - y) / z;
double tmp;
if (y <= -3.2e+44) {
tmp = y / (y - z);
} else if (y <= -2.2e-125) {
tmp = t_0;
} else if (y <= 1.05e-67) {
tmp = x / (z - y);
} else if (y <= 3.4e+51) {
tmp = t_0;
} else {
tmp = 1.0 - (x / y);
}
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 = (x - y) / z
if (y <= (-3.2d+44)) then
tmp = y / (y - z)
else if (y <= (-2.2d-125)) then
tmp = t_0
else if (y <= 1.05d-67) then
tmp = x / (z - y)
else if (y <= 3.4d+51) then
tmp = t_0
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x - y) / z;
double tmp;
if (y <= -3.2e+44) {
tmp = y / (y - z);
} else if (y <= -2.2e-125) {
tmp = t_0;
} else if (y <= 1.05e-67) {
tmp = x / (z - y);
} else if (y <= 3.4e+51) {
tmp = t_0;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): t_0 = (x - y) / z tmp = 0 if y <= -3.2e+44: tmp = y / (y - z) elif y <= -2.2e-125: tmp = t_0 elif y <= 1.05e-67: tmp = x / (z - y) elif y <= 3.4e+51: tmp = t_0 else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) t_0 = Float64(Float64(x - y) / z) tmp = 0.0 if (y <= -3.2e+44) tmp = Float64(y / Float64(y - z)); elseif (y <= -2.2e-125) tmp = t_0; elseif (y <= 1.05e-67) tmp = Float64(x / Float64(z - y)); elseif (y <= 3.4e+51) tmp = t_0; else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x - y) / z; tmp = 0.0; if (y <= -3.2e+44) tmp = y / (y - z); elseif (y <= -2.2e-125) tmp = t_0; elseif (y <= 1.05e-67) tmp = x / (z - y); elseif (y <= 3.4e+51) tmp = t_0; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -3.2e+44], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -2.2e-125], t$95$0, If[LessEqual[y, 1.05e-67], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.4e+51], t$95$0, N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x - y}{z}\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{+44}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;y \leq -2.2 \cdot 10^{-125}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.05 \cdot 10^{-67}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+51}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if y < -3.20000000000000004e44Initial program 100.0%
Taylor expanded in x around 0 88.8%
neg-mul-188.8%
distribute-neg-frac88.8%
Simplified88.8%
frac-2neg88.8%
div-inv88.5%
remove-double-neg88.5%
sub-neg88.5%
distribute-neg-in88.5%
remove-double-neg88.5%
Applied egg-rr88.5%
associate-*r/88.8%
*-rgt-identity88.8%
+-commutative88.8%
unsub-neg88.8%
Simplified88.8%
if -3.20000000000000004e44 < y < -2.19999999999999995e-125 or 1.0500000000000001e-67 < y < 3.39999999999999984e51Initial program 100.0%
Taylor expanded in z around inf 76.2%
if -2.19999999999999995e-125 < y < 1.0500000000000001e-67Initial program 100.0%
Taylor expanded in x around inf 94.1%
if 3.39999999999999984e51 < y Initial program 100.0%
Taylor expanded in z around 0 89.3%
div-sub89.3%
sub-neg89.3%
*-inverses89.3%
metadata-eval89.3%
distribute-lft-in89.3%
metadata-eval89.3%
+-commutative89.3%
mul-1-neg89.3%
unsub-neg89.3%
Simplified89.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.26e+70) (not (<= y 6.5e+46))) (- 1.0 (/ x y)) (/ x (- z y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.26e+70) || !(y <= 6.5e+46)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
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) :: tmp
if ((y <= (-1.26d+70)) .or. (.not. (y <= 6.5d+46))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / (z - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.26e+70) || !(y <= 6.5e+46)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (z - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.26e+70) or not (y <= 6.5e+46): tmp = 1.0 - (x / y) else: tmp = x / (z - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.26e+70) || !(y <= 6.5e+46)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / Float64(z - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.26e+70) || ~((y <= 6.5e+46))) tmp = 1.0 - (x / y); else tmp = x / (z - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.26e+70], N[Not[LessEqual[y, 6.5e+46]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.26 \cdot 10^{+70} \lor \neg \left(y \leq 6.5 \cdot 10^{+46}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z - y}\\
\end{array}
\end{array}
if y < -1.26000000000000001e70 or 6.50000000000000008e46 < y Initial program 100.0%
Taylor expanded in z around 0 88.0%
div-sub88.0%
sub-neg88.0%
*-inverses88.0%
metadata-eval88.0%
distribute-lft-in88.0%
metadata-eval88.0%
+-commutative88.0%
mul-1-neg88.0%
unsub-neg88.0%
Simplified88.0%
if -1.26000000000000001e70 < y < 6.50000000000000008e46Initial program 100.0%
Taylor expanded in x around inf 78.1%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.5e+43) (not (<= y 1.9e-23))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e+43) || !(y <= 1.9e-23)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
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) :: tmp
if ((y <= (-8.5d+43)) .or. (.not. (y <= 1.9d-23))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -8.5e+43) || !(y <= 1.9e-23)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.5e+43) or not (y <= 1.9e-23): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.5e+43) || !(y <= 1.9e-23)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.5e+43) || ~((y <= 1.9e-23))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.5e+43], N[Not[LessEqual[y, 1.9e-23]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+43} \lor \neg \left(y \leq 1.9 \cdot 10^{-23}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
if y < -8.5e43 or 1.90000000000000006e-23 < y Initial program 100.0%
Taylor expanded in z around 0 79.7%
div-sub79.7%
sub-neg79.7%
*-inverses79.7%
metadata-eval79.7%
distribute-lft-in79.7%
metadata-eval79.7%
+-commutative79.7%
mul-1-neg79.7%
unsub-neg79.7%
Simplified79.7%
if -8.5e43 < y < 1.90000000000000006e-23Initial program 100.0%
Taylor expanded in y around 0 72.0%
Final simplification75.5%
(FPCore (x y z) :precision binary64 (if (<= y -4.4e+39) (/ y (- y z)) (if (<= y 7e+46) (/ x (- z y)) (- 1.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+39) {
tmp = y / (y - z);
} else if (y <= 7e+46) {
tmp = x / (z - y);
} else {
tmp = 1.0 - (x / y);
}
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) :: tmp
if (y <= (-4.4d+39)) then
tmp = y / (y - z)
else if (y <= 7d+46) then
tmp = x / (z - y)
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.4e+39) {
tmp = y / (y - z);
} else if (y <= 7e+46) {
tmp = x / (z - y);
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.4e+39: tmp = y / (y - z) elif y <= 7e+46: tmp = x / (z - y) else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.4e+39) tmp = Float64(y / Float64(y - z)); elseif (y <= 7e+46) tmp = Float64(x / Float64(z - y)); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.4e+39) tmp = y / (y - z); elseif (y <= 7e+46) tmp = x / (z - y); else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.4e+39], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7e+46], N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+39}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+46}:\\
\;\;\;\;\frac{x}{z - y}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
if y < -4.4000000000000003e39Initial program 100.0%
Taylor expanded in x around 0 88.0%
neg-mul-188.0%
distribute-neg-frac88.0%
Simplified88.0%
frac-2neg88.0%
div-inv87.8%
remove-double-neg87.8%
sub-neg87.8%
distribute-neg-in87.8%
remove-double-neg87.8%
Applied egg-rr87.8%
associate-*r/88.0%
*-rgt-identity88.0%
+-commutative88.0%
unsub-neg88.0%
Simplified88.0%
if -4.4000000000000003e39 < y < 6.9999999999999997e46Initial program 100.0%
Taylor expanded in x around inf 79.3%
if 6.9999999999999997e46 < y Initial program 100.0%
Taylor expanded in z around 0 86.5%
div-sub86.5%
sub-neg86.5%
*-inverses86.5%
metadata-eval86.5%
distribute-lft-in86.5%
metadata-eval86.5%
+-commutative86.5%
mul-1-neg86.5%
unsub-neg86.5%
Simplified86.5%
(FPCore (x y z) :precision binary64 (if (<= y -1.65e+44) 1.0 (if (<= y 7e+46) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e+44) {
tmp = 1.0;
} else if (y <= 7e+46) {
tmp = x / z;
} else {
tmp = 1.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) :: tmp
if (y <= (-1.65d+44)) then
tmp = 1.0d0
else if (y <= 7d+46) then
tmp = x / z
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.65e+44) {
tmp = 1.0;
} else if (y <= 7e+46) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.65e+44: tmp = 1.0 elif y <= 7e+46: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.65e+44) tmp = 1.0; elseif (y <= 7e+46) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.65e+44) tmp = 1.0; elseif (y <= 7e+46) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.65e+44], 1.0, If[LessEqual[y, 7e+46], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+44}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+46}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.65000000000000007e44 or 6.9999999999999997e46 < y Initial program 100.0%
Taylor expanded in y around inf 77.1%
if -1.65000000000000007e44 < y < 6.9999999999999997e46Initial program 100.0%
Taylor expanded in y around 0 67.3%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in y around inf 35.0%
(FPCore (x y z) :precision binary64 (- (/ x (- z y)) (/ y (- z y))))
double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
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)) - (y / (z - y))
end function
public static double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
def code(x, y, z): return (x / (z - y)) - (y / (z - y))
function code(x, y, z) return Float64(Float64(x / Float64(z - y)) - Float64(y / Float64(z - y))) end
function tmp = code(x, y, z) tmp = (x / (z - y)) - (y / (z - y)); end
code[x_, y_, z_] := N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z - y} - \frac{y}{z - y}
\end{array}
herbie shell --seed 2024108
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
:alt
(- (/ x (- z y)) (/ y (- z y)))
(/ (- x y) (- z y)))