
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (* (- 1.0 x) (- 1.0 y))))
double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + ((1.0d0 - x) * (1.0d0 - y))
end function
public static double code(double x, double y) {
return x + ((1.0 - x) * (1.0 - y));
}
def code(x, y): return x + ((1.0 - x) * (1.0 - y))
function code(x, y) return Float64(x + Float64(Float64(1.0 - x) * Float64(1.0 - y))) end
function tmp = code(x, y) tmp = x + ((1.0 - x) * (1.0 - y)); end
code[x_, y_] := N[(x + N[(N[(1.0 - x), $MachinePrecision] * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(1 - x\right) \cdot \left(1 - y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma x y (- 1.0 y)))
double code(double x, double y) {
return fma(x, y, (1.0 - y));
}
function code(x, y) return fma(x, y, Float64(1.0 - y)) end
code[x_, y_] := N[(x * y + N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, 1 - y\right)
\end{array}
Initial program 80.2%
sub-neg80.2%
distribute-rgt-in80.2%
*-lft-identity80.2%
associate-+r+91.0%
+-commutative91.0%
sub-neg91.0%
associate-+l+100.0%
neg-mul-1100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
metadata-eval100.0%
associate-*r*100.0%
neg-mul-1100.0%
mul0-lft100.0%
metadata-eval100.0%
sub-neg100.0%
distribute-rgt-in100.0%
*-lft-identity100.0%
associate-+r+100.0%
sub-neg100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -5200000000.0)
(* x y)
(if (<= x -5e-23)
1.0
(if (<= x -2.3e-72)
(- y)
(if (<= x 4.5e-296)
1.0
(if (<= x 2.3e-245) (- y) (if (<= x 280000000.0) 1.0 (* x y))))))))
double code(double x, double y) {
double tmp;
if (x <= -5200000000.0) {
tmp = x * y;
} else if (x <= -5e-23) {
tmp = 1.0;
} else if (x <= -2.3e-72) {
tmp = -y;
} else if (x <= 4.5e-296) {
tmp = 1.0;
} else if (x <= 2.3e-245) {
tmp = -y;
} else if (x <= 280000000.0) {
tmp = 1.0;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-5200000000.0d0)) then
tmp = x * y
else if (x <= (-5d-23)) then
tmp = 1.0d0
else if (x <= (-2.3d-72)) then
tmp = -y
else if (x <= 4.5d-296) then
tmp = 1.0d0
else if (x <= 2.3d-245) then
tmp = -y
else if (x <= 280000000.0d0) then
tmp = 1.0d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5200000000.0) {
tmp = x * y;
} else if (x <= -5e-23) {
tmp = 1.0;
} else if (x <= -2.3e-72) {
tmp = -y;
} else if (x <= 4.5e-296) {
tmp = 1.0;
} else if (x <= 2.3e-245) {
tmp = -y;
} else if (x <= 280000000.0) {
tmp = 1.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5200000000.0: tmp = x * y elif x <= -5e-23: tmp = 1.0 elif x <= -2.3e-72: tmp = -y elif x <= 4.5e-296: tmp = 1.0 elif x <= 2.3e-245: tmp = -y elif x <= 280000000.0: tmp = 1.0 else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -5200000000.0) tmp = Float64(x * y); elseif (x <= -5e-23) tmp = 1.0; elseif (x <= -2.3e-72) tmp = Float64(-y); elseif (x <= 4.5e-296) tmp = 1.0; elseif (x <= 2.3e-245) tmp = Float64(-y); elseif (x <= 280000000.0) tmp = 1.0; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5200000000.0) tmp = x * y; elseif (x <= -5e-23) tmp = 1.0; elseif (x <= -2.3e-72) tmp = -y; elseif (x <= 4.5e-296) tmp = 1.0; elseif (x <= 2.3e-245) tmp = -y; elseif (x <= 280000000.0) tmp = 1.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5200000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, -5e-23], 1.0, If[LessEqual[x, -2.3e-72], (-y), If[LessEqual[x, 4.5e-296], 1.0, If[LessEqual[x, 2.3e-245], (-y), If[LessEqual[x, 280000000.0], 1.0, N[(x * y), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5200000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -5 \cdot 10^{-23}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq -2.3 \cdot 10^{-72}:\\
\;\;\;\;-y\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{-296}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-245}:\\
\;\;\;\;-y\\
\mathbf{elif}\;x \leq 280000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.2e9 or 2.8e8 < x Initial program 58.4%
Taylor expanded in x around inf 58.0%
mul-1-neg58.0%
unsub-neg58.0%
sub-neg58.0%
associate--r+80.8%
metadata-eval80.8%
neg-sub080.8%
remove-double-neg80.8%
Simplified80.8%
if -5.2e9 < x < -5.0000000000000002e-23 or -2.29999999999999995e-72 < x < 4.5000000000000002e-296 or 2.3000000000000002e-245 < x < 2.8e8Initial program 100.0%
Taylor expanded in y around 0 61.8%
if -5.0000000000000002e-23 < x < -2.29999999999999995e-72 or 4.5000000000000002e-296 < x < 2.3000000000000002e-245Initial program 100.0%
Taylor expanded in y around inf 85.3%
mul-1-neg85.3%
distribute-rgt-neg-in85.3%
sub-neg85.3%
distribute-neg-in85.3%
metadata-eval85.3%
remove-double-neg85.3%
Simplified85.3%
Taylor expanded in x around 0 85.3%
neg-mul-185.3%
Simplified85.3%
Final simplification73.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1800000000.0) (not (<= x 1.05e-15))) (* y (+ x -1.0)) (- 1.0 y)))
double code(double x, double y) {
double tmp;
if ((x <= -1800000000.0) || !(x <= 1.05e-15)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1800000000.0d0)) .or. (.not. (x <= 1.05d-15))) then
tmp = y * (x + (-1.0d0))
else
tmp = 1.0d0 - y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1800000000.0) || !(x <= 1.05e-15)) {
tmp = y * (x + -1.0);
} else {
tmp = 1.0 - y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1800000000.0) or not (x <= 1.05e-15): tmp = y * (x + -1.0) else: tmp = 1.0 - y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1800000000.0) || !(x <= 1.05e-15)) tmp = Float64(y * Float64(x + -1.0)); else tmp = Float64(1.0 - y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1800000000.0) || ~((x <= 1.05e-15))) tmp = y * (x + -1.0); else tmp = 1.0 - y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1800000000.0], N[Not[LessEqual[x, 1.05e-15]], $MachinePrecision]], N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 - y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1800000000 \lor \neg \left(x \leq 1.05 \cdot 10^{-15}\right):\\
\;\;\;\;y \cdot \left(x + -1\right)\\
\mathbf{else}:\\
\;\;\;\;1 - y\\
\end{array}
\end{array}
if x < -1.8e9 or 1.0499999999999999e-15 < x Initial program 58.7%
Taylor expanded in y around inf 81.3%
mul-1-neg81.3%
distribute-rgt-neg-in81.3%
sub-neg81.3%
distribute-neg-in81.3%
metadata-eval81.3%
remove-double-neg81.3%
Simplified81.3%
if -1.8e9 < x < 1.0499999999999999e-15Initial program 100.0%
Taylor expanded in x around 0 99.8%
Final simplification90.9%
(FPCore (x y) :precision binary64 (if (<= x -7400000000.0) (* x y) (if (<= x 14500000.0) (- 1.0 y) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -7400000000.0) {
tmp = x * y;
} else if (x <= 14500000.0) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7400000000.0d0)) then
tmp = x * y
else if (x <= 14500000.0d0) then
tmp = 1.0d0 - y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7400000000.0) {
tmp = x * y;
} else if (x <= 14500000.0) {
tmp = 1.0 - y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7400000000.0: tmp = x * y elif x <= 14500000.0: tmp = 1.0 - y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -7400000000.0) tmp = Float64(x * y); elseif (x <= 14500000.0) tmp = Float64(1.0 - y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7400000000.0) tmp = x * y; elseif (x <= 14500000.0) tmp = 1.0 - y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7400000000.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 14500000.0], N[(1.0 - y), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7400000000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 14500000:\\
\;\;\;\;1 - y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -7.4e9 or 1.45e7 < x Initial program 58.4%
Taylor expanded in x around inf 58.0%
mul-1-neg58.0%
unsub-neg58.0%
sub-neg58.0%
associate--r+80.8%
metadata-eval80.8%
neg-sub080.8%
remove-double-neg80.8%
Simplified80.8%
if -7.4e9 < x < 1.45e7Initial program 100.0%
Taylor expanded in x around 0 99.8%
Final simplification90.7%
(FPCore (x y) :precision binary64 (- (+ 1.0 (* x y)) y))
double code(double x, double y) {
return (1.0 + (x * y)) - y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 + (x * y)) - y
end function
public static double code(double x, double y) {
return (1.0 + (x * y)) - y;
}
def code(x, y): return (1.0 + (x * y)) - y
function code(x, y) return Float64(Float64(1.0 + Float64(x * y)) - y) end
function tmp = code(x, y) tmp = (1.0 + (x * y)) - y; end
code[x_, y_] := N[(N[(1.0 + N[(x * y), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + x \cdot y\right) - y
\end{array}
Initial program 80.2%
Taylor expanded in x around -inf 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (- y) (if (<= y 0.014) 1.0 (- y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 0.014) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.0d0)) then
tmp = -y
else if (y <= 0.014d0) then
tmp = 1.0d0
else
tmp = -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = -y;
} else if (y <= 0.014) {
tmp = 1.0;
} else {
tmp = -y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = -y elif y <= 0.014: tmp = 1.0 else: tmp = -y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(-y); elseif (y <= 0.014) tmp = 1.0; else tmp = Float64(-y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = -y; elseif (y <= 0.014) tmp = 1.0; else tmp = -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], (-y), If[LessEqual[y, 0.014], 1.0, (-y)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 0.014:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-y\\
\end{array}
\end{array}
if y < -1 or 0.0140000000000000003 < y Initial program 99.9%
Taylor expanded in y around inf 99.2%
mul-1-neg99.2%
distribute-rgt-neg-in99.2%
sub-neg99.2%
distribute-neg-in99.2%
metadata-eval99.2%
remove-double-neg99.2%
Simplified99.2%
Taylor expanded in x around 0 48.7%
neg-mul-148.7%
Simplified48.7%
if -1 < y < 0.0140000000000000003Initial program 59.4%
Taylor expanded in y around 0 73.1%
Final simplification60.6%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 80.2%
Taylor expanded in y around 0 37.2%
Final simplification37.2%
(FPCore (x y) :precision binary64 (- (* y x) (- y 1.0)))
double code(double x, double y) {
return (y * x) - (y - 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * x) - (y - 1.0d0)
end function
public static double code(double x, double y) {
return (y * x) - (y - 1.0);
}
def code(x, y): return (y * x) - (y - 1.0)
function code(x, y) return Float64(Float64(y * x) - Float64(y - 1.0)) end
function tmp = code(x, y) tmp = (y * x) - (y - 1.0); end
code[x_, y_] := N[(N[(y * x), $MachinePrecision] - N[(y - 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x - \left(y - 1\right)
\end{array}
herbie shell --seed 2023200
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.Vectors:renderPlotVectors from Chart-1.5.3"
:precision binary64
:herbie-target
(- (* y x) (- y 1.0))
(+ x (* (- 1.0 x) (- 1.0 y))))